From patchwork Sat Dec 30 16:29:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 19356 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 7AB3CC32BD for ; Sat, 30 Dec 2023 16:29:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E8B7462B68; Sat, 30 Dec 2023 17:29:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1703953779; bh=uREwC1sYmKn54w5oKXVCF/CAeWzzERz9UG3mEK9qtCA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=flHbiBFaj170dvQBVK1RF+n3ZHqiCKoxdGL0hbwlr9Mu0hssLqgwd0F3Cr5wppsaL W1xzZSX2KpM9xtwI4/z09PthVwKNeF8GP/YBt6zLzBS8VGGY29BjCs+vNj7sTugpfW 9cqGYVC6wHRvl8hccsPY92RP5mHDBVoHJUedtampxlBVh6jfKb736psDZNcuuNThxG LkztVjCqAljfo+SC2cZTHokcCx+83ImHKeEBXal99xTCPX41BLcTUUiLhw7G6ig+Ys 4O/UIqfhPfTtdeUPhEu2i96I1QB4fo+PheBwvxGHito4YcKOmeCdjBHmQDw6lvl2Xm hXLmFisCeVLVQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BC4CF62B54 for ; Sat, 30 Dec 2023 17:29:33 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="BxMPbBtX"; dkim-atps=neutral Received: from localhost.localdomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5E38D8BE; Sat, 30 Dec 2023 17:28:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1703953716; bh=uREwC1sYmKn54w5oKXVCF/CAeWzzERz9UG3mEK9qtCA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BxMPbBtXS08t0TVol8cMU+tNHi6TmEK56QEgvVktzSipCwnhdFBdxHdgKIIGiCz3S qHXYQZFtSoIfOs52K8Ph1DXFUPSSHkME0cY3S31CFj7TmmMm1NJg0e4Lt9/FGd+FJg EjQfWsQjCAPw/kgP31ogNBNVkBFFJZpTGmUyYZRI= To: libcamera-devel@lists.libcamera.org Date: Sat, 30 Dec 2023 17:29:10 +0100 Message-ID: <20231230162912.827669-6-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231230162912.827669-1-jacopo.mondi@ideasonboard.com> References: <20231230162912.827669-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 5/7] apps: lc-compliance: Test for mandatory controls 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-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Test for mandatory controls and properties to be supported by a Camera. Signed-off-by: Jacopo Mondi --- src/apps/lc-compliance/meson.build | 1 + .../lc-compliance/tests/controls_test.cpp | 98 +++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 src/apps/lc-compliance/tests/controls_test.cpp diff --git a/src/apps/lc-compliance/meson.build b/src/apps/lc-compliance/meson.build index ae8c6f4db51b..c927dd12e9f4 100644 --- a/src/apps/lc-compliance/meson.build +++ b/src/apps/lc-compliance/meson.build @@ -15,6 +15,7 @@ lc_compliance_sources = files([ 'helpers/capture.cpp', 'main.cpp', 'tests/capture_test.cpp', + 'tests/controls_test.cpp' ]) lc_compliance_includes = ([ diff --git a/src/apps/lc-compliance/tests/controls_test.cpp b/src/apps/lc-compliance/tests/controls_test.cpp new file mode 100644 index 000000000000..e9bdf6fdb7e3 --- /dev/null +++ b/src/apps/lc-compliance/tests/controls_test.cpp @@ -0,0 +1,98 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2023, Ideas On Board Oy + * + * controls_test.cpp - Test controls and properties + */ + +#include +#include + +#include +#include +#include + +#include + +#include "environment.h" + +using namespace libcamera; + +std::array controlMaps = { + &controls::controls, + &properties::properties, +}; + +class ControlTest : public testing::TestWithParam +{ +public: + static std::string nameParameters(const testing::TestParamInfo &info); + +protected: + void SetUp() override; + void TearDown() override; + + std::shared_ptr camera_; +}; + +void ControlTest::SetUp() +{ + Environment *env = Environment::get(); + + camera_ = env->cm()->get(env->cameraId()); + + ASSERT_EQ(camera_->acquire(), 0); +} + +void ControlTest::TearDown() +{ + if (!camera_) + return; + + camera_->release(); + camera_.reset(); +} + +std::string ControlTest::nameParameters(const testing::TestParamInfo &info) +{ + const ControlIdMap *idMap = info.param; + if (idMap == &controls::controls) + return "controls"; + else if (idMap == &properties::properties) + return "properties"; + + return "vendor"; +} + +/* Test that mandatory controls and properties are supported by a camera. */ +TEST_P(ControlTest, RequiredControls) +{ + auto controlMap = GetParam(); + + for (const auto &[id, ctrl] : *controlMap) { + if (!ctrl->required()) + continue; + + if (controlMap == &controls::controls) { + const auto it = camera_->controls().find(ctrl); + + if (it == camera_->controls().end()) + FAIL() << "Mandatory control \"" << ctrl->name() + << "\" not supported" << std::endl; + } else if (controlMap == &properties::properties) { + bool found = camera_->properties().contains(id); + + if (!found) + FAIL() << "Mandatory property \"" << ctrl->name() + << "\" not supported" << std::endl; + } + } +} + +/* + * Use a Value-Parametrized Test case so that vendors can easily test vendor + * control lists by expading 'controlMaps'. + */ +INSTANTIATE_TEST_SUITE_P(ControlsTest, ControlTest, + testing::ValuesIn(controlMaps), + ControlTest::nameParameters);