From 2ac262f138e874188f0dca4af528d4fb7260f885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 3 Mar 2021 10:57:40 +0100 Subject: [PATCH] tests/clutter: Port to MetaContext The clutter tests neeed to start and stop, thus uses their own main loop instead of the one in MetaContext. Shouldn't matter, since nothing in mutter should happen that makes the test self-terminate from inside mutter. Part-of: --- src/tests/clutter-test-utils.c | 77 ++++++----------------- src/tests/clutter-test-utils.h | 6 +- src/tests/clutter/interactive/test-main.c | 15 +---- src/tests/meson.build | 31 ++++----- 4 files changed, 40 insertions(+), 89 deletions(-) diff --git a/src/tests/clutter-test-utils.c b/src/tests/clutter-test-utils.c index c480b4043..800664cd4 100644 --- a/src/tests/clutter-test-utils.c +++ b/src/tests/clutter-test-utils.c @@ -13,6 +13,8 @@ typedef struct { static ClutterTestEnvironment *test_environ = NULL; +static GMainLoop *clutter_test_main_loop = NULL; + #define DBUS_NAME_WARNING "Lost or failed to acquire name" static gboolean @@ -29,58 +31,6 @@ log_func (const gchar *log_domain, return TRUE; } -static const char * -test_get_plugin_name (void) -{ - const char *name; - - name = g_getenv ("MUTTER_TEST_PLUGIN_PATH"); - if (name) - return name; - else - return "libdefault"; -} - -static void -init_common_pre (void) -{ - const char *display; - - if (G_UNLIKELY (test_environ != NULL)) - g_error ("Attempting to initialize the test suite more than once, " - "aborting...\n"); - - meta_plugin_manager_load (test_get_plugin_name ()); - meta_override_x11_display_policy (META_X11_DISPLAY_POLICY_DISABLED); - meta_test_init (); - - display = g_getenv ("DISPLAY"); - if (!display || *display == '\0') - { - g_error ("No DISPLAY environment variable found, but we require a " - "DISPLAY set in order to run the conformance test suite.\n" - "Skipping all tests.\n"); - } - - /* we explicitly disable the synchronisation to the vertical refresh - * rate, and run the master clock using a 60 fps timer instead. - */ - _clutter_set_sync_to_vblank (FALSE); -} - -static void -init_common_post (int *argc, - char ***argv) -{ - g_test_init (argc, argv, NULL); - g_test_bug_base ("https://bugzilla.gnome.org/show_bug.cgi?id=%s"); - - /* our global state, accessible from each test unit */ - test_environ = g_new0 (ClutterTestEnvironment, 1); - - meta_start (); -} - /* * clutter_test_init: * @argc: (inout): number of arguments in @argv @@ -94,9 +44,18 @@ void clutter_test_init (int *argc, char ***argv) { - init_common_pre (); - g_assert (clutter_init (NULL, NULL) == CLUTTER_INIT_SUCCESS); - init_common_post (argc, argv); + MetaContext *context; + + context = meta_create_test_context (META_CONTEXT_TEST_TYPE_NESTED, + META_CONTEXT_TEST_FLAG_NO_X11); + g_assert (meta_context_configure (context, argc, argv, NULL)); + g_assert (meta_context_setup (context, NULL)); + + test_environ = g_new0 (ClutterTestEnvironment, 1); + + g_assert (meta_context_start (context, NULL)); + + clutter_test_main_loop = g_main_loop_new (NULL, FALSE); } /** @@ -306,13 +265,17 @@ clutter_test_run (void) void clutter_test_main (void) { - meta_run_main_loop (); + g_assert_nonnull (clutter_test_main_loop); + + g_main_loop_run (clutter_test_main_loop); } void clutter_test_quit (void) { - meta_quit (META_EXIT_SUCCESS); + g_assert_nonnull (clutter_test_main_loop); + + g_main_loop_quit (clutter_test_main_loop); } typedef struct { diff --git a/src/tests/clutter-test-utils.h b/src/tests/clutter-test-utils.h index 96a93de8a..48443f201 100644 --- a/src/tests/clutter-test-utils.h +++ b/src/tests/clutter-test-utils.h @@ -30,12 +30,8 @@ #include "clutter/clutter-actor.h" #include "clutter/clutter-color.h" #include "clutter/clutter-private.h" -#include "core/main-private.h" #include "meta/common.h" -#include "meta/main.h" -#include "backends/x11/nested/meta-backend-x11-nested.h" -#include "wayland/meta-wayland.h" -#include "wayland/meta-xwayland.h" +#include "tests/meta-context-test.h" G_BEGIN_DECLS diff --git a/src/tests/clutter/interactive/test-main.c b/src/tests/clutter/interactive/test-main.c index 681d4ba95..541a0e01b 100644 --- a/src/tests/clutter/interactive/test-main.c +++ b/src/tests/clutter/interactive/test-main.c @@ -6,11 +6,9 @@ #include #include "backends/x11/nested/meta-backend-x11-nested.h" -#include "core/main-private.h" -#include "meta/main.h" -#include "meta/meta-enums.h" -#include "wayland/meta-wayland.h" -#include "wayland/meta-xwayland.h" +#include "tests/clutter-test-utils.h" +#include "tests/meta-context-test.h" + #include "test-unit-names.h" #define MAX_DESC_SIZE 72 @@ -127,13 +125,6 @@ main (int argc, char **argv) g_option_context_free (context); - meta_wayland_override_display_name ("mutter-test-display"); - meta_xwayland_override_display_number (512); - meta_override_compositor_configuration (META_COMPOSITOR_TYPE_WAYLAND, - META_TYPE_BACKEND_X11_NESTED, - NULL); - meta_init (); - module = g_module_open (NULL, 0); if (!module) g_error ("*** Failed to open self for symbol lookup"); diff --git a/src/tests/meson.build b/src/tests/meson.build index 65f4d4bb3..26368c868 100644 --- a/src/tests/meson.build +++ b/src/tests/meson.build @@ -1,4 +1,20 @@ +test_context_sources = [ + 'meta-backend-test.c', + 'meta-backend-test.h', + 'meta-context-test.c', + 'meta-context-test.h', + 'meta-gpu-test.c', + 'meta-gpu-test.h', + 'meta-monitor-manager-test.c', + 'meta-monitor-manager-test.h', + 'monitor-test-utils.c', + 'monitor-test-utils.h', + 'test-utils.c', + 'test-utils.h', +] + clutter_test_utils = files ( + test_context_sources, 'clutter-test-utils.c', 'clutter-test-utils.h', ) @@ -42,21 +58,6 @@ test_env.set('G_TEST_SRCDIR', join_paths(meson.source_root(), 'src')) test_env.set('G_TEST_BUILDDIR', meson.build_root()) test_env.set('MUTTER_TEST_PLUGIN_PATH', '@0@'.format(default_plugin.full_path())) -test_context_sources = [ - 'meta-backend-test.c', - 'meta-backend-test.h', - 'meta-context-test.c', - 'meta-context-test.h', - 'meta-gpu-test.c', - 'meta-gpu-test.h', - 'meta-monitor-manager-test.c', - 'meta-monitor-manager-test.h', - 'monitor-test-utils.c', - 'monitor-test-utils.h', - 'test-utils.c', - 'test-utils.h', -] - test_client = executable('mutter-test-client', sources: ['test-client.c'], include_directories: tests_includepath,