Patch Detail
Show a patch.
GET /api/patches/1826/?format=api
{ "id": 1826, "url": "https://patchwork.libcamera.org/api/patches/1826/?format=api", "web_url": "https://patchwork.libcamera.org/patch/1826/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "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-9-laurent.pinchart@ideasonboard.com>", "date": "2019-08-17T15:20:54", "name": "[libcamera-devel,v2,08/18] test: Add Object::invokeMethod() test", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "3f9f1a8020c7808dc756ed7fdb69ad0f9cc8c5a8", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/1826/mbox/", "series": [ { "id": 463, "url": "https://patchwork.libcamera.org/api/series/463/?format=api", "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/1826/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/1826/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 DD1AB61932\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 17 Aug 2019 17:21:15 +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 778B7556\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 17 Aug 2019 17:21:15 +0200 (CEST)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1566055275;\n\tbh=5I5e4OvS/sL/8yEUrXmn1WlovVKSeJ58DKzXdqlmXXc=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=csJD5mMuohY1Gm9LQRsCH9/QU2bV8ObPCcsfWzSJsZ6X7+7xfgyKpbXn9vWEFvGU9\n\tn1AuYG2KLqesd01xLXST3y/WURGpp28SOKKsYNBm5DVYMqA50OoQVuGerq/3Q37eIs\n\tEukqFevBfKTLJDIooG1yv+xjYFpmAN2t/EisAKjM=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Sat, 17 Aug 2019 18:20:54 +0300", "Message-Id": "<20190817152104.10834-9-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-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 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": "Sat, 17 Aug 2019 15:21:17 -0000" }, "content": "The test verifies correct behaviour of asynchronous method invocation\nfor Object instances.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\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", "v2", "08/18" ] }