From 6f6f16c2b109c8ad3a2670b801575b7e3b6c556e Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Mon, 30 Oct 2023 15:50:40 +0100 Subject: [PATCH] tests/wayland-test-client-utils: Sync event serial in same dispatch If multiple sync events are send in the same dispatch, a further call to wait_for_sync_event will get stuck. Fix this by keeping track of the latest sync event serial in the display and always compare against that. This also means sync event sequences must start at 0 and increase by 1. The wayland-x11 interop test is the only one where that wasn't already the case. Part-of: --- .../wayland-test-client-utils.c | 17 +++++++++-------- .../wayland-test-client-utils.h | 2 ++ src/tests/wayland-x11-interop-tests.c | 4 ++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/tests/wayland-test-clients/wayland-test-client-utils.c b/src/tests/wayland-test-clients/wayland-test-client-utils.c index 97d28b8e1..a964d4c38 100644 --- a/src/tests/wayland-test-clients/wayland-test-client-utils.c +++ b/src/tests/wayland-test-clients/wayland-test-client-utils.c @@ -553,23 +553,24 @@ wait_for_view_verified (WaylandDisplay *display, static void on_sync_event (WaylandDisplay *display, uint32_t serial, - uint32_t *expected_serial) + void *user_data) { - g_assert_cmpuint (serial, ==, *expected_serial); - *expected_serial = serial + 1; + g_assert_cmpuint (serial, ==, display->sync_event_serial_next); + display->sync_event_serial_next = serial + 1; } void wait_for_sync_event (WaylandDisplay *display, - uint32_t serial) + uint32_t expected_serial) { - uint32_t expected_serial = serial; + gulong handler_id; + handler_id = g_signal_connect (display, "sync-event", G_CALLBACK (on_sync_event), NULL); - g_signal_connect (display, "sync-event", G_CALLBACK (on_sync_event), - &expected_serial); - while (expected_serial != serial + 1) + while (expected_serial + 1 > display->sync_event_serial_next) { if (wl_display_dispatch (display->display) == -1) g_error ("%s: Failed to dispatch Wayland display", __func__); } + + g_signal_handler_disconnect (display, handler_id); } diff --git a/src/tests/wayland-test-clients/wayland-test-client-utils.h b/src/tests/wayland-test-clients/wayland-test-client-utils.h index 332964938..6451f369f 100644 --- a/src/tests/wayland-test-clients/wayland-test-client-utils.h +++ b/src/tests/wayland-test-clients/wayland-test-client-utils.h @@ -34,6 +34,8 @@ typedef struct _WaylandDisplay struct xdg_wm_base *xdg_wm_base; struct test_driver *test_driver; + uint32_t sync_event_serial_next; + GHashTable *properties; } WaylandDisplay; diff --git a/src/tests/wayland-x11-interop-tests.c b/src/tests/wayland-x11-interop-tests.c index 2ea87d7aa..6141bb79d 100644 --- a/src/tests/wayland-x11-interop-tests.c +++ b/src/tests/wayland-x11-interop-tests.c @@ -185,7 +185,7 @@ service_client_thread_func (gpointer user_data) data->xwindow); wl_surface_commit (surface->wl_surface); - wait_for_sync_event (display, 1); + wait_for_sync_event (display, 0); mutter_x11_interop_destroy (x11_interop); g_object_unref (display); @@ -231,7 +231,7 @@ meta_test_wayland_client_x11_interop_x11_parent (void) g_assert_true (meta_window_get_transient_for (wayland_window) == x11_window); - meta_wayland_test_driver_emit_sync_event (test_driver, 1); + meta_wayland_test_driver_emit_sync_event (test_driver, 0); g_debug ("Waiting for client to disconnect"); while (!g_atomic_int_get (&data.client_terminated))