summaryrefslogtreecommitdiffstats
path: root/tests/event-loop-test.c
diff options
context:
space:
mode:
authorMarek Chalupa <mchqwerty@gmail.com>2014-08-19 12:03:48 +0200
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>2014-08-19 14:34:50 +0300
commitb24fa4c8216e3f0f7b644c7b8c6949925f19ada9 (patch)
tree3dd1c8181614badcca6efae3cd229161eb858bc4 /tests/event-loop-test.c
parenttests: event_loop_timer_updates - add asserts and fix indentation (diff)
downloadwayland-b24fa4c8216e3f0f7b644c7b8c6949925f19ada9.tar
wayland-b24fa4c8216e3f0f7b644c7b8c6949925f19ada9.tar.gz
wayland-b24fa4c8216e3f0f7b644c7b8c6949925f19ada9.tar.bz2
wayland-b24fa4c8216e3f0f7b644c7b8c6949925f19ada9.tar.lz
wayland-b24fa4c8216e3f0f7b644c7b8c6949925f19ada9.tar.xz
wayland-b24fa4c8216e3f0f7b644c7b8c6949925f19ada9.tar.zst
wayland-b24fa4c8216e3f0f7b644c7b8c6949925f19ada9.zip
tests: fix event_loop_timer_updates
It may happen that there's some time between the first and the other timer expire. If epoll_wait is called after the first timer expired and the other not, it returns only one source to dispatch and therefore the test fails. To fix that, sleep a while before wl_event_loop_dispatch() to make sure both timers expired. To be 100% sure, we could use poll() before calling wl_event_loop_dispatch(), but that would need modification in libwayland (need to get the source's fd somehow) https://bugs.freedesktop.org/show_bug.cgi?id=80594 Signed-off-by: Marek Chalupa <mchqwerty@gmail.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Diffstat (limited to 'tests/event-loop-test.c')
-rw-r--r--tests/event-loop-test.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/event-loop-test.c b/tests/event-loop-test.c
index bd85473..1a45db1 100644
--- a/tests/event-loop-test.c
+++ b/tests/event-loop-test.c
@@ -240,6 +240,8 @@ TEST(event_loop_timer)
wl_event_loop_destroy(loop);
}
+#define MSEC_TO_USEC(msec) ((msec) * 1000)
+
struct timer_update_context {
struct wl_event_source *source1, *source2;
int count;
@@ -291,6 +293,18 @@ TEST(event_loop_timer_updates)
context.count = 0;
+ /* Since calling the functions between source2's update and
+ * wl_event_loop_dispatch() takes some time, it may happen
+ * that only one timer expires until we call epoll_wait.
+ * This naturally means that only one source is dispatched
+ * and the test fails. To fix that, sleep 15 ms before
+ * calling wl_event_loop_dispatch(). That should be enough
+ * for the second timer to expire.
+ *
+ * https://bugs.freedesktop.org/show_bug.cgi?id=80594
+ */
+ usleep(MSEC_TO_USEC(15));
+
gettimeofday(&start_time, NULL);
wl_event_loop_dispatch(loop, 20);
gettimeofday(&end_time, NULL);