From 5bed9e46e735da5b43c4619b12034d8b94f5b5c7 Mon Sep 17 00:00:00 2001 From: Marek Chalupa Date: Tue, 12 Aug 2014 11:35:07 +0200 Subject: [PATCH] tests: add one more test for event-loop signal source Test if when we get a signal, all signal sources for that signal get dispatched. Signed-off-by: Marek Chalupa Reviewed-by: Pekka Paalanen --- tests/event-loop-test.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/event-loop-test.c b/tests/event-loop-test.c index e327a66..1709a1a 100644 --- a/tests/event-loop-test.c +++ b/tests/event-loop-test.c @@ -173,6 +173,44 @@ TEST(event_loop_signal) wl_event_loop_destroy(loop); } +TEST(event_loop_multiple_same_signals) +{ + struct wl_event_loop *loop = wl_event_loop_create(); + struct wl_event_source *s1, *s2; + int calls_no = 0; + int i; + + s1 = wl_event_loop_add_signal(loop, SIGUSR1, + signal_callback, &calls_no); + assert(s1); + + s2 = wl_event_loop_add_signal(loop, SIGUSR1, + signal_callback, &calls_no); + assert(s2); + + assert(wl_event_loop_dispatch(loop, 0) == 0); + assert(!calls_no); + + /* Try it more times */ + for (i = 0; i < 5; ++i) { + calls_no = 0; + kill(getpid(), SIGUSR1); + assert(wl_event_loop_dispatch(loop, 0) == 0); + assert(calls_no == 2); + } + + wl_event_source_remove(s1); + + /* Try it again with one source */ + calls_no = 0; + kill(getpid(), SIGUSR1); + assert(wl_event_loop_dispatch(loop, 0) == 0); + assert(calls_no == 1); + + wl_event_source_remove(s2); + + wl_event_loop_destroy(loop); +} static int timer_callback(void *data) -- 2.7.4