From patchwork Wed Mar 6 02:47:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 708 Return-Path: Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 18231611A8 for ; Wed, 6 Mar 2019 03:48:22 +0100 (CET) X-Halon-ID: 4d650ea3-3fba-11e9-985a-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id 4d650ea3-3fba-11e9-985a-005056917f90; Wed, 06 Mar 2019 03:48:21 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Wed, 6 Mar 2019 03:47:54 +0100 Message-Id: <20190306024755.28726-5-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190306024755.28726-1-niklas.soderlund@ragnatech.se> References: <20190306024755.28726-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/5] test: camera: Add capture test X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Mar 2019 02:48:22 -0000 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 --- 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 + +#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 &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 streams = { stream }; + std::map 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 requests; + for (Buffer &buffer : pool.buffers()) { + Request *request = camera_->createRequest(); + if (!request) { + cout << "Creating request failed" << endl; + return TestFail; + } + + std::map 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