3 # Copyright © 2016 Collabora Ltd.
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:
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
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
28 export DBUS_DEBUG_OUTPUT=1
29 echo "# dbus-daemon binary: ${DBUS_TEST_DAEMON:=dbus-daemon}"
30 echo "# dbus-launch binary: ${DBUS_TEST_DBUS_LAUNCH:=dbus-launch}"
31 echo "# dbus-monitor binary: ${DBUS_TEST_DBUS_LAUNCH:=dbus-monitor}"
32 echo "# dbus-send binary: ${DBUS_TEST_DBUS_SEND:=dbus-send}"
33 echo "# dbus-uuidgen binary: ${DBUS_TEST_DBUS_UUIDGEN:=dbus-uuidgen}"
35 if test -n "$DBUS_TEST_DATA"; then
36 echo "# test data: $DBUS_TEST_DATA"
37 bus_config="--config-file=$DBUS_TEST_DATA/valid-config-files/session.conf"
38 launch_config="$bus_config"
39 elif test -n "$DBUS_TEST_DATADIR"; then
40 echo "# datadir: $DBUS_TEST_DATADIR"
41 bus_config="--config-file=$DBUS_TEST_DATADIR/dbus-1/session.conf"
42 launch_config="$bus_config"
44 echo "# using standard session bus configuration"
45 bus_config="--session"
46 # dbus-launch doesn't accept --session so add a harmless command-line
48 launch_config="--sh-syntax"
51 if ! "${DBUS_TEST_DBUS_UUIDGEN}" --get >/dev/null; then
52 if test -n "$DBUS_TEST_UNINSTALLED"; then
53 echo "1..0 # SKIP - Unable to test dbus-launch without a machine ID"
56 echo "Bail out! dbus not correctly installed: no machine ID"
61 if ! workdir="$(mktemp -d)"; then
62 echo "1..0 # SKIP - mktemp -d doesn't work"
66 if ! xvfb-run --auto-servernum true; then
67 echo "1..0 # SKIP - xvfb-run doesn't work"
77 rm -f "$workdir/display"
78 rm -f "$workdir/ready"
79 rm -f "$workdir/x-session-pid"
80 rm -f "$workdir/xauthority"
81 rm -f "$workdir/xvfb-done"
83 # Run an X session in the background for up to 5 minutes.
86 xvfb-run --auto-servernum \
87 sh -c 'echo "$$" > "$1/x-session-pid"; echo "$XAUTHORITY" > "$1/xauthority"; echo "$DISPLAY" > "$1/display"; touch "$1/ready"; exec sleep 300' \
89 touch "$workdir/xvfb-done"
93 while ! [ -e "$workdir/ready" ]; do
94 if [ $tries -ge 10 ]; then
95 echo "# Failed to start xvfb-run within $tries seconds"
102 x_session_pid="$(cat "$workdir/x-session-pid")"
103 export DISPLAY="$(cat "$workdir/display")"
104 export XAUTHORITY="$(cat "$workdir/xauthority")"
105 kill -0 "$x_session_pid"
108 test_disconnection () {
109 rm -f "$workdir/disconnected"
112 ${DBUS_TEST_DBUS_MONITOR} > "$workdir/dbus-monitor.log" 2>&1
113 touch "$workdir/disconnected"
116 kill "$x_session_pid"
119 while ! [ -e "$workdir/disconnected" ]; do
120 if [ $tries -ge 10 ]; then
121 echo "# dbus-monitor was not disconnected within $tries seconds" >&2
124 tries=$(($tries + 1))
129 while ! [ -e "$workdir/xvfb-done" ]; do
130 if [ $tries -ge 10 ]; then
131 echo "# xvfb-run did not exit within $tries seconds" >&2
134 tries=$(($tries + 1))
139 test_exit_with_x11 () {
141 unset DBUS_SESSION_BUS_ADDRESS
142 unset DBUS_SESSION_BUS_PID
143 unset DBUS_SESSION_BUS_WINDOWID
146 eval "$($DBUS_TEST_DBUS_LAUNCH --sh-syntax "$arg" "$launch_config" </dev/null)"
148 test -n "$DBUS_SESSION_BUS_ADDRESS"
149 env | grep '^DBUS_SESSION_BUS_ADDRESS='
151 test -n "$DBUS_SESSION_BUS_PID"
152 test "x$(env | grep '^DBUS_SESSION_BUS_PID=')" = "x"
153 kill -0 "$DBUS_SESSION_BUS_PID"
155 test -n "$DBUS_SESSION_BUS_WINDOWID"
156 test "x$(env | grep '^DBUS_SESSION_BUS_WINDOWID=')" = "x"
158 ${DBUS_TEST_DBUS_SEND} --session --dest=org.freedesktop.DBus \
159 --type=method_call --print-reply / org.freedesktop.DBus.ListNames >&2
163 test_num=$(($test_num + 1))
164 echo "ok ${test_num} - dbus-launch $arg"
168 unset DBUS_SESSION_BUS_ADDRESS
169 unset DBUS_SESSION_BUS_PID
170 unset DBUS_SESSION_BUS_WINDOWID
171 unset XDG_RUNTIME_DIR
172 fake_uuid="ffffffffffffffffffffffffffffffff"
175 eval "$($DBUS_TEST_DBUS_LAUNCH --sh-syntax --autolaunch=${fake_uuid} "$launch_config" </dev/null)"
177 test -n "$DBUS_SESSION_BUS_ADDRESS"
178 env | grep '^DBUS_SESSION_BUS_ADDRESS='
180 test -n "$DBUS_SESSION_BUS_PID"
181 test "x$(env | grep '^DBUS_SESSION_BUS_PID=')" = "x"
182 kill -0 "$DBUS_SESSION_BUS_PID"
184 test -n "$DBUS_SESSION_BUS_WINDOWID"
185 test "x$(env | grep '^DBUS_SESSION_BUS_WINDOWID=')" = "x"
188 old_address="$DBUS_SESSION_BUS_ADDRESS"
189 old_pid="$DBUS_SESSION_BUS_PID"
190 old_window="$DBUS_SESSION_BUS_WINDOWID"
191 eval "$($DBUS_TEST_DBUS_LAUNCH --sh-syntax --autolaunch=${fake_uuid} "$launch_config" </dev/null)"
192 test "$DBUS_SESSION_BUS_ADDRESS" = "$old_address"
193 test "$DBUS_SESSION_BUS_PID" = "$old_pid"
194 test "$DBUS_SESSION_BUS_WINDOWID" = "$old_window"
196 ${DBUS_TEST_DBUS_SEND} --session --dest=org.freedesktop.DBus \
197 --type=method_call --print-reply / org.freedesktop.DBus.ListNames >&2
201 test_num=$(($test_num + 1))
202 echo "ok ${test_num} - dbus-launch --autolaunch"
205 test_xdg_runtime_dir () {
206 unset DBUS_SESSION_BUS_ADDRESS
207 unset DBUS_SESSION_BUS_PID
208 unset DBUS_SESSION_BUS_WINDOWID
209 export XDG_RUNTIME_DIR="$workdir"
210 fake_uuid="ffffffffffffffffffffffffffffffff"
212 if echo "$workdir" | grep '[^-0-9A-Za-z_/.]'; then
213 test_num=$(($test_num + 1))
214 echo "ok ${test_num} # SKIP - $workdir would need escaping"
218 ${DBUS_TEST_DAEMON} "$bus_config" --address="unix:path=$XDG_RUNTIME_DIR/bus" --print-pid=9 --fork 9>"$workdir/bus-pid"
219 bus_pid="$(cat "$workdir/bus-pid")"
223 eval "$($DBUS_TEST_DBUS_LAUNCH --sh-syntax --autolaunch=${fake_uuid} "$launch_config" </dev/null)"
225 env | grep '^DBUS_SESSION_BUS_ADDRESS='
226 test "$DBUS_SESSION_BUS_ADDRESS" = "unix:path=$XDG_RUNTIME_DIR/bus"
228 # When dbus-launch picks up the address from XDG_RUNTIME_DIR/bus, it
229 # doesn't know the pid
230 test -z "$DBUS_SESSION_BUS_PID"
232 # It still knows which window it stashed the information in
233 test -n "$DBUS_SESSION_BUS_WINDOWID"
234 test "x$(env | grep '^DBUS_SESSION_BUS_WINDOWID=')" = "x"
236 ${DBUS_TEST_DBUS_SEND} --session --dest=org.freedesktop.DBus \
237 --type=method_call --print-reply / org.freedesktop.DBus.ListNames >&2
239 kill "$x_session_pid"
242 while ! [ -e "$workdir/xvfb-done" ]; do
243 if [ $tries -ge 10 ]; then
244 echo "# xvfb-run did not exit within $tries seconds" >&2
247 tries=$(($tries + 1))
251 # dbus-launch has gone but the dbus-daemon is still alive
252 ${DBUS_TEST_DBUS_SEND} --session --dest=org.freedesktop.DBus \
253 --type=method_call --print-reply / org.freedesktop.DBus.ListNames >&2
257 test_num=$(($test_num + 1))
258 echo "ok ${test_num} - dbus-launch --autolaunch with XDG_RUNTIME_DIR"
262 test_exit_with_x11 --exit-with-session
263 test_exit_with_x11 --exit-with-x11
267 # vim:set sw=4 sts=4 et: