summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2017-06-08 17:04:24 +0100
committerSimon McVittie <smcv@collabora.com>2017-06-08 18:30:39 +0100
commitffa410a0403dcba0116f644749c82e7fc2a0c49f (patch)
tree307407bcf138c1880a7b7204a1c4dbc0b52446f5
parent015a5cf36d431a7431d67185f87398368508c488 (diff)
downloaddbus-ffa410a0403dcba0116f644749c82e7fc2a0c49f.tar.gz
tests: Don't exercise GetMachineId() or autolaunch if no machine ID
At the moment there is a hack in the implementation of GetMachineId() to stop tests from failing during "make check" on a system where dbus has never been installed, by silently generating a new unique fake "machine ID" for each process. I'm about to change that behaviour to report errors properly; skip affected test-cases if we can't read the real machine ID. The shell scripts to test dbus-launch are run both as "make check" tests (for which it is valid for dbus to be not correctly installed) and as installed-tests (for which that is not valid), so make them pass during "make check" but fail during installed testing. The tests in bus/ and test/name-test/ are only run during "make check" so they only have the code path where they are skipped. Signed-off-by: Simon McVittie <smcv@collabora.com> Reviewed-by: Philip Withnall <withnall@endlessm.com> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=13194
-rw-r--r--bus/dispatch.c11
-rw-r--r--test/Makefile.am2
-rw-r--r--test/name-test/test-autolaunch.c10
-rwxr-xr-xtest/test-dbus-launch-eval.sh11
-rwxr-xr-xtest/test-dbus-launch-x11.sh11
5 files changed, 45 insertions, 0 deletions
diff --git a/bus/dispatch.c b/bus/dispatch.c
index 2b590741..19228bed 100644
--- a/bus/dispatch.c
+++ b/bus/dispatch.c
@@ -3330,10 +3330,21 @@ static dbus_bool_t
check_existent_get_machine_id (BusContext *context,
DBusConnection *connection)
{
+ DBusError error = DBUS_ERROR_INIT;
DBusMessage *message;
dbus_uint32_t serial;
+ DBusGUID uuid;
const char *machine_id;
+ if (!_dbus_read_local_machine_uuid (&uuid, FALSE, &error))
+ {
+ /* Unable to test further: either we ran out of memory, or neither
+ * dbus nor systemd was ever correctly installed on this machine */
+ _dbus_verbose ("Machine UUID not available: %s", error.message);
+ dbus_error_free (&error);
+ return TRUE;
+ }
+
message = dbus_message_new_method_call (EXISTENT_SERVICE_NAME,
"/org/freedesktop/TestSuite",
"org.freedesktop.DBus.Peer",
diff --git a/test/Makefile.am b/test/Makefile.am
index 7c3f2ce1..869d4d85 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -235,6 +235,7 @@ installcheck_environment = \
export DBUS_TEST_DBUS_LAUNCH=$(DESTDIR)$(bindir)/dbus-launch$(EXEEXT); \
export DBUS_TEST_DBUS_MONITOR=$(DESTDIR)$(bindir)/dbus-monitor$(EXEEXT); \
export DBUS_TEST_DBUS_SEND=$(DESTDIR)$(bindir)/dbus-send$(EXEEXT); \
+ export DBUS_TEST_DBUS_UUIDGEN=$(DESTDIR)$(bindir)/dbus-uuidgen$(EXEEXT); \
export DBUS_TEST_EXEC=@abs_top_builddir@/test; \
export DBUS_TEST_HOMEDIR=@abs_top_builddir@/dbus; \
export DBUS_TEST_DATADIR=$(DESTDIR)$(datadir); \
@@ -254,6 +255,7 @@ AM_TESTS_ENVIRONMENT = \
export DBUS_TEST_DBUS_LAUNCH=@abs_top_builddir@/tools/dbus-launch$(EXEEXT); \
export DBUS_TEST_DBUS_MONITOR=@abs_top_builddir@/tools/dbus-monitor$(EXEEXT); \
export DBUS_TEST_DBUS_SEND=@abs_top_builddir@/tools/dbus-send$(EXEEXT); \
+ export DBUS_TEST_DBUS_UUIDGEN=@abs_top_builddir@/tools/dbus-uuidgen$(EXEEXT); \
export DBUS_TEST_DATA=@abs_top_builddir@/test/data; \
export DBUS_TEST_EXEC=@abs_top_builddir@/test; \
export DBUS_TEST_HOMEDIR=@abs_top_builddir@/dbus; \
diff --git a/test/name-test/test-autolaunch.c b/test/name-test/test-autolaunch.c
index 8b5206a6..0d4a0952 100644
--- a/test/name-test/test-autolaunch.c
+++ b/test/name-test/test-autolaunch.c
@@ -8,6 +8,7 @@
#endif
#include <dbus/dbus.h>
+#include "dbus/dbus-internals.h"
#include "dbus/dbus-sysdeps.h"
int
@@ -15,11 +16,20 @@ main (int argc, char *argv[])
{
DBusConnection *conn = NULL;
DBusError error;
+ DBusGUID uuid;
dbus_setenv ("DBUS_SESSION_BUS_ADDRESS", NULL);
dbus_error_init (&error);
+ if (!_dbus_read_local_machine_uuid (&uuid, FALSE, &error))
+ {
+ /* We can't expect autolaunching to work in this situation */
+ fprintf (stderr, "%s\n", error.message);
+ dbus_error_free (&error);
+ return 0;
+ }
+
conn = dbus_bus_get (DBUS_BUS_SESSION, &error);
#ifdef DBUS_ENABLE_X11_AUTOLAUNCH
diff --git a/test/test-dbus-launch-eval.sh b/test/test-dbus-launch-eval.sh
index 7b5a66d4..cd960650 100755
--- a/test/test-dbus-launch-eval.sh
+++ b/test/test-dbus-launch-eval.sh
@@ -28,6 +28,7 @@ export DBUS_DEBUG_OUTPUT=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}"
+echo "# dbus-uuidgen binary: ${DBUS_TEST_DBUS_UUIDGEN:=dbus-uuidgen}"
if test -n "$DBUS_TEST_DATA"; then
echo "# test data: $DBUS_TEST_DATA"
@@ -41,6 +42,16 @@ else
config="--sh-syntax"
fi
+if ! "${DBUS_TEST_DBUS_UUIDGEN}" --get >/dev/null; then
+ if test -n "$DBUS_TEST_UNINSTALLED"; then
+ echo "1..0 # SKIP - Unable to test dbus-launch without a machine ID"
+ exit 0
+ else
+ echo "Bail out! dbus not correctly installed: no machine ID"
+ exit 1
+ fi
+fi
+
echo "1..1"
unset DBUS_SESSION_BUS_ADDRESS
diff --git a/test/test-dbus-launch-x11.sh b/test/test-dbus-launch-x11.sh
index 8f049101..48c2718c 100755
--- a/test/test-dbus-launch-x11.sh
+++ b/test/test-dbus-launch-x11.sh
@@ -30,6 +30,7 @@ echo "# dbus-daemon binary: ${DBUS_TEST_DAEMON:=dbus-daemon}"
echo "# dbus-launch binary: ${DBUS_TEST_DBUS_LAUNCH:=dbus-launch}"
echo "# dbus-monitor binary: ${DBUS_TEST_DBUS_LAUNCH:=dbus-monitor}"
echo "# dbus-send binary: ${DBUS_TEST_DBUS_SEND:=dbus-send}"
+echo "# dbus-uuidgen binary: ${DBUS_TEST_DBUS_UUIDGEN:=dbus-uuidgen}"
if test -n "$DBUS_TEST_DATA"; then
echo "# test data: $DBUS_TEST_DATA"
@@ -47,6 +48,16 @@ else
launch_config="--sh-syntax"
fi
+if ! "${DBUS_TEST_DBUS_UUIDGEN}" --get >/dev/null; then
+ if test -n "$DBUS_TEST_UNINSTALLED"; then
+ echo "1..0 # SKIP - Unable to test dbus-launch without a machine ID"
+ exit 0
+ else
+ echo "Bail out! dbus not correctly installed: no machine ID"
+ exit 1
+ fi
+fi
+
if ! workdir="$(mktemp -d)"; then
echo "1..0 # SKIP - mktemp -d doesn't work"
exit 0