From patchwork Wed Feb 6 06:07:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 523 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 40EFB61031 for ; Wed, 6 Feb 2019 07:08:25 +0100 (CET) Received: from pendragon.ideasonboard.com (d51A4137F.access.telenet.be [81.164.19.127]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E1B472D7 for ; Wed, 6 Feb 2019 07:08:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1549433305; bh=YIvPvFriiZwE+IFaKBq5lVADB1qrbFQm8NRuhv1MsSo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=vA/z/mLdcvK/MDSRjGe2Pr0H/J8WLM52g56kNauK8rQzF287C7m8kgih7j6FJHsFD vVHL49cEMDHmxvA9A7CgmzA+bbck1neJI4A71xRHkk5LSCo66OP+Mw9XCdtvz5qIjl 0FBsyJeUfZT4q6vaRmJV5iAtsSf13KvYSNiMVxFQ= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 6 Feb 2019 08:07:59 +0200 Message-Id: <20190206060818.13907-9-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190206060818.13907-1-laurent.pinchart@ideasonboard.com> References: <20190206060818.13907-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 08/27] test: v4l2_device: Provide asynchronous 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 Feb 2019 06:08:26 -0000 From: Kieran Bingham 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 in the same timeout period. Signed-off-by: Kieran Bingham Signed-off-by: Jacopo Mondi Signed-off-by: Laurent Pinchart Signed-off-by: Niklas Söderlund --- test/v4l2_device/capture_async.cpp | 86 ++++++++++++++++++++++++++++++ test/v4l2_device/meson.build | 1 + 2 files changed, 87 insertions(+) create mode 100644 test/v4l2_device/capture_async.cpp diff --git a/test/v4l2_device/capture_async.cpp b/test/v4l2_device/capture_async.cpp new file mode 100644 index 000000000000..7a0735f65535 --- /dev/null +++ b/test/v4l2_device/capture_async.cpp @@ -0,0 +1,86 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * libcamera V4L2 API tests + */ + +#include +#include +#include +#include + +#include + +#include "v4l2_device_test.h" + +class CaptureAsyncTest : public V4L2DeviceTest +{ +public: + CaptureAsyncTest() + : frames(0){}; + + void receiveBuffer(Buffer *buffer) + { + std::cout << "Received buffer " << buffer->index() << std::endl; + frames++; + + /* Requeue the buffer for further use. */ + dev_->queueBuffer(buffer); + } + +protected: + int run() + { + const unsigned int bufferCount = 8; + + EventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher(); + Timer timeout; + int ret; + + createBuffers(bufferCount); + + ret = dev_->exportBuffers(bufferCount, &pool_); + if (ret) + return TestFail; + + dev_->bufferReady.connect(this, &CaptureAsyncTest::receiveBuffer); + + /* Queue all the buffers to the device. */ + for (Buffer &b : pool_.buffers()) { + if (dev_->queueBuffer(&b)) + return TestFail; + } + + ret = dev_->streamOn(); + if (ret) + return TestFail; + + 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; + + ret = dev_->streamOff(); + if (ret) + return TestFail; + + return TestPass; + } + +private: + unsigned int frames; +}; + +TEST_REGISTER(CaptureAsyncTest); diff --git a/test/v4l2_device/meson.build b/test/v4l2_device/meson.build index cbaa79da9b81..ec2c7f9f11ff 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_async', 'capture_async.cpp' ], ] foreach t : v4l2_device_tests