From f50e9816fdb6b9e8df52eab5c91ba8ef08c271cb Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 21 Jul 2016 10:20:21 +0100 Subject: [PATCH] Add a regression test for dbus-launch in X11 Signed-off-by: Simon McVittie --- .travis.yml | 2 + test/Makefile.am | 3 + test/test-dbus-launch-x11.sh | 254 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 259 insertions(+) create mode 100755 test/test-dbus-launch-x11.sh diff --git a/.travis.yml b/.travis.yml index db29673..7f09c1d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,8 +27,10 @@ install: python-dbus python-gi valgrind + xauth xmlto xsltproc + xvfb - > test "$dbus_ci_host" != mingw || sudo apt-get -qq -y install binutils-mingw-w64-i686 g++-mingw-w64-i686 wine:i386 diff --git a/test/Makefile.am b/test/Makefile.am index a588077..85799fe 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -176,6 +176,7 @@ dist_installable_test_scripts += \ if DBUS_ENABLE_EMBEDDED_TESTS dist_installable_test_scripts += \ test-dbus-launch-eval.sh \ + test-dbus-launch-x11.sh \ $(NULL) endif DBUS_ENABLE_EMBEDDED_TESTS @@ -200,6 +201,7 @@ installcheck_environment = \ export XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR; \ export DBUS_TEST_DAEMON=$(DESTDIR)$(DBUS_DAEMONDIR)/dbus-daemon$(EXEEXT); \ export DBUS_TEST_DBUS_LAUNCH=$(DESTDIR)$(bindir)/dbus-launch$(EXEEXT); \ + export DBUS_TEST_DBUS_MONITOR=$(DESTDIR)$(bindir)/dbus-monitor$(EXEEXT); \ export DBUS_TEST_DBUS_SEND=$(DESTDIR)$(bindir)/dbus-send$(EXEEXT); \ export DBUS_TEST_HOMEDIR=@abs_top_builddir@/dbus; \ export DBUS_TEST_DATADIR=$(DESTDIR)$(datadir); \ @@ -210,6 +212,7 @@ AM_TESTS_ENVIRONMENT = \ export DBUS_FATAL_WARNINGS=1; \ export DBUS_TEST_DAEMON=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT); \ export DBUS_TEST_DBUS_LAUNCH=@abs_top_builddir@/tools/dbus-launch$(EXEEXT); \ + export DBUS_TEST_DBUS_MONITOR=@abs_top_builddir@/tools/dbus-monitor$(EXEEXT); \ export DBUS_TEST_DBUS_SEND=@abs_top_builddir@/tools/dbus-send$(EXEEXT); \ export DBUS_TEST_DATA=@abs_top_builddir@/test/data; \ export DBUS_TEST_HOMEDIR=@abs_top_builddir@/dbus; \ diff --git a/test/test-dbus-launch-x11.sh b/test/test-dbus-launch-x11.sh new file mode 100755 index 0000000..7c87690 --- /dev/null +++ b/test/test-dbus-launch-x11.sh @@ -0,0 +1,254 @@ +#!/bin/sh + +# Copyright © 2016 Collabora Ltd. +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +set -e +set -x + +export DBUS_DEBUG_OUTPUT=1 +echo "# dbus-daemon binary: ${DBUS_TEST_DAEMON:=dbus-daemon}" +echo "# dbus-launch binary: ${DBUS_TEST_DBUS_LAUNCH:=dbus-launch}" +echo "# dbus-monitor binary: ${DBUS_TEST_DBUS_LAUNCH:=dbus-monitor}" +echo "# dbus-send binary: ${DBUS_TEST_DBUS_SEND:=dbus-send}" + +if test -n "$DBUS_TEST_DATA"; then + echo "# test data: $DBUS_TEST_DATA" + bus_config="--config-file=$DBUS_TEST_DATA/valid-config-files/session.conf" + launch_config="$bus_config" +elif test -n "$DBUS_TEST_DATADIR"; then + echo "# datadir: $DBUS_TEST_DATADIR" + bus_config="--config-file=$DBUS_TEST_DATADIR/dbus-1/session.conf" + launch_config="$bus_config" +else + echo "# using standard session bus configuration" + bus_config="--session" + # dbus-launch doesn't accept --session so add a harmless command-line + # argument + launch_config="--sh-syntax" +fi + +if ! workdir="$(mktemp -d)"; then + echo "1..0 # SKIP - mktemp -d doesn't work" + exit 0 +fi + +if ! xvfb-run --auto-servernum true; then + echo "1..0 # SKIP - xvfb-run doesn't work" + exit 0 +fi + +test_num=0 +x_session_pid= +unset DISPLAY +unset XAUTHORITY + +start_xvfb () { + rm -f "$workdir/display" + rm -f "$workdir/ready" + rm -f "$workdir/x-session-pid" + rm -f "$workdir/xauthority" + rm -f "$workdir/xvfb-done" + + # Run an X session in the background for up to 1 hour. + ( + set +e + xvfb-run --auto-servernum \ + sh -c 'echo "$$" > "$1/x-session-pid"; echo "$XAUTHORITY" > "$1/xauthority"; echo "$DISPLAY" > "$1/display"; touch "$1/ready"; exec sleep 3600' \ + sh "$workdir" + touch "$workdir/xvfb-done" + ) & + + tries=0 + while ! [ -e "$workdir/ready" ]; do + if [ $tries -ge 10 ]; then + echo "# Failed to start xvfb-run within $tries seconds" + exit 1 + fi + tries=$(($tries + 1)) + sleep 1 + done + + x_session_pid="$(cat "$workdir/x-session-pid")" + export DISPLAY="$(cat "$workdir/display")" + export XAUTHORITY="$(cat "$workdir/xauthority")" + kill -0 "$x_session_pid" +} + +test_disconnection () { + rm -f "$workdir/disconnected" + ( + set +e + ${DBUS_TEST_DBUS_MONITOR} > "$workdir/dbus-monitor.log" 2>&1 + touch "$workdir/disconnected" + ) & + + kill "$x_session_pid" + + tries=0 + while ! [ -e "$workdir/disconnected" ]; do + if [ $tries -ge 10 ]; then + echo "# dbus-monitor was not disconnected within $tries seconds" >&2 + exit 1 + fi + tries=$(($tries + 1)) + sleep 1 + done + + tries=0 + while ! [ -e "$workdir/xvfb-done" ]; do + if [ $tries -ge 10 ]; then + echo "# xvfb-run did not exit within $tries seconds" >&2 + exit 1 + fi + tries=$(($tries + 1)) + sleep 1 + done +} + +test_exit_with_x11 () { + unset DBUS_SESSION_BUS_ADDRESS + unset DBUS_SESSION_BUS_PID + unset DBUS_SESSION_BUS_WINDOWID + + start_xvfb + eval "$($DBUS_TEST_DBUS_LAUNCH --sh-syntax --exit-with-session "$launch_config" "$workdir/bus-pid" + bus_pid="$(cat "$workdir/bus-pid")" + kill -0 "$bus_pid" + + start_xvfb + eval "$($DBUS_TEST_DBUS_LAUNCH --sh-syntax --autolaunch=${fake_uuid} "$launch_config"