Commit 71141288 authored by Marek Chalupa's avatar Marek Chalupa Committed by Pekka Paalanen

tests: add test for reading after an error occurred

This test shows that it's possible to successfully call wl_display_prepare_read
and wl_display_read_events after an error occurred. That may lead to
deadlock.

When you call prepare read from two threads and then call read_events,
one thread gets sleeping. The call from the other thread will return -1 and invokes
display_fatal_error, but since
we have display->last_error already set, the broadcast is not called and
the sleeping thread sleeps indefinitely.
Reviewed-by: Pekka Paalanen's avatarPekka Paalanen <pekka.paalanen@collabora.co.uk>
parent 213366e6
......@@ -482,3 +482,63 @@ TEST(threading_cancel_read_tst)
display_destroy(d);
}
static void *
thread_prepare_and_read2(void *data)
{
struct client *c = data;
while(wl_display_prepare_read(c->wl_display) != 0 && errno == EAGAIN)
assert(wl_display_dispatch_pending(c->wl_display) == -1);
assert(wl_display_flush(c->wl_display) == -1);
c->display_stopped = 1;
assert(wl_display_read_events(c->wl_display) == -1);
assert(wl_display_dispatch_pending(c->wl_display) == -1);
pthread_exit(NULL);
}
static void
threading_read_after_error(void)
{
struct client *c = client_connect();
pthread_t thread;
/* create an error */
close(wl_display_get_fd(c->wl_display));
assert(wl_display_dispatch(c->wl_display) == -1);
/* try to prepare for reading */
while(wl_display_prepare_read(c->wl_display) != 0 && errno == EAGAIN)
assert(wl_display_dispatch_pending(c->wl_display) == -1);
assert(wl_display_flush(c->wl_display) == -1);
assert(pthread_create(&thread, NULL,
thread_prepare_and_read2, c) == 0);
/* make sure thread is sleeping */
while (c->display_stopped == 0)
usleep(500);
usleep(10000);
assert(wl_display_read_events(c->wl_display) == -1);
/* kill test in 3 seconds */
alarm(3);
pthread_join(thread, NULL);
wl_proxy_destroy((struct wl_proxy *) c->tc);
wl_display_disconnect(c->wl_display);
}
TEST(threading_read_after_error_tst)
{
struct display *d = display_create();
client_create(d, threading_read_after_error);
display_run(d);
display_destroy(d);
}
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