From patchwork Fri Dec 22 16:40:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 19342 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 A8291C32BD for ; Fri, 22 Dec 2023 16:40:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F15BE62B60; Fri, 22 Dec 2023 17:40:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1703263256; bh=k8Mbr2+JgGuhmFwIhLIu3QQyr3B588Uw/2u4g5cSFgE=; 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=dIgQTc4FlKkQrL/EDK9qE2pPaIg7L7R8Rfld9KFINkJ2viGmIZi4WQAY1g5apxaVC B8gsb1Hsm1sE6TROQerESfxQYarJp/2Zw5FS0xC+BrdYJqZppDMBPJH40gAGcD4Qqi znEn/O7sTAJalmV6E0HEwBl5DNWtcYtpZgWqktq00T9PA+lQHJzT3S9yE3ybupIOHT 4/1XtXyOt2zSphDXuMh5GJJ8RkZETZ2Ip+A/1/IeN3yTR9dnP6J2NlEzLR2XhW7UOS BmuEkPUu6E8P7pVgFsw1thGGi3YRbl3xLaUuDXiMMhgy6D4EK1GclBjiRzf1Fl0ArL H9f7QR98StpBw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DFF3762B53 for ; Fri, 22 Dec 2023 17:40:50 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="IyJ8DDr8"; 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 1040B250; Fri, 22 Dec 2023 17:39:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1703263199; bh=k8Mbr2+JgGuhmFwIhLIu3QQyr3B588Uw/2u4g5cSFgE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IyJ8DDr8Li3KRr97A7loKd9dp2AI2Bt3aKXJU9E+6b/6PGCBG8w4O3iWGMERXI5g/ UvJ1q+Yr/lQm6yp2UCzOMcLNEHmKl7gY1jEKOB7yxx+88DPeK/6FewDlVIV0Fd3FHa 2Jxou+j7E8wtRAKiOemnNYyizGcUnjfAG4vbMmSg= To: libcamera-devel@lists.libcamera.org Date: Fri, 22 Dec 2023 17:40:36 +0100 Message-ID: <20231222164036.649245-6-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231222164036.649245-1-jacopo.mondi@ideasonboard.com> References: <20231222164036.649245-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 5/5] 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/controls_test.cpp | 98 ++++++++++++++++++++++++ src/apps/lc-compliance/meson.build | 1 + 2 files changed, 99 insertions(+) create mode 100644 src/apps/lc-compliance/controls_test.cpp diff --git a/src/apps/lc-compliance/controls_test.cpp b/src/apps/lc-compliance/controls_test.cpp new file mode 100644 index 000000000000..e9bdf6fdb7e3 --- /dev/null +++ b/src/apps/lc-compliance/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); 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 = ([