[libcamera-devel] [PATCH 14/21] test: serialization: Add V4L2ControlList serialization test
Jacopo Mondi
jacopo at jmondi.org
Tue Sep 24 19:24:56 CEST 2019
Add test to serialize and de-serialize a V4L2ControlList.
Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
---
test/serialization/meson.build | 1 +
test/serialization/v4l2_control_list.cpp | 114 +++++++++++++++++++++++
2 files changed, 115 insertions(+)
create mode 100644 test/serialization/v4l2_control_list.cpp
diff --git a/test/serialization/meson.build b/test/serialization/meson.build
index 510bd8c30d38..65ecdf2cf249 100644
--- a/test/serialization/meson.build
+++ b/test/serialization/meson.build
@@ -1,6 +1,7 @@
serialization_tests = [
[ 'control_list', 'control_list.cpp' ],
[ 'control_info_list', 'control_info_list.cpp' ],
+ [ 'v4l2_control_list', 'v4l2_control_list.cpp' ],
]
foreach t : serialization_tests
diff --git a/test/serialization/v4l2_control_list.cpp b/test/serialization/v4l2_control_list.cpp
new file mode 100644
index 000000000000..338ca4dadc78
--- /dev/null
+++ b/test/serialization/v4l2_control_list.cpp
@@ -0,0 +1,114 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2019, Google Inc.
+ *
+ * v4l2_control_list.cpp - Serialize and de-serialize a list of v4l2 controls
+ */
+
+#include <iostream>
+
+#include <libcamera/camera.h>
+#include <libcamera/camera_manager.h>
+#include <libcamera/controls.h>
+
+#include "test.h"
+#include "serializer.h"
+#include "serialization_test.h"
+#include "v4l2_controls.h"
+
+using namespace std;
+using namespace libcamera;
+
+class V4L2ControlListSerializeTest : public SerializationTest
+{
+private:
+ void initializeValidationMatrix()
+ {
+ valueValidationMatrix[0][0] = V4L2_CID_SATURATION;
+ valueValidationMatrix[0][1] = DataTypeInteger;
+ valueValidationMatrix[0][2] = 8;
+ valueValidationMatrix[0][3] = 50;
+ valueValidationMatrix[0][4] = false;
+ valueValidationMatrix[1][0] = V4L2_CID_CONTRAST;
+ valueValidationMatrix[1][1] = DataTypeInteger;
+ valueValidationMatrix[1][2] = 8;
+ valueValidationMatrix[1][3] = 128;
+ valueValidationMatrix[1][4] = false;
+ valueValidationMatrix[2][0] = V4L2_CID_BRIGHTNESS;
+ valueValidationMatrix[2][1] = DataTypeInteger;
+ valueValidationMatrix[2][2] = 8;
+ valueValidationMatrix[2][3] = 255;
+ valueValidationMatrix[2][4] = false;
+
+ numCtrls_ = 3;
+ }
+
+ int init()
+ {
+ int ret = SerializationTest::init();
+ if (ret != TestPass)
+ return ret;
+
+ ret = initSubdevice();
+ if (ret < 0)
+ return ret;
+
+ return TestPass;
+ }
+
+ int run()
+ {
+ V4L2ControlList controls;
+
+ controls.add(V4L2_CID_BRIGHTNESS, 255);
+ controls.add(V4L2_CID_CONTRAST, 128);
+ controls.add(V4L2_CID_SATURATION, 50);
+
+ int ret = sensor_->setControls(&controls);
+ if (ret) {
+ cerr << "Failed to set controls" << endl;
+ return ret;
+ }
+
+ initializeValidationMatrix();
+
+ /* Serialize and verify the produced blob size. */
+ std::unique_ptr<DataBlob> blob = controls.serialize();
+ if (!blob) {
+ cerr << "Failed to serialize the control list" << endl;
+ return TestFail;
+ }
+
+ ret = validateValueBlobSize(blob.get());
+ if (ret)
+ return ret;
+
+ /* Validate each serialized data value. */
+ uint8_t *b = blob->data();
+ for (unsigned int i = 0; i < numCtrls_; ++i) {
+ if (!validateValueBlob(b))
+ return TestFail;
+
+ b += VALUE_BLOB_SIZE;
+ }
+
+ /* De-serialize a control list and re-validate it. */
+ V4L2ControlList newList;
+ newList.deserialize(blob->data(), blob->size());
+ for (auto it : newList) {
+ if (!validateDataValue(it.id(), it))
+ return TestFail;
+ }
+
+ /* Does it still work when re-applied to a subdevice? */
+ ret = sensor_->setControls(&newList);
+ if (ret) {
+ cerr << "Failed to set controls" << endl;
+ return ret;
+ }
+
+ return TestPass;
+ }
+};
+
+TEST_REGISTER(V4L2ControlListSerializeTest)
--
2.23.0
More information about the libcamera-devel
mailing list