summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2023-04-18 23:55:30 +0200
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2023-05-15 19:21:52 +0200
commit5a51199c0a558f2f1b0757a584bff07f9167acbd (patch)
tree8df0fba2cea490ceea2dff1d93f98b4e93c17d3a
parentcf5dd09e45861d7a0235aa096082d6f1a212eb1f (diff)
downloadmutter-5a51199c0a558f2f1b0757a584bff07f9167acbd.tar.gz
tests: Add check for compositor state on XWayland startup
Check that the first X11 window started has a compositor defined. See: https://gitlab.gnome.org/GNOME/mutter/-/issues/2472#note_1582262 Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2970>
-rw-r--r--src/tests/meson.build19
-rw-r--r--src/tests/x11-compositor-checker.c52
-rw-r--r--src/tests/xwayland-tests.c59
3 files changed, 129 insertions, 1 deletions
diff --git a/src/tests/meson.build b/src/tests/meson.build
index 81150046b..11838970b 100644
--- a/src/tests/meson.build
+++ b/src/tests/meson.build
@@ -474,11 +474,28 @@ if have_native_tests
},
]
if have_xwayland
+ x11_compositor_checker = executable('x11-compositor-checker',
+ sources: ['x11-compositor-checker.c'],
+ include_directories: tests_includes,
+ c_args: [
+ tests_c_args,
+ ],
+ dependencies: [
+ x11_dep,
+ ],
+ install: have_installed_tests,
+ install_dir: mutter_installed_tests_libexecdir,
+ install_rpath: pkglibdir,
+ )
+
test_cases += [
{
'name': 'xwayland',
'suite': 'wayland',
- 'depends': [ test_client ],
+ 'depends': [
+ test_client,
+ x11_compositor_checker,
+ ],
'sources': [
'xwayland-tests.c',
],
diff --git a/src/tests/x11-compositor-checker.c b/src/tests/x11-compositor-checker.c
new file mode 100644
index 000000000..77e415909
--- /dev/null
+++ b/src/tests/x11-compositor-checker.c
@@ -0,0 +1,52 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2022 Alan Jenkins.
+ * Copyright (C) 2023 Canonical Ltd.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+static int
+has_compositor (Display *dpy,
+ int screen)
+{
+ char prop_name[20];
+
+ snprintf (prop_name, 20, "_NET_WM_CM_S%d", screen);
+ return XGetSelectionOwner (dpy, XInternAtom (dpy, prop_name, False)) != None;
+}
+
+int
+main (void)
+{
+ Display *dpy = XOpenDisplay ("");
+
+ if (has_compositor (dpy, XDefaultScreen (dpy)))
+ {
+ printf ("X11 Compositor is available for display %s.%d\n",
+ DisplayString (dpy), XDefaultScreen (dpy));
+ return 0;
+ }
+
+ printf ("NO X11 Compositor is available for display %s:%d\n",
+ DisplayString (dpy), XDefaultScreen (dpy));
+
+ return 1;
+}
diff --git a/src/tests/xwayland-tests.c b/src/tests/xwayland-tests.c
index dc3608b5e..cb2fd6c9d 100644
--- a/src/tests/xwayland-tests.c
+++ b/src/tests/xwayland-tests.c
@@ -248,8 +248,67 @@ meta_test_hammer_activate (void)
}
static void
+compositor_check_proc_async (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ g_autoptr (GError) error = NULL;
+ GMainLoop *loop = user_data;
+
+ g_subprocess_wait_check_finish (G_SUBPROCESS (source_object), res, &error);
+ g_assert_no_error (error);
+ g_main_loop_quit (loop);
+}
+
+static void
+meta_test_xwayland_compositor_selection (void)
+{
+ g_autoptr (GError) error = NULL;
+ g_autoptr (GSubprocessLauncher) launcher = NULL;
+ g_autoptr (GSubprocess) subprocess = NULL;
+ g_autoptr (GMainLoop) loop = NULL;
+ MetaDisplay *display = meta_context_get_display (test_context);
+ MetaWaylandCompositor *compositor;
+ const char *x11_display_name;
+ const char *x11_compositor_checker;
+
+ g_assert_null (meta_display_get_x11_display (display));
+
+ g_assert (meta_is_wayland_compositor ());
+ compositor = meta_context_get_wayland_compositor (test_context);
+ x11_display_name = meta_wayland_get_public_xwayland_display_name (compositor);
+ g_assert_nonnull (x11_display_name);
+
+ launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_NONE);
+ g_subprocess_launcher_setenv (launcher,
+ "DISPLAY", x11_display_name,
+ TRUE);
+
+ x11_compositor_checker = g_test_build_filename (G_TEST_BUILT,
+ "src",
+ "tests",
+ "x11-compositor-checker",
+ NULL);
+
+ subprocess = g_subprocess_launcher_spawn (launcher,
+ &error,
+ x11_compositor_checker,
+ NULL);
+ g_assert_no_error (error);
+
+ loop = g_main_loop_new (NULL, FALSE);
+ g_subprocess_wait_check_async (subprocess, NULL,
+ compositor_check_proc_async, loop);
+ g_main_loop_run (loop);
+
+ g_assert_nonnull (meta_display_get_x11_display (display));
+}
+
+static void
init_tests (void)
{
+ g_test_add_func ("/backends/xwayland/compositor/selection",
+ meta_test_xwayland_compositor_selection);
g_test_add_func ("/backends/xwayland/restart/selection",
meta_test_xwayland_restart_selection);
g_test_add_func ("/backends/xwayland/crash/only-x11",