[libcamera-devel] [PATCH 29/31] DNI: test array controls

Laurent Pinchart laurent.pinchart at ideasonboard.com
Sat Feb 29 17:42:52 CET 2020


From: Jacopo Mondi <jacopo at jmondi.org>

Define a fictional array control and register it in  the VIMC
pipeline handler. Add a test to exercise it.

Do not include, just a proof of concept. The test could be included once
we'll have real array controls defined.

Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
---
 src/libcamera/control_ids.yaml   |   5 ++
 src/libcamera/pipeline/vimc.cpp  |   5 ++
 test/controls/array_controls.cpp | 107 +++++++++++++++++++++++++++++++
 test/controls/meson.build        |   1 +
 4 files changed, 118 insertions(+)
 create mode 100644 test/controls/array_controls.cpp

diff --git a/src/libcamera/control_ids.yaml b/src/libcamera/control_ids.yaml
index 4befec746a59..14adb0dc78e8 100644
--- a/src/libcamera/control_ids.yaml
+++ b/src/libcamera/control_ids.yaml
@@ -50,4 +50,9 @@ controls:
       type: int32_t
       description: Specify a fixed gain parameter
 
+  - BayerGains:
+      type: float
+      description: Gains to apply to the four Bayer colour components for white balance
+      size: [4]
+
 ...
diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp
index 5d3d12fef30b..3fa4d222e06e 100644
--- a/src/libcamera/pipeline/vimc.cpp
+++ b/src/libcamera/pipeline/vimc.cpp
@@ -451,6 +451,11 @@ int VimcCameraData::init(MediaDevice *media)
 		ctrls.emplace(id, range);
 	}
 
+	/* Register a compound control. */
+	ctrls.emplace(std::piecewise_construct,
+		      std::forward_as_tuple(&controls::BayerGains),
+		      std::forward_as_tuple(0.5f, 4.0f));
+
 	controlInfo_ = std::move(ctrls);
 
 	/* Initialize the camera properties. */
diff --git a/test/controls/array_controls.cpp b/test/controls/array_controls.cpp
new file mode 100644
index 000000000000..b75219d82c37
--- /dev/null
+++ b/test/controls/array_controls.cpp
@@ -0,0 +1,107 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2019, Google Inc.
+ *
+ * array_controls.cpp - Array controls test
+ */
+
+#include <iostream>
+#include <typeinfo>
+#include <vector>
+
+#include <libcamera/camera.h>
+#include <libcamera/camera_manager.h>
+#include <libcamera/control_ids.h>
+#include <libcamera/controls.h>
+#include <libcamera/span.h>
+
+#include "camera_controls.h"
+
+#include "camera_test.h"
+#include "test.h"
+
+using namespace std;
+using namespace libcamera;
+
+class ArrayControlsTest : public CameraTest, public Test
+{
+public:
+	ArrayControlsTest()
+		: CameraTest("VIMC Sensor B")
+	{
+	}
+
+protected:
+	int init() override
+	{
+		return status_;
+	}
+
+	template<typename T, typename R>
+	int compareValues(const Span<T> &span, const R &value)
+	{
+		if (value.size() != span.size()) {
+			cerr << "set(" << typeid(T).name() << ") and get() dimension mismatch" << endl;
+			return TestFail;
+		}
+
+		for (unsigned int i = 0; i < value.size(); ++i) {
+			if (value[i] != span[i]) {
+				cerr << "set(" << typeid(T).name() << ") and get() value mismatch" << endl;
+				return TestFail;
+			}
+		}
+
+		return TestPass;
+	}
+
+	int run() override
+	{
+		CameraControlValidator validator(camera_.get());
+		ControlList list(controls::controls, &validator);
+
+		/*
+		 * Test array control get and set. set() is tested using
+		 * std::initializer_list, std::array, std::vector, and Span()
+		 * constructed from both an array and a vector as from a plain
+		 * C array. Const and non-const versions are compile-tested.
+		 */
+		constexpr float const_array[4] = { 1.1, 1.0, 1.2, 0.9 };
+		float array[4] = { 1.1, 1.0, 1.2, 0.9 };
+
+		list.set(controls::BayerGains, { 1.1f, 1.0f, 1.2f, 0.9f });
+		list.set(controls::BayerGains, Span<const float>(const_array));
+		list.set(controls::BayerGains, Span<float>(array));
+		list.set(controls::BayerGains, const_array);
+		list.set(controls::BayerGains, array);
+
+		if (compareValues(list.get(controls::BayerGains), Span<const float>(array)) == TestFail)
+			return TestFail;
+
+		constexpr std::array<float, 4> const_std_array{ 1.3, 0.9, 1.5, 0.8 };
+		std::array<float, 4> std_array{ 1.3, 0.9, 1.5, 0.8 };
+
+		list.set(controls::BayerGains, Span<const float>(const_std_array));
+		list.set(controls::BayerGains, Span<float>(std_array));
+		list.set(controls::BayerGains, const_std_array);
+		list.set(controls::BayerGains, std_array);
+
+		if (compareValues(list.get(controls::BayerGains), std_array) == TestFail)
+			return TestFail;
+
+		const std::vector<float> const_vector{ 1.0, 1.0, 1.0, 1.0 };
+		std::vector<float> vector{ 1.0, 1.0, 1.0, 1.0 };
+
+		list.set(controls::BayerGains, Span<const float>(const_vector));
+		list.set(controls::BayerGains, Span<float>(vector));
+		list.set(controls::BayerGains, const_vector);
+		list.set(controls::BayerGains, vector);
+
+		if (compareValues(list.get(controls::BayerGains), const_vector) == TestFail)
+			return TestFail;
+
+		return TestPass;
+	}
+};
+
+TEST_REGISTER(ArrayControlsTest)
diff --git a/test/controls/meson.build b/test/controls/meson.build
index f0850df28c8a..9d9b6ed1d666 100644
--- a/test/controls/meson.build
+++ b/test/controls/meson.build
@@ -1,4 +1,5 @@
 control_tests = [
+    [ 'array_controls', 'array_controls.cpp'],
     [ 'control_info',   'control_info.cpp' ],
     [ 'control_list',   'control_list.cpp' ],
     [ 'control_range',  'control_range.cpp' ],
-- 
Regards,

Laurent Pinchart



More information about the libcamera-devel mailing list