From 4390d7327c949d178f62c0c88939277a64859df7 Mon Sep 17 00:00:00 2001 From: Chengwei Yang Date: Fri, 13 Sep 2013 16:56:26 +0800 Subject: [PATCH 1/2] Use test binaries in build dir to do test When do autolaunch testing, libdbus will try to start dbus-launch in installed direcotry, if fail then fall back to dbus-launch in $PATH. dbus-launch does a relative better thing to start dbus-daemon in build directory, however, in most of case, the build $prefix is different from the real prefix where dbus-daemon installed. So dbus-daemon will fail to start due to can't find its config file. And then dbus-launch will fall back to finally the installed dbus-daemon. This patch fix this behavior and will start dbus-launch and dbus-daemon in build directory in test environment. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=37849 --- configure.ac | 3 +++ dbus/dbus-sysdeps-unix.c | 9 +++++++-- test/name-test/Makefile.am | 7 ++++++- tools/dbus-launch.c | 10 +++++++++- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index ab7b1e1..b6ff769 100644 --- a/configure.ac +++ b/configure.ac @@ -1647,6 +1647,9 @@ AC_DEFINE_UNQUOTED(TEST_BUS_BINARY, ["$DBUS_PWD/bus/dbus-daemon$EXEEXT"], [Full path to the daemon in the builddir]) AC_SUBST(TEST_BUS_BINARY) +AC_DEFINE_UNQUOTED(TEST_BUS_LAUNCH_BINARY, ["$DBUS_PWD/tools/dbus-launch$EXEEXT"], + [Full path to the dbus-launch in the builddir]) + ## Export the non-setuid external helper TEST_LAUNCH_HELPER_BINARY="$DBUS_PWD/bus/dbus-daemon-launch-helper-test$EXEEXT" AC_SUBST(TEST_LAUNCH_HELPER_BINARY) diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 1cb4a58..3f2d6a8 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -3503,7 +3503,12 @@ _dbus_get_autolaunch_address (const char *scope, } i = 0; - argv[i] = "dbus-launch"; +#ifdef DBUS_ENABLE_EMBEDDED_TESTS + if (_dbus_getenv ("DBUS_USE_TEST_BINARY") != NULL) + argv[i] = TEST_BUS_LAUNCH_BINARY; + else +#endif + argv[i] = DBUS_BINDIR "/dbus-launch"; ++i; argv[i] = "--autolaunch"; ++i; @@ -3518,7 +3523,7 @@ _dbus_get_autolaunch_address (const char *scope, _dbus_assert (i == _DBUS_N_ELEMENTS (argv)); - retval = _read_subprocess_line_argv (DBUS_BINDIR "/dbus-launch", + retval = _read_subprocess_line_argv (argv[0], TRUE, argv, address, error); diff --git a/test/name-test/Makefile.am b/test/name-test/Makefile.am index 54b02af..931cb2c 100644 --- a/test/name-test/Makefile.am +++ b/test/name-test/Makefile.am @@ -13,7 +13,12 @@ AM_LDFLAGS = @R_DYNAMIC_LDFLAG@ ## so if adding tests not to be run in make check, don't add them to ## TESTS if DBUS_ENABLE_EMBEDDED_TESTS -TESTS_ENVIRONMENT=DBUS_TOP_BUILDDIR=@abs_top_builddir@ DBUS_TOP_SRCDIR=@abs_top_srcdir@ PYTHON=@PYTHON@ +TESTS_ENVIRONMENT = \ + DBUS_TOP_BUILDDIR=@abs_top_builddir@ \ + DBUS_TOP_SRCDIR=@abs_top_srcdir@ \ + PYTHON=@PYTHON@ \ + DBUS_TEST_DATA=@abs_top_builddir@/test/data \ + $(NULL) TESTS=run-test.sh run-test-systemserver.sh else TESTS= diff --git a/tools/dbus-launch.c b/tools/dbus-launch.c index 1524975..14fa226 100644 --- a/tools/dbus-launch.c +++ b/tools/dbus-launch.c @@ -1110,8 +1110,16 @@ main (int argc, char **argv) #ifdef DBUS_ENABLE_EMBEDDED_TESTS /* exec from testdir */ - if (getenv("DBUS_USE_TEST_BINARY") != NULL) + if (getenv ("DBUS_USE_TEST_BINARY") != NULL) { + if (config_file == NULL && getenv ("DBUS_TEST_DATA") != NULL) + { + ret = asprintf (&config_file, "%s/valid-config-files/session.conf", + getenv ("DBUS_TEST_DATA")); + } + if (ret == -1 && config_file != NULL) + free (config_file); + execl (TEST_BUS_BINARY, TEST_BUS_BINARY, "--fork", -- 1.7.9.5