new file mode 100644
@@ -0,0 +1,69 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2019, Google Inc.
+ *
+ * libcamera V4L2 API tests
+ */
+
+#include <libcamera/buffer.h>
+#include <libcamera/camera_manager.h>
+#include <libcamera/event_dispatcher.h>
+#include <libcamera/timer.h>
+
+#include <iostream>
+
+#include "v4l2_device_test.h"
+
+class CaptureAsync : public V4L2DeviceTest
+{
+public:
+ CaptureAsync()
+ : frames(0){};
+
+ void ReceiveBuffer(Buffer *buffer)
+ {
+ std::cout << "Received a Buffer" << std::endl;
+ frames++;
+ }
+
+protected:
+ int run()
+ {
+ EventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher();
+ Timer timeout;
+ int ret;
+
+ BufferPool *pool = dev_->requestBuffers(8);
+ if (!pool)
+ return TestFail;
+
+ dev_->bufferReady.connect(this, &CaptureAsync::ReceiveBuffer);
+
+ ret = dev_->streamOn();
+ if (ret)
+ return ret;
+
+ timeout.start(5000);
+ while (timeout.isRunning())
+ dispatcher->processEvents();
+
+ if (frames < 1) {
+ std::cout << "Failed to capture any frames within timeout." << std::endl;
+ return TestFail;
+ }
+
+ if (frames < 30) {
+ std::cout << "Failed to capture 30 frames within timeout." << std::endl;
+ return TestFail;
+ }
+
+ std::cout << "Processed " << frames << " frames" << std::endl;
+
+ return dev_->streamOff();
+ }
+
+private:
+ unsigned int frames;
+};
+
+TEST_REGISTER(CaptureAsync);
@@ -5,6 +5,7 @@ v4l2_device_tests = [
[ 'request_buffers', 'request_buffers.cpp' ],
[ 'stream_on_off', 'stream_on_off.cpp' ],
[ 'capture_frames', 'capture_frames.cpp' ],
+ [ 'capture_async', 'capture_async.cpp' ],
]
foreach t : v4l2_device_tests
Utilise the event_dispatcher to create a default event loop, and process asynchronous buffer receive events. If no frames are captured in 5 seconds, the test will fail. It will also fail if less than 30 frames have been captured int the same timeout period. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> --- test/v4l2_device/capture_async.cpp | 69 ++++++++++++++++++++++++++++++ test/v4l2_device/meson.build | 1 + 2 files changed, 70 insertions(+) create mode 100644 test/v4l2_device/capture_async.cpp