From patchwork Fri Jun 25 19:39:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= X-Patchwork-Id: 12712 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 0FADCC321A for ; Fri, 25 Jun 2021 19:39:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CD857684D5; Fri, 25 Jun 2021 21:39:57 +0200 (CEST) Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CD2AA684CA for ; Fri, 25 Jun 2021 21:39:56 +0200 (CEST) Received: from localhost.localdomain (unknown [IPv6:2804:14c:1a9:2434:51f6:da24:ae79:702d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: nfraprado) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 6C0D11F4487C; Fri, 25 Jun 2021 20:39:53 +0100 (BST) From: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= To: libcamera-devel@lists.libcamera.org Date: Fri, 25 Jun 2021 16:39:23 -0300 Message-Id: <20210625193925.517406-4-nfraprado@collabora.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210625193925.517406-1-nfraprado@collabora.com> References: <20210625193925.517406-1-nfraprado@collabora.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v9 3/5] lc-compliance: Add Environment singleton 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: , Cc: kernel@collabora.com, =?utf-8?q?Andr=C3=A9_Almeida?= Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a singleton Environment class in order to make the camera available inside all tests. This is needed for the Googletest refactor, otherwise the tests, which are statically declared, won't be able to access the camera. Signed-off-by: Nícolas F. R. A. Prado Reviewed-by: Niklas Söderlund Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- No changes in v9 Changes in v8: - Thanks to Laurent: - Fixed compiling error in Clang - Thanks to Kieran: - Fixed coding style issues Changes in v7: - Thanks to Jacopo: - Fixed style issue - Made CameraManager a unique_ptr and passed to Environment as raw pointer Changes in v6: - Thanks to Niklas: - Made cameraId() return const& Changes in v5: - Thanks to Laurent: - Stored CameraManager and cameraId instead of Camera in Environment - Thanks to Laurent & Niklas: - Improved Environment singleton class instantiation and destruction Added in v4 src/lc-compliance/environment.cpp | 20 ++++++++++++++++++++ src/lc-compliance/environment.h | 31 +++++++++++++++++++++++++++++++ src/lc-compliance/meson.build | 1 + 3 files changed, 52 insertions(+) create mode 100644 src/lc-compliance/environment.cpp create mode 100644 src/lc-compliance/environment.h diff --git a/src/lc-compliance/environment.cpp b/src/lc-compliance/environment.cpp new file mode 100644 index 000000000000..9e24b5e34e4a --- /dev/null +++ b/src/lc-compliance/environment.cpp @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2021, Collabora Ltd. + * + * environment.cpp - Common environment for tests + */ + +#include "environment.h" + +Environment *Environment::get() +{ + static Environment instance; + return &instance; +} + +void Environment::setup(CameraManager *cm, std::string cameraId) +{ + cm_ = cm; + cameraId_ = cameraId; +} diff --git a/src/lc-compliance/environment.h b/src/lc-compliance/environment.h new file mode 100644 index 000000000000..1c7d9a558dc2 --- /dev/null +++ b/src/lc-compliance/environment.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2021, Collabora Ltd. + * + * environment.h - Common environment for tests + */ +#ifndef __LC_COMPLIANCE_ENVIRONMENT_H__ +#define __LC_COMPLIANCE_ENVIRONMENT_H__ + +#include + +using namespace libcamera; + +class Environment +{ +public: + static Environment *get(); + + void setup(CameraManager *cm, std::string cameraId); + + const std::string &cameraId() const { return cameraId_; } + CameraManager *cm() const { return cm_; } + +private: + Environment() = default; + + std::string cameraId_; + CameraManager *cm_; +}; + +#endif /* __LC_COMPLIANCE_ENVIRONMENT_H__ */ diff --git a/src/lc-compliance/meson.build b/src/lc-compliance/meson.build index a2bfcceb1259..6dd49085569f 100644 --- a/src/lc-compliance/meson.build +++ b/src/lc-compliance/meson.build @@ -12,6 +12,7 @@ lc_compliance_enabled = true lc_compliance_sources = files([ '../cam/event_loop.cpp', '../cam/options.cpp', + 'environment.cpp', 'main.cpp', 'results.cpp', 'simple_capture.cpp',