{"id":1786,"url":"https://patchwork.libcamera.org/api/patches/1786/?format=json","web_url":"https://patchwork.libcamera.org/patch/1786/","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":"<20190812124642.24287-9-laurent.pinchart@ideasonboard.com>","date":"2019-08-12T12:46:32","name":"[libcamera-devel,08/18] test: Add Object::invokeMethod() test","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"3f9f1a8020c7808dc756ed7fdb69ad0f9cc8c5a8","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/1786/mbox/","series":[{"id":455,"url":"https://patchwork.libcamera.org/api/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/1786/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1786/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 ED8226162C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Aug 2019 14:46:51 +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 81915327\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Aug 2019 14:46:51 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1565614011;\n\tbh=kmVYcc9nis1ryUT0ovS1IW2Zz7iLEbw0YytBD+VbYH4=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=Um/h2NY41mVPKpC079eRhc/OSEr2oVWI1NR5md5zqFGZLjGKaVlSdBhVTzfnxxdv3\n\toEPoUrVTbSwmBBdWUOyjMvTarqw1KezwsR9ytAdzxHe7mcCa1TZeB7q4vsuqyucXvG\n\tvDs44fiBlLeL4j8Q4ngWBPXPdsi5q2CeS3pFBf4s=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 12 Aug 2019 15:46:32 +0300","Message-Id":"<20190812124642.24287-9-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 08/18] test: Add Object::invokeMethod()\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:53 -0000"},"content":"The test verifies correct behaviour of asynchronous method invocation\nfor Object instances.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n test/meson.build       |   1 +\n test/object-invoke.cpp | 137 +++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 138 insertions(+)\n create mode 100644 test/object-invoke.cpp","diff":"diff --git a/test/meson.build b/test/meson.build\nindex b2f809e60986..7c9abc630230 100644\n--- a/test/meson.build\n+++ b/test/meson.build\n@@ -24,6 +24,7 @@ public_tests = [\n internal_tests = [\n     ['camera-sensor',                   'camera-sensor.cpp'],\n     ['message',                         'message.cpp'],\n+    ['object-invoke',                   'object-invoke.cpp'],\n     ['signal-threads',                  'signal-threads.cpp'],\n     ['threads',                         'threads.cpp'],\n ]\ndiff --git a/test/object-invoke.cpp b/test/object-invoke.cpp\nnew file mode 100644\nindex 000000000000..7221930f4380\n--- /dev/null\n+++ b/test/object-invoke.cpp\n@@ -0,0 +1,137 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * object-invoke.cpp - Cross-thread Object method invocation test\n+ */\n+\n+#include <chrono>\n+#include <iostream>\n+#include <thread>\n+\n+#include <libcamera/camera_manager.h>\n+#include <libcamera/event_dispatcher.h>\n+#include <libcamera/object.h>\n+\n+#include \"thread.h\"\n+#include \"test.h\"\n+\n+using namespace std;\n+using namespace libcamera;\n+\n+class InvokedObject : public Object\n+{\n+public:\n+\tenum Status {\n+\t\tNoCall,\n+\t\tInvalidThread,\n+\t\tCallReceived,\n+\t};\n+\n+\tInvokedObject()\n+\t\t: status_(NoCall)\n+\t{\n+\t}\n+\n+\tStatus status() const { return status_; }\n+\tint value() const { return value_; }\n+\tvoid reset()\n+\t{\n+\t\tstatus_ = NoCall;\n+\t\tvalue_ = 0;\n+\t}\n+\n+\tvoid method(int value)\n+\t{\n+\t\tif (Thread::current() != thread())\n+\t\t\tstatus_ = InvalidThread;\n+\t\telse\n+\t\t\tstatus_ = CallReceived;\n+\n+\t\tvalue_ = value;\n+\t}\n+\n+private:\n+\tStatus status_;\n+\tint value_;\n+};\n+\n+class ObjectInvokeTest : public Test\n+{\n+protected:\n+\tint run()\n+\t{\n+\t\tEventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher();\n+\t\tInvokedObject object;\n+\n+\t\t/*\n+\t\t * Test that method invocation in the same thread goes through\n+\t\t * the event dispatcher.\n+\t\t */\n+\t\tobject.invokeMethod(&InvokedObject::method, 42);\n+\n+\t\tif (object.status() != InvokedObject::NoCall) {\n+\t\t\tcerr << \"Method not invoked asynchronously\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tdispatcher->processEvents();\n+\n+\t\tswitch (object.status()) {\n+\t\tcase InvokedObject::NoCall:\n+\t\t\tcout << \"Method not invoked for main thread\" << endl;\n+\t\t\treturn TestFail;\n+\t\tcase InvokedObject::InvalidThread:\n+\t\t\tcout << \"Method invoked in incorrect thread for main thread\" << endl;\n+\t\t\treturn TestFail;\n+\t\tdefault:\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (object.value() != 42) {\n+\t\t\tcout << \"Method invoked with incorrect value for main thread\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Move the object to a thread and verify that the method is\n+\t\t * delivered in the correct thread.\n+\t\t */\n+\t\tobject.reset();\n+\t\tobject.moveToThread(&thread_);\n+\n+\t\tthread_.start();\n+\n+\t\tobject.invokeMethod(&InvokedObject::method, 42);\n+\t\tthis_thread::sleep_for(chrono::milliseconds(100));\n+\n+\t\tswitch (object.status()) {\n+\t\tcase InvokedObject::NoCall:\n+\t\t\tcout << \"Method not invoked for custom thread\" << endl;\n+\t\t\treturn TestFail;\n+\t\tcase InvokedObject::InvalidThread:\n+\t\t\tcout << \"Method invoked in incorrect thread for custom thread\" << endl;\n+\t\t\treturn TestFail;\n+\t\tdefault:\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (object.value() != 42) {\n+\t\t\tcout << \"Method invoked with incorrect value for custom thread\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\treturn TestPass;\n+\t}\n+\n+\tvoid cleanup()\n+\t{\n+\t\tthread_.exit(0);\n+\t\tthread_.wait();\n+\t}\n+\n+private:\n+\tThread thread_;\n+};\n+\n+TEST_REGISTER(ObjectInvokeTest)\n","prefixes":["libcamera-devel","08/18"]}