aboutsummaryrefslogtreecommitdiffstats
path: root/tests/event-loop-test.c
diff options
context:
space:
mode:
authorManuel Stoeckl <code@mstoeckl.com>2020-01-16 08:07:41 -0500
committerSimon Ser <contact@emersion.fr>2020-01-21 11:31:35 +0000
commit75d14834570bb0c851e792b520814888fb324c08 (patch)
treec0a50c1fa357e6ab0ddf4291c64f0806b0d73633 /tests/event-loop-test.c
parentevent-loop-test: Verify proper timer cancellation (diff)
downloadwayland-75d14834570bb0c851e792b520814888fb324c08.tar
wayland-75d14834570bb0c851e792b520814888fb324c08.tar.gz
wayland-75d14834570bb0c851e792b520814888fb324c08.tar.bz2
wayland-75d14834570bb0c851e792b520814888fb324c08.tar.lz
wayland-75d14834570bb0c851e792b520814888fb324c08.tar.xz
wayland-75d14834570bb0c851e792b520814888fb324c08.tar.zst
wayland-75d14834570bb0c851e792b520814888fb324c08.zip
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: Manuel Stoeckl <code@mstoeckl.com>
Diffstat (limited to 'tests/event-loop-test.c')
-rw-r--r--tests/event-loop-test.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/tests/event-loop-test.c b/tests/event-loop-test.c
index 3002e6d..e9e636c 100644
--- a/tests/event-loop-test.c
+++ b/tests/event-loop-test.c
@@ -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);
}