From patchwork Mon Jul 1 20:15:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 1571 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1984861FAE for ; Mon, 1 Jul 2019 22:15:32 +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 B0F27120A for ; Mon, 1 Jul 2019 22:15:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1562012131; bh=GpI0w1AfwKmT2AQKF+PZAkjbN548YkhJCCn67q3xugM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=bS3Iyp0vevErMpLlh9a5UNI5rXUnUjV3edVrJTK0WpoDpdgbm1qSeAradAcN4BEai 92+sjUWGbQeWY8l18Rvz+nqWG0u1QcLaz5vCuOpZ786+Wvjy0G3zlE7cqC9uH3+KMs dSp9yE83E3K6y3VOcn8w2mH5pHsrG8RVPOPlpxIU= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Jul 2019 23:15:03 +0300 Message-Id: <20190701201504.28487-13-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190701201504.28487-1-laurent.pinchart@ideasonboard.com> References: <20190701201504.28487-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 12/13] libcamera: test: Add ControlList tests 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: Mon, 01 Jul 2019 20:15:33 -0000 From: Kieran Bingham Add tests of the ControlList infrastructure and public API. Signed-off-by: Kieran Bingham Reviewed-by: Niklas Söderlund --- test/controls/control_list.cpp | 213 +++++++++++++++++++++++++++++++++ test/controls/meson.build | 1 + 2 files changed, 214 insertions(+) create mode 100644 test/controls/control_list.cpp diff --git a/test/controls/control_list.cpp b/test/controls/control_list.cpp new file mode 100644 index 000000000000..c834edc352f5 --- /dev/null +++ b/test/controls/control_list.cpp @@ -0,0 +1,213 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * control_list.cpp - ControlList tests + */ + +#include + +#include +#include +#include + +#include "test.h" + +using namespace std; +using namespace libcamera; + +class ControlListTest : public Test +{ +protected: + int init() + { + cm_ = CameraManager::instance(); + + if (cm_->start()) { + cout << "Failed to start camera manager" << endl; + return TestFail; + } + + camera_ = cm_->get("VIMC Sensor B"); + if (!camera_) { + cout << "Can not find VIMC camera" << endl; + return TestSkip; + } + + return TestPass; + } + + int run() + { + ControlList list(camera_.get()); + + /* Test that the list is initially empty. */ + if (!list.empty()) { + cout << "List should to be empty" << endl; + return TestFail; + } + + if (list.size() != 0) { + cout << "List should contain zero items" << endl; + return TestFail; + } + + if (list.contains(Brightness)) { + cout << "List should not contain Brightness control" << endl; + return TestFail; + } + + unsigned int count = 0; + for (auto iter = list.begin(); iter != list.end(); ++iter) + count++; + + if (count != 0) { + cout << "List iteration should not produce any item" << endl; + return TestFail; + } + + /* + * Set a control, and verify that the list now contains it, and + * nothing else. + */ + list[Brightness] = 255; + + if (list.empty()) { + cout << "List should not be empty" << endl; + return TestFail; + } + + if (list.size() != 1) { + cout << "List should contain one item" << endl; + return TestFail; + } + + if (!list.contains(Brightness)) { + cout << "List should contain Brightness control" << endl; + return TestFail; + } + + count = 0; + for (auto iter = list.begin(); iter != list.end(); ++iter) + count++; + + if (count != 1) { + cout << "List iteration should produce one item" << endl; + return TestFail; + } + + if (list[Brightness].getInt() != 255) { + cout << "Incorrest Brightness control value" << endl; + return TestFail; + } + + if (list.contains(Contrast)) { + cout << "List should not contain Contract control" << endl; + return TestFail; + } + + /* + * Set a second control through ControlInfo and retrieve it + * through both controlId and ControlInfo. + */ + const ControlInfoMap &controls = camera_->controls(); + const ControlInfo *brightness = &controls.find(Brightness)->second; + const ControlInfo *contrast = &controls.find(Contrast)->second; + + list[brightness] = 64; + list[contrast] = 128; + + if (!list.contains(Contrast) || !list.contains(contrast)) { + cout << "List should contain Contrast control" << endl; + return TestFail; + } + + /* + * Test control value retrieval and update through ControlInfo. + */ + if (list[brightness].getInt() != 64 || + list[contrast].getInt() != 128) { + cout << "Failed to retrieve control value" << endl; + return TestFail; + } + + list[brightness] = 10; + list[contrast] = 20; + + if (list[brightness].getInt() != 10 || + list[contrast].getInt() != 20) { + cout << "Failed to update control value" << endl; + return TestFail; + } + + /* + * Assert that the container has not grown with the control + * updated. + */ + if (list.size() != 2) { + cout << "List should contain two elements" << endl; + return TestFail; + } + + /* + * Test list merging. Create a new list, add two controls with + * one overlapping the existing list, merge the lists and clear + * the old list. Verify that the new list is empty and that the + * new list contains the expected items and values. + */ + ControlList newList(camera_.get()); + + newList[Brightness] = 128; + newList[Saturation] = 255; + newList.update(list); + + list.clear(); + + if (list.size() != 0) { + cout << "Old List should contain zero items" << endl; + return TestFail; + } + + if (!list.empty()) { + cout << "Old List should be empty" << endl; + return TestFail; + } + + if (newList.size() != 3) { + cout << "New list has incorrect size" << endl; + return TestFail; + } + + if (!newList.contains(Brightness) || + !newList.contains(Contrast) || + !newList.contains(Saturation)) { + cout << "New list contains incorrect items" << endl; + return TestFail; + } + + if (newList[Brightness].getInt() != 10 || + newList[Contrast].getInt() != 20 || + newList[Saturation].getInt() != 255) { + cout << "New list contains incorrect values" << endl; + return TestFail; + } + + return TestPass; + } + + void cleanup() + { + if (camera_) { + camera_->release(); + camera_.reset(); + } + + cm_->stop(); + } + +private: + CameraManager *cm_; + std::shared_ptr camera_; +}; + +TEST_REGISTER(ControlListTest) diff --git a/test/controls/meson.build b/test/controls/meson.build index f8cda2877e73..f4fc7b947dd9 100644 --- a/test/controls/meson.build +++ b/test/controls/meson.build @@ -1,5 +1,6 @@ control_tests = [ [ 'control_info', 'control_info.cpp' ], + [ 'control_list', 'control_list.cpp' ], [ 'control_value', 'control_value.cpp' ], ]