cmake: Add X11 include path for tools
[platform/upstream/dbus.git] / test / test-dbus-daemon-fork.sh
1 #!/bin/sh
2
3 # Copyright © 2016 Collabora Ltd.
4 #
5 # Permission is hereby granted, free of charge, to any person
6 # obtaining a copy of this software and associated documentation files
7 # (the "Software"), to deal in the Software without restriction,
8 # including without limitation the rights to use, copy, modify, merge,
9 # publish, distribute, sublicense, and/or sell copies of the Software,
10 # and to permit persons to whom the Software is furnished to do so,
11 # subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 # SOFTWARE.
24
25 set -e
26
27 export DBUS_DEBUG_OUTPUT=1
28 echo "# dbus-daemon binary: ${DBUS_TEST_DAEMON:=dbus-daemon}"
29 echo "# dbus-send binary: ${DBUS_TEST_DBUS_SEND:=dbus-send}"
30
31 if test -n "$DBUS_TEST_DATA"; then
32     echo "# test data: $DBUS_TEST_DATA"
33     config="--config-file=$DBUS_TEST_DATA/valid-config-files/session.conf"
34 elif test -n "$DBUS_TEST_DATADIR"; then
35     echo "# datadir: $DBUS_TEST_DATADIR"
36     config="--config-file=$DBUS_TEST_DATADIR/dbus-1/session.conf"
37 else
38     echo "# using standard session bus configuration"
39     config="--session"
40 fi
41
42 if ! workdir="$(mktemp -d)"; then
43     echo "1..0 # SKIP - mktemp -d doesn't work"
44     exit 0
45 fi
46
47 echo "1..3"
48
49 unset DBUS_SESSION_BUS_ADDRESS
50 unset DBUS_SESSION_BUS_PID
51 rm -f "$workdir"/address "$workdir"/pid
52
53 ${DBUS_TEST_DAEMON} --fork --print-address=8 --print-pid=9 "$config" \
54     8>"$workdir/address" 9>"$workdir/pid"
55
56 export DBUS_SESSION_BUS_ADDRESS="$(cat "$workdir"/address)"
57 test -n "$DBUS_SESSION_BUS_ADDRESS"
58 DBUS_SESSION_BUS_PID="$(cat "$workdir"/pid)"
59 kill -0 "$DBUS_SESSION_BUS_PID"
60
61 ${DBUS_TEST_DBUS_SEND} --session --dest=org.freedesktop.DBus \
62     --type=method_call --print-reply / org.freedesktop.DBus.ListNames >&2
63
64 kill "$DBUS_SESSION_BUS_PID"
65
66 echo "ok 1 - normal dbus-daemon"
67
68 unset DBUS_SESSION_BUS_ADDRESS
69 unset DBUS_SESSION_BUS_PID
70 rm -f "$workdir"/address "$workdir"/pid
71
72 ${DBUS_TEST_DAEMON} --fork --print-address=8 --print-pid=9 "$config" \
73     8>"$workdir/address" 9>"$workdir/pid" <&-
74
75 export DBUS_SESSION_BUS_ADDRESS="$(cat "$workdir"/address)"
76 test -n "$DBUS_SESSION_BUS_ADDRESS"
77 DBUS_SESSION_BUS_PID="$(cat "$workdir"/pid)"
78 kill -0 "$DBUS_SESSION_BUS_PID"
79
80 ${DBUS_TEST_DBUS_SEND} --session --dest=org.freedesktop.DBus \
81     --type=method_call --print-reply / org.freedesktop.DBus.ListNames >&2
82
83 kill "$DBUS_SESSION_BUS_PID"
84
85 echo "ok 2 - dbus-daemon with stdin closed"
86
87 unset DBUS_SESSION_BUS_ADDRESS
88 unset DBUS_SESSION_BUS_PID
89 rm -f "$workdir"/address "$workdir"/pid
90
91 ${DBUS_TEST_DAEMON} --fork --print-address=8 --print-pid=9 "$config" \
92     8>"$workdir/address" 9>"$workdir/pid" <&- >&- 2>&-
93
94 export DBUS_SESSION_BUS_ADDRESS="$(cat "$workdir"/address)"
95 test -n "$DBUS_SESSION_BUS_ADDRESS"
96 DBUS_SESSION_BUS_PID="$(cat "$workdir"/pid)"
97 kill -0 "$DBUS_SESSION_BUS_PID"
98
99 ${DBUS_TEST_DBUS_SEND} --session --dest=org.freedesktop.DBus \
100     --type=method_call --print-reply / org.freedesktop.DBus.ListNames >&2
101
102 kill "$DBUS_SESSION_BUS_PID"
103
104 echo "ok 3 - dbus-daemon with stdin, stdout, stderr closed"
105
106 rm -r "$workdir"