diff options
author | Simon McVittie <smcv@debian.org> | 2015-12-06 17:46:21 +0000 |
---|---|---|
committer | Simon McVittie <smcv@debian.org> | 2015-12-06 17:46:21 +0000 |
commit | b95a7f0f596e3e3d000c3756bb520d28b127d5e1 (patch) | |
tree | 706f048532efb395836aa782484fedc0aad43721 /test | |
parent | f8379493b1c413d7b583025d47a38f042b710d89 (diff) |
Simplify testing by using dbus-run-session and Automake "log compiler"
Fall back to Telepathy's old with-session-bus.sh script if dbus doesn't
have dbus-run-session (versions < 1.8).
Also run most of the tests individually, instead of under run-test.sh.
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.am | 38 | ||||
-rwxr-xr-x | test/run-test.sh | 104 | ||||
-rwxr-xr-x | test/run-with-tmp-session-bus.sh | 89 | ||||
-rwxr-xr-x | test/with-session-bus.sh | 103 |
4 files changed, 167 insertions, 167 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index a37b57d..d7674eb 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -6,7 +6,6 @@ EXTRA_DIST = \ cross-test-server.py \ crosstest.py \ run-test.sh \ - run-with-tmp-session-bus.sh \ test-client.py \ test-exception-py2.py \ test-exception-py3.py \ @@ -16,7 +15,9 @@ EXTRA_DIST = \ test-standalone.py \ test-unusable-main-loop.py \ TestSuitePythonService.service.in \ - tmp-session-bus.conf.in + tmp-session-bus.conf.in \ + with-session-bus.sh \ + $(NULL) # If you try to make this noinst, libtool helpfully gives us a static # library, which doesn't work as a Python extension: so force the install @@ -51,9 +52,40 @@ AM_TESTS_ENVIRONMENT = \ export DBUS_PYTHON_VERSION='$(PACKAGE_VERSION)'; \ export PYTHONPATH="$(abs_top_builddir)/test/.libs:$(abs_top_srcdir):$(abs_top_srcdir)/test:$(abs_top_builddir)/_dbus_bindings/.libs:$(abs_top_builddir)/_dbus_glib_bindings/.libs"; \ export PYTHON='$(PYTHON)'; \ + export DBUS_FATAL_WARNINGS=1; \ $(NULL) -TESTS = run-test.sh test-import-repeatedly +TEST_EXTENSIONS = .sh .py + +if HAVE_DBUS_RUN_SESSION +LOG_COMPILER = $(DBUS_RUN_SESSION) \ + --config-file=tmp-session-bus.conf \ + -- +else +LOG_COMPILER = \ + $(top_srcdir)/test/with-session-bus.sh \ + --config-file=tmp-session-bus.conf \ + -- +endif + +SH_LOG_COMPILER = $(LOG_COMPILER) $(SHELL) +PY_LOG_COMPILER = $(LOG_COMPILER) $(PYTHON) + +TESTS = \ + run-test.sh \ + test-client.py \ + test-import-repeatedly \ + test-p2p.py \ + test-signals.py \ + test-standalone.py \ + test-unusable-main-loop.py \ + $(NULL) + +if HAVE_PYTHON_3 +TESTS += test-exception-py3.py +else +TESTS += test-exception-py2.py +endif check_PROGRAMS = test-import-repeatedly diff --git a/test/run-test.sh b/test/run-test.sh index 2daecbd..2142353 100755 --- a/test/run-test.sh +++ b/test/run-test.sh @@ -23,45 +23,9 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. -export DBUS_FATAL_WARNINGS=1 -ulimit -c unlimited - +failed= skipped= -function die() -{ - if ! test -z "$DBUS_SESSION_BUS_PID" ; then - echo "killing message bus $DBUS_SESSION_BUS_PID" >&2 - kill -9 "$DBUS_SESSION_BUS_PID" - fi - echo "$SCRIPTNAME: $*" >&2 - exit 1 -} - -if test -z "$PYTHON"; then - echo "Warning: \$PYTHON not set, assuming 'python'" >&2 - export PYTHON=python -fi - -if test -z "$DBUS_TOP_SRCDIR" ; then - die "Must set DBUS_TOP_SRCDIR" -fi - -if test -z "$DBUS_TOP_BUILDDIR" ; then - die "Must set DBUS_TOP_BUILDDIR" -fi - -SCRIPTNAME=$0 - -## so the tests can complain if you fail to use the script to launch them -export DBUS_TEST_PYTHON_RUN_TEST_SCRIPT=1 -# Rerun ourselves with tmp session bus if we're not already -if test -z "$DBUS_TEST_PYTHON_IN_RUN_TEST"; then - DBUS_TEST_PYTHON_IN_RUN_TEST=1 - export DBUS_TEST_PYTHON_IN_RUN_TEST - exec "$DBUS_TOP_SRCDIR"/test/run-with-tmp-session-bus.sh $SCRIPTNAME -fi - dbus-monitor > "$DBUS_TOP_BUILDDIR"/test/monitor.log & echo "DBUS_TOP_SRCDIR=$DBUS_TOP_SRCDIR" @@ -69,18 +33,6 @@ echo "DBUS_TOP_BUILDDIR=$DBUS_TOP_BUILDDIR" echo "PYTHONPATH=$PYTHONPATH" echo "PYTHON=$PYTHON" -# the exceptions handling test is version specific -PYMAJOR=$($PYTHON -c 'import sys;print(sys.version_info[0])') -PYTEST=test-exception-py$PYMAJOR.py -echo "running $PYTEST" -$PYTHON "$DBUS_TOP_SRCDIR"/test/$PYTEST || die "$PYTEST failed" - -echo "running test-standalone.py" -$PYTHON "$DBUS_TOP_SRCDIR"/test/test-standalone.py || die "test-standalone.py failed" - -echo "running test-unusable-main-loop.py" -$PYTHON "$DBUS_TOP_SRCDIR"/test/test-unusable-main-loop.py || die "... failed" - #echo "running the examples" #$PYTHON "$DBUS_TOP_SRCDIR"/examples/example-service.py & @@ -96,59 +48,61 @@ $PYTHON "$DBUS_TOP_SRCDIR"/test/test-unusable-main-loop.py || die "... failed" echo "running cross-test (for better diagnostics use mjj29's dbus-test)" -$PYTHON "$DBUS_TOP_SRCDIR"/test/cross-test-server.py > "$DBUS_TOP_BUILDDIR"/test/cross-server.log& +$PYTHON "$DBUS_TOP_SRCDIR"/test/cross-test-server.py > "$DBUS_TOP_BUILDDIR"/test/cross-server.log & sleep 1 $PYTHON "$DBUS_TOP_SRCDIR"/test/cross-test-client.py > "$DBUS_TOP_BUILDDIR"/test/cross-client.log e=$? +echo "test-client exit status: $e" if test $e = 77; then - : # skipped + echo "cross-test-client exited $e, marking as skipped" + skipped=yes elif grep . "$DBUS_TOP_BUILDDIR"/test/cross-client.log >/dev/null; then - : # OK + echo "OK, cross-test-client produced some output" else - die "cross-test client produced no output" + echo "cross-test-client produced no output" >&2 + failed=yes fi if test $e = 77; then - : # skipped + echo "test-client exited $e, marking as skipped" + skipped=yes elif grep . "$DBUS_TOP_BUILDDIR"/test/cross-server.log >/dev/null; then - : # OK + echo "OK, cross-test-server produced some output" else - die "cross-test server produced no output" + echo "cross-test-server produced no output" >&2 + failed=yes fi if grep fail "$DBUS_TOP_BUILDDIR"/test/cross-client.log; then - die "^^^ Cross-test client reports failures, see test/cross-client.log" + failed=yes else echo " - cross-test client reported no failures" fi + if grep untested "$DBUS_TOP_BUILDDIR"/test/cross-server.log; then - die "^^^ Cross-test server reports incomplete test coverage" + failed=yes else echo " - cross-test server reported no untested functions" fi -for script in test-client.py test-signals.py test-p2p.py; do - echo "running ${script}" - $PYTHON "$DBUS_TOP_SRCDIR"/test/${script} - e=$? - case "$e" in - (77) - echo "SKIP: ${script} not run, dependencies missing?" - skipped=1 - ;; - (0) - echo "PASS: ${script}" - ;; - (*) - die "${script} failed" - esac -done +echo "==== client log ====" +cat "$DBUS_TOP_BUILDDIR"/test/cross-client.log +echo "==== end ====" + +echo "==== server log ====" +cat "$DBUS_TOP_BUILDDIR"/test/cross-server.log +echo "==== end ====" rm -f "$DBUS_TOP_BUILDDIR"/test/test-service.log rm -f "$DBUS_TOP_BUILDDIR"/test/cross-client.log rm -f "$DBUS_TOP_BUILDDIR"/test/cross-server.log rm -f "$DBUS_TOP_BUILDDIR"/test/monitor.log -if test -n $skipped; then exit 77; fi +if test -n "$skipped"; then + exit 77 +fi +if test -n "$failed"; then + exit 1 +fi exit 0 diff --git a/test/run-with-tmp-session-bus.sh b/test/run-with-tmp-session-bus.sh deleted file mode 100755 index 48f48b0..0000000 --- a/test/run-with-tmp-session-bus.sh +++ /dev/null @@ -1,89 +0,0 @@ -#! /bin/bash - -# Copyright (C) 2003-2005 Red Hat Inc. <http://www.redhat.com/> -# Copyright (C) 2005 Colin Walters -# Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/> -# -# 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. - -SCRIPTNAME=$0 -WRAPPED_SCRIPT=$1 -shift - -function die() -{ - if ! test -z "$DBUS_SESSION_BUS_PID" ; then - echo "killing message bus $DBUS_SESSION_BUS_PID" >&2 - kill -9 "$DBUS_SESSION_BUS_PID" - fi - echo "$SCRIPTNAME: $*" >&2 - exit 1 -} - -if test -z "$DBUS_TOP_BUILDDIR" ; then - die "Must set DBUS_TOP_BUILDDIR" -fi - -## convenient to be able to ctrl+C without leaking the message bus process -trap 'die "Received SIGINT"' SIGINT - -CONFIG_FILE="$DBUS_TOP_BUILDDIR"/test/tmp-session-bus.conf - -unset DBUS_STARTER_ADDRESS -unset DBUS_STARTER_BUS_TYPE -unset DBUS_SESSION_BUS_ADDRESS -unset DBUS_SESSION_BUS_PID - -echo "Running dbus-launch --sh-syntax --config-file=$CONFIG_FILE" >&2 -eval `dbus-launch --sh-syntax --config-file=$CONFIG_FILE` - -if test -z "$DBUS_SESSION_BUS_PID" ; then - die "Failed to launch message bus for introspection generation to run" -fi - -echo "Started bus pid $DBUS_SESSION_BUS_PID at $DBUS_SESSION_BUS_ADDRESS" >&2 - -# Execute wrapped script -echo "Running: $WRAPPED_SCRIPT $*" >&2 -"$WRAPPED_SCRIPT" "$@" -e=$? - -case "$e" in - (77) - echo "script \"$WRAPPED_SCRIPT\" skipped" >&2 - ;; - (0) - ;; - (*) - die "script \"$WRAPPED_SCRIPT\" failed" - ;; -esac - -kill -TERM "$DBUS_SESSION_BUS_PID" \ - || die "Message bus vanished! should not have happened" \ - && echo "Killed daemon $DBUS_SESSION_BUS_PID" >&2 - -sleep 2 - -## be sure it really died -kill -9 $DBUS_SESSION_BUS_PID > /dev/null 2>&1 || true - -exit 0 diff --git a/test/with-session-bus.sh b/test/with-session-bus.sh new file mode 100755 index 0000000..d20701d --- /dev/null +++ b/test/with-session-bus.sh @@ -0,0 +1,103 @@ +#!/bin/sh +# with-session-bus.sh - run a program with a temporary D-Bus session daemon +# +# Copyright (C) 2007-2008 Collabora Ltd. <http://www.collabora.co.uk/> +# +# Copying and distribution of this file, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. + +set -e + +me=with-session-bus + +dbus_daemon_args="--print-address=5 --print-pid=6 --fork" +sleep=0 + +usage () +{ + echo "usage: $me [options] -- program [program_options]" >&2 + echo "Requires write access to the current directory." >&2 + echo "" >&2 + echo "If \$WITH_SESSION_BUS_FORK_DBUS_MONITOR is set, fork dbus-monitor" >&2 + echo "with the arguments in \$WITH_SESSION_BUS_FORK_DBUS_MONITOR_OPT." >&2 + echo "The output of dbus-monitor is saved in $me-<pid>.dbus-monitor-logs" >&2 + exit 2 +} + +while test "z$1" != "z--"; do + case "$1" in + --sleep=*) + sleep="$1" + sleep="${sleep#--sleep=}" + shift + ;; + --session) + dbus_daemon_args="$dbus_daemon_args --session" + shift + ;; + --config-file=*) + # FIXME: assumes config file doesn't contain any special characters + dbus_daemon_args="$dbus_daemon_args $1" + shift + ;; + *) + usage + ;; + esac +done +shift +if test "z$1" = "z"; then usage; fi + +exec 5> $me-$$.address +exec 6> $me-$$.pid + +cleanup () +{ + pid=`head -n1 $me-$$.pid` + if test -n "$pid" ; then + if [ -n "$VERBOSE_TESTS" ]; then + echo "Killing temporary bus daemon: $pid" >&2 + fi + kill -INT "$pid" + fi + rm -f $me-$$.address + rm -f $me-$$.pid +} + +trap cleanup INT HUP TERM +dbus-daemon $dbus_daemon_args + +if [ -n "$VERBOSE_TESTS" ]; then + { echo -n "Temporary bus daemon is "; cat $me-$$.address; } >&2 + { echo -n "Temporary bus daemon PID is "; head -n1 $me-$$.pid; } >&2 +fi + +e=0 + +# These might be non-null when run from e.g. gnome-terminal 3.8, which uses +# an activatable service for its windows; we don't want to inherit them either +unset DBUS_STARTER_ADDRESS +unset DBUS_STARTER_BUS_TYPE + +DBUS_SESSION_BUS_ADDRESS="`cat $me-$$.address`" +export DBUS_SESSION_BUS_ADDRESS +DBUS_SESSION_BUS_PID="`cat $me-$$.pid`" +export DBUS_SESSION_BUS_PID + +if [ -n "$WITH_SESSION_BUS_FORK_DBUS_MONITOR" ] ; then + echo -n "Forking dbus-monitor $WITH_SESSION_BUS_FORK_DBUS_MONITOR_OPT" >&2 + dbus-monitor $WITH_SESSION_BUS_FORK_DBUS_MONITOR_OPT \ + > $me-$$.dbus-monitor-logs 2>&1 & +fi + +"$@" || e=$? + +if test $sleep != 0; then + sleep $sleep +fi + +trap - INT HUP TERM +cleanup + +exit $e |