{"id":173,"url":"https://patchwork.libcamera.org/api/1.1/patches/173/?format=json","web_url":"https://patchwork.libcamera.org/patch/173/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20190107231151.23291-11-laurent.pinchart@ideasonboard.com>","date":"2019-01-07T23:11:50","name":"[libcamera-devel,v2,10/11] test: Add timer test","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"84b0db2856c666d63e597a9ff628db45af6d88c8","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/173/mbox/","series":[{"id":56,"url":"https://patchwork.libcamera.org/api/1.1/series/56/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=56","date":"2019-01-07T23:11:40","name":"libcamera: Add event notification and timers","version":2,"mbox":"https://patchwork.libcamera.org/series/56/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/173/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/173/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6DC2E60B3B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  8 Jan 2019 00:10:51 +0100 (CET)","from avalon.bb.dnainternet.fi\n\t(dfj612ybrt5fhg77mgycy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0C81D530\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  8 Jan 2019 00:10:50 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1546902651;\n\tbh=EFC44LTYh6j6cf8EntrQmYs5h81lgV/hX2CyS04vst4=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=e7gulBaor8unftMQ1vxzhjy9GVC0qUpc1fVRKYcVhy2qvEY6tmglmPfjg7u9hS0sn\n\tMeZ/S/G79kQrs/2hN6/+CLv13Jbu+Kk6G2ICM3vXpHp4/+KP2/pPCccA+upC51G3Wx\n\t/7pW+layo+TjVvBDKEX6m7eYXQH2awqGCp91eono=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue,  8 Jan 2019 01:11:50 +0200","Message-Id":"<20190107231151.23291-11-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.19.2","In-Reply-To":"<20190107231151.23291-1-laurent.pinchart@ideasonboard.com>","References":"<20190107231151.23291-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 10/11] test: Add timer test","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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":"Mon, 07 Jan 2019 23:10:51 -0000"},"content":"Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n test/meson.build |   1 +\n test/timer.cpp   | 149 +++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 150 insertions(+)\n create mode 100644 test/timer.cpp","diff":"diff --git a/test/meson.build b/test/meson.build\nindex 4000bd51808a..f26c8701d827 100644\n--- a/test/meson.build\n+++ b/test/meson.build\n@@ -5,6 +5,7 @@ subdir('media_device')\n public_tests = [\n     ['list-cameras',    'list-cameras.cpp'],\n     ['signal',          'signal.cpp'],\n+    ['timer',           'timer.cpp'],\n ]\n \n internal_tests = [\ndiff --git a/test/timer.cpp b/test/timer.cpp\nnew file mode 100644\nindex 000000000000..6a3cda70bef4\n--- /dev/null\n+++ b/test/timer.cpp\n@@ -0,0 +1,149 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * timer.cpp - Timer test\n+ */\n+\n+#include <iostream>\n+\n+#include <libcamera/camera_manager.h>\n+#include <libcamera/event_dispatcher.h>\n+#include <libcamera/timer.h>\n+\n+#include \"test.h\"\n+\n+using namespace std;\n+using namespace libcamera;\n+\n+class ManagedTimer : public Timer\n+{\n+public:\n+\tManagedTimer() : Timer()\n+\t{\n+\t\ttimeout.connect(this, &ManagedTimer::timeoutHandler);\n+\t}\n+\n+\tvoid start(int msec)\n+\t{\n+\t\tinterval_ = msec;\n+\t\tclock_gettime(CLOCK_MONOTONIC, &start_);\n+\t\texpiration_ = { 0, 0 };\n+\n+\t\tTimer::start(msec);\n+\t}\n+\n+\tint jitter()\n+\t{\n+\t\tint duration = (expiration_.tv_sec - start_.tv_sec) * 1000;\n+\t\tduration += (expiration_.tv_nsec - start_.tv_nsec) / 1000000;\n+\t\treturn abs(duration - interval_);\n+\t}\n+\n+private:\n+\tvoid timeoutHandler(Timer *timer)\n+\t{\n+\t\tclock_gettime(CLOCK_MONOTONIC, &expiration_);\n+\t}\n+\n+\tint interval_;\n+\tstruct timespec start_;\n+\tstruct timespec expiration_;\n+};\n+\n+class TimerTest : public Test\n+{\n+protected:\n+\tint init()\n+\t{\n+\t\treturn 0;\n+\t}\n+\n+\tint run()\n+\t{\n+\t\tEventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher();\n+\t\tManagedTimer timer;\n+\t\tManagedTimer timer2;\n+\n+\t\t/* Timer expiration. */\n+\t\ttimer.start(1000);\n+\n+\t\tif (!timer.isRunning()) {\n+\t\t\tcout << \"Timer expiration test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tdispatcher->processEvents();\n+\n+\t\tif (timer.isRunning() || timer.jitter() > 50) {\n+\t\t\tcout << \"Timer expiration test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Timer restart. */\n+\t\ttimer.start(500);\n+\n+\t\tif (!timer.isRunning()) {\n+\t\t\tcout << \"Timer restart test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tdispatcher->processEvents();\n+\n+\t\tif (timer.isRunning() || timer.jitter() > 50) {\n+\t\t\tcout << \"Timer restart test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Two timers. */\n+\t\ttimer.start(1000);\n+\t\ttimer2.start(300);\n+\n+\t\tdispatcher->processEvents();\n+\n+\t\tif (!timer.isRunning()) {\n+\t\t\tcout << \"Two timers test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (timer2.jitter() > 50) {\n+\t\t\tcout << \"Two timers test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tdispatcher->processEvents();\n+\n+\t\tif (timer.jitter() > 50) {\n+\t\t\tcout << \"Two timers test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Restart timer before expiration. */\n+\t\ttimer.start(1000);\n+\t\ttimer2.start(300);\n+\n+\t\tdispatcher->processEvents();\n+\n+\t\tif (timer2.jitter() > 50) {\n+\t\t\tcout << \"Two timers test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\ttimer.start(1000);\n+\n+\t\tdispatcher->processEvents();\n+\n+\t\tif (timer.jitter() > 50) {\n+\t\t\tcout << \"Two timers test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\treturn TestPass;\n+\t}\n+\n+\tvoid cleanup()\n+\t{\n+\t}\n+};\n+\n+TEST_REGISTER(TimerTest)\n","prefixes":["libcamera-devel","v2","10/11"]}