tests/test-client: Add 'stop_after_next' and 'continue' commands

The 'stop_after_next' will execeute one command, then not return to the main
loop until a 'continue' command is passed. Commands will still be
processed between 'stop_after_next' and 'continue'.

This is intended to be used to induce race conditions.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2066>
This commit is contained in:
Jonas Ådahl 2021-10-29 21:18:56 +02:00 committed by Marge Bot
parent 2eda6d0a7c
commit 028ed0685d
2 changed files with 58 additions and 0 deletions

View File

@ -34,6 +34,7 @@ GHashTable *windows;
GQuark event_source_quark; GQuark event_source_quark;
GQuark event_handlers_quark; GQuark event_handlers_quark;
GQuark can_take_focus_quark; GQuark can_take_focus_quark;
gboolean sync_after_lines = -1;
typedef void (*XEventHandler) (GtkWidget *window, XEvent *event); typedef void (*XEventHandler) (GtkWidget *window, XEvent *event);
@ -824,6 +825,26 @@ process_line (const char *line)
goto out; goto out;
} }
} }
else if (strcmp (argv[0], "stop_after_next") == 0)
{
if (sync_after_lines != -1)
{
g_print ("Can't invoke 'stop_after_next' while already stopped");
goto out;
}
sync_after_lines = 1;
}
else if (strcmp (argv[0], "continue") == 0)
{
if (sync_after_lines != 0)
{
g_print ("Can only invoke 'continue' while stopped");
goto out;
}
sync_after_lines = -1;
}
else else
{ {
g_print ("Unknown command %s\n", argv[0]); g_print ("Unknown command %s\n", argv[0]);
@ -862,6 +883,30 @@ on_line_received (GObject *source,
static void static void
read_next_line (GDataInputStream *in) read_next_line (GDataInputStream *in)
{ {
while (sync_after_lines == 0)
{
GdkDisplay *display = gdk_display_get_default ();
g_autoptr (GError) error = NULL;
g_autofree char *line = NULL;
size_t length;
gdk_display_flush (display);
line = g_data_input_stream_read_line (in, &length, NULL, &error);
if (!line)
{
if (error)
g_printerr ("Error reading from stdin: %s\n", error->message);
gtk_main_quit ();
return;
}
process_line (line);
}
if (sync_after_lines >= 0)
sync_after_lines--;
g_data_input_stream_read_line_async (in, G_PRIORITY_DEFAULT, NULL, g_data_input_stream_read_line_async (in, G_PRIORITY_DEFAULT, NULL,
on_line_received, NULL); on_line_received, NULL);
} }

View File

@ -960,6 +960,19 @@ test_case_do (TestCase *test,
return FALSE; return FALSE;
} }
} }
else if (strcmp (argv[0], "stop_after_next") == 0 ||
strcmp (argv[0], "continue") == 0)
{
if (argc != 2)
BAD_COMMAND("usage: %s <client-id>", argv[0]);
MetaTestClient *client = test_case_lookup_client (test, argv[1], error);
if (!client)
return FALSE;
if (!meta_test_client_do (client, error, argv[0], NULL))
return FALSE;
}
else else
{ {
BAD_COMMAND("Unknown command %s", argv[0]); BAD_COMMAND("Unknown command %s", argv[0]);