test: add a regression test for eval "$(dbus-launch --sh-syntax)"
authorSimon McVittie <smcv@debian.org>
Wed, 20 Jul 2016 11:00:34 +0000 (12:00 +0100)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Fri, 12 Aug 2016 17:21:01 +0000 (18:21 +0100)
[Modified for the dbus-1.10 branch: DBUS_USE_TEST_BINARY is needed.]

Signed-off-by: Simon McVittie <smcv@debian.org>
test/Makefile.am
test/test-dbus-launch-eval.sh [new file with mode: 0755]

index 82c76f4..cf08e66 100644 (file)
@@ -124,6 +124,7 @@ EXTRA_DIST += dbus-test-runner
 testexecdir = $(libexecdir)/installed-tests/dbus
 testmetadir = $(datadir)/installed-tests/dbus
 
+dist_testexec_SCRIPTS =
 testexec_PROGRAMS =
 testmeta_DATA =
 
@@ -133,8 +134,10 @@ installable_tests = \
        $(NULL)
 installable_manual_tests = \
        manual-dir-iter \
-        manual-tcp \
-        $(NULL)
+       manual-tcp \
+       $(NULL)
+dist_installable_test_scripts = \
+       $(NULL)
 
 if DBUS_WIN
 installable_manual_tests += manual-paths
@@ -160,6 +163,14 @@ if DBUS_UNIX
 installable_tests += \
        test-sd-activation \
        $(NULL)
+
+# Testing dbus-launch relies on special code in that binary.
+if DBUS_ENABLE_EMBEDDED_TESTS
+dist_installable_test_scripts += \
+       test-dbus-launch-eval.sh \
+       $(NULL)
+endif DBUS_ENABLE_EMBEDDED_TESTS
+
 endif DBUS_UNIX
 
 installable_manual_tests += \
@@ -167,13 +178,21 @@ installable_manual_tests += \
        $(NULL)
 endif DBUS_WITH_GLIB
 
-installable_test_meta = $(installable_tests:=.test)
-installable_test_meta_with_config = $(installable_tests:=_with_config.test)
+installable_test_meta = \
+       $(dist_installable_test_scripts:=.test) \
+       $(installable_tests:=.test) \
+       $(NULL)
+installable_test_meta_with_config = \
+       $(dist_installable_test_scripts:=_with_config.test) \
+       $(installable_tests:=_with_config.test) \
+       $(NULL)
 
 installcheck_tests =
 installcheck_environment = \
        export XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR; \
        export DBUS_TEST_DAEMON=$(DESTDIR)$(DBUS_DAEMONDIR)/dbus-daemon$(EXEEXT); \
+       export DBUS_TEST_DBUS_LAUNCH=$(DESTDIR)$(bindir)/dbus-launch$(EXEEXT); \
+       export DBUS_TEST_DBUS_SEND=$(DESTDIR)$(bindir)/dbus-send$(EXEEXT); \
        export DBUS_TEST_HOMEDIR=@abs_top_builddir@/dbus; \
        export DBUS_TEST_DATADIR=$(DESTDIR)$(datadir); \
        ${NULL}
@@ -182,6 +201,8 @@ AM_TESTS_ENVIRONMENT = \
        export XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR; \
        export DBUS_FATAL_WARNINGS=1; \
        export DBUS_TEST_DAEMON=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT); \
+       export DBUS_TEST_DBUS_LAUNCH=@abs_top_builddir@/tools/dbus-launch$(EXEEXT); \
+       export DBUS_TEST_DBUS_SEND=@abs_top_builddir@/tools/dbus-send$(EXEEXT); \
        export DBUS_TEST_DATA=@abs_top_builddir@/test/data; \
        export DBUS_TEST_HOMEDIR=@abs_top_builddir@/dbus; \
        $(NULL)
@@ -268,12 +289,16 @@ test_fdpass_LDADD = \
     $(GLIB_LIBS) \
     $(NULL)
 
+TESTS += $(dist_installable_test_scripts)
+installcheck_tests += $(dist_installable_test_scripts)
+
 if DBUS_ENABLE_MODULAR_TESTS
 TESTS += $(installable_tests)
 installcheck_tests += $(installable_tests)
 
 if DBUS_ENABLE_INSTALLED_TESTS
   testexec_PROGRAMS += $(installable_tests) $(installable_manual_tests)
+  dist_testexec_SCRIPTS += $(dist_installable_test_scripts)
 
   testmeta_DATA += $(installable_test_meta)
   testmeta_DATA += $(installable_test_meta_with_config)
diff --git a/test/test-dbus-launch-eval.sh b/test/test-dbus-launch-eval.sh
new file mode 100755 (executable)
index 0000000..7b464bf
--- /dev/null
@@ -0,0 +1,64 @@
+#!/bin/sh
+
+# Copyright © 2016 Collabora Ltd.
+#
+# Permission is hereby granted, free of charge, to any person
+# obtaining a copy of this software and associated documentation files
+# (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge,
+# publish, distribute, sublicense, and/or sell copies of the Software,
+# and to permit persons to whom the Software is furnished to do so,
+# subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+set -e
+
+export DBUS_DEBUG_OUTPUT=1
+export DBUS_USE_TEST_BINARY=1
+echo "# dbus-daemon binary: ${DBUS_TEST_DAEMON:=dbus-daemon}"
+echo "# dbus-launch binary: ${DBUS_TEST_DBUS_LAUNCH:=dbus-launch}"
+echo "# dbus-send binary: ${DBUS_TEST_DBUS_SEND:=dbus-send}"
+
+if test -n "$DBUS_TEST_DATA"; then
+    echo "# test data: $DBUS_TEST_DATA"
+    config="--config-file=$DBUS_TEST_DATA/valid-config-files/session.conf"
+elif test -n "$DBUS_TEST_DATADIR"; then
+    echo "# datadir: $DBUS_TEST_DATADIR"
+    config="--config-file=$DBUS_TEST_DATADIR/dbus-1/session.conf"
+else
+    echo "# using standard session bus configuration"
+    # add a harmless command-line argument
+    config="--sh-syntax"
+fi
+
+echo "1..1"
+
+unset DBUS_SESSION_BUS_ADDRESS
+unset DBUS_SESSION_BUS_PID
+
+eval "$(${DBUS_TEST_DBUS_LAUNCH} --sh-syntax "$config")"
+
+test -n "$DBUS_SESSION_BUS_ADDRESS"
+env | grep '^DBUS_SESSION_BUS_ADDRESS='
+
+test -n "$DBUS_SESSION_BUS_PID"
+test "x$(env | grep '^DBUS_SESSION_BUS_PID=')" = "x"
+kill -0 "$DBUS_SESSION_BUS_PID"
+
+${DBUS_TEST_DBUS_SEND} --session --dest=org.freedesktop.DBus \
+    --type=method_call --print-reply / org.freedesktop.DBus.ListNames >&2
+
+kill "$DBUS_SESSION_BUS_PID"
+
+echo "ok 1 - normal dbus-launch"