[libcamera-devel,08/11] test: v4l2_device: Add a functional capture test

Message ID 20190203110102.5663-9-kieran.bingham@ideasonboard.com
State Superseded
Headers show
Series
  • libcamera: V4L2 Streams
Related show

Commit Message

Kieran Bingham Feb. 3, 2019, 11 a.m. UTC
We now have enough infrastructure to be able to capture frames from a
basic UVC device. Provide a test loop which captures frames, and returns
them back to the kernel.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 test/v4l2_device/capture_frames.cpp | 51 +++++++++++++++++++++++++++++
 test/v4l2_device/meson.build        |  1 +
 2 files changed, 52 insertions(+)
 create mode 100644 test/v4l2_device/capture_frames.cpp

Patch

diff --git a/test/v4l2_device/capture_frames.cpp b/test/v4l2_device/capture_frames.cpp
new file mode 100644
index 000000000000..276be91a9a82
--- /dev/null
+++ b/test/v4l2_device/capture_frames.cpp
@@ -0,0 +1,51 @@ 
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2019, Google Inc.
+ *
+ * libcamera V4L2 API tests
+ */
+
+#include "v4l2_device_test.h"
+
+class CaptureFrames : public V4L2DeviceTest
+{
+protected:
+	int run()
+	{
+		int ret;
+
+		BufferPool *pool = dev_->requestBuffers(8);
+		if (!pool)
+			return TestFail;
+
+		ret = dev_->streamOn();
+		if (ret)
+			return ret;
+
+		/*
+		 * With no dispatcher loop, the internal asynchronous buffer
+		 * retrieval will not operate.
+		 *
+		 * We can manually validate the dequeueBuffer() and
+		 * queueBuffer() calls directly here.
+		 *
+		 * The application should not use these calls directly if it
+		 * makes any calls to:
+		 * 	dispatcher->processEvents();
+		 */
+		for (unsigned int i; i < 30; ++i) {
+			auto buffer = dev_->dequeueBuffer();
+
+			/* Check buffer */
+			if (!buffer)
+				return TestFail;
+
+			if (dev_->queueBuffer(buffer))
+				return TestFail;
+		}
+
+		return dev_->streamOff();
+	}
+};
+
+TEST_REGISTER(CaptureFrames);
diff --git a/test/v4l2_device/meson.build b/test/v4l2_device/meson.build
index cbaa79da9b81..f04c7ded009c 100644
--- a/test/v4l2_device/meson.build
+++ b/test/v4l2_device/meson.build
@@ -4,6 +4,7 @@  v4l2_device_tests = [
   [ 'double_open',        'double_open.cpp' ],
   [ 'request_buffers',    'request_buffers.cpp' ],
   [ 'stream_on_off',      'stream_on_off.cpp' ],
+  [ 'capture_frames',     'capture_frames.cpp' ],
 ]
 
 foreach t : v4l2_device_tests