[gimp/wip/nielsdg/xvfb-run] meson: Allow running tests headless



commit 1d9e7edee17eea350cefe8c23a3ddfb87c72e5ac
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Thu May 14 17:51:55 2020 +0200

    meson: Allow running tests headless
    
    This commit makes sure we can properly run the tests in a headless
    environment, i.e. they don't mess with the user's X display or their
    session bus. The latter is also needed for parallel tests as they fail
    to simultaneously own the same name on the session bus.
    
    Replaced the "xvfb-run" meson option with the "headless" option, which
    is more intuitive (and also more correct, since we now also require
    `dbus-run-session` to run the tests, not only `xvfb-run`).
    
    Finally, note that we need a version of `xvfb-run` that supports the
    `-d` (`--auto-display`) option. The problem with `--auto-servernum`
    which is also regularly used, is that it doesn't shut down cleanly,
    returning a non-zero exit code, wich makes the test fail.
    
    Fixes https://gitlab.gnome.org/GNOME/gimp/-/issues/5078

 app/tests/meson.build       |  1 +
 build/meson/run_test_env.sh | 23 +++++++++++++++++++++++
 meson.build                 | 15 +++++++++++++--
 meson_options.txt           |  2 +-
 4 files changed, 38 insertions(+), 3 deletions(-)
---
diff --git a/app/tests/meson.build b/app/tests/meson.build
index 7b3cca1c9b..2900e061b4 100644
--- a/app/tests/meson.build
+++ b/app/tests/meson.build
@@ -58,6 +58,7 @@ foreach test_name : app_tests
       'GIMP_TESTING_ABS_TOP_BUILDDIR='+ meson.build_root(),
       'GIMP_TESTING_PLUGINDIRS=' +      meson.build_root()/'plug-ins'/'common',
       'GIMP_TESTING_PLUGINDIRS_BASENAME_IGNORES=mkgen.pl',
+      'UI_TEST=yes',
     ],
     suite: 'app',
   )
diff --git a/build/meson/run_test_env.sh b/build/meson/run_test_env.sh
new file mode 100644
index 0000000000..f71585a432
--- /dev/null
+++ b/build/meson/run_test_env.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+#
+# Wrapper script to use for the Meson test setup.
+#
+# Define the "UI_TEST" for all tests that should run headless
+
+if [[ -n "${UI_TEST}" ]]; then
+  # Use Xvfb to simulate a graphical session; note that this needs
+  # a new enough version which has the -d option.
+  #
+  # Also use dbus-run-session to make sure parallel tests aren't failing
+  # as they simultaneously try to own the "org.gimp.GIMP.UI" D-Bus name
+
+  xvfb-run -d --server-args="-screen 0 1280x1024x24" \
+    dbus-run-session -- "$@"
+
+else
+  # Run the executable directly,
+  # i.e. no need to run Xvfb (which will have a timeout)
+
+  "$@"
+fi
+
diff --git a/meson.build b/meson.build
index 304c79fe4f..b28497932a 100644
--- a/meson.build
+++ b/meson.build
@@ -1086,8 +1086,19 @@ if have_vector_icons
   endif
 endif
 
-xvfb_run = find_program('xvfb-run', required: get_option('xvfb-run'))
-conf.set('HAVE_XVFB_RUN', xvfb_run.found())
+# Running tests headless
+xvfb_run = find_program('xvfb-run', required: get_option('headless-tests'))
+dbus_run_session = find_program('dbus-run-session', required: get_option('headless-tests'))
+if xvfb_run.found() and dbus_run_session.found()
+  add_test_setup('default',
+    exe_wrapper: find_program('build' / 'meson' / 'run_test_env.sh'),
+    is_default: true,
+  )
+else
+  add_test_setup('default',
+    is_default: true,
+  )
+endif
 
 # Set bug report URL
 
diff --git a/meson_options.txt b/meson_options.txt
index 10255dc9ca..e59524d450 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -50,7 +50,7 @@ option('webp',              type: 'feature', value: 'auto', description: 'Webp s
 option('wmf',               type: 'feature', value: 'auto', description: 'Wmf support')
 option('xcursor',           type: 'feature', value: 'auto', description: 'Xcursor support')
 option('xpm',               type: 'feature', value: 'auto', description: 'XPM support')
-option('xvfb-run',          type: 'feature', value: 'auto', description: 'Use xvfb-run for UI-dependent 
automatic tests')
+option('headless-tests',    type: 'feature', value: 'auto', description: 'Use xvfb-run/dbus-run-session for 
UI-dependent automatic tests')
 
 option('gtk-doc',           type: 'boolean', value: true,   description: 'Build developer documentation')
 option('gtk-doc-app',       type: 'boolean', value: false,  description: 'Build developer documentation for 
app')


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