[libcamera-devel] [PATCH v5 3/7] tests: delayed_controls: Add cookie tests
Naushir Patuck
naush at raspberrypi.com
Mon Oct 31 12:45:18 CET 2022
Add a test for passing and returning cookie values in DelayedControls.
Add a test to simulate frame skips ensuring cookie values are returned
correctly.
Signed-off-by: Naushir Patuck <naush at raspberrypi.com>
Reviewed-by: David Plowman <david.plowman at raspberrypi.com>
---
test/delayed_controls.cpp | 97 +++++++++++++++++++++++++++++++++++++++
1 file changed, 97 insertions(+)
diff --git a/test/delayed_controls.cpp b/test/delayed_controls.cpp
index 26037268f245..387958a339a2 100644
--- a/test/delayed_controls.cpp
+++ b/test/delayed_controls.cpp
@@ -267,6 +267,93 @@ protected:
return TestPass;
}
+ int cookieValue()
+ {
+ std::unordered_map<uint32_t, DelayedControls::ControlParams> delays = {
+ { V4L2_CID_BRIGHTNESS, { 1, false } },
+ };
+ std::unique_ptr<DelayedControls> delayed =
+ std::make_unique<DelayedControls>(dev_.get(), delays);
+ ControlList ctrls;
+
+ /* Set a cookie to the reset value. */
+ const unsigned int startCookie = 0x1234;
+ ctrls.set(V4L2_CID_BRIGHTNESS, 1);
+ dev_->setControls(&ctrls);
+ delayed->reset(startCookie);
+
+ /* Trigger the first frame start event */
+ delayed->applyControls(0);
+
+ for (unsigned int i = 1; i < 100; i++) {
+ ctrls.set(V4L2_CID_BRIGHTNESS, 1);
+ delayed->push(ctrls, startCookie + i);
+
+ delayed->applyControls(i);
+
+ auto [result, cookie] = delayed->get(i);
+ unsigned int expected = startCookie + i - 1;
+ if (cookie != expected) {
+ cerr << "Failed cookie value"
+ << " frame " << i
+ << " expected cookie " << expected
+ << " got cookie " << cookie
+ << endl;
+ return TestFail;
+ }
+ }
+
+ return TestPass;
+ }
+
+ int cookieSkip()
+ {
+ std::unordered_map<uint32_t, DelayedControls::ControlParams> delays = {
+ { V4L2_CID_BRIGHTNESS, { 1, false } },
+ };
+ std::unique_ptr<DelayedControls> delayed =
+ std::make_unique<DelayedControls>(dev_.get(), delays);
+ ControlList ctrls;
+
+ /* Set a cookie to the reset value. */
+ unsigned int cookie = 0x1234;
+ ctrls.set(V4L2_CID_BRIGHTNESS, 1);
+ dev_->setControls(&ctrls);
+ delayed->reset(cookie);
+
+ /* Trigger the first frame start event */
+ delayed->applyControls(0);
+
+ unsigned int expected = cookie++;
+ for (unsigned int i = 1; i < 100; i++) {
+ /*
+ * Send a control for 2 out of every 3 frames, simulating
+ * some frame skips.
+ */
+ if (i % 3) {
+ ctrls.set(V4L2_CID_BRIGHTNESS, 1);
+ delayed->push(ctrls, cookie);
+ }
+
+ delayed->applyControls(i);
+
+ auto [result, getCookie] = delayed->get(i);
+ if (expected != getCookie) {
+ cerr << "Failed cookie value"
+ << " frame " << i
+ << " expected cookie " << expected
+ << " got cookie " << getCookie
+ << endl;
+ return TestFail;
+ }
+
+ if (i % 3)
+ expected = cookie++;
+ }
+
+ return TestPass;
+ }
+
int run() override
{
int ret;
@@ -291,6 +378,16 @@ protected:
if (ret)
return ret;
+ /* Test cookie values. */
+ ret = cookieValue();
+ if (ret)
+ return ret;
+
+ /* Test cookie values with frame skips. */
+ ret = cookieSkip();
+ if (ret)
+ return ret;
+
return TestPass;
}
--
2.25.1
More information about the libcamera-devel
mailing list