[gtk/test-text-buffer-undo: 4/5] ci: Use mutter for tests




commit dd6e6efec45e622946efceb636ca8dd2cf40c47d
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat May 1 19:41:25 2021 -0400

    ci: Use mutter for tests
    
    Use mutter --headless instead of westons headless
    backend for running tests under Wayland. It is a little
    more compliated: in order to get surfaces focused, we
    need to start a remote desktop session. The upside is
    that we will be able to inject input events via D-Bus,
    in the future.

 .gitlab-ci/run-tests.sh         | 39 +++++++++++---------
 .gitlab-ci/start-remote-session | 79 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 101 insertions(+), 17 deletions(-)
---
diff --git a/.gitlab-ci/run-tests.sh b/.gitlab-ci/run-tests.sh
index fa29859b6f..9b1b7fb140 100755
--- a/.gitlab-ci/run-tests.sh
+++ b/.gitlab-ci/run-tests.sh
@@ -15,10 +15,9 @@ case "${backend}" in
   x11)
     xvfb-run -a -s "-screen 0 1024x768x24 -noreset" \
           meson test -C ${builddir} \
-                --timeout-multiplier "${MESON_TEST_TIMEOUT_MULTIPLIER}" \
+                --timeout-multiplier "${MESON_TEST_TIMEOUT_MULTIPLIER:-1}" \
                 --print-errorlogs \
-                --setup=${backend} \
-                --suite=gtk \
+                --setup=x11 \
                 --no-suite=gsk-compare-broadway
 
     # Store the exit code for the CI run, but always
@@ -29,19 +28,26 @@ case "${backend}" in
   wayland)
     export XDG_RUNTIME_DIR="$(mktemp -p $(pwd) -d xdg-runtime-XXXXXX)"
 
-    weston --backend=headless-backend.so --socket=wayland-5 --idle-time=0 &
-    compositor=$!
-    export WAYLAND_DISPLAY=wayland-5
+    dbus-run-session sh <<EOF
 
-    meson test -C ${builddir} \
-                --timeout-multiplier "${MESON_TEST_TIMEOUT_MULTIPLIER}" \
-                --print-errorlogs \
-                --setup=${backend} \
-                --suite=gtk \
-                --no-suite=gsk-compare-broadway
+mutter --headless --no-x11 --sm-disable --virtual-monitor 1024x768 --wayland-display wayland-5 &
 
-    exit_code=$?
-    kill ${compositor}
+compositor=\$!
+export WAYLAND_DISPLAY=wayland-5
+
+python ${srcdir}/.gitlab-ci/start-remote-session &
+
+meson test -C ${builddir} \
+           --timeout-multiplier "${MESON_TEST_TIMEOUT_MULTIPLIER:-1}" \
+           --print-errorlogs \
+           --setup=wayland \
+           --no-suite=gsk-compare-broadway
+
+exit_code=\$?
+kill \${compositor}
+exit \${exit_code}
+
+EOF
     ;;
 
   broadway)
@@ -52,10 +58,9 @@ case "${backend}" in
     export BROADWAY_DISPLAY=:5
 
     meson test -C ${builddir} \
-                --timeout-multiplier "${MESON_TEST_TIMEOUT_MULTIPLIER}" \
+                --timeout-multiplier "${MESON_TEST_TIMEOUT_MULTIPLIER:-1}" \
                 --print-errorlogs \
-                --setup=${backend} \
-                --suite=gtk \
+                --setup=broadway \
                 --no-suite=gsk-compare-opengl
 
     # don't let Broadway failures fail the run, for now
diff --git a/.gitlab-ci/start-remote-session b/.gitlab-ci/start-remote-session
new file mode 100644
index 0000000000..0b5790f6ea
--- /dev/null
+++ b/.gitlab-ci/start-remote-session
@@ -0,0 +1,79 @@
+import sys
+import subprocess
+import gi
+
+gi.require_version('Gdk', '4.0')
+
+from gi.repository import GLib, Gdk
+from pydbus import SessionBus
+
+verbose = True
+observe = False
+
+done = False
+session = None
+
+def terminate():
+    sys.exit(1)
+
+def stream_added(node_id):
+    freq = 60
+    width = 1024
+    height = 768
+
+    # Use gstreamer out-of-process, since the gst gl support gets
+    # itself into a twist with its wayland connection when monitors
+    # disappear
+    pipeline_desc = f'gst-launch-1.0 pipewiresrc path={node_id} ! 
video/x-raw,max-framerate={freq}/1,width={width},height={height} ! videoconvert ! glimagesink'
+    if verbose:
+        print(f'launching {pipeline_desc}')
+    subprocess.Popen([pipeline_desc], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
+
+def mutter_appeared(name):
+    global session
+    if verbose:
+        print("mutter appeared on the bus")
+    remote_desktop = bus.get('org.gnome.Mutter.RemoteDesktop',
+                             '/org/gnome/Mutter/RemoteDesktop')
+    session_path = remote_desktop.CreateSession()
+    session = bus.get('org.gnome.Mutter.RemoteDesktop', session_path)
+
+    if verbose:
+        print(f'remote desktop session {session_path}')
+
+    screen_cast = bus.get('org.gnome.Mutter.ScreenCast',
+                          '/org/gnome/Mutter/ScreenCast')
+    path = screen_cast.CreateSession({ ' remote-desktop-session-id' : GLib.Variant('s', session.SessionId) })
+
+    if verbose:
+        print(f'screen cast session {path}')
+
+    if observe:
+        screen_cast_session = bus.get('org.gnome.Mutter.ScreenCast', path)
+
+        stream_path = screen_cast_session.RecordMonitor('Meta-0', { })
+
+        if verbose:
+            print(f'stream path {stream_path}')
+
+        stream = bus.get('org.gnome.Mutter.ScreenCast', stream_path)
+        stream.onPipeWireStreamAdded = stream_added
+        screen_cast_session.Start()
+
+    session.Start()
+
+def mutter_vanished():
+    global done
+    if session != None:
+        if verbose:
+           print("mutter left the bus")
+        done = True
+
+bus = SessionBus()
+bus.watch_name('org.gnome.Mutter.RemoteDesktop', 0, mutter_appeared, mutter_vanished)
+
+try:
+    while not done:
+      GLib.MainContext.default().iteration(True)
+except KeyboardInterrupt:
+    print('Interrupted')


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]