From patchwork Sun Feb 3 11:01:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 497 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0FFF760DD6 for ; Sun, 3 Feb 2019 12:01:09 +0100 (CET) Received: from localhost.localdomain (218.182-78-194.adsl-static.isp.belgacom.be [194.78.182.218]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B1B0C41; Sun, 3 Feb 2019 12:01:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1549191668; bh=oDxTNucYy3vOWg1TqMKzYuhw/t7U6/nsw1sEYLipvrg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qd43pd34Hdx/YSHHDaVFFbtHILlpv3XzdFwb6DN5SvXPX6CAFbwnzmGg2orfo02hk AyTuw0j+ZdzAerOZeO4aQKX1bwf26MQFeqyYnLcqPu++weFXgSPK1plXAe7EzXsxc3 yk1TJBYcg1YDUA43b8fIdqJ+JC68F1ANEjtZSNXY= From: Kieran Bingham To: LibCamera Devel Date: Sun, 3 Feb 2019 12:01:01 +0100 Message-Id: <20190203110102.5663-11-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190203110102.5663-1-kieran.bingham@ideasonboard.com> References: <20190203110102.5663-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 10/11] 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: Sun, 03 Feb 2019 11:01:10 -0000 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 --- 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 diff --git a/test/v4l2_device/capture_async.cpp b/test/v4l2_device/capture_async.cpp new file mode 100644 index 000000000000..70f340dba3f1 --- /dev/null +++ b/test/v4l2_device/capture_async.cpp @@ -0,0 +1,69 @@ +/* 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 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); diff --git a/test/v4l2_device/meson.build b/test/v4l2_device/meson.build index f04c7ded009c..2a37b7b06134 100644 --- a/test/v4l2_device/meson.build +++ b/test/v4l2_device/meson.build @@ -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