{"id":2090,"url":"https://patchwork.libcamera.org/api/patches/2090/?format=json","web_url":"https://patchwork.libcamera.org/patch/2090/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20191003174941.1296988-9-niklas.soderlund@ragnatech.se>","date":"2019-10-03T17:49:38","name":"[libcamera-devel,v4,08/11] test: Add timeline test","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"f33a0e17e078018518e2b8ccc7ca86087a710347","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/2090/mbox/","series":[{"id":516,"url":"https://patchwork.libcamera.org/api/series/516/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=516","date":"2019-10-03T17:49:31","name":"libcamera: ipa: Add basic IPA support","version":4,"mbox":"https://patchwork.libcamera.org/series/516/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/2090/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/2090/checks/","tags":{},"headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net\n\t[195.74.38.229])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4DB2A61925\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  3 Oct 2019 19:50:41 +0200 (CEST)","from bismarck.berto.se (unknown [84.172.88.101])\n\tby bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA\n\tid 33b48f9b-e606-11e9-837a-0050569116f7;\n\tThu, 03 Oct 2019 19:49:52 +0200 (CEST)"],"X-Halon-ID":"33b48f9b-e606-11e9-837a-0050569116f7","Authorized-sender":"niklas@soderlund.pp.se","From":"=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu,  3 Oct 2019 19:49:38 +0200","Message-Id":"<20191003174941.1296988-9-niklas.soderlund@ragnatech.se>","X-Mailer":"git-send-email 2.23.0","In-Reply-To":"<20191003174941.1296988-1-niklas.soderlund@ragnatech.se>","References":"<20191003174941.1296988-1-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 08/11] test: Add timeline test","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Thu, 03 Oct 2019 17:50:41 -0000"},"content":"Add a test of the timeline to make sure events fire and the estimated\nframe interval are OK.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n test/meson.build  |  1 +\n test/timeline.cpp | 97 +++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 98 insertions(+)\n create mode 100644 test/timeline.cpp","diff":"diff --git a/test/meson.build b/test/meson.build\nindex 84722cceb35db86e..6a4c4cd373043469 100644\n--- a/test/meson.build\n+++ b/test/meson.build\n@@ -28,6 +28,7 @@ internal_tests = [\n     ['object-invoke',                   'object-invoke.cpp'],\n     ['signal-threads',                  'signal-threads.cpp'],\n     ['threads',                         'threads.cpp'],\n+    ['timeline',                        'timeline.cpp'],\n     ['timer',                           'timer.cpp'],\n     ['timer-thread',                    'timer-thread.cpp'],\n ]\ndiff --git a/test/timeline.cpp b/test/timeline.cpp\nnew file mode 100644\nindex 0000000000000000..55b651b455a07ffc\n--- /dev/null\n+++ b/test/timeline.cpp\n@@ -0,0 +1,97 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * timeline.cpp - Timeline test\n+ */\n+\n+#include <chrono>\n+#include <iostream>\n+#include <unistd.h>\n+\n+#include <libcamera/event_dispatcher.h>\n+\n+#include \"test.h\"\n+#include \"thread.h\"\n+#include \"timeline.h\"\n+\n+using namespace std;\n+using namespace libcamera;\n+\n+enum TimelineTestActionType {\n+\tInc,\n+};\n+\n+class IncrementAction : public FrameAction\n+{\n+public:\n+\tIncrementAction(unsigned int frame, unsigned int *counter)\n+\t\t: FrameAction(Inc, frame), counter_(counter)\n+\t{\n+\t}\n+\n+\tvoid run() override\n+\t{\n+\t\t(*counter_)++;\n+\t}\n+\n+private:\n+\tunsigned int *counter_;\n+};\n+\n+class TimelineTest : public Test\n+{\n+public:\n+\tvoid fakeSOE()\n+\t{\n+\t\ttimeline_.notifyStartOfExposure(sequence_++,\n+\t\t\t\t\t\tstd::chrono::steady_clock::now());\n+\t}\n+\n+\tint init()\n+\t{\n+\t\tsequence_ = 0;\n+\t\treturn 0;\n+\t}\n+\n+\tint run()\n+\t{\n+\t\tEventDispatcher *dispatcher = Thread::current()->eventDispatcher();\n+\t\tunsigned int loops, counter;\n+\t\tTimer timer;\n+\n+\t\t/*\n+\t\t * Run frames and make sure an event is fired for each and that\n+\t\t * the messured frame interval is true.\n+\t\t */\n+\t\tloops = 500;\n+\t\tcounter = 0;\n+\t\tfor (unsigned int i = 0; i < loops; i++) {\n+\t\t\ttimeline_.scheduleAction(new IncrementAction(i + 1, &counter));\n+\t\t\tfakeSOE();\n+\t\t\ttimer.start(10);\n+\t\t\twhile (timer.isRunning())\n+\t\t\t\tdispatcher->processEvents();\n+\t\t}\n+\n+\t\tcout << \"Got \" << counter << \" evens, expected \" << loops - 1 << endl;\n+\t\tif (counter != loops - 1)\n+\t\t\treturn TestFail;\n+\n+\t\tunsigned int interval = std::chrono::duration_cast<std::chrono::milliseconds>(timeline_.frameInterval()).count();\n+\t\tcout << \"Messured frame interval \" << interval << \" expected 10\" << endl;\n+\t\tif (interval != 10)\n+\t\t\treturn TestFail;\n+\n+\t\treturn TestPass;\n+\t}\n+\n+\tvoid cleanup()\n+\t{\n+\t}\n+private:\n+\tunsigned int sequence_;\n+\tTimeline timeline_;\n+};\n+\n+TEST_REGISTER(TimelineTest)\n","prefixes":["libcamera-devel","v4","08/11"]}