From patchwork Wed Nov 27 08:49:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2380 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 98A196136B for ; Wed, 27 Nov 2019 09:49:24 +0100 (CET) Received: from pendragon.tok.corp.google.com (unknown [104.132.253.101]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5392E9F4 for ; Wed, 27 Nov 2019 09:49:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1574844564; bh=+tpnpNuEmXB3XPxl4jcSTh2xdJ+b2KJSVHjtw6pzFPQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=kwqSz6BCKtjtoObXiMJLJM9iDgB7Tfn11m6f9jVKtB5QJyFlwuNfSrZZ9iIYufzdo L8L6xtU3K/y0/l9Xxczop5d3/0D2AGGAP+ZC60DuEhL559t2T2CeWLHGu9gT0+hcdR nN2nwUtHEDe58s0HvBW4XCJr1L+c09bknaa/zZ3M= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 27 Nov 2019 10:49:06 +0200 Message-Id: <20191127084909.10612-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191127084909.10612-1-laurent.pinchart@ideasonboard.com> References: <20191127084909.10612-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/5] test: message: Add slow receiver test X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Nov 2019 08:49:25 -0000 There's a race in the message delivery against object deletion. Add a test that triggers it reliably. This test is expected to fail with an assertion error. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- test/message.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/message.cpp b/test/message.cpp index cf21d5ca50d1..7ebedb557502 100644 --- a/test/message.cpp +++ b/test/message.cpp @@ -52,6 +52,25 @@ private: Status status_; }; +class SlowMessageReceiver : public Object +{ +protected: + void message(Message *msg) + { + if (msg->type() != Message::None) { + Object::message(msg); + return; + } + + /* + * Don't access any member of the object here (including the + * vtable) as the object will be deleted by the main thread + * while we're sleeping. + */ + this_thread::sleep_for(chrono::milliseconds(100)); + } +}; + class MessageTest : public Test { protected: @@ -88,6 +107,19 @@ protected: break; } + /* + * Test for races between message delivery and object deletion. + * Failures result in assertion errors, there is no need for + * explicit checks. + */ + SlowMessageReceiver *slowReceiver = new SlowMessageReceiver(); + slowReceiver->moveToThread(&thread_); + slowReceiver->postMessage(utils::make_unique(Message::None)); + + this_thread::sleep_for(chrono::milliseconds(10)); + + delete slowReceiver; + return TestPass; }