Skip to content

Commit

Permalink
Tests: launch a temporary D-Bus session
Browse files Browse the repository at this point in the history
  • Loading branch information
mardy committed May 1, 2019
1 parent 916f2ca commit ed11b9e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/common.pri
Expand Up @@ -12,6 +12,6 @@ INCLUDEPATH += $$PWD/../src/extensions
target.path = /opt/tests/qtcontacts-sqlite-qt5
INSTALLS += target

check.commands = "LC_ALL=C QT_PLUGIN_PATH=$$shadowed($${PWD})/../src/engine/ ./$${TARGET}"
check.commands = "$${PWD}/run_test.sh $$shadowed($${PWD})/.. ./$${TARGET}"
check.depends = $${TARGET}
QMAKE_EXTRA_TARGETS += check
35 changes: 35 additions & 0 deletions tests/run_test.sh
@@ -0,0 +1,35 @@
#! /bin/sh

# Usage:
# run_test.sh <TOP_BUILD_DIR> <TEST_PROGRAM>
#
# Run TEST_PROGRAM within a proper environment; this includes a D-Bus session
# and any environment variable needed for the succesful completion of the test.
#
# If the TEST_WRAPPER environment variable is set, then it will be executed and
# the test program will be passed as an argument to it; this can be useful, for
# example, to run the tests in valgrind or strace.

set -e

TOP_BUILD_DIR="$1"
TEST_PROGRAM="$2"

export LC_ALL=C
export QT_PLUGIN_PATH="${TOP_BUILD_DIR}/src/engine/"

OUTPUT=$(dbus-daemon --session --print-address '' --print-pid '' --fork)
export DBUS_SESSION_BUS_ADDRESS=$(echo "$OUTPUT" | head -1)
DBUS_DAEMON_PID=$(echo "$OUTPUT" | tail -1)

cleanUp() {
echo "Killing the temporary D-Bus daemon"
kill "$DBUS_DAEMON_PID"
}

trap cleanUp EXIT INT TERM

$TEST_WRAPPER $TEST_PROGRAM

trap - EXIT
cleanUp

0 comments on commit ed11b9e

Please sign in to comment.