Patch Detail
Show a patch.
GET /api/1.1/patches/1649/?format=api
{ "id": 1649, "url": "https://patchwork.libcamera.org/api/1.1/patches/1649/?format=api", "web_url": "https://patchwork.libcamera.org/patch/1649/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/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": "<20190710191708.13049-6-laurent.pinchart@ideasonboard.com>", "date": "2019-07-10T19:17:08", "name": "[libcamera-devel,6/6] test: Add test case for signal delivery across threads", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "caf55c7f24acf021804bb79363bc512192e04285", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/1649/mbox/", "series": [ { "id": 414, "url": "https://patchwork.libcamera.org/api/1.1/series/414/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=414", "date": "2019-07-10T19:17:03", "name": "[libcamera-devel,1/6] libcamera: Add thread support", "version": 1, "mbox": "https://patchwork.libcamera.org/series/414/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/1649/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/1649/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 DBF9C6156E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 10 Jul 2019 21:17:49 +0200 (CEST)", "from pendragon.ideasonboard.com (softbank126163157105.bbtec.net\n\t[126.163.157.105])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8A4BC54B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 10 Jul 2019 21:17:48 +0200 (CEST)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1562786269;\n\tbh=CK8a7gmWvZY09dYumDGB1As4oCZj7stHZcbwYbdrBgA=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=adpfBEYRKtP/Yf94fR7yVkTetKSnWV0MkitRO8dAyxK0e8kI3xxAbi3AMKNCl3g/o\n\t7ySUkl37ybhd/EpjYFXx6iXBMP7VAW32Qmgn4zANx/KyDKUcl6W1TWfK4zKEL/vCE1\n\tI6ZOimE7G+YEOF3n1ThfhOFnjxRAc/2mvMGFFHJk=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 10 Jul 2019 22:17:08 +0300", "Message-Id": "<20190710191708.13049-6-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.21.0", "In-Reply-To": "<20190710191708.13049-1-laurent.pinchart@ideasonboard.com>", "References": "<20190710191708.13049-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 6/6] test: Add test case for signal\n\tdelivery across threads", "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": "Wed, 10 Jul 2019 19:17:50 -0000" }, "content": "The test case creates a receiver inheriting from Object, connects a\nsignal to one of its slot, moves the receiver to a different thread,\nemits the signal and verifies that it gets delivered in the correct\nthread with the expected value.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n test/meson.build | 1 +\n test/signal-threads.cpp | 125 ++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 126 insertions(+)\n create mode 100644 test/signal-threads.cpp", "diff": "diff --git a/test/meson.build b/test/meson.build\nindex 1f87319aeb65..60ce9601cc55 100644\n--- a/test/meson.build\n+++ b/test/meson.build\n@@ -22,6 +22,7 @@ public_tests = [\n internal_tests = [\n ['camera-sensor', 'camera-sensor.cpp'],\n ['message', 'message.cpp'],\n+ ['signal-threads', 'signal-threads.cpp'],\n ['threads', 'threads.cpp'],\n ]\n \ndiff --git a/test/signal-threads.cpp b/test/signal-threads.cpp\nnew file mode 100644\nindex 000000000000..c21f32ae0c20\n--- /dev/null\n+++ b/test/signal-threads.cpp\n@@ -0,0 +1,125 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * signal-threads.cpp - Cross-thread signal delivery test\n+ */\n+\n+#include <chrono>\n+#include <iostream>\n+#include <thread>\n+\n+#include \"message.h\"\n+#include \"thread.h\"\n+#include \"test.h\"\n+#include \"utils.h\"\n+\n+using namespace std;\n+using namespace libcamera;\n+\n+class SignalReceiver : public Object\n+{\n+public:\n+\tenum Status {\n+\t\tNoSignal,\n+\t\tInvalidThread,\n+\t\tSignalReceived,\n+\t};\n+\n+\tSignalReceiver()\n+\t\t: status_(NoSignal)\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_ = NoSignal;\n+\t\tvalue_ = 0;\n+\t}\n+\n+\tvoid slot(int value)\n+\t{\n+\t\tif (Thread::current() != thread())\n+\t\t\tstatus_ = InvalidThread;\n+\t\telse\n+\t\t\tstatus_ = SignalReceived;\n+\n+\t\tvalue_ = value;\n+\t}\n+\n+private:\n+\tStatus status_;\n+\tint value_;\n+};\n+\n+class SignalThreadsTest : public Test\n+{\n+protected:\n+\tint run()\n+\t{\n+\t\tSignalReceiver receiver;\n+\t\tsignal_.connect(&receiver, &SignalReceiver::slot);\n+\n+\t\t/* Test that a signal is received in the main thread. */\n+\t\tsignal_.emit(42);\n+\n+\t\tswitch (receiver.status()) {\n+\t\tcase SignalReceiver::NoSignal:\n+\t\t\tcout << \"No signal received for direct connection\" << endl;\n+\t\t\treturn TestFail;\n+\t\tcase SignalReceiver::InvalidThread:\n+\t\t\tcout << \"Signal received in incorrect thread \"\n+\t\t\t\t\"for direct connection\" << endl;\n+\t\t\treturn TestFail;\n+\t\tdefault:\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Move the object to a thread and verify that the signal is\n+\t\t * correctly delivered, with the correct data.\n+\t\t */\n+\t\treceiver.reset();\n+\t\treceiver.moveToThread(&thread_);\n+\n+\t\tthread_.start();\n+\n+\t\tsignal_.emit(42);\n+\n+\t\tthis_thread::sleep_for(chrono::milliseconds(100));\n+\n+\t\tswitch (receiver.status()) {\n+\t\tcase SignalReceiver::NoSignal:\n+\t\t\tcout << \"No signal received for message connection\" << endl;\n+\t\t\treturn TestFail;\n+\t\tcase SignalReceiver::InvalidThread:\n+\t\t\tcout << \"Signal received in incorrect thread \"\n+\t\t\t\t\"for message connection\" << endl;\n+\t\t\treturn TestFail;\n+\t\tdefault:\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (receiver.value() != 42) {\n+\t\t\tcout << \"Signal received with incorrect value\" << 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+\tSignal<int> signal_;\n+};\n+\n+TEST_REGISTER(SignalThreadsTest)\n", "prefixes": [ "libcamera-devel", "6/6" ] }