mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-10-31 22:25:25 -04:00
tests: use test compositor in queue-test
Most of the code of the queue-test is covered by the test compositor, so we can save few lines and use the test compositor instead. I think it's also more readable. This patch removes timeout from the test. We plan to add timeout to all tests later, though. v2. rebased to master Signed-off-by: Marek Chalupa <mchqwerty@gmail.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
This commit is contained in:
parent
85d08e8bd6
commit
93e654061b
1 changed files with 29 additions and 151 deletions
|
|
@ -31,33 +31,17 @@
|
||||||
#include "wayland-client.h"
|
#include "wayland-client.h"
|
||||||
#include "wayland-server.h"
|
#include "wayland-server.h"
|
||||||
#include "test-runner.h"
|
#include "test-runner.h"
|
||||||
|
#include "test-compositor.h"
|
||||||
#define SOCKET_NAME "wayland-queue-test"
|
|
||||||
|
|
||||||
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
|
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
|
||||||
|
|
||||||
#define client_assert(expr) \
|
|
||||||
do { \
|
|
||||||
if (!(expr)) { \
|
|
||||||
fprintf(stderr, "%s:%d: " \
|
|
||||||
"Assertion `%s' failed.\n", \
|
|
||||||
__FILE__, __LINE__, #expr); \
|
|
||||||
exit(EXIT_FAILURE); \
|
|
||||||
} \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
struct display {
|
|
||||||
struct wl_display *display;
|
|
||||||
int child_exit_status;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
registry_handle_global(void *data, struct wl_registry *registry,
|
registry_handle_global(void *data, struct wl_registry *registry,
|
||||||
uint32_t id, const char *interface, uint32_t version)
|
uint32_t id, const char *interface, uint32_t version)
|
||||||
{
|
{
|
||||||
int *pcounter = data;
|
int *pcounter = data;
|
||||||
(*pcounter)++;
|
(*pcounter)++;
|
||||||
client_assert(*pcounter == 1);
|
assert(*pcounter == 1);
|
||||||
wl_registry_destroy(registry);
|
wl_registry_destroy(registry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -68,15 +52,15 @@ static const struct wl_registry_listener registry_listener = {
|
||||||
|
|
||||||
/* Test that destroying a proxy object doesn't result in any more
|
/* Test that destroying a proxy object doesn't result in any more
|
||||||
* callback being invoked, even though were many queued. */
|
* callback being invoked, even though were many queued. */
|
||||||
static int
|
static void
|
||||||
client_test_proxy_destroy(void)
|
client_test_proxy_destroy(void)
|
||||||
{
|
{
|
||||||
struct wl_display *display;
|
struct wl_display *display;
|
||||||
struct wl_registry *registry;
|
struct wl_registry *registry;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
|
||||||
display = wl_display_connect(SOCKET_NAME);
|
display = wl_display_connect(NULL);
|
||||||
client_assert(display);
|
assert(display);
|
||||||
|
|
||||||
registry = wl_display_get_registry(display);
|
registry = wl_display_get_registry(display);
|
||||||
assert(registry != NULL);
|
assert(registry != NULL);
|
||||||
|
|
@ -84,13 +68,11 @@ client_test_proxy_destroy(void)
|
||||||
&counter);
|
&counter);
|
||||||
wl_display_roundtrip(display);
|
wl_display_roundtrip(display);
|
||||||
|
|
||||||
client_assert(counter == 1);
|
assert(counter == 1);
|
||||||
|
|
||||||
/* don't destroy the registry, we have already destroyed them
|
/* don't destroy the registry, we have already destroyed them
|
||||||
* in the global handler */
|
* in the global handler */
|
||||||
wl_display_disconnect(display);
|
wl_display_disconnect(display);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct multiple_queues_state {
|
struct multiple_queues_state {
|
||||||
|
|
@ -119,7 +101,7 @@ static const struct wl_callback_listener sync_listener = {
|
||||||
/* Test that when receiving the first of two synchronization
|
/* Test that when receiving the first of two synchronization
|
||||||
* callback events, destroying the second one doesn't cause any
|
* callback events, destroying the second one doesn't cause any
|
||||||
* errors even if the delete_id event is handled out of order. */
|
* errors even if the delete_id event is handled out of order. */
|
||||||
static int
|
static void
|
||||||
client_test_multiple_queues(void)
|
client_test_multiple_queues(void)
|
||||||
{
|
{
|
||||||
struct wl_event_queue *queue;
|
struct wl_event_queue *queue;
|
||||||
|
|
@ -127,11 +109,11 @@ client_test_multiple_queues(void)
|
||||||
struct multiple_queues_state state;
|
struct multiple_queues_state state;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
state.display = wl_display_connect(SOCKET_NAME);
|
state.display = wl_display_connect(NULL);
|
||||||
client_assert(state.display);
|
assert(state.display);
|
||||||
|
|
||||||
queue = wl_display_create_queue(state.display);
|
queue = wl_display_create_queue(state.display);
|
||||||
client_assert(queue);
|
assert(queue);
|
||||||
|
|
||||||
state.done = false;
|
state.done = false;
|
||||||
callback1 = wl_display_sync(state.display);
|
callback1 = wl_display_sync(state.display);
|
||||||
|
|
@ -152,7 +134,7 @@ client_test_multiple_queues(void)
|
||||||
wl_event_queue_destroy(queue);
|
wl_event_queue_destroy(queue);
|
||||||
wl_display_disconnect(state.display);
|
wl_display_disconnect(state.display);
|
||||||
|
|
||||||
return ret == -1 ? -1 : 0;
|
exit(ret == -1 ? -1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -168,7 +150,7 @@ static const struct wl_callback_listener sync_listener_roundtrip = {
|
||||||
|
|
||||||
/* Test that doing a roundtrip on a queue only the events on that
|
/* Test that doing a roundtrip on a queue only the events on that
|
||||||
* queue get dispatched. */
|
* queue get dispatched. */
|
||||||
static int
|
static void
|
||||||
client_test_queue_roundtrip(void)
|
client_test_queue_roundtrip(void)
|
||||||
{
|
{
|
||||||
struct wl_event_queue *queue;
|
struct wl_event_queue *queue;
|
||||||
|
|
@ -178,11 +160,11 @@ client_test_queue_roundtrip(void)
|
||||||
bool done1 = false;
|
bool done1 = false;
|
||||||
bool done2 = false;
|
bool done2 = false;
|
||||||
|
|
||||||
display = wl_display_connect(SOCKET_NAME);
|
display = wl_display_connect(NULL);
|
||||||
client_assert(display);
|
assert(display);
|
||||||
|
|
||||||
queue = wl_display_create_queue(display);
|
queue = wl_display_create_queue(display);
|
||||||
client_assert(queue);
|
assert(queue);
|
||||||
|
|
||||||
/* arm a callback on the default queue */
|
/* arm a callback on the default queue */
|
||||||
callback1 = wl_display_sync(display);
|
callback1 = wl_display_sync(display);
|
||||||
|
|
@ -197,8 +179,8 @@ client_test_queue_roundtrip(void)
|
||||||
|
|
||||||
/* roundtrip on default queue must not dispatch the other queue. */
|
/* roundtrip on default queue must not dispatch the other queue. */
|
||||||
wl_display_roundtrip(display);
|
wl_display_roundtrip(display);
|
||||||
client_assert(done1 == true);
|
assert(done1 == true);
|
||||||
client_assert(done2 == false);
|
assert(done2 == false);
|
||||||
|
|
||||||
/* re-arm the sync callback on the default queue, so we see that
|
/* re-arm the sync callback on the default queue, so we see that
|
||||||
* wl_display_roundtrip_queue() does not dispatch the default queue. */
|
* wl_display_roundtrip_queue() does not dispatch the default queue. */
|
||||||
|
|
@ -209,66 +191,14 @@ client_test_queue_roundtrip(void)
|
||||||
wl_callback_add_listener(callback1, &sync_listener_roundtrip, &done1);
|
wl_callback_add_listener(callback1, &sync_listener_roundtrip, &done1);
|
||||||
|
|
||||||
wl_display_roundtrip_queue(display, queue);
|
wl_display_roundtrip_queue(display, queue);
|
||||||
client_assert(done1 == false);
|
assert(done1 == false);
|
||||||
client_assert(done2 == true);
|
assert(done2 == true);
|
||||||
|
|
||||||
wl_callback_destroy(callback1);
|
wl_callback_destroy(callback1);
|
||||||
wl_callback_destroy(callback2);
|
wl_callback_destroy(callback2);
|
||||||
wl_event_queue_destroy(queue);
|
wl_event_queue_destroy(queue);
|
||||||
|
|
||||||
wl_display_disconnect(display);
|
wl_display_disconnect(display);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
client_alarm_handler(int sig)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Received SIGALRM signal, aborting.\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
client_sigsegv_handler(int sig)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Received SIGSEGV signal, aborting.\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
client_main(int fd)
|
|
||||||
{
|
|
||||||
bool cont = false;
|
|
||||||
|
|
||||||
signal(SIGSEGV, client_sigsegv_handler);
|
|
||||||
signal(SIGALRM, client_alarm_handler);
|
|
||||||
alarm(2);
|
|
||||||
|
|
||||||
if (read(fd, &cont, sizeof cont) != 1) {
|
|
||||||
close(fd);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
if (!cont)
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
|
|
||||||
if (client_test_proxy_destroy() != 0) {
|
|
||||||
fprintf(stderr, "proxy destroy test failed\n");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (client_test_multiple_queues() != 0) {
|
|
||||||
fprintf(stderr, "multiple proxy test failed\n");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (client_test_queue_roundtrip() != 0) {
|
|
||||||
fprintf(stderr, "queue rountrip test failed\n");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -277,35 +207,9 @@ dummy_bind(struct wl_client *client,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
sigchld_handler(int signal_number, void *data)
|
|
||||||
{
|
|
||||||
struct display *display = data;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
waitpid(-1, &status, 0);
|
|
||||||
display->child_exit_status = status;
|
|
||||||
|
|
||||||
wl_display_terminate(display->display);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
signal_client(int fd, bool cont)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = write(fd, &cont, sizeof cont);
|
|
||||||
close(fd);
|
|
||||||
assert(ret == sizeof cont);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(queue)
|
TEST(queue)
|
||||||
{
|
{
|
||||||
struct display display;
|
struct display *d;
|
||||||
struct wl_event_loop *loop;
|
|
||||||
struct wl_event_source *signal_source;
|
|
||||||
const struct wl_interface *dummy_interfaces[] = {
|
const struct wl_interface *dummy_interfaces[] = {
|
||||||
&wl_seat_interface,
|
&wl_seat_interface,
|
||||||
&wl_pointer_interface,
|
&wl_pointer_interface,
|
||||||
|
|
@ -313,48 +217,22 @@ TEST(queue)
|
||||||
&wl_surface_interface
|
&wl_surface_interface
|
||||||
};
|
};
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
pid_t pid;
|
|
||||||
int fds[2];
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = pipe(fds);
|
d = display_create();
|
||||||
assert(ret == 0);
|
|
||||||
|
|
||||||
pid = fork();
|
|
||||||
if (pid == -1) {
|
|
||||||
perror("fork");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
} else if (pid == 0) {
|
|
||||||
close(fds[1]);
|
|
||||||
exit(client_main(fds[0]));
|
|
||||||
}
|
|
||||||
close(fds[0]);
|
|
||||||
|
|
||||||
display.child_exit_status = EXIT_FAILURE;
|
|
||||||
display.display = wl_display_create();
|
|
||||||
if (!display.display) {
|
|
||||||
signal_client(fds[1], false);
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_LENGTH(dummy_interfaces); i++)
|
for (i = 0; i < ARRAY_LENGTH(dummy_interfaces); i++)
|
||||||
wl_global_create(display.display, dummy_interfaces[i],
|
wl_global_create(d->wl_display, dummy_interfaces[i],
|
||||||
dummy_interfaces[i]->version,
|
dummy_interfaces[i]->version,
|
||||||
NULL, dummy_bind);
|
NULL, dummy_bind);
|
||||||
|
|
||||||
ret = wl_display_add_socket(display.display, SOCKET_NAME);
|
client_create(d, client_test_proxy_destroy);
|
||||||
assert(ret == 0);
|
display_run(d);
|
||||||
|
|
||||||
loop = wl_display_get_event_loop(display.display);
|
client_create(d, client_test_multiple_queues);
|
||||||
signal_source = wl_event_loop_add_signal(loop, SIGCHLD, sigchld_handler,
|
display_run(d);
|
||||||
&display);
|
|
||||||
|
|
||||||
signal_client(fds[1], true);
|
client_create(d, client_test_queue_roundtrip);
|
||||||
wl_display_run(display.display);
|
display_run(d);
|
||||||
|
|
||||||
wl_event_source_remove(signal_source);
|
display_destroy(d);
|
||||||
wl_display_destroy(display.display);
|
|
||||||
|
|
||||||
assert(WIFEXITED(display.child_exit_status) &&
|
|
||||||
WEXITSTATUS(display.child_exit_status) == EXIT_SUCCESS);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue