3 # Copyright © 2017 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
27 if test -z "$XDG_RUNTIME_DIR"; then
28 echo "1..0 # SKIP - $XDG_RUNTIME_DIR is empty or unset"
32 # test -O is non-POSIX, but bash and dash have it. If it doesn't work,
33 # we're probably not on Linux and so would likely be skipping this test
35 if ! test -O "$XDG_RUNTIME_DIR"; then
36 echo "1..0 # SKIP - $XDG_RUNTIME_DIR is not ours or test -O does not work"
40 if ! test -S "$XDG_RUNTIME_DIR/bus"; then
41 echo "1..0 # SKIP - $XDG_RUNTIME_DIR/bus is not a socket"
45 if ! test -O "$XDG_RUNTIME_DIR/bus"; then
46 echo "1..0 # SKIP - $XDG_RUNTIME_DIR/bus is not ours"
50 if test -n "$DBUS_SESSION_BUS_ADDRESS" && \
51 ! test "unix:path=$XDG_RUNTIME_DIR/bus" = "$DBUS_SESSION_BUS_ADDRESS"; then
52 echo "1..0 # SKIP - DBUS_SESSION_BUS_ADDRESS does not point to $XDG_RUNTIME_DIR/bus"
56 # Any unique token that won't collide would do here. It must start with
57 # a letter or underscore.
58 unique="t$(dbus-uuidgen)"
60 if ! workdir="$(mktemp -d)"; then
61 echo "1..0 # SKIP - mktemp -d doesn't work"
67 rm -f "$XDG_RUNTIME_DIR/dbus-1/services/com.example.DBusTests.$unique.tmp"
68 rm -f "$XDG_RUNTIME_DIR/dbus-1/services/com.example.DBusTests.$unique.service"
69 rm -f "$XDG_RUNTIME_DIR/dbus-1/services/com.example.DBusTests.Systemd.$unique.tmp"
70 rm -f "$XDG_RUNTIME_DIR/dbus-1/services/com.example.DBusTests.Systemd.$unique.service"
71 rm -f "$XDG_RUNTIME_DIR/systemd/user/dbus-com.example.DBusTests.Systemd.$unique.service"
77 # This is an integration test, so we expect the dbus-daemon to already be
79 if ! test -d "$XDG_RUNTIME_DIR/dbus-1/services"; then
80 echo "Bail out! $XDG_RUNTIME_DIR/dbus-1/services is not a directory"
84 cd "$XDG_RUNTIME_DIR/dbus-1/services"
86 sed -e 's/^ *//' > "com.example.DBusTests.$unique.tmp" <<EOF
88 Name=com.example.DBusTests.$unique
89 Exec=/bin/sh -c 'touch "\$1"; exit 1' sh '$workdir/ran-$unique'
91 mv "com.example.DBusTests.$unique.tmp" "com.example.DBusTests.$unique.service"
94 dbus-send --session --dest="org.freedesktop.DBus" \
95 --type=method_call --print-reply /org/freedesktop/DBus \
96 org.freedesktop.DBus.ReloadConfig || touch "$workdir/failed" \
97 ) 2>&1 | sed -e 's/^/# /'
99 if [ -e "$workdir/failed" ]; then
100 echo "Bail out! Unable to tell dbus-daemon to reload"
104 # Because the service never actually takes a bus name, we expect this to fail;
105 # but its exit status is ignored because it's in a pipeline.
106 dbus-send --session --dest="com.example.DBusTests.$unique" \
107 --type=method_call --print-reply / com.example.DBusTests.ThisWillFail \
108 2>&1 | sed -e 's/^/# /'
110 if [ -e "$workdir/ran-$unique" ]; then
111 echo "ok 1 - attempted to run transient service directly"
113 echo "not ok 1 - no sign of having run transient service"
116 # See whether systemd is on the session bus.
118 dbus-send --session --dest="org.freedesktop.systemd1" \
119 --type=method_call --print-reply /org/freedesktop/systemd1/Manager \
120 org.freedesktop.DBus.Peer.Ping || touch "$workdir/no-systemd" \
121 ) 2>&1 | sed -e 's/^/# /'
123 if [ -d "$XDG_RUNTIME_DIR/systemd" ] && ! [ -e "$workdir/no-systemd" ]; then
125 # systemd is Linux-specific, so we can assume GNU mkdir.
126 mkdir -p -m700 "$XDG_RUNTIME_DIR/systemd/user"
127 cd "$XDG_RUNTIME_DIR/systemd/user"
129 sed -e 's/^ *//' > "dbus-com.example.DBusTests.Systemd.$unique.tmp" <<EOF
131 Description=Non-functional service in the dbus integration tests
133 ExecStart=/bin/sh -c 'touch "\$1"; exit 1' sh '$workdir/ran-$unique-via-systemd'
136 mv "dbus-com.example.DBusTests.Systemd.$unique.tmp" \
137 "dbus-com.example.DBusTests.Systemd.$unique.service"
139 if ! systemctl --user daemon-reload; then
140 echo "Bail out! Unable to tell systemd to reload"
144 cd "$XDG_RUNTIME_DIR/dbus-1/services"
146 sed -e 's/^ *//' > "com.example.DBusTests.Systemd.$unique.tmp" <<EOF
148 Name=com.example.DBusTests.Systemd.$unique
149 SystemdService=dbus-com.example.DBusTests.Systemd.$unique.service
150 Exec=/bin/sh -c 'touch "\$1"; exit 1' sh '$workdir/ran-$unique-wrong'
152 mv "com.example.DBusTests.Systemd.$unique.tmp" \
153 "com.example.DBusTests.Systemd.$unique.service"
156 dbus-send --session --dest="org.freedesktop.DBus" \
157 --type=method_call --print-reply /org/freedesktop/DBus \
158 org.freedesktop.DBus.ReloadConfig || touch "$workdir/failed" \
159 ) 2>&1 | sed -e 's/^/# /'
161 if [ -e "$workdir/failed" ]; then
162 echo "Bail out! Unable to tell dbus-daemon to reload"
166 # Because the service never actually takes a bus name, we expect this to fail;
167 # but its exit status is ignored because it's in a pipeline.
169 # systemd never sends back an ActivationFailure message for a service
170 # if it starts the job but the service subsequently doesn't behave as
171 # intended, so use a relatively short timeout (3000ms).
172 dbus-send --session --dest="com.example.DBusTests.Systemd.$unique" \
173 --reply-timeout=3000 --type=method_call --print-reply \
174 / com.example.DBusTests.ThisWillFail \
175 2>&1 | sed -e 's/^/# /'
177 if [ -e "$workdir/ran-$unique-via-systemd" ]; then
178 echo "ok 2 - attempted to run transient service via systemd"
179 elif [ -e "$workdir/ran-$unique-wrong" ]; then
180 echo "not ok 2 - ran transient service incorrectly"
182 echo "not ok 2 - no sign of having run transient service"
185 echo "ok 2 # SKIP session bus does not appear to be managed by systemd"