summaryrefslogtreecommitdiff
path: root/test/event-dispatcher.cpp
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-01-23 10:53:37 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-01-23 18:51:56 +0200
commiteb1ecc92ce2fac649f7cbaecd58be29d23602713 (patch)
tree7ea3af3a705597c94f040c13dd0c185435379f16 /test/event-dispatcher.cpp
parent4d470eb37fe31cc9899ee36e81134b35b02a36f3 (diff)
tests: event-dispatcher: Add processEvents() interruption test
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 <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Diffstat (limited to 'test/event-dispatcher.cpp')
-rw-r--r--test/event-dispatcher.cpp32
1 files changed, 31 insertions, 1 deletions
diff --git a/test/event-dispatcher.cpp b/test/event-dispatcher.cpp
index 06c2657f..e8818dca 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;
}