[libcamera-devel] [PATCH 4/5] test: camera: Add capture test
Niklas Söderlund
niklas.soderlund at ragnatech.se
Wed Mar 6 03:47:54 CET 2019
Add positive capture test. Correctly configure the camera using the
default format and run a capture session for 100 milliseconds, which is
plenty of time, in tests over 600 requests completed using the vimc
pipeline.
The test passes if at least one requests completes.
Signed-off-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
---
test/camera/capture.cpp | 130 ++++++++++++++++++++++++++++++++++++++++
test/camera/meson.build | 1 +
2 files changed, 131 insertions(+)
create mode 100644 test/camera/capture.cpp
diff --git a/test/camera/capture.cpp b/test/camera/capture.cpp
new file mode 100644
index 0000000000000000..133b38318e471f3f
--- /dev/null
+++ b/test/camera/capture.cpp
@@ -0,0 +1,130 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2019, Google Inc.
+ *
+ * libcamera Camera API tests
+ */
+
+#include <iostream>
+
+#include "camera_test.h"
+
+using namespace std;
+
+namespace {
+
+class Capture : public CameraTest
+{
+protected:
+ unsigned int count_buffers_;
+ unsigned int count_requests_;
+
+ void bufferComplete(Request *request, Buffer *buffer)
+ {
+ count_buffers_++;
+ }
+
+ void requestComplete(Request *request, const std::map<Stream *, Buffer *> &buffers)
+ {
+ if (request->status() == Request::RequestCancelled)
+ return;
+
+ count_requests_++;
+
+ /* Reuse the buffers for a new request. */
+ request = camera_->createRequest();
+ request->setBuffers(buffers);
+ camera_->queueRequest(request);
+ }
+
+ int run()
+ {
+ if (camera_->acquire()) {
+ cout << "Acquiring the camera failed" << endl;
+ return TestFail;
+ }
+
+ Stream *stream = *camera_->streams().begin();
+ std::set<Stream *> streams = { stream };
+ std::map<Stream *, StreamConfiguration> conf =
+ camera_->streamConfiguration(streams);
+ if (conf.size() != 1) {
+ cout << "Reading default format failed" << endl;
+ return TestFail;
+ }
+
+ if (camera_->configureStreams(conf)) {
+ cout << "Setting valid format failed" << endl;
+ return TestFail;
+ }
+
+ if (camera_->allocateBuffers()) {
+ cout << "Allocating buffers failed" << endl;
+ return TestFail;
+ }
+
+ BufferPool &pool = stream->bufferPool();
+ std::vector<Request *> requests;
+ for (Buffer &buffer : pool.buffers()) {
+ Request *request = camera_->createRequest();
+ if (!request) {
+ cout << "Creating request failed" << endl;
+ return TestFail;
+ }
+
+ std::map<Stream *, Buffer *> map = { { stream, &buffer } };
+ if (request->setBuffers(map)) {
+ cout << "Associating buffer with request failed" << endl;
+ return TestFail;
+ }
+
+ requests.push_back(request);
+ }
+
+ if (camera_->start()) {
+ cout << "Starting camera failed" << endl;
+ return TestFail;
+ }
+
+ for (Request *request : requests) {
+ if (camera_->queueRequest(request)) {
+ cout << "Queueing request failed" << endl;
+ return TestFail;
+ }
+ }
+
+ camera_->bufferCompleted.connect(this, &Capture::bufferComplete);
+ camera_->requestCompleted.connect(this, &Capture::requestComplete);
+
+ count_requests_ = 0;
+ count_buffers_ = 0;
+
+ EventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher();
+
+ Timer timer;
+ timer.start(100);
+ while (timer.isRunning())
+ dispatcher->processEvents();
+
+ if (!count_requests_ || !count_buffers_) {
+ cout << "Capture failed" << endl;
+ return TestFail;
+ }
+
+ if (camera_->stop()) {
+ cout << "Stopping camera failed" << endl;
+ return TestFail;
+ }
+
+ if (camera_->freeBuffers()) {
+ cout << "Freeing buffers failed" << endl;
+ return TestFail;
+ }
+
+ return TestPass;
+ }
+};
+
+} /* namespace */
+
+TEST_REGISTER(Capture);
diff --git a/test/camera/meson.build b/test/camera/meson.build
index f5f27c4229ac307f..6da297714f34a4e3 100644
--- a/test/camera/meson.build
+++ b/test/camera/meson.build
@@ -3,6 +3,7 @@
camera_tests = [
[ 'format_default', 'format_default.cpp' ],
[ 'format_set', 'format_set.cpp' ],
+ [ 'capture', 'capture.cpp' ],
]
foreach t : camera_tests
--
2.21.0
More information about the libcamera-devel
mailing list