diff options
| author | Manuel Stoeckl <code@mstoeckl.com> | 2019-12-24 23:57:29 -0500 |
|---|---|---|
| committer | Pekka Paalanen <pq@iki.fi> | 2020-01-15 13:18:56 +0000 |
| commit | e449232f37256a7db3311399b311984271efa1e7 (patch) | |
| tree | a223d03007efa0255e0a46b94196799ebf5e6cad /tests/display-test.c | |
| parent | Revert "build: check wayland-scanner version" (diff) | |
| download | wayland-e449232f37256a7db3311399b311984271efa1e7.tar wayland-e449232f37256a7db3311399b311984271efa1e7.tar.gz wayland-e449232f37256a7db3311399b311984271efa1e7.tar.bz2 wayland-e449232f37256a7db3311399b311984271efa1e7.tar.lz wayland-e449232f37256a7db3311399b311984271efa1e7.tar.xz wayland-e449232f37256a7db3311399b311984271efa1e7.tar.zst wayland-e449232f37256a7db3311399b311984271efa1e7.zip | |
tests: Fix race condition in send overflow test
This change ensures that the compositor process is not able to respond
to any of the noop requests sent by the client process, by using the
test compositor's `stop_display` mechanism to coordinate when the
compositor should stop processing messages.
(Before this change, it was possible that one of the calls of
wl_event_loop_dispatch in the compositor process could respond to all
the client's noop requests before returning.)
Signed-off-by: Manuel Stoeckl <code@mstoeckl.com>
Diffstat (limited to 'tests/display-test.c')
| -rw-r--r-- | tests/display-test.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/tests/display-test.c b/tests/display-test.c index 533916c..f155d08 100644 --- a/tests/display-test.c +++ b/tests/display-test.c @@ -1431,6 +1431,9 @@ send_overflow_client(void *data) int *pipes = data; char tmp = '\0'; + /* Request to break out of 'display_run' in the main process */ + assert(stop_display(c, 1) >= 0); + /* On Linux, the Unix socket default buffer size is <=256KB, and * each noop request requires 8 bytes; the buffer should thus * overflow within about 32K /unhandled/ iterations */ @@ -1457,7 +1460,7 @@ TEST(send_overflow_disconnection) struct display *d; char tmp; int rpipe[2]; - int i; + ssize_t ret; assert(pipe(rpipe) != -1); @@ -1469,16 +1472,18 @@ TEST(send_overflow_disconnection) * interrupted if the client dies */ close(rpipe[1]); - /* At least 2 loops of this are needed to respond for the client to - * set up the test interface */ - for (i = 0; i < 5; i++) { - wl_display_flush_clients(d->wl_display); - wl_event_loop_dispatch(wl_display_get_event_loop(d->wl_display), -1); - } + /* Run the display until the client sends a `stop_display`, then + * send a resume message but don't actually look at new messages */ + display_run(d); + display_post_resume_events(d); + wl_display_flush_clients(d->wl_display); - /* Wait until all noop requests have been sent, or until client - * process aborts */ - (void)read(rpipe[0], &tmp, sizeof(tmp)); + /* Wait until all noop requests have been sent (read returns 1), or + * until client process aborts (read returns 0) */ + do { + ret = read(rpipe[0], &tmp, sizeof(tmp)); + } while (ret == -1 && errno == EINTR); + assert(ret != -1); close(rpipe[0]); /* For a clean shutdown */ |
