[PATCH 05/12] event-loop-test: Add some more assertions and work around a FreeBSD bug

Philip Withnall philip at tecnocode.co.uk
Fri Feb 15 04:56:45 PST 2013


There’s a bug in FreeBSD’s handling of timer events which means we have to
be more relaxed about how we check when timer events have happened because
FreeBSD can’t manage enough precision on scheduling the events.

Signed-off-by: Philip Withnall <philip at tecnocode.co.uk>
---
 tests/event-loop-test.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/tests/event-loop-test.c b/tests/event-loop-test.c
index c46d3b0..cf9dabe 100644
--- a/tests/event-loop-test.c
+++ b/tests/event-loop-test.c
@@ -155,10 +155,11 @@ TEST(event_loop_signal)
 
 	source = wl_event_loop_add_signal(loop, SIGUSR1,
 					  signal_callback, &got_it);
-	wl_event_loop_dispatch(loop, 0);
+	assert(source);
+	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);
+	assert(wl_event_loop_dispatch(loop, 0) == 0);
 	assert(got_it);
 
 	wl_event_source_remove(source);
@@ -183,12 +184,21 @@ TEST(event_loop_timer)
 	int got_it = 0;
 
 	source = wl_event_loop_add_timer(loop, timer_callback, &got_it);
-	wl_event_source_timer_update(source, 10);
-	wl_event_loop_dispatch(loop, 0);
+	assert(source);
+	assert(wl_event_source_timer_update(source, 10) == 0);
+	assert(wl_event_loop_dispatch(loop, 0) == 0);
 	assert(!got_it);
-	wl_event_loop_dispatch(loop, 20);
+	/* FreeBSD has a bug where it converts ms_timeout to ticks; it always adds 1 to the tick count.
+	 * Consequently, we need to grossly overcompensate here.
+	 * See: http://unix.derkeiler.com/Mailing-Lists/FreeBSD/hackers/2012-07/msg00319.html */
+	assert(wl_event_loop_dispatch(loop, 50) == 0);
 	assert(got_it);
 
+	/* Check it doesn't fire again. */
+	got_it = 0;
+	assert(wl_event_loop_dispatch(loop, 20) == 0);
+	assert(!got_it);
+
 	wl_event_source_remove(source);
 	wl_event_loop_destroy(loop);
 }
-- 
1.7.11.7

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 230 bytes
Desc: This is a digitally signed message part
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20130215/964a611f/attachment.pgp>


More information about the wayland-devel mailing list