bus: Assign a serial number for messages from the driver
[platform/upstream/dbus.git] / test / name-test / run-test.sh
1 #! /bin/sh
2
3 SCRIPTNAME=$0
4 MODE=$1
5
6 ## so the tests can complain if you fail to use the script to launch them
7 DBUS_TEST_NAME_RUN_TEST_SCRIPT=1
8 export DBUS_TEST_NAME_RUN_TEST_SCRIPT
9
10 # Rerun ourselves with tmp session bus if we're not already
11 if test -z "$DBUS_TEST_NAME_IN_RUN_TEST"; then
12   DBUS_TEST_NAME_IN_RUN_TEST=1
13   export DBUS_TEST_NAME_IN_RUN_TEST
14   exec $DBUS_TOP_SRCDIR/tools/run-with-tmp-session-bus.sh $SCRIPTNAME $MODE
15 fi 
16
17 if test -n "$DBUS_TEST_MONITOR"; then
18   dbus-monitor --session >&2 &
19 fi
20
21 XDG_RUNTIME_DIR="$DBUS_TOP_BUILDDIR"/test/XDG_RUNTIME_DIR
22 test -d "$XDG_RUNTIME_DIR" || mkdir "$XDG_RUNTIME_DIR"
23 chmod 0700 "$XDG_RUNTIME_DIR"
24 export XDG_RUNTIME_DIR
25
26 # Translate a command and exit status into TAP syntax.
27 # Usage: interpret_result $? description-of-test
28 # Uses global variable $test_num.
29 interpret_result () {
30   e="$1"
31   shift
32   case "$e" in
33     (0)
34       echo "ok $test_num $*"
35       ;;
36     (77)
37       echo "ok $test_num # SKIP $*"
38       ;;
39     (*)
40       echo "not ok $test_num $*"
41       ;;
42   esac
43   test_num=$(( $test_num + 1 ))
44 }
45
46 c_test () {
47   t="$1"
48   shift
49   e=0
50   echo "# running test $t"
51   "${DBUS_TOP_BUILDDIR}/libtool" --mode=execute $DEBUG "$DBUS_TOP_BUILDDIR/test/name-test/$t" "$@" >&2 || e=$?
52   echo "# exit status $e"
53   interpret_result "$e" "$t" "$@"
54 }
55
56 py_test () {
57   t="$1"
58   shift
59   if test "x$PYTHON" = "x:"; then
60     interpret_result 77 "$t" "(Python interpreter not found)"
61   else
62     e=0
63     echo "# running test $t"
64     $PYTHON "$DBUS_TOP_SRCDIR/test/name-test/$t" "$@" >&2 || e=$?
65     interpret_result "$e" "$t" "$@"
66   fi
67 }
68
69 test_num=1
70 # TAP test plan: we will run 2 tests
71 echo "1..2"
72
73 py_test test-activation-forking.py
74 c_test test-autolaunch