Branched from 2.0alpha and pushed for 2.0
[profile/ivi/dbus-python.git] / test / run-test.sh
1 #! /bin/bash
2
3 # Copyright (C) 2006 Red Hat Inc. <http://www.redhat.com/>
4 # Copyright (C) 2006-2007 Collabora Ltd. <http://www.collabora.co.uk/>
5 #
6 # Permission is hereby granted, free of charge, to any person
7 # obtaining a copy of this software and associated documentation
8 # files (the "Software"), to deal in the Software without
9 # restriction, including without limitation the rights to use, copy,
10 # modify, merge, publish, distribute, sublicense, and/or sell copies
11 # of the Software, and to permit persons to whom the Software is
12 # furnished to do so, subject to the following conditions:
13 #
14 # The above copyright notice and this permission notice shall be
15 # included in all copies or substantial portions of the Software.
16 #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 # DEALINGS IN THE SOFTWARE.
25
26 export DBUS_FATAL_WARNINGS=1
27 ulimit -c unlimited
28
29 function die() 
30 {
31     if ! test -z "$DBUS_SESSION_BUS_PID" ; then
32         echo "killing message bus $DBUS_SESSION_BUS_PID" >&2
33         kill -9 "$DBUS_SESSION_BUS_PID"
34     fi
35     echo "$SCRIPTNAME: $*" >&2
36     exit 1
37 }
38
39 if test -z "$PYTHON"; then
40     echo "Warning: \$PYTHON not set, assuming 'python'" >&2
41     export PYTHON=python
42 fi
43
44 if test -z "$DBUS_TOP_SRCDIR" ; then
45     die "Must set DBUS_TOP_SRCDIR"
46 fi
47
48 if test -z "$DBUS_TOP_BUILDDIR" ; then
49     die "Must set DBUS_TOP_BUILDDIR"
50 fi
51
52 SCRIPTNAME=$0
53
54 ## so the tests can complain if you fail to use the script to launch them
55 export DBUS_TEST_PYTHON_RUN_TEST_SCRIPT=1
56 # Rerun ourselves with tmp session bus if we're not already
57 if test -z "$DBUS_TEST_PYTHON_IN_RUN_TEST"; then
58   DBUS_TEST_PYTHON_IN_RUN_TEST=1
59   export DBUS_TEST_PYTHON_IN_RUN_TEST
60   exec "$DBUS_TOP_SRCDIR"/test/run-with-tmp-session-bus.sh $SCRIPTNAME
61 fi  
62
63 dbus-monitor > "$DBUS_TOP_BUILDDIR"/test/monitor.log &
64
65 echo "running test-standalone.py"
66 $PYTHON "$DBUS_TOP_SRCDIR"/test/test-standalone.py || die "test-standalone.py failed"
67
68 echo "running test-unusable-main-loop.py"
69 $PYTHON "$DBUS_TOP_SRCDIR"/test/test-unusable-main-loop.py || die "... failed"
70
71 #echo "running the examples"
72
73 #$PYTHON "$DBUS_TOP_SRCDIR"/examples/example-service.py &
74 #$PYTHON "$DBUS_TOP_SRCDIR"/examples/example-signal-emitter.py &
75 #$PYTHON "$DBUS_TOP_SRCDIR"/examples/list-system-services.py --session ||
76 #  die "list-system-services.py --session failed!"
77 #$PYTHON "$DBUS_TOP_SRCDIR"/examples/example-async-client.py ||
78 #  die "example-async-client failed!"
79 #$PYTHON "$DBUS_TOP_SRCDIR"/examples/example-client.py --exit-service ||
80 #  die "example-client failed!"
81 #$PYTHON "$DBUS_TOP_SRCDIR"/examples/example-signal-recipient.py --exit-service ||
82 #  die "example-signal-recipient failed!"
83
84 echo "running cross-test (for better diagnostics use mjj29's dbus-test)"
85
86 ${MAKE:-make} -s cross-test-server > "$DBUS_TOP_BUILDDIR"/test/cross-server.log&
87 sleep 1
88 ${MAKE:-make} -s cross-test-client > "$DBUS_TOP_BUILDDIR"/test/cross-client.log
89
90 if grep . "$DBUS_TOP_BUILDDIR"/test/cross-client.log >/dev/null; then
91   :     # OK
92 else
93   die "cross-test client produced no output"
94 fi
95 if grep . "$DBUS_TOP_BUILDDIR"/test/cross-server.log >/dev/null; then
96   :     # OK
97 else
98   die "cross-test server produced no output"
99 fi
100
101 if grep fail "$DBUS_TOP_BUILDDIR"/test/cross-client.log; then
102   die "^^^ Cross-test client reports failures, see test/cross-client.log"
103 else
104   echo "  - cross-test client reported no failures"
105 fi
106 if grep untested "$DBUS_TOP_BUILDDIR"/test/cross-server.log; then
107   die "^^^ Cross-test server reports incomplete test coverage"
108 else
109   echo "  - cross-test server reported no untested functions"
110 fi
111
112 echo "running test-client.py"
113 $PYTHON "$DBUS_TOP_SRCDIR"/test/test-client.py || die "test-client.py failed"
114 echo "running test-signals.py"
115 $PYTHON "$DBUS_TOP_SRCDIR"/test/test-signals.py || die "test-signals.py failed"
116
117 echo "running test-p2p.py"
118 $PYTHON "$DBUS_TOP_SRCDIR"/test/test-p2p.py || die "... failed"
119
120 rm -f "$DBUS_TOP_BUILDDIR"/test/test-service.log
121 rm -f "$DBUS_TOP_BUILDDIR"/test/cross-client.log
122 rm -f "$DBUS_TOP_BUILDDIR"/test/cross-server.log
123 rm -f "$DBUS_TOP_BUILDDIR"/test/monitor.log
124 exit 0