diff options
Diffstat (limited to 'tests/event-loop-test.c')
-rw-r--r-- | tests/event-loop-test.c | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/tests/event-loop-test.c b/tests/event-loop-test.c index cbeaf8e..a51ba8f 100644 --- a/tests/event-loop-test.c +++ b/tests/event-loop-test.c @@ -24,6 +24,7 @@ * SOFTWARE. */ +#define _GNU_SOURCE #include <stdlib.h> #include <stdint.h> #include <assert.h> @@ -168,10 +169,22 @@ TEST(event_loop_signal) signal_callback, &got_it); assert(source); - wl_event_loop_dispatch(loop, 0); + assert(wl_event_loop_dispatch(loop, 0) == 0); assert(!got_it); - kill(getpid(), SIGUSR1); - wl_event_loop_dispatch(loop, 0); + assert(kill(getpid(), SIGUSR1) == 0); + /* + * On Linux the signal will be immediately visible in the epoll_wait() + * call. However, on FreeBSD we may need a small delay between kill() + * call and the signal being visible to the kevent() call. This + * sometimes happens when the signal processing and kevent processing + * runs on different CPUs, so becomes more likely when the system is + * under load (e.g. running all tests in parallel). + * See https://github.com/jiixyj/epoll-shim/pull/32 + * Passing 1ms as the timeout appears to avoid this race condition in + * all cases tested so far, but to be safe we use 1000ms which should + * be enough time even on a really slow (or emulated) system. + */ + assert(wl_event_loop_dispatch(loop, 1000) == 0); assert(got_it == 1); wl_event_source_remove(source); @@ -199,8 +212,12 @@ TEST(event_loop_multiple_same_signals) /* 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(kill(getpid(), SIGUSR1) == 0); + /* + * We need a non-zero timeout here to allow the test to pass + * on non-Linux systems (see comment in event_loop_signal). + */ + assert(wl_event_loop_dispatch(loop, 1000) == 0); assert(calls_no == 2); } @@ -208,8 +225,12 @@ TEST(event_loop_multiple_same_signals) /* Try it again with one source */ calls_no = 0; - kill(getpid(), SIGUSR1); - assert(wl_event_loop_dispatch(loop, 0) == 0); + assert(kill(getpid(), SIGUSR1) == 0); + /* + * We need a non-zero timeout here to allow the test to pass + * on non-Linux systems (see comment in event_loop_signal). + */ + assert(wl_event_loop_dispatch(loop, 1000) == 0); assert(calls_no == 1); wl_event_source_remove(s2); |