{"id":174,"url":"https://patchwork.libcamera.org/api/patches/174/?format=json","web_url":"https://patchwork.libcamera.org/patch/174/","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":"<20190107231151.23291-12-laurent.pinchart@ideasonboard.com>","date":"2019-01-07T23:11:51","name":"[libcamera-devel,v2,11/11] test: Add event notifier test","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"81334bdc3a1f9d5fa6edc1da50c46e85cdba8e1a","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/174/mbox/","series":[{"id":56,"url":"https://patchwork.libcamera.org/api/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/174/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/174/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 C11F860B50\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 5B20117CF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  8 Jan 2019 00:10:51 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1546902651;\n\tbh=HNfymYSEmXhYJ09QR+EBjEfNVr259lR2sHWY52LI+38=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=Pd0kGO41oTSbv7O4ItrVtF+JeJ/5/1MICrXtGxLW5jDV2s+MgO9a3hGaUqxL3Yjf+\n\thsGT1kHSsfd2D1T+ljJeWg7gRXo5K8Kt8SukUBsdjbXIPuBNj5ugEENSaqiFHIgl4V\n\tj3bCPi3/vX/IY+iNWTyUv/A+8WClDV3Rb5wYOk1o=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue,  8 Jan 2019 01:11:51 +0200","Message-Id":"<20190107231151.23291-12-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 11/11] test: Add event notifier 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/event.cpp   | 117 +++++++++++++++++++++++++++++++++++++++++++++++\n test/meson.build |   1 +\n 2 files changed, 118 insertions(+)\n create mode 100644 test/event.cpp","diff":"diff --git a/test/event.cpp b/test/event.cpp\nnew file mode 100644\nindex 000000000000..52bc0c7e77f5\n--- /dev/null\n+++ b/test/event.cpp\n@@ -0,0 +1,117 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * event.cpp - Event test\n+ */\n+\n+#include <iostream>\n+#include <string.h>\n+#include <unistd.h>\n+\n+#include <libcamera/camera_manager.h>\n+#include <libcamera/event_dispatcher.h>\n+#include <libcamera/event_notifier.h>\n+#include <libcamera/timer.h>\n+\n+#include \"test.h\"\n+\n+using namespace std;\n+using namespace libcamera;\n+\n+class EventTest : public Test\n+{\n+protected:\n+\tvoid readReady(EventNotifier *notifier)\n+\t{\n+\t\tsize_ = read(notifier->fd(), data_, sizeof(data_));\n+\t\tnotified_ = true;\n+\t}\n+\n+\tint init()\n+\t{\n+\t\treturn pipe(pipefd_);\n+\t}\n+\n+\tint run()\n+\t{\n+\t\tEventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher();\n+\t\tstd::string data(\"H2G2\");\n+\t\tTimer timeout;\n+\n+\t\tEventNotifier readNotifier(pipefd_[0], EventNotifier::Read);\n+\t\treadNotifier.activated.connect(this, &EventTest::readReady);\n+\n+\t\t/* Test read notification with data. */\n+\t\tmemset(data_, 0, sizeof(data_));\n+\t\tsize_ = 0;\n+\n+\t\twrite(pipefd_[1], data.data(), data.size());\n+\n+\t\ttimeout.start(100);\n+\t\tdispatcher->processEvents();\n+\t\ttimeout.stop();\n+\n+\t\tif (static_cast<size_t>(size_) != data.size()) {\n+\t\t\tcout << \"Event notifier read ready test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Test read notification without data. */\n+\t\tnotified_ = false;\n+\n+\t\ttimeout.start(100);\n+\t\tdispatcher->processEvents();\n+\t\ttimeout.stop();\n+\n+\t\tif (notified_) {\n+\t\t\tcout << \"Event notifier read no ready test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Test read notifier disabling. */\n+\t\tnotified_ = false;\n+\t\treadNotifier.setEnabled(false);\n+\n+\t\twrite(pipefd_[1], data.data(), data.size());\n+\n+\t\ttimeout.start(100);\n+\t\tdispatcher->processEvents();\n+\t\ttimeout.stop();\n+\n+\t\tif (notified_) {\n+\t\t\tcout << \"Event notifier read disabling failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Test read notifier enabling. */\n+\t\tnotified_ = false;\n+\t\treadNotifier.setEnabled(true);\n+\n+\t\ttimeout.start(100);\n+\t\tdispatcher->processEvents();\n+\t\ttimeout.stop();\n+\n+\t\tif (!notified_) {\n+\t\t\tcout << \"Event notifier read enabling 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\tclose(pipefd_[0]);\n+\t\tclose(pipefd_[1]);\n+\t}\n+\n+private:\n+\tint pipefd_[2];\n+\n+\tbool notified_;\n+\tchar data_[16];\n+\tssize_t size_;\n+};\n+\n+TEST_REGISTER(EventTest)\ndiff --git a/test/meson.build b/test/meson.build\nindex f26c8701d827..32152888a55e 100644\n--- a/test/meson.build\n+++ b/test/meson.build\n@@ -3,6 +3,7 @@ subdir('libtest')\n subdir('media_device')\n \n public_tests = [\n+    ['event',           'event.cpp'],\n     ['list-cameras',    'list-cameras.cpp'],\n     ['signal',          'signal.cpp'],\n     ['timer',           'timer.cpp'],\n","prefixes":["libcamera-devel","v2","11/11"]}