diff options
| author | Sebastian Wick <sebastian.wick@redhat.com> | 2025-01-28 21:24:46 +0100 |
|---|---|---|
| committer | Derek Foreman <derek.foreman@collabora.com> | 2025-02-04 14:09:51 +0000 |
| commit | 74f322c35a4eef1332456ce9985255df7269f82f (patch) | |
| tree | ce708df4b8563f62860779baa7487b690bde8ff1 | |
| parent | client: Add wl_display_dispatch_timeout (diff) | |
| download | wayland-74f322c35a4eef1332456ce9985255df7269f82f.tar wayland-74f322c35a4eef1332456ce9985255df7269f82f.tar.gz wayland-74f322c35a4eef1332456ce9985255df7269f82f.tar.bz2 wayland-74f322c35a4eef1332456ce9985255df7269f82f.tar.lz wayland-74f322c35a4eef1332456ce9985255df7269f82f.tar.xz wayland-74f322c35a4eef1332456ce9985255df7269f82f.tar.zst wayland-74f322c35a4eef1332456ce9985255df7269f82f.zip | |
tests: Add dispatch timeout tests
Add tests which verify that...
* wl_display_dispatch_timeout with a big enough timeout behaves the same
as wl_display_dispatch
* wl_display_dispatch_timeout will time out when there are no messages
to dispatch
Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com>
| -rw-r--r-- | tests/queue-test.c | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/tests/queue-test.c b/tests/queue-test.c index cb61a85..7dfdd30 100644 --- a/tests/queue-test.c +++ b/tests/queue-test.c @@ -40,6 +40,7 @@ #include "wayland-server.h" #include "test-runner.h" #include "test-compositor.h" +#include "../src/timespec-util.h" #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) @@ -572,6 +573,68 @@ client_test_queue_names(void) } static void +dispatch_timeout_sync_callback(void *data, struct wl_callback *callback, + uint32_t serial) +{ + bool *done = data; + + *done = true; + wl_callback_destroy(callback); +} + +static const struct wl_callback_listener dispatch_timeout_sync_listener = { + dispatch_timeout_sync_callback +}; + +static void +client_test_queue_dispatch_simple(void) +{ + struct wl_display *display; + struct timespec timeout; + struct wl_callback *callback; + bool done = false; + int ret = 0; + + display = wl_display_connect(NULL); + assert(display); + + callback = wl_display_sync(display); + assert(callback != NULL); + wl_callback_add_listener(callback, &dispatch_timeout_sync_listener, &done); + + timespec_from_msec(&timeout, 1000); + + while (!done) { + ret = wl_display_dispatch_timeout(display, &timeout); + assert(ret > 0); + } + + wl_display_disconnect(display); + + exit(0); +} + +static void +client_test_queue_dispatch_timeout(void) +{ + struct wl_display *display; + struct timespec timeout; + int ret = 0; + + display = wl_display_connect(NULL); + assert(display); + + timespec_from_msec(&timeout, 100); + + ret = wl_display_dispatch_timeout(display, &timeout); + assert(ret == 0); + + wl_display_disconnect(display); + + exit(0); +} + +static void dummy_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id) { @@ -709,3 +772,27 @@ TEST(queue_names) display_destroy(d); } + +TEST(queue_dispatch_simple) +{ + struct display *d = display_create(); + + test_set_timeout(2); + + client_create_noarg(d, client_test_queue_dispatch_simple); + display_run(d); + + display_destroy(d); +} + +TEST(queue_dispatch_timeout) +{ + struct display *d = display_create(); + + test_set_timeout(2); + + client_create_noarg(d, client_test_queue_dispatch_timeout); + display_run(d); + + display_destroy(d); +} |
