Remove Read/Write test in camera_V4L2

Remove related codes since all existing camera devices do not support
V4L2_CAP_READWRITE.

BUG=chromium:708396
TEST=test_that -b ${BOARD} ${IP} camera_V4L2

Change-Id: Ibe80bb1bc7931181c32245d4afbad9f23c813d40
Reviewed-on: https://chromium-review.googlesource.com/475850
Commit-Ready: Heng-ruey Hsu <henryhsu@chromium.org>
Tested-by: Heng-ruey Hsu <henryhsu@chromium.org>
Reviewed-by: Heng-ruey Hsu <henryhsu@chromium.org>
diff --git a/client/site_tests/camera_V4L2/camera_V4L2.py b/client/site_tests/camera_V4L2/camera_V4L2.py
index 841d98b..95dd805 100644
--- a/client/site_tests/camera_V4L2/camera_V4L2.py
+++ b/client/site_tests/camera_V4L2/camera_V4L2.py
@@ -117,9 +117,6 @@
         pattern = r"support streaming i/o interface.>>>"
         self.support_streaming = True if re.search(pattern, stdout) else False
 
-        pattern = r"support streaming read/write interface.>>>"
-        self.support_readwrite = True if re.search(pattern, stdout) else False
-
         # Currently I assume streaming (mmap) is mandatroy.
         if not self.support_streaming:
             raise error.TestFail(device + " does not support streaming!")
@@ -156,11 +153,6 @@
     def run_v4l2_capture_tests(self, device):
         default_options = ["--device=%s" % device]
 
-        # If the device claims to support read/write i/o.
-        if self.support_readwrite:
-            option = default_options + ["--read"]
-            okay, stdout = self.run_v4l2_capture_test(False, option)
-
         # If the device claims to support stream i/o.
         # This could mean either mmap stream i/o or user pointer stream i/o.
         if self.support_streaming:
diff --git a/client/site_tests/camera_V4L2/src/media_v4l2_device.cc b/client/site_tests/camera_V4L2/src/media_v4l2_device.cc
index 8899d6a..82d0fa8 100644
--- a/client/site_tests/camera_V4L2/src/media_v4l2_device.cc
+++ b/client/site_tests/camera_V4L2/src/media_v4l2_device.cc
@@ -65,12 +65,6 @@
   }
 
   switch (io_) {
-    case IO_METHOD_READ:
-      if (!(cap.capabilities & V4L2_CAP_READWRITE)) {
-        printf("<<< Error: %s does not support read i/o.>>>\n", dev_name_);
-        return false;
-      }
-      break;
     case IO_METHOD_MMAP:
     case IO_METHOD_USERPTR:
       if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
@@ -147,8 +141,6 @@
   pixfmt_ = fmt;
 
   switch (io_) {
-    case IO_METHOD_READ:
-      return InitReadIO(fmt.fmt.pix.sizeimage);
     case IO_METHOD_MMAP:
       return InitMmapIO();
     case IO_METHOD_USERPTR:
@@ -159,10 +151,6 @@
 
 bool V4L2Device::UninitDevice() {
   switch (io_) {
-    case IO_METHOD_READ:
-      // Only one buffer for read() i/o.
-      free(v4l2_buffers_[0].start);
-      break;
     case IO_METHOD_MMAP:
       for (uint32_t i = 0; i < num_buffers_; ++i)
         if (-1 == munmap(v4l2_buffers_[i].start, v4l2_buffers_[i].length)) {
@@ -184,9 +172,6 @@
   uint32_t i;
   v4l2_buf_type type;
   switch (io_) {
-    case IO_METHOD_READ:
-      // Nothing to do.
-      break;
     case IO_METHOD_MMAP:
       for (i = 0; i < num_buffers_; ++i) {
         memset(&buf, 0, sizeof(buf));
@@ -230,9 +215,6 @@
 bool V4L2Device::StopCapture() {
   v4l2_buf_type type;
   switch (io_) {
-    case IO_METHOD_READ:
-      // Nothing to do.
-      break;
     case IO_METHOD_MMAP:
     case IO_METHOD_USERPTR:
       type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
@@ -312,21 +294,6 @@
   memset(&buf, 0, sizeof(buf));
   uint32_t i;
   switch (io_) {
-    case IO_METHOD_READ:
-      if (-1 == read(fd_, v4l2_buffers_[0].start, v4l2_buffers_[0].length)) {
-        switch (errno) {
-          case EAGAIN:
-            return 0;
-          case EIO:
-            // Could ignore EIO, see spec.
-            // Fall through.
-          default:
-            printf("<<< Error: read() failed on %s.>>>\n", dev_name_);
-            return -1;
-        }
-      }
-      ProcessImage(v4l2_buffers_[0].start);
-      break;
     case IO_METHOD_MMAP:
       buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
       buf.memory = V4L2_MEMORY_MMAP;
@@ -398,18 +365,6 @@
   return true;
 }
 
-bool V4L2Device::InitReadIO(uint32_t buffer_size) {
-  if (!AllocateBuffer(1))
-    return false;
-  v4l2_buffers_[0].length = buffer_size;
-  v4l2_buffers_[0].start = new uint8_t[buffer_size];
-  if (!v4l2_buffers_[0].start) {
-    printf("<<< Error: Out of memory.>>>\n");
-    return false;
-  }
-  return true;
-}
-
 bool V4L2Device::InitMmapIO() {
   v4l2_requestbuffers req;
   memset(&req, 0, sizeof(req));
@@ -766,8 +721,6 @@
     if (cap->capabilities & V4L2_CAP_AUDIO)
       printf("<<< Info: %s support audio i/o interface.>>>\n", dev_name_);
 
-    if (cap->capabilities & V4L2_CAP_READWRITE)
-      printf("<<< Info: %s support read/write interface.>>>\n", dev_name_);
     if (cap->capabilities & V4L2_CAP_STREAMING)
       printf("<<< Info: %s support streaming i/o interface.>>>\n", dev_name_);
     if (cap->capabilities & V4L2_CAP_TIMEPERFRAME)
diff --git a/client/site_tests/camera_V4L2/src/media_v4l2_device.h b/client/site_tests/camera_V4L2/src/media_v4l2_device.h
index 2300889..2299b2f 100644
--- a/client/site_tests/camera_V4L2/src/media_v4l2_device.h
+++ b/client/site_tests/camera_V4L2/src/media_v4l2_device.h
@@ -20,7 +20,6 @@
 class V4L2Device {
  public:
   enum IOMethod {
-    IO_METHOD_READ,
     IO_METHOD_MMAP,
     IO_METHOD_USERPTR,
   };
@@ -87,7 +86,6 @@
  private:
   int32_t DoIoctl(int32_t request, void* arg);
   int32_t ReadOneFrame();
-  bool InitReadIO(uint32_t buffer_size);
   bool InitMmapIO();
   bool InitUserPtrIO(uint32_t buffer_size);
   bool AllocateBuffer(uint32_t buffer_count);
diff --git a/client/site_tests/camera_V4L2/src/media_v4l2_test.cc b/client/site_tests/camera_V4L2/src/media_v4l2_test.cc
index 87bd87a..f3268d4 100644
--- a/client/site_tests/camera_V4L2/src/media_v4l2_test.cc
+++ b/client/site_tests/camera_V4L2/src/media_v4l2_test.cc
@@ -14,7 +14,6 @@
          "--device=DEVICE_NAME    Video device name [/dev/video]\n"
          "--help                  Print usage\n"
          "--mmap                  Use memory mapped buffers\n"
-         "--read                  Use read() calls\n"
          "--userp                 Use application allocated buffers\n"
          "--buffers=[NUM]         Minimum buffers required\n"
          "--frames=[NUM]          Maximum frame to capture\n"
@@ -32,7 +31,6 @@
         { "device",       required_argument, NULL, 'd' },
         { "help",         no_argument,       NULL, '?' },
         { "mmap",         no_argument,       NULL, 'm' },
-        { "read",         no_argument,       NULL, 'r' },
         { "userp",        no_argument,       NULL, 'u' },
         { "buffers",      required_argument, NULL, 'n' },
         { "frames",       required_argument, NULL, 'f' },
@@ -73,9 +71,6 @@
       case 'm':
         io = V4L2Device::IO_METHOD_MMAP;
         break;
-      case 'r':
-        io = V4L2Device::IO_METHOD_READ;
-        break;
       case 'u':
         io = V4L2Device::IO_METHOD_USERPTR;
         break;
diff --git a/client/site_tests/camera_V4L2/src/media_v4l2_unittest.cc b/client/site_tests/camera_V4L2/src/media_v4l2_unittest.cc
index 59932fb..ceb183e 100644
--- a/client/site_tests/camera_V4L2/src/media_v4l2_unittest.cc
+++ b/client/site_tests/camera_V4L2/src/media_v4l2_unittest.cc
@@ -237,7 +237,6 @@
          "--device=DEVICE_NAME   Video device name [/dev/video]\n"
          "--help                 Print usage\n"
          "--buffer-io=mmap       Use memory mapped buffers\n"
-         "--buffer-io=read       Use read() calls\n"
          "--buffer-io=userp      Use application allocated buffers\n");
 }
 
@@ -272,8 +271,6 @@
         io_name = strdup(optarg);
         if (io_name == "mmap") {
           io = V4L2Device::IO_METHOD_MMAP;
-        } else if (io_name == "read") {
-          io = V4L2Device::IO_METHOD_READ;
         } else if (io_name == "userp") {
           io = V4L2Device::IO_METHOD_USERPTR;
         } else {