{"id":12763,"url":"https://patchwork.libcamera.org/api/1.1/patches/12763/?format=json","web_url":"https://patchwork.libcamera.org/patch/12763/","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":"<20210701230741.14320-3-laurent.pinchart@ideasonboard.com>","date":"2021-07-01T23:07:40","name":"[libcamera-devel,2/3] test: message: Test recursive Thread::dispatchMessages() calls","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"f3f6ae8fce07991219cc19b396eb5c40b6f80166","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":{"id":14,"url":"https://patchwork.libcamera.org/api/1.1/users/14/?format=json","username":"pinchartl","first_name":"Laurent","last_name":"Pinchart","email":"laurent.pinchart@ideasonboard.com"},"mbox":"https://patchwork.libcamera.org/patch/12763/mbox/","series":[{"id":2198,"url":"https://patchwork.libcamera.org/api/1.1/series/2198/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2198","date":"2021-07-01T23:07:38","name":"base: Fix crash with recursive messages dispatch","version":1,"mbox":"https://patchwork.libcamera.org/series/2198/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/12763/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/12763/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 71A4EC3222\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  1 Jul 2021 23:08:32 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 452C9684FA;\n\tFri,  2 Jul 2021 01:08:31 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 439D8684E4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  2 Jul 2021 01:08:26 +0200 (CEST)","from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D4142D89;\n\tFri,  2 Jul 2021 01:08:25 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Us7I5Qkg\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1625180906;\n\tbh=iWNAMCBnINoGWXKaO/8sOU6Au1BP2vvyHmdX6CATKbg=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Us7I5QkgzXfwEv15SDMa9iz1BLTUZO69efkKKDUIgNr17fWGKrpb2Qj0ZXBGREU7E\n\tDlcddu9W/Lhrp5cI4W45dDNLh8guB8Xr219eFzciU6Aq04PZIz6SyVvLtOAwQiDUJa\n\t2ewOUg2+icsFQX+kyVgAf9DQesvgHxgYQza3BAZs=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri,  2 Jul 2021 02:07:40 +0300","Message-Id":"<20210701230741.14320-3-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.31.1","In-Reply-To":"<20210701230741.14320-1-laurent.pinchart@ideasonboard.com>","References":"<20210701230741.14320-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 2/3] test: message: Test recursive\n\tThread::dispatchMessages() calls","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"The Thread::dispatchMessages() function needs to support recursive\ncalls, for instance to allow flushing delivery of invoked methods. Add a\ncorresponding test, which currently fails with a double free.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n test/message.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++--\n 1 file changed, 64 insertions(+), 2 deletions(-)","diff":"diff --git a/test/message.cpp b/test/message.cpp\nindex eeea57feab76..7895cd7c2106 100644\n--- a/test/message.cpp\n+++ b/test/message.cpp\n@@ -26,8 +26,8 @@ public:\n \t\tMessageReceived,\n \t};\n \n-\tMessageReceiver()\n-\t\t: status_(NoMessage)\n+\tMessageReceiver(Object *parent = nullptr)\n+\t\t: Object(parent), status_(NoMessage)\n \t{\n \t}\n \n@@ -52,6 +52,45 @@ private:\n \tStatus status_;\n };\n \n+class RecursiveMessageReceiver : public Object\n+{\n+public:\n+\tRecursiveMessageReceiver()\n+\t\t: child_(this), success_(false)\n+\t{\n+\t}\n+\n+\tbool success() const { return success_; }\n+\n+protected:\n+\tvoid message([[maybe_unused]] Message *msg)\n+\t{\n+\t\tif (msg->type() != Message::None) {\n+\t\t\tObject::message(msg);\n+\t\t\treturn;\n+\t\t}\n+\n+\t\tchild_.postMessage(std::make_unique<Message>(Message::None));\n+\n+\t\t/*\n+\t\t * If the child has already received the message, something is\n+\t\t * wrong.\n+\t\t */\n+\t\tif (child_.status() != MessageReceiver::NoMessage)\n+\t\t\treturn;\n+\n+\t\tThread::current()->dispatchMessages(Message::None);\n+\n+\t\t/* The child should now have received the message. */\n+\t\tif (child_.status() == MessageReceiver::MessageReceived)\n+\t\t\tsuccess_ = true;\n+\t}\n+\n+private:\n+\tMessageReceiver child_;\n+\tbool success_;\n+};\n+\n class SlowMessageReceiver : public Object\n {\n protected:\n@@ -120,6 +159,29 @@ protected:\n \n \t\tdelete slowReceiver;\n \n+\t\tthis_thread::sleep_for(chrono::milliseconds(100));\n+\n+\t\t/*\n+\t\t * Test recursive calls to Thread::dispatchMessages(). Messages\n+\t\t * should be delivered correctly, without crashes or memory\n+\t\t * leaks. Two messages need to be posted to ensure we don't only\n+\t\t * test the simple case of a queue containing a single message.\n+\t\t */\n+\t\tRecursiveMessageReceiver *recursiveReceiver = new RecursiveMessageReceiver();\n+\t\trecursiveReceiver->moveToThread(&thread_);\n+\n+\t\trecursiveReceiver->postMessage(std::make_unique<Message>(Message::None));\n+\t\trecursiveReceiver->postMessage(std::make_unique<Message>(Message::UserMessage));\n+\n+\t\tthis_thread::sleep_for(chrono::milliseconds(10));\n+\n+\t\tif (!recursiveReceiver->success()) {\n+\t\t\tcout << \"Recursive message delivery failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tdelete recursiveReceiver;\n+\n \t\treturn TestPass;\n \t}\n \n","prefixes":["libcamera-devel","2/3"]}