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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3358>
This commit is contained in:
Sebastian Wick 2023-10-30 15:50:40 +01:00 committed by Marge Bot
parent c79332a5f8
commit 6f6f16c2b1
3 changed files with 13 additions and 10 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -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))