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>
This commit is contained in:
Laurent Pinchart 2019-01-23 10:53:37 +02:00
parent 4d470eb37f
commit eb1ecc92ce

View file

@ -18,16 +18,23 @@
using namespace std; using namespace std;
using namespace libcamera; using namespace libcamera;
static EventDispatcher *dispatcher;
static bool interrupt;
class EventDispatcherTest : public Test class EventDispatcherTest : public Test
{ {
protected: protected:
static void sigAlarmHandler(int) static void sigAlarmHandler(int)
{ {
cout << "SIGALARM received" << endl; cout << "SIGALARM received" << endl;
if (interrupt)
dispatcher->interrupt();
} }
int init() int init()
{ {
dispatcher = CameraManager::instance()->eventDispatcher();
struct sigaction sa = {}; struct sigaction sa = {};
sa.sa_handler = &sigAlarmHandler; sa.sa_handler = &sigAlarmHandler;
sigaction(SIGALRM, &sa, nullptr); sigaction(SIGALRM, &sa, nullptr);
@ -37,7 +44,6 @@ protected:
int run() int run()
{ {
EventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher();
Timer timer; Timer timer;
/* Event processing interruption by signal. */ /* Event processing interruption by signal. */
@ -48,6 +54,7 @@ protected:
struct itimerval itimer = {}; struct itimerval itimer = {};
itimer.it_value.tv_usec = 500000; itimer.it_value.tv_usec = 500000;
interrupt = false;
setitimer(ITIMER_REAL, &itimer, nullptr); setitimer(ITIMER_REAL, &itimer, nullptr);
dispatcher->processEvents(); dispatcher->processEvents();
@ -62,6 +69,29 @@ protected:
return TestFail; 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; return TestPass;
} }