[libcamera-devel] [PATCH v3 10/13] test: Add timeline test
Niklas Söderlund
niklas.soderlund at ragnatech.se
Fri Sep 27 04:44:14 CEST 2019
Add a test of the timeline to make sure events fire and the estimated
frame interval are OK.
Signed-off-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
---
test/meson.build | 1 +
test/timeline.cpp | 97 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 98 insertions(+)
create mode 100644 test/timeline.cpp
diff --git a/test/meson.build b/test/meson.build
index 84722cceb35db86e..6a4c4cd373043469 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -28,6 +28,7 @@ internal_tests = [
['object-invoke', 'object-invoke.cpp'],
['signal-threads', 'signal-threads.cpp'],
['threads', 'threads.cpp'],
+ ['timeline', 'timeline.cpp'],
['timer', 'timer.cpp'],
['timer-thread', 'timer-thread.cpp'],
]
diff --git a/test/timeline.cpp b/test/timeline.cpp
new file mode 100644
index 0000000000000000..55b651b455a07ffc
--- /dev/null
+++ b/test/timeline.cpp
@@ -0,0 +1,97 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2019, Google Inc.
+ *
+ * timeline.cpp - Timeline test
+ */
+
+#include <chrono>
+#include <iostream>
+#include <unistd.h>
+
+#include <libcamera/event_dispatcher.h>
+
+#include "test.h"
+#include "thread.h"
+#include "timeline.h"
+
+using namespace std;
+using namespace libcamera;
+
+enum TimelineTestActionType {
+ Inc,
+};
+
+class IncrementAction : public FrameAction
+{
+public:
+ IncrementAction(unsigned int frame, unsigned int *counter)
+ : FrameAction(Inc, frame), counter_(counter)
+ {
+ }
+
+ void run() override
+ {
+ (*counter_)++;
+ }
+
+private:
+ unsigned int *counter_;
+};
+
+class TimelineTest : public Test
+{
+public:
+ void fakeSOE()
+ {
+ timeline_.notifyStartOfExposure(sequence_++,
+ std::chrono::steady_clock::now());
+ }
+
+ int init()
+ {
+ sequence_ = 0;
+ return 0;
+ }
+
+ int run()
+ {
+ EventDispatcher *dispatcher = Thread::current()->eventDispatcher();
+ unsigned int loops, counter;
+ Timer timer;
+
+ /*
+ * Run frames and make sure an event is fired for each and that
+ * the messured frame interval is true.
+ */
+ loops = 500;
+ counter = 0;
+ for (unsigned int i = 0; i < loops; i++) {
+ timeline_.scheduleAction(new IncrementAction(i + 1, &counter));
+ fakeSOE();
+ timer.start(10);
+ while (timer.isRunning())
+ dispatcher->processEvents();
+ }
+
+ cout << "Got " << counter << " evens, expected " << loops - 1 << endl;
+ if (counter != loops - 1)
+ return TestFail;
+
+ unsigned int interval = std::chrono::duration_cast<std::chrono::milliseconds>(timeline_.frameInterval()).count();
+ cout << "Messured frame interval " << interval << " expected 10" << endl;
+ if (interval != 10)
+ return TestFail;
+
+ return TestPass;
+ }
+
+ void cleanup()
+ {
+ }
+private:
+ unsigned int sequence_;
+ Timeline timeline_;
+};
+
+TEST_REGISTER(TimelineTest)
--
2.23.0
More information about the libcamera-devel
mailing list