[libcamera-devel] [PATCH 2/2] [DNI?] lc-compliance: Add resolutions test

Jacopo Mondi jacopo at jmondi.org
Wed Aug 25 18:13:03 CEST 2021


This probably does not fully qualify as a compliance test, as there are
no mandatory formats a camera is requested to support.

However this test proves to be useful to verify that a set of known
resolutions is valid after a change.

In particular, I have used this to test the IPU3 ImgU pipe configuration
results.

Run it with
$ lc-compliance -f "CaptureTest/ResolutionsTest*.*"

Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
---
 src/lc-compliance/meson.build          |   1 +
 src/lc-compliance/resolutions_test.cpp | 190 +++++++++++++++++++++++++
 2 files changed, 191 insertions(+)
 create mode 100644 src/lc-compliance/resolutions_test.cpp

diff --git a/src/lc-compliance/meson.build b/src/lc-compliance/meson.build
index aa5852f6cb87..88b306d7d75f 100644
--- a/src/lc-compliance/meson.build
+++ b/src/lc-compliance/meson.build
@@ -17,6 +17,7 @@ lc_compliance_sources = files([
     'main.cpp',
     'simple_capture.cpp',
     'capture_test.cpp',
+    'resolutions_test.cpp'
 ])
 
 lc_compliance  = executable('lc-compliance', lc_compliance_sources,
diff --git a/src/lc-compliance/resolutions_test.cpp b/src/lc-compliance/resolutions_test.cpp
new file mode 100644
index 000000000000..f30ea3c5ed4a
--- /dev/null
+++ b/src/lc-compliance/resolutions_test.cpp
@@ -0,0 +1,190 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2020, Google Inc.
+ * Copyright (C) 2021, Collabora Ltd.
+ *
+ * capture_test.cpp - Test camera capture
+ */
+
+#include <iostream>
+
+#include <gtest/gtest.h>
+
+#include <libcamera/stream.h>
+
+#include "environment.h"
+#include "simple_capture.h"
+
+using namespace libcamera;
+
+const std::vector<Size> RESOLUTIONS = {
+	{ 2560, 1440 },
+	{ 1920, 1080 },
+	{ 1280, 720 },
+	{ 1024, 576 },
+	{ 640, 480 },
+	{ 320, 240 },
+};
+
+/* Test stream resolutions with a single stream. */
+
+class ResolutionsTestSingle : public testing::TestWithParam<Size>
+{
+public:
+	static std::string nameParameters(const testing::TestParamInfo<ResolutionsTestSingle::ParamType> &info);
+
+protected:
+	void SetUp() override;
+	void TearDown() override;
+
+	std::shared_ptr<Camera> camera_;
+};
+
+/*
+ * We use gtest's SetUp() and TearDown() instead of constructor and destructor
+ * in order to be able to assert on them.
+ */
+void ResolutionsTestSingle::SetUp()
+{
+	Environment *env = Environment::get();
+
+	camera_ = env->cm()->get(env->cameraId());
+
+	ASSERT_EQ(camera_->acquire(), 0);
+}
+
+void ResolutionsTestSingle::TearDown()
+{
+	if (!camera_)
+		return;
+
+	camera_->release();
+	camera_.reset();
+}
+
+std::string ResolutionsTestSingle::nameParameters(const testing::TestParamInfo<ResolutionsTestSingle::ParamType> &info)
+{
+	Size sz = info.param;
+	return sz.toString();
+}
+
+TEST_P(ResolutionsTestSingle, Single)
+{
+	Size sz = GetParam();
+
+	std::cout << "Testing " << sz.toString();
+	StreamRoles roles = {
+		libcamera::StreamRole::Viewfinder,
+	};
+
+	std::unique_ptr<CameraConfiguration> config =
+		camera_->generateConfiguration(roles);
+	StreamConfiguration &stream = config->at(0);
+	stream.size.width = sz.width;
+	stream.size.height = sz.height;
+
+	switch (config->validate()) {
+	case CameraConfiguration::Valid:
+		return;
+
+	case CameraConfiguration::Adjusted:
+		if (stream.size != sz)
+			FAIL() << "Resolution " << sz.toString() << " not supported";
+		return;
+
+	default:
+		FAIL() << "Resolution " << sz.toString() << " not supported";
+	}
+}
+
+INSTANTIATE_TEST_SUITE_P(CaptureTest,
+			 ResolutionsTestSingle,
+			 testing::ValuesIn(RESOLUTIONS),
+			 ResolutionsTestSingle::nameParameters);
+
+/* Test stream resolutions with 2 streams. */
+
+class ResolutionsTestPair : public testing::TestWithParam<std::tuple<Size, Size>>
+{
+public:
+	static std::string nameParameters(const testing::TestParamInfo<ResolutionsTestPair::ParamType> &info);
+
+protected:
+	void SetUp() override;
+	void TearDown() override;
+
+	std::shared_ptr<Camera> camera_;
+};
+
+/*
+ * We use gtest's SetUp() and TearDown() instead of constructor and destructor
+ * in order to be able to assert on them.
+ */
+void ResolutionsTestPair::SetUp()
+{
+	Environment *env = Environment::get();
+
+	camera_ = env->cm()->get(env->cameraId());
+
+	ASSERT_EQ(camera_->acquire(), 0);
+}
+
+void ResolutionsTestPair::TearDown()
+{
+	if (!camera_)
+		return;
+
+	camera_->release();
+	camera_.reset();
+}
+
+std::string ResolutionsTestPair::nameParameters(const testing::TestParamInfo<ResolutionsTestPair::ParamType> &info)
+{
+	auto [sz, sz2] = info.param;
+	return sz.toString() + "_" + sz2.toString();
+}
+
+TEST_P(ResolutionsTestPair, Single)
+{
+	auto [sz, sz2] = GetParam();
+
+	std::cout << "Testing " << sz.toString() << " - " << sz2.toString();
+	StreamRoles roles = {
+		libcamera::StreamRole::Viewfinder,
+		libcamera::StreamRole::Viewfinder,
+	};
+
+	std::unique_ptr<CameraConfiguration> config =
+		camera_->generateConfiguration(roles);
+
+	/* Camera does not support multiple streams. */
+	if (config->size() < 2)
+		GTEST_SKIP();
+
+	StreamConfiguration &stream = config->at(0);
+	stream.size.width = sz.width;
+	stream.size.height = sz.height;
+
+	StreamConfiguration &stream2 = config->at(1);
+	stream2.size.width = sz2.width;
+	stream2.size.height = sz2.height;
+
+	switch (config->validate()) {
+	case CameraConfiguration::Valid:
+		return;
+
+	case CameraConfiguration::Adjusted:
+		if (stream.size != sz || stream2.size != sz2)
+			FAIL() << "Resolution " << sz.toString() << " not supported";
+		return;
+
+	default:
+		FAIL() << "Resolution " << sz.toString() << " not supported";
+	}
+}
+
+INSTANTIATE_TEST_SUITE_P(CaptureTest,
+			 ResolutionsTestPair,
+			 testing::Combine(testing::ValuesIn(RESOLUTIONS),
+					  testing::ValuesIn(RESOLUTIONS)),
+			 ResolutionsTestPair::nameParameters);
-- 
2.32.0



More information about the libcamera-devel mailing list