diff options
author | Marek Chalupa <mchqwerty@gmail.com> | 2014-08-05 11:39:51 +0200 |
---|---|---|
committer | Pekka Paalanen <pekka.paalanen@collabora.co.uk> | 2014-08-22 12:58:25 +0300 |
commit | 71141288f0aaf7df9d06469d4a0ee21d7384243b (patch) | |
tree | ebdee352c0587c3d75c06f1869fc248987823438 /tests | |
parent | 213366e698fedf0caac0e7a0bf2f05e2446ba113 (diff) |
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 <pekka.paalanen@collabora.co.uk>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/display-test.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/display-test.c b/tests/display-test.c index 28ef40b..c420cbe 100644 --- a/tests/display-test.c +++ b/tests/display-test.c @@ -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); +} |