[libcamera-devel,v10,15/19] lc-compliance: Move camera setup to CameraHolder class
diff mbox series

Message ID 20221228223003.2265712-16-paul.elder@ideasonboard.com
State New
Headers show
Series
  • lc-compliance: Add test to queue more requests than hardware depth
Related show

Commit Message

Paul Elder Dec. 28, 2022, 10:29 p.m. UTC
From: Nícolas F. R. A. Prado <nfraprado@collabora.com>

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 <nfraprado@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>

---
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

Patch
diff mbox series

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 <gtest/gtest.h>
 
-#include "environment.h"
 #include "simple_capture.h"
+#include "test_base.h"
 
 using namespace libcamera;
 
@@ -23,7 +23,7 @@  const std::vector<StreamRole> ROLES = {
 	StreamRole::Viewfinder
 };
 
-class SingleStream : public testing::TestWithParam<std::tuple<StreamRole, int>>
+class SingleStream : public testing::TestWithParam<std::tuple<StreamRole, int>>, public CameraHolder
 {
 public:
 	static std::string nameParameters(const testing::TestParamInfo<SingleStream::ParamType> &info);
@@ -31,8 +31,6 @@  public:
 protected:
 	void SetUp() override;
 	void TearDown() override;
-
-	std::shared_ptr<Camera> 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<SingleStream::ParamType> &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 <libcamera/libcamera.h>
+
+#include <gtest/gtest.h>
+
+class CameraHolder
+{
+protected:
+	void acquireCamera();
+	void releaseCamera();
+
+	std::shared_ptr<libcamera::Camera> camera_;
+};
+
+#endif /* __LC_COMPLIANCE_TEST_BASE_H__ */