From patchwork Wed Jan 23 08:59:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 348 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8089E60C7F for ; Wed, 23 Jan 2019 09:59:30 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C3A3223F for ; Wed, 23 Jan 2019 09:59:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1548233970; bh=KDgVquP+m6F7TWbHW2iZPAwE3pqrPt/LzxLNzahKTwQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=amwSUgqILAXzXhYRyvC58ji3pRZFs9smD+BwrxNGxa+BKYAARTlsTnli6Fi3G9GiT 9Yu8GGBEVpiWASGq5vWBLPWOpDC1l4fa2spzx4IkPqgJWSWO7IPnJBMqmypdLA1sfZ bx8dV/KqqksZiRdz3AlBxyaaR4piKpfduRr5a/t8= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 23 Jan 2019 10:59:23 +0200 Message-Id: <20190123085923.12524-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190123085923.12524-1-laurent.pinchart@ideasonboard.com> References: <20190123085923.12524-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/4] tests: event-dispatcher: Add processEvents() interruption test X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Jan 2019 08:59:30 -0000 Test that the EventDispatcher::interrupt() function correctly interrupts the processEvents() function, both when called before processEvents() and when called while it is running. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- test/event-dispatcher.cpp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/test/event-dispatcher.cpp b/test/event-dispatcher.cpp index 06c2657f09d6..e8818dcab4ad 100644 --- a/test/event-dispatcher.cpp +++ b/test/event-dispatcher.cpp @@ -18,16 +18,23 @@ using namespace std; using namespace libcamera; +static EventDispatcher *dispatcher; +static bool interrupt; + class EventDispatcherTest : public Test { protected: static void sigAlarmHandler(int) { cout << "SIGALARM received" << endl; + if (interrupt) + dispatcher->interrupt(); } int init() { + dispatcher = CameraManager::instance()->eventDispatcher(); + struct sigaction sa = {}; sa.sa_handler = &sigAlarmHandler; sigaction(SIGALRM, &sa, nullptr); @@ -37,7 +44,6 @@ protected: int run() { - EventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher(); Timer timer; /* Event processing interruption by signal. */ @@ -48,6 +54,7 @@ protected: struct itimerval itimer = {}; itimer.it_value.tv_usec = 500000; + interrupt = false; setitimer(ITIMER_REAL, &itimer, nullptr); dispatcher->processEvents(); @@ -62,6 +69,29 @@ protected: return TestFail; } + /* Event processing interruption. */ + timer.start(1000); + dispatcher->interrupt(); + + dispatcher->processEvents(); + + if (!timer.isRunning()) { + cout << "Event processing immediate interruption failed" << endl; + return TestFail; + } + + timer.start(1000); + itimer.it_value.tv_usec = 500000; + interrupt = true; + setitimer(ITIMER_REAL, &itimer, nullptr); + + dispatcher->processEvents(); + + if (!timer.isRunning()) { + cout << "Event processing delayed interruption failed" << endl; + return TestFail; + } + return TestPass; }