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
This commit is contained in:
Niels De Graef 2020-05-14 17:51:55 +02:00
parent b11e529316
commit 0352559efa
4 changed files with 34 additions and 3 deletions

View File

@ -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',
)

View File

@ -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

View File

@ -1086,8 +1086,15 @@ 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('headless',
exe_wrapper: find_program('build' / 'meson' / 'run_test_env.sh'),
is_default: true,
)
endif
# Set bug report URL

View File

@ -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')