From b48351005e86aeb7197c16d3b5a698b825558d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 18 Apr 2023 23:55:30 +0200 Subject: [PATCH] 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: --- src/tests/meson.build | 19 +++++++++- src/tests/x11-compositor-checker.c | 52 ++++++++++++++++++++++++++ src/tests/xwayland-tests.c | 59 ++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 src/tests/x11-compositor-checker.c diff --git a/src/tests/meson.build b/src/tests/meson.build index 558971ae8..16c77b7bd 100644 --- a/src/tests/meson.build +++ b/src/tests/meson.build @@ -464,6 +464,20 @@ 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': 'wayland-x11-interop', @@ -480,7 +494,10 @@ if have_native_tests { '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 . + */ + +#include "config.h" + +#include +#include +#include + +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 @@ -247,9 +247,68 @@ meta_test_hammer_activate (void) meta_test_client_destroy (wayland_client); } +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",