diff options
| author | Marek Chalupa <mchqwerty@gmail.com> | 2014-09-10 12:47:12 +0200 |
|---|---|---|
| committer | Pekka Paalanen <pekka.paalanen@collabora.co.uk> | 2014-09-11 10:21:08 +0300 |
| commit | 65d02b7a83329ab5a65a0effde854baf8d5d2040 (patch) | |
| tree | 51b7fec066238366d156ca171069858ab2f62d68 | |
| parent | tests: use nanosleep instead of usleep (diff) | |
| download | wayland-65d02b7a83329ab5a65a0effde854baf8d5d2040.tar wayland-65d02b7a83329ab5a65a0effde854baf8d5d2040.tar.gz wayland-65d02b7a83329ab5a65a0effde854baf8d5d2040.tar.bz2 wayland-65d02b7a83329ab5a65a0effde854baf8d5d2040.tar.lz wayland-65d02b7a83329ab5a65a0effde854baf8d5d2040.tar.xz wayland-65d02b7a83329ab5a65a0effde854baf8d5d2040.tar.zst wayland-65d02b7a83329ab5a65a0effde854baf8d5d2040.zip | |
display-test: test if threads are woken up on EAGAIN
When wl_connection_read() in wl_display_read_events() returns with EAGAIN,
we want the sleeping threads to be woken up. Test it!
Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
| -rw-r--r-- | tests/display-test.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/display-test.c b/tests/display-test.c index 451cabd..a1e45b1 100644 --- a/tests/display-test.c +++ b/tests/display-test.c @@ -495,6 +495,45 @@ TEST(threading_cancel_read_tst) display_destroy(d); } +static void +threading_read_eagain(void) +{ + struct client *c = client_connect(); + pthread_t th1, th2, th3; + + register_reading(c->wl_display); + + th1 = create_thread(c, thread_prepare_and_read); + th2 = create_thread(c, thread_prepare_and_read); + th3 = create_thread(c, thread_prepare_and_read); + + /* All the threads are sleeping, waiting until read or cancel + * is called. Since we have no data on socket waiting, + * the wl_connection_read should end up with error and set errno + * to EAGAIN. Check if the threads are woken up in this case. */ + assert(wl_display_read_events(c->wl_display) == 0); + /* errno should be still set to EAGAIN if wl_connection_read + * set it - check if we're testing the right case */ + assert(errno == EAGAIN); + + alarm(3); + pthread_join(th1, NULL); + pthread_join(th2, NULL); + pthread_join(th3, NULL); + + client_disconnect(c); +} + +TEST(threading_read_eagain_tst) +{ + struct display *d = display_create(); + client_create(d, threading_read_eagain); + + display_run(d); + + display_destroy(d); +} + static void * thread_prepare_and_read2(void *data) { |
