From patchwork Sat Oct 12 18:44:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2169 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5E7E361986 for ; Sat, 12 Oct 2019 20:44:21 +0200 (CEST) Received: from pendragon.bb.dnainternet.fi (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id F228C33A for ; Sat, 12 Oct 2019 20:44:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1570905861; bh=sG7Ifl84SxV6o5oFM/Kb4BddvDTqdPqV0WkoKLzi/8E=; h=From:To:Subject:Date:In-Reply-To:References:From; b=YvZqbOQo6x9OKjCQhUVxvV/E33yZZsEW8nn0CrvWfPpRKS1wjnYNFA4k1J/do49q1 OalPgxql7qsU0jY+muIigfHpEaws/cQsDf8HgsDkujdJ1TFO2ZEGWsJ3W7aUl/hUDF V5zRf9yID98YiLfaH3ESpfMOsWDr4vvhRm1nrDR8= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 12 Oct 2019 21:44:01 +0300 Message-Id: <20191012184407.31684-9-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191012184407.31684-1-laurent.pinchart@ideasonboard.com> References: <20191012184407.31684-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 08/14] test: v4l2_videodevice: Add V4L2 control test X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Oct 2019 18:44:21 -0000 Add a test that exercises the control enumeration, get and set APIs on a V4L2Device. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- test/v4l2_videodevice/controls.cpp | 98 ++++++++++++++++++++++++++++++ test/v4l2_videodevice/meson.build | 1 + 2 files changed, 99 insertions(+) create mode 100644 test/v4l2_videodevice/controls.cpp diff --git a/test/v4l2_videodevice/controls.cpp b/test/v4l2_videodevice/controls.cpp new file mode 100644 index 000000000000..4a7535245c00 --- /dev/null +++ b/test/v4l2_videodevice/controls.cpp @@ -0,0 +1,98 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * controls.cpp - V4L2 device controls handling test + */ + +#include +#include + +#include "v4l2_videodevice.h" + +#include "v4l2_videodevice_test.h" + +using namespace std; +using namespace libcamera; + +class V4L2ControlTest : public V4L2VideoDeviceTest +{ +public: + V4L2ControlTest() + : V4L2VideoDeviceTest("vivid", "vivid-000-vid-cap") {} + +protected: + int run() + { + const V4L2ControlInfoMap &info = capture_->controls(); + + /* Test control enumeration. */ + if (info.empty()) { + cerr << "Failed to enumerate controls" << endl; + return TestFail; + } + + if (info.find(V4L2_CID_BRIGHTNESS) == info.end() || + info.find(V4L2_CID_CONTRAST) == info.end() || + info.find(V4L2_CID_SATURATION) == info.end()) { + cerr << "Missing controls" << endl; + return TestFail; + } + + const V4L2ControlInfo &brightness = info.find(V4L2_CID_BRIGHTNESS)->second; + const V4L2ControlInfo &contrast = info.find(V4L2_CID_CONTRAST)->second; + const V4L2ControlInfo &saturation = info.find(V4L2_CID_SATURATION)->second; + + /* Test getting controls. */ + V4L2ControlList ctrls; + ctrls.add(V4L2_CID_BRIGHTNESS); + ctrls.add(V4L2_CID_CONTRAST); + ctrls.add(V4L2_CID_SATURATION); + + int ret = capture_->getControls(&ctrls); + if (ret != 0) { + cerr << "Failed to get controls" << endl; + return TestFail; + } + + if (ctrls[V4L2_CID_BRIGHTNESS]->value().get() == -1 || + ctrls[V4L2_CID_CONTRAST]->value().get() == -1 || + ctrls[V4L2_CID_SATURATION]->value().get() == -1) { + cerr << "Incorrect value for retrieved controls" << endl; + return TestFail; + } + + /* Test setting controls. */ + ctrls[V4L2_CID_BRIGHTNESS]->value() = brightness.range().min(); + ctrls[V4L2_CID_CONTRAST]->value() = contrast.range().max(); + ctrls[V4L2_CID_SATURATION]->value() = saturation.range().min(); + + ret = capture_->setControls(&ctrls); + if (ret != 0) { + cerr << "Failed to set controls" << endl; + return TestFail; + } + + /* Test setting controls outside of range. */ + ctrls[V4L2_CID_BRIGHTNESS]->value() = brightness.range().min().get() - 1; + ctrls[V4L2_CID_CONTRAST]->value() = contrast.range().max().get() + 1; + ctrls[V4L2_CID_SATURATION]->value() = saturation.range().min().get() + 1; + + ret = capture_->setControls(&ctrls); + if (ret != 0) { + cerr << "Failed to set controls (out of range)" << endl; + return TestFail; + } + + if (ctrls[V4L2_CID_BRIGHTNESS]->value() != brightness.range().min() || + ctrls[V4L2_CID_CONTRAST]->value() != brightness.range().max() || + ctrls[V4L2_CID_SATURATION]->value() != saturation.range().min().get() + 1) { + cerr << "Controls not updated when set" << endl; + return TestFail; + } + + return TestPass; + } +}; + +TEST_REGISTER(V4L2ControlTest); diff --git a/test/v4l2_videodevice/meson.build b/test/v4l2_videodevice/meson.build index ad41898b5f8b..5c52da7219c2 100644 --- a/test/v4l2_videodevice/meson.build +++ b/test/v4l2_videodevice/meson.build @@ -2,6 +2,7 @@ # They are not alphabetically sorted. v4l2_videodevice_tests = [ [ 'double_open', 'double_open.cpp' ], + [ 'controls', 'controls.cpp' ], [ 'formats', 'formats.cpp' ], [ 'request_buffers', 'request_buffers.cpp' ], [ 'stream_on_off', 'stream_on_off.cpp' ],