{"id":159,"url":"https://patchwork.libcamera.org/api/patches/159/?format=json","web_url":"https://patchwork.libcamera.org/patch/159/","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":"<20190106023328.10989-10-laurent.pinchart@ideasonboard.com>","date":"2019-01-06T02:33:27","name":"[libcamera-devel,10/11] test: Add timer test","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"3952fcc526f249801c0e020bd5fdfecd2ab05c0b","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/159/mbox/","series":[{"id":53,"url":"https://patchwork.libcamera.org/api/series/53/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=53","date":"2019-01-06T02:33:18","name":"[libcamera-devel,01/11] libcamera: log: Add a LogFatal log level","version":1,"mbox":"https://patchwork.libcamera.org/series/53/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/159/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/159/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 2896460B45\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  6 Jan 2019 03:32:30 +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 B74CA99A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  6 Jan 2019 03:32:29 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1546741949;\n\tbh=VNMkZIqq5U/OE47VJFWGJVOH6e/51C9z3VfVxO8AZgo=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=lYnUDzsJqhH+8C7uJTJYw2ib8qUEUOPsq7CndUktSTHe75h3mup9rH1/CpFnSCC5m\n\twx3WNIA+wPYQtOdVWgpYiw+IXe9qsade5aj8b7r9Dghpb8GL/s7UgbU8BXx75bNe1/\n\tdp2h8/gfKgu+qXC8/bEOAcmbiHO7ILRMECJy11lY=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Sun,  6 Jan 2019 04:33:27 +0200","Message-Id":"<20190106023328.10989-10-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.19.2","In-Reply-To":"<20190106023328.10989-1-laurent.pinchart@ideasonboard.com>","References":"<20190106023328.10989-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 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":"Sun, 06 Jan 2019 02:32:30 -0000"},"content":"Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\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 4d334025f3d3..12e7b30d4f73 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.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","10/11"]}