{"id":1791,"url":"https://patchwork.libcamera.org/api/1.1/patches/1791/?format=json","web_url":"https://patchwork.libcamera.org/patch/1791/","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":"<20190812124642.24287-14-laurent.pinchart@ideasonboard.com>","date":"2019-08-12T12:46:37","name":"[libcamera-devel,13/18] test: Add EventNotifier thread move test","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"f531b6f7e112be40e47d9c9c60b4b1e6fae47f7f","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/1791/mbox/","series":[{"id":455,"url":"https://patchwork.libcamera.org/api/1.1/series/455/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=455","date":"2019-08-12T12:46:24","name":"Object & Thread enhancements","version":1,"mbox":"https://patchwork.libcamera.org/series/455/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1791/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1791/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 10E9461623\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Aug 2019 14:46:54 +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 9893A124E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Aug 2019 14:46:53 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1565614013;\n\tbh=VSXTWHfirqfgjeX+OumSYkxyH4jZlyyj00vsHloC1fE=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=rqKDMwoebnjrzJpwmOQ6b9+iGUpoYzYw8qTRMzw0B7dIVt+8uYV1zHpdzYBotV+tm\n\tA/7RPUzSv0Zt+ATwYoMqz5YSPyP5JaYCH3N4KnNxoU35GRYJLRZ6nEIyoXwSX0LNet\n\tXsv3YSOI/bGaGfkmvknRHtpOBB7dyVBQfSOgpvoI=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 12 Aug 2019 15:46:37 +0300","Message-Id":"<20190812124642.24287-14-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.21.0","In-Reply-To":"<20190812124642.24287-1-laurent.pinchart@ideasonboard.com>","References":"<20190812124642.24287-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 13/18] test: Add EventNotifier thread move\n\ttest","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, 12 Aug 2019 12:46:54 -0000"},"content":"The test verifies correct behaviour of an enabled event notifier moved\nto a different thread.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/event_notifier.cpp |   2 +-\n test/event-thread.cpp            | 112 +++++++++++++++++++++++++++++++\n test/meson.build                 |   1 +\n 3 files changed, 114 insertions(+), 1 deletion(-)\n create mode 100644 test/event-thread.cpp","diff":"diff --git a/src/libcamera/event_notifier.cpp b/src/libcamera/event_notifier.cpp\nindex 515e6d1770a1..96be27601982 100644\n--- a/src/libcamera/event_notifier.cpp\n+++ b/src/libcamera/event_notifier.cpp\n@@ -127,7 +127,7 @@ void EventNotifier::message(Message *msg)\n \tif (msg->type() == Message::ThreadMoveMessage) {\n \t\tif (enabled_) {\n \t\t\tsetEnabled(false);\n-\t\t\tinvokeMethod(this, &EventNotifier::setEnabled, true);\n+\t\t\tinvokeMethod(&EventNotifier::setEnabled, true);\n \t\t}\n \t}\n \ndiff --git a/test/event-thread.cpp b/test/event-thread.cpp\nnew file mode 100644\nindex 000000000000..4a82d49b94f1\n--- /dev/null\n+++ b/test/event-thread.cpp\n@@ -0,0 +1,112 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * event-thread.cpp - Threaded event test\n+ */\n+\n+#include <chrono>\n+#include <iostream>\n+#include <string.h>\n+#include <unistd.h>\n+\n+#include <libcamera/event_notifier.h>\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 EventHandler : public Object\n+{\n+public:\n+\tEventHandler()\n+\t{\n+\t\tpipe(pipefd_);\n+\n+\t\tnotifier_ = new EventNotifier(pipefd_[0], EventNotifier::Read);\n+\t\tnotifier_->activated.connect(this, &EventHandler::readReady);\n+\t}\n+\n+\t~EventHandler()\n+\t{\n+\t\tdelete notifier_;\n+\n+\t\tclose(pipefd_[0]);\n+\t\tclose(pipefd_[1]);\n+\t}\n+\n+\tint notify()\n+\t{\n+\t\tstd::string data(\"H2G2\");\n+\t\tssize_t ret;\n+\n+\t\tmemset(data_, 0, sizeof(data_));\n+\t\tsize_ = 0;\n+\n+\t\tret = write(pipefd_[1], data.data(), data.size());\n+\t\tif (ret < 0) {\n+\t\t\tcout << \"Pipe write failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\treturn TestPass;\n+\t}\n+\n+\tbool notified() const\n+\t{\n+\t\treturn notified_;\n+\t}\n+\n+\tvoid moveToThread(Thread *thread)\n+\t{\n+\t\tObject::moveToThread(thread);\n+\t\tnotifier_->moveToThread(thread);\n+\t}\n+\n+private:\n+\tvoid readReady(EventNotifier *notifier)\n+\t{\n+\t\tsize_ = read(notifier->fd(), data_, sizeof(data_));\n+\t\tnotified_ = true;\n+\t}\n+\n+\tEventNotifier *notifier_;\n+\n+\tint pipefd_[2];\n+\n+\tbool notified_;\n+\tchar data_[16];\n+\tssize_t size_;\n+};\n+\n+class EventThreadTest : public Test\n+{\n+protected:\n+\tint run()\n+\t{\n+\t\tThread thread;\n+\t\tthread.start();\n+\n+\t\tEventHandler handler;\n+\t\thandler.notify();\n+\t\thandler.moveToThread(&thread);\n+\n+\t\tthis_thread::sleep_for(chrono::milliseconds(100));\n+\n+\t\t/* Must stop thread before destroying the handler. */\n+\t\tthread.exit(0);\n+\t\tthread.wait();\n+\n+\t\tif (!handler.notified()) {\n+\t\t\tcout << \"Thread event handling test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\treturn TestPass;\n+\t}\n+};\n+\n+TEST_REGISTER(EventThreadTest)\ndiff --git a/test/meson.build b/test/meson.build\nindex c6601813db78..f695ffd7be44 100644\n--- a/test/meson.build\n+++ b/test/meson.build\n@@ -23,6 +23,7 @@ public_tests = [\n \n internal_tests = [\n     ['camera-sensor',                   'camera-sensor.cpp'],\n+    ['event-thread',                    'event-thread.cpp'],\n     ['message',                         'message.cpp'],\n     ['object',                          'object.cpp'],\n     ['object-invoke',                   'object-invoke.cpp'],\n","prefixes":["libcamera-devel","13/18"]}