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

Dima Ryazanov dima at gmail.com
Fri Feb 15 06:48:35 PST 2013


On Fri, Feb 15, 2013 at 7:56 AM, Philip Withnall <philip at tecnocode.co.uk>wrote:

> 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);
>

You shouldn't put code with side effects inside asserts, since it'll be
compiled out in release mode.


>         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
>
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20130215/71230def/attachment.html>


More information about the wayland-devel mailing list