From patchwork Wed Dec 28 22:29:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 18071 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 A8474C3291 for ; Wed, 28 Dec 2022 22:30:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 54E7562608; Wed, 28 Dec 2022 23:30:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1672266642; bh=WoN22LIegFrp62olPQq8QlNLCc0xK4dHM9kOmMmOYSw=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=3Y1rel1ZyxfE9fNwtNW/HB1aCvcmJcsi3u5XrcyFUGK0NnEEFTCs2SbUjnRoUzKbD Cv/4UvkXueonkeCX6A7IDzOehaWhxZhWUQ/U0tsQv5sD64WU4VTPXN/p9DgiGLa36N iyQ0kpgeveMsJt+oqlY1PDBP+knN2sgd38mbYm+fnNZQ+7neazztDy6BxgFj76i9gy //cmGDajDaa6BRv36yipEXFyaUiigo6BODS+4VL2YZZZjpSZSROkhPuJcC9ZZkDa9g 0CDHmYk51h1tiXpPDvQumrt7cSf5zM8HQA6GgKMlfGWcpDNPSoMT7DuV8Ol+6OCruw f62GhG+GZ2Xww== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6CF61625EF for ; Wed, 28 Dec 2022 23:30:36 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="nT3Vkg6s"; dkim-atps=neutral Received: from pyrite.mediacom.info (unknown [IPv6:2604:2d80:ad8a:9000:1bf9:855b:22de:3645]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 02909109; Wed, 28 Dec 2022 23:30:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1672266636; bh=WoN22LIegFrp62olPQq8QlNLCc0xK4dHM9kOmMmOYSw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nT3Vkg6sZonncODwm62E9ouZTy+HT36k6xTIPajG8QRNUzieqHzzLM4yWSvpKyS9F yneCJQ8htGCk7L1anSlGdwQf2DVEDXVvaZG3mi0XrckxlFtkf+slwuQDUQoR/vXUZG J/2kwVFCu9pqRT67mCwWKnI420Vjx57b4+Krdpgo= To: libcamera-devel@lists.libcamera.org Date: Wed, 28 Dec 2022 16:29:59 -0600 Message-Id: <20221228223003.2265712-16-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221228223003.2265712-1-paul.elder@ideasonboard.com> References: <20221228223003.2265712-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v10 15/19] lc-compliance: Move camera setup to CameraHolder class 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: Paul Elder via libcamera-devel From: Paul Elder Reply-To: Paul Elder Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: NĂ­colas F. R. A. Prado Different base classes can be used for different setups on tests, but all of them will need to setup the camera for the test. To reuse that code, move it to a separate CameraHolder class that is inherited by test classes. Signed-off-by: NĂ­colas F. R. A. Prado Reviewed-by: Laurent Pinchart Reviewed-by: Paul Elder Signed-off-by: Paul Elder --- Changes in v9: - rebased Changes in v8: - Moved CameraHolder to new test_base.{cpp,h} files Changes in v5: - New --- src/apps/lc-compliance/capture_test.cpp | 18 ++++------------ src/apps/lc-compliance/meson.build | 1 + src/apps/lc-compliance/test_base.cpp | 28 +++++++++++++++++++++++++ src/apps/lc-compliance/test_base.h | 24 +++++++++++++++++++++ 4 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 src/apps/lc-compliance/test_base.cpp create mode 100644 src/apps/lc-compliance/test_base.h diff --git a/src/apps/lc-compliance/capture_test.cpp b/src/apps/lc-compliance/capture_test.cpp index 923395cf..2b82443a 100644 --- a/src/apps/lc-compliance/capture_test.cpp +++ b/src/apps/lc-compliance/capture_test.cpp @@ -10,8 +10,8 @@ #include -#include "environment.h" #include "simple_capture.h" +#include "test_base.h" using namespace libcamera; @@ -23,7 +23,7 @@ const std::vector ROLES = { StreamRole::Viewfinder }; -class SingleStream : public testing::TestWithParam> +class SingleStream : public testing::TestWithParam>, public CameraHolder { public: static std::string nameParameters(const testing::TestParamInfo &info); @@ -31,8 +31,6 @@ public: protected: void SetUp() override; void TearDown() override; - - std::shared_ptr camera_; }; /* @@ -41,20 +39,12 @@ protected: */ void SingleStream::SetUp() { - Environment *env = Environment::get(); - - camera_ = env->cm()->get(env->cameraId()); - - ASSERT_EQ(camera_->acquire(), 0); + acquireCamera(); } void SingleStream::TearDown() { - if (!camera_) - return; - - camera_->release(); - camera_.reset(); + releaseCamera(); } std::string SingleStream::nameParameters(const testing::TestParamInfo &info) diff --git a/src/apps/lc-compliance/meson.build b/src/apps/lc-compliance/meson.build index 3b1927fd..fae290bb 100644 --- a/src/apps/lc-compliance/meson.build +++ b/src/apps/lc-compliance/meson.build @@ -15,6 +15,7 @@ lc_compliance_sources = files([ 'environment.cpp', 'main.cpp', 'simple_capture.cpp', + 'test_base.cpp', ]) lc_compliance = executable('lc-compliance', lc_compliance_sources, diff --git a/src/apps/lc-compliance/test_base.cpp b/src/apps/lc-compliance/test_base.cpp new file mode 100644 index 00000000..c9957b9e --- /dev/null +++ b/src/apps/lc-compliance/test_base.cpp @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2021, Collabora Ltd. + * + * test_base.cpp - Base definitions for tests + */ + +#include "test_base.h" + +#include "environment.h" + +void CameraHolder::acquireCamera() +{ + Environment *env = Environment::get(); + + camera_ = env->cm()->get(env->cameraId()); + + ASSERT_EQ(camera_->acquire(), 0); +} + +void CameraHolder::releaseCamera() +{ + if (!camera_) + return; + + camera_->release(); + camera_.reset(); +} diff --git a/src/apps/lc-compliance/test_base.h b/src/apps/lc-compliance/test_base.h new file mode 100644 index 00000000..52347749 --- /dev/null +++ b/src/apps/lc-compliance/test_base.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2021, Collabora Ltd. + * + * test_base.h - Base definitions for tests + */ + +#ifndef __LC_COMPLIANCE_TEST_BASE_H__ +#define __LC_COMPLIANCE_TEST_BASE_H__ + +#include + +#include + +class CameraHolder +{ +protected: + void acquireCamera(); + void releaseCamera(); + + std::shared_ptr camera_; +}; + +#endif /* __LC_COMPLIANCE_TEST_BASE_H__ */