{"id":1832,"url":"https://patchwork.libcamera.org/api/patches/1832/?format=json","web_url":"https://patchwork.libcamera.org/patch/1832/","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":"<20190817152104.10834-15-laurent.pinchart@ideasonboard.com>","date":"2019-08-17T15:21:00","name":"[libcamera-devel,v2,14/18] test: Add Timer thread move test","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"f323cd7b78b801ce58fd0e9efcad6719bb8d7321","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/1832/mbox/","series":[{"id":463,"url":"https://patchwork.libcamera.org/api/series/463/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=463","date":"2019-08-17T15:20:46","name":"Object & Thread enhancements","version":2,"mbox":"https://patchwork.libcamera.org/series/463/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1832/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1832/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0539261934\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 17 Aug 2019 17:21:18 +0200 (CEST)","from pendragon.bb.dnainternet.fi\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 954FC98C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 17 Aug 2019 17:21:17 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1566055277;\n\tbh=N1mhhFSYqEjSDQUGdhRRh64q6tkmDj+kG6oWe/dACsA=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=IlTDc8f6fhA4PQ0vSbKtncdI+5dmbApIVvfZ/0RrNu1u7/vfyrF+3f/8Xo+wLhnw1\n\tVjkR6BrW7tmm1yUyZMiCZOWSV3CjaddMtE1PtlDp/JSoBPGZVtE2TTTEbmtvFiAGS1\n\tmrJz6imz22HMf4s+KNDI6q11vU2f6i3k8Flwez10=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Sat, 17 Aug 2019 18:21:00 +0300","Message-Id":"<20190817152104.10834-15-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.21.0","In-Reply-To":"<20190817152104.10834-1-laurent.pinchart@ideasonboard.com>","References":"<20190817152104.10834-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 14/18] test: Add Timer thread move 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":"Sat, 17 Aug 2019 15:21:18 -0000"},"content":"The test verifies correct behaviour of a running timer moved to a\ndifferent thread.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n test/meson.build      |  1 +\n test/timer-thread.cpp | 78 +++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 79 insertions(+)\n create mode 100644 test/timer-thread.cpp","diff":"diff --git a/test/meson.build b/test/meson.build\nindex f695ffd7be44..05265b7d4976 100644\n--- a/test/meson.build\n+++ b/test/meson.build\n@@ -29,6 +29,7 @@ internal_tests = [\n     ['object-invoke',                   'object-invoke.cpp'],\n     ['signal-threads',                  'signal-threads.cpp'],\n     ['threads',                         'threads.cpp'],\n+    ['timer-thread',                    'timer-thread.cpp'],\n ]\n \n foreach t : public_tests\ndiff --git a/test/timer-thread.cpp b/test/timer-thread.cpp\nnew file mode 100644\nindex 000000000000..b9373050068c\n--- /dev/null\n+++ b/test/timer-thread.cpp\n@@ -0,0 +1,78 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * timer-thread.cpp - Threaded timer test\n+ */\n+\n+#include <chrono>\n+#include <iostream>\n+\n+#include <libcamera/timer.h>\n+\n+#include \"test.h\"\n+#include \"thread.h\"\n+\n+using namespace std;\n+using namespace libcamera;\n+\n+class TimeoutHandler : public Object\n+{\n+public:\n+\tTimeoutHandler()\n+\t\t: timeout_(false)\n+\t{\n+\t\ttimer_.timeout.connect(this, &TimeoutHandler::timeoutHandler);\n+\t\ttimer_.start(100);\n+\t}\n+\n+\tbool timeout() const\n+\t{\n+\t\treturn timeout_;\n+\t}\n+\n+\tvoid moveToThread(Thread *thread)\n+\t{\n+\t\tObject::moveToThread(thread);\n+\t\ttimer_.moveToThread(thread);\n+\t}\n+\n+private:\n+\tvoid timeoutHandler(Timer *timer)\n+\t{\n+\t\ttimeout_ = true;\n+\t}\n+\n+\tTimer timer_;\n+\tbool timeout_;\n+};\n+\n+class TimerThreadTest : public Test\n+{\n+protected:\n+\tint run()\n+\t{\n+\t\tThread thread;\n+\t\tthread.start();\n+\n+\t\tTimeoutHandler timeout;\n+\t\ttimeout.moveToThread(&thread);\n+\n+\t\tthis_thread::sleep_for(chrono::milliseconds(100));\n+\n+\t\t/* Must stop thread before destroying timeout. */\n+\t\tthread.exit(0);\n+\t\tthread.wait();\n+\n+\t\tif (!timeout.timeout()) {\n+\t\t\tcout << \"Timer expiration test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\treturn TestPass;\n+\t}\n+\n+private:\n+};\n+\n+TEST_REGISTER(TimerThreadTest)\n","prefixes":["libcamera-devel","v2","14/18"]}