diff options
| author | Marek Chalupa <mchqwerty@gmail.com> | 2014-08-05 11:39:50 +0200 |
|---|---|---|
| committer | Pekka Paalanen <pekka.paalanen@collabora.co.uk> | 2014-08-22 12:55:37 +0300 |
| commit | 213366e698fedf0caac0e7a0bf2f05e2446ba113 (patch) | |
| tree | 9a965826b89ea6195fb8e3d8c5f47c9b4ac209cf /tests/display-test.c | |
| parent | tests: test if thread can block on error (diff) | |
| download | wayland-213366e698fedf0caac0e7a0bf2f05e2446ba113.tar wayland-213366e698fedf0caac0e7a0bf2f05e2446ba113.tar.gz wayland-213366e698fedf0caac0e7a0bf2f05e2446ba113.tar.bz2 wayland-213366e698fedf0caac0e7a0bf2f05e2446ba113.tar.lz wayland-213366e698fedf0caac0e7a0bf2f05e2446ba113.tar.xz wayland-213366e698fedf0caac0e7a0bf2f05e2446ba113.tar.zst wayland-213366e698fedf0caac0e7a0bf2f05e2446ba113.zip | |
tests: add tests for wl_display_cancel_read
Test if wl_display_cancel_read wakes up other threads.
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Diffstat (limited to 'tests/display-test.c')
| -rw-r--r-- | tests/display-test.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/display-test.c b/tests/display-test.c index 26f946b..28ef40b 100644 --- a/tests/display-test.c +++ b/tests/display-test.c @@ -413,3 +413,72 @@ TEST(threading_errors_tst) display_destroy(d); } + +static void * +thread_prepare_and_read(void *data) +{ + struct client *c = data; + + register_reading(c->wl_display); + + c->display_stopped = 1; + + assert(wl_display_read_events(c->wl_display) == 0); + assert(wl_display_dispatch_pending(c->wl_display) == 0); + + pthread_exit(NULL); +} + +static pthread_t +create_thread(struct client *c) +{ + pthread_t thread; + + c->display_stopped = 0; + assert(pthread_create(&thread, NULL, thread_prepare_and_read, c) == 0); + + /* make sure thread is sleeping */ + while (c->display_stopped == 0) + usleep(500); + usleep(10000); + + return thread; +} + +/* test cancel read*/ +static void +threading_cancel_read(void) +{ + struct client *c = client_connect(); + pthread_t th1, th2, th3; + + register_reading(c->wl_display); + + th1 = create_thread(c); + th2 = create_thread(c); + th3 = create_thread(c); + + /* all the threads are sleeping, waiting until read or cancel + * is called. Cancel the read and let the threads proceed */ + wl_display_cancel_read(c->wl_display); + + /* kill test in 3 seconds. This should be enough time for the + * thread to exit if it's not blocking. If everything is OK, than + * the thread was woken up and the test will end before the SIGALRM */ + alarm(3); + pthread_join(th1, NULL); + pthread_join(th2, NULL); + pthread_join(th3, NULL); + + client_disconnect(c); +} + +TEST(threading_cancel_read_tst) +{ + struct display *d = display_create(); + + client_create(d, threading_cancel_read); + display_run(d); + + display_destroy(d); +} |
