tests: Don't exercise GetMachineId() or autolaunch if no machine ID
authorSimon McVittie <smcv@collabora.com>
Thu, 8 Jun 2017 16:04:24 +0000 (17:04 +0100)
committerSimon McVittie <smcv@collabora.com>
Thu, 8 Jun 2017 17:30:39 +0000 (18:30 +0100)
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

bus/dispatch.c
test/Makefile.am
test/name-test/test-autolaunch.c
test/test-dbus-launch-eval.sh
test/test-dbus-launch-x11.sh

index 2b59074..19228be 100644 (file)
@@ -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",
index 7c3f2ce..869d4d8 100644 (file)
@@ -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; \
index 8b5206a..0d4a095 100644 (file)
@@ -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
index 7b5a66d..cd96065 100755 (executable)
@@ -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
index 8f04910..48c2718 100755 (executable)
@@ -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