From patchwork Wed Mar 20 10:16:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 19782 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 BAEE1C3272 for ; Wed, 20 Mar 2024 10:17:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AF41062D32; Wed, 20 Mar 2024 11:17:08 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="I61e5ZOX"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D2FA562CA8 for ; Wed, 20 Mar 2024 11:17:04 +0100 (CET) Received: from localhost.localdomain (unknown [IPv6:2001:b07:5d2e:52c9:cc1e:e404:491f:e6ea]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7E181C58; Wed, 20 Mar 2024 11:16:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1710929797; bh=CfzT+mr+GuWMnVHAecA6FVm0MCys20U3JH+JVaKeW/w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I61e5ZOX/Dw8xM0SbMWN+17vCPRQP/Bi9SQezpl+HGLhyjVXb9FvJEHtY0JJz7O36 Kp1AsRmKh9JgbSUZNKvZ5sOnYK6wTfahcxRtgsARNxY03QxgSVQYZyQTOGjNDeTInV nkaFAFtDVWN6csPJIKlqi3DmJbcW/iRJPQoBa+iU= From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi Subject: [PATCH 2/4] apps: lc-compliance: Test for mandatory controls Date: Wed, 20 Mar 2024 11:16:49 +0100 Message-ID: <20240320101652.12873-3-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240320101652.12873-1-jacopo.mondi@ideasonboard.com> References: <20240320101652.12873-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 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: , 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 b1f605f3392a..09f068628d53 100644 --- a/src/apps/lc-compliance/meson.build +++ b/src/apps/lc-compliance/meson.build @@ -16,6 +16,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..ff594fbe672a --- /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 expanding 'controlMaps'. + */ +INSTANTIATE_TEST_SUITE_P(ControlsTest, ControlTest, + testing::ValuesIn(controlMaps), + ControlTest::nameParameters);