Commit 75d14834 authored by Manuel Stoeckl's avatar Manuel Stoeckl Committed by Simon Ser

event-loop-test: Confirm distant timers do not fire

This change expands the `event_loop_timer` test to use two different
timers with different timeouts; it now implicitly checks that e.g.
both timers do not expire at the same time, and that the first timer
expiring does not prevent the second from doing so. (While such failure
modes are unlikely with timer event sources based on individual
timerfds, they are possible when multiple timers share a common timerfd.)
Signed-off-by: default avatarManuel Stoeckl <code@mstoeckl.com>
parent a0d941e4
......@@ -230,18 +230,33 @@ timer_callback(void *data)
TEST(event_loop_timer)
{
struct wl_event_loop *loop = wl_event_loop_create();
struct wl_event_source *source;
struct wl_event_source *source1, *source2;
int got_it = 0;
source = wl_event_loop_add_timer(loop, timer_callback, &got_it);
assert(source);
wl_event_source_timer_update(source, 10);
source1 = wl_event_loop_add_timer(loop, timer_callback, &got_it);
assert(source1);
wl_event_source_timer_update(source1, 20);
source2 = wl_event_loop_add_timer(loop, timer_callback, &got_it);
assert(source2);
wl_event_source_timer_update(source2, 100);
/* Check that the timer marked for 20 msec from now fires within 30
* msec, and that the timer marked for 100 msec is expected to fire
* within an additional 90 msec. (Some extra wait time is provided to
* account for reasonable code execution / thread preemption delays.) */
wl_event_loop_dispatch(loop, 0);
assert(!got_it);
wl_event_loop_dispatch(loop, 20);
assert(got_it == 0);
wl_event_loop_dispatch(loop, 30);
assert(got_it == 1);
wl_event_loop_dispatch(loop, 0);
assert(got_it == 1);
wl_event_loop_dispatch(loop, 90);
assert(got_it == 2);
wl_event_source_remove(source);
wl_event_source_remove(source1);
wl_event_source_remove(source2);
wl_event_loop_destroy(loop);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment