[PATCH] tests: add test for reading after an error occurred
Marek Chalupa
mchqwerty at gmail.com
Tue Aug 5 02:39:51 PDT 2014
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.
---
tests/display-test.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
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);
+}
--
2.0.4
More information about the wayland-devel
mailing list