mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-10-29 05:40:16 -04:00
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>
This commit is contained in:
parent
00dcf6b323
commit
74f322c35a
1 changed files with 87 additions and 0 deletions
|
|
@ -40,6 +40,7 @@
|
||||||
#include "wayland-server.h"
|
#include "wayland-server.h"
|
||||||
#include "test-runner.h"
|
#include "test-runner.h"
|
||||||
#include "test-compositor.h"
|
#include "test-compositor.h"
|
||||||
|
#include "../src/timespec-util.h"
|
||||||
|
|
||||||
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
|
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
|
||||||
|
|
||||||
|
|
@ -571,6 +572,68 @@ client_test_queue_names(void)
|
||||||
wl_display_disconnect(display);
|
wl_display_disconnect(display);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
static void
|
||||||
dummy_bind(struct wl_client *client,
|
dummy_bind(struct wl_client *client,
|
||||||
void *data, uint32_t version, uint32_t id)
|
void *data, uint32_t version, uint32_t id)
|
||||||
|
|
@ -709,3 +772,27 @@ TEST(queue_names)
|
||||||
|
|
||||||
display_destroy(d);
|
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);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue