tests/screen-cast: Move executable launching into helper
It doesn't contain anything screen cast specific, except the XDG_RUNTIME_DIR, so make it usable from elsewhere. While at it, prepare it for being able to run the glib test functionality. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3859>
This commit is contained in:
parent
acd7fa7f50
commit
8cf41761a9
@ -917,3 +917,80 @@ meta_flush_input (MetaContext *context)
|
||||
g_mutex_unlock (&mutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
GSubprocess *
|
||||
meta_launch_test_executable (const char *name,
|
||||
const char *argv0,
|
||||
...)
|
||||
{
|
||||
g_autoptr (GPtrArray) args = NULL;
|
||||
const char *arg;
|
||||
va_list ap;
|
||||
g_autofree char *test_client_path = NULL;
|
||||
GSubprocessLauncher *launcher;
|
||||
GSubprocess *subprocess;
|
||||
GError *error = NULL;
|
||||
|
||||
args = g_ptr_array_new ();
|
||||
|
||||
test_client_path = g_test_build_filename (G_TEST_BUILT, name, NULL);
|
||||
g_ptr_array_add (args, test_client_path);
|
||||
|
||||
va_start (ap, argv0);
|
||||
g_ptr_array_add (args, (char *) argv0);
|
||||
while ((arg = va_arg (ap, const char *)))
|
||||
g_ptr_array_add (args, (char *) arg);
|
||||
|
||||
g_ptr_array_add (args, NULL);
|
||||
va_end (ap);
|
||||
|
||||
launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_NONE);
|
||||
g_subprocess_launcher_setenv (launcher,
|
||||
"XDG_RUNTIME_DIR", getenv ("XDG_RUNTIME_DIR"),
|
||||
TRUE);
|
||||
g_subprocess_launcher_setenv (launcher,
|
||||
"G_TEST_SRCDIR", g_test_get_dir (G_TEST_DIST),
|
||||
TRUE);
|
||||
g_subprocess_launcher_setenv (launcher,
|
||||
"G_TEST_BUILDDIR", g_test_get_dir (G_TEST_BUILT),
|
||||
TRUE);
|
||||
g_subprocess_launcher_setenv (launcher,
|
||||
"G_MESSAGES_DEBUG", "all",
|
||||
TRUE);
|
||||
subprocess = g_subprocess_launcher_spawnv (launcher,
|
||||
(const char * const *) args->pdata,
|
||||
&error);
|
||||
if (!subprocess)
|
||||
g_error ("Failed to launch screen cast test client: %s", error->message);
|
||||
|
||||
return subprocess;
|
||||
}
|
||||
|
||||
static void
|
||||
test_client_exited (GObject *source_object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
if (!g_subprocess_wait_finish (G_SUBPROCESS (source_object),
|
||||
result,
|
||||
&error))
|
||||
g_error ("Screen cast test client exited with an error: %s", error->message);
|
||||
|
||||
g_main_loop_quit (user_data);
|
||||
}
|
||||
|
||||
void
|
||||
meta_wait_test_process (GSubprocess *subprocess)
|
||||
{
|
||||
GMainLoop *loop;
|
||||
|
||||
loop = g_main_loop_new (NULL, FALSE);
|
||||
g_subprocess_wait_check_async (subprocess,
|
||||
NULL,
|
||||
test_client_exited,
|
||||
loop);
|
||||
g_main_loop_run (loop);
|
||||
g_assert_true (g_subprocess_get_successful (subprocess));
|
||||
}
|
||||
|
@ -128,3 +128,11 @@ MetaVirtualMonitor * meta_create_test_monitor (MetaContext *context,
|
||||
|
||||
META_EXPORT
|
||||
void meta_flush_input (MetaContext *context);
|
||||
|
||||
META_EXPORT
|
||||
GSubprocess * meta_launch_test_executable (const char *name,
|
||||
const char *argv0,
|
||||
...);
|
||||
|
||||
META_EXPORT
|
||||
void meta_wait_test_process (GSubprocess *subprocess);
|
||||
|
@ -23,61 +23,18 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "meta/util.h"
|
||||
#include "tests/meta-test-utils.h"
|
||||
#include "tests/meta-test/meta-context-test.h"
|
||||
|
||||
static void
|
||||
test_client_exited (GObject *source_object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
if (!g_subprocess_wait_finish (G_SUBPROCESS (source_object),
|
||||
result,
|
||||
&error))
|
||||
g_error ("Screen cast test client exited with an error: %s", error->message);
|
||||
|
||||
g_main_loop_quit (user_data);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_test_screen_cast_record_virtual (void)
|
||||
{
|
||||
GSubprocessLauncher *launcher;
|
||||
g_autofree char *test_client_path = NULL;
|
||||
GError *error = NULL;
|
||||
GSubprocess *subprocess;
|
||||
GMainLoop *loop;
|
||||
|
||||
launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_NONE);
|
||||
g_autoptr (GSubprocess) subprocess = NULL;
|
||||
|
||||
meta_add_verbose_topic (META_DEBUG_SCREEN_CAST);
|
||||
|
||||
test_client_path = g_test_build_filename (G_TEST_BUILT,
|
||||
"mutter-screen-cast-client",
|
||||
subprocess = meta_launch_test_executable ("mutter-screen-cast-client",
|
||||
NULL);
|
||||
g_subprocess_launcher_setenv (launcher,
|
||||
"XDG_RUNTIME_DIR", getenv ("XDG_RUNTIME_DIR"),
|
||||
TRUE);
|
||||
g_subprocess_launcher_setenv (launcher,
|
||||
"G_MESSAGES_DEBUG", "all",
|
||||
TRUE);
|
||||
subprocess = g_subprocess_launcher_spawn (launcher,
|
||||
&error,
|
||||
test_client_path,
|
||||
NULL);
|
||||
if (!subprocess)
|
||||
g_error ("Failed to launch screen cast test client: %s", error->message);
|
||||
|
||||
loop = g_main_loop_new (NULL, FALSE);
|
||||
g_subprocess_wait_check_async (subprocess,
|
||||
NULL,
|
||||
test_client_exited,
|
||||
loop);
|
||||
g_main_loop_run (loop);
|
||||
g_assert_true (g_subprocess_get_successful (subprocess));
|
||||
g_object_unref (subprocess);
|
||||
|
||||
meta_wait_test_process (subprocess);
|
||||
meta_remove_verbose_topic (META_DEBUG_SCREEN_CAST);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user