diff options
17 files changed, 144 insertions, 54 deletions
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index cfba103d..af68cc48 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -359,18 +359,20 @@ endif(X11_FOUND) # test binary names if (WIN32) set (EXT ".exe") + # compatible with Automake .in files + set (EXEEXT ".exe") endif(WIN32) if (MSVC_IDE) if(CMAKE_BUILD_TYPE MATCHES Debug) - set(IDE_BIN Debug/ ) + set(IDE_BIN /Debug ) message(STATUS) message(STATUS "Visual Studio: test programs will only work with 'Debug' configuration!") message(STATUS "To run tests with 'Release' configuration use -DCMAKE_BUILD_TYPE=Release") message(STATUS "Add '..\\..\\test\\data' to the command line option of the test programs") message(STATUS) else(CMAKE_BUILD_TYPE MATCHES Debug) - set(IDE_BIN Release/) + set(IDE_BIN /Release) message(STATUS) message(STATUS "Visual Studio: test programs will only work with 'Release' configuration!") message(STATUS "To run tests with 'Debug' configuration use -DCMAKE_BUILD_TYPE=Debug") @@ -382,11 +384,6 @@ if (MSVC_IDE) endif (MSVC_IDE) set(TEST_SERVICE_DIR ${CMAKE_BINARY_DIR}/test/data/valid-service-files CACHE STRING "Full path to test file test/data/valid-service-files in builddir" ) -set(TEST_SERVICE_BINARY ${CMAKE_BINARY_DIR}/bin/${IDE_BIN}test-service${EXT} CACHE STRING "Full path to test file test/test-service in builddir" ${TEST_PATH_FORCE}) -set(TEST_SHELL_SERVICE_BINARY ${CMAKE_BINARY_DIR}/bin/${IDE_BIN}test-shell-service${EXT} CACHE STRING "Full path to test file test/test-shell-service in builddir" ${TEST_PATH_FORCE}) -set(TEST_EXIT_BINARY ${CMAKE_BINARY_DIR}/bin/${IDE_BIN}test-exit${EXT} CACHE STRING "Full path to test file test/test-exit in builddir" ${TEST_PATH_FORCE}) -set(TEST_SEGFAULT_BINARY ${CMAKE_BINARY_DIR}/bin/${IDE_BIN}test-segfault${EXT} CACHE STRING "Full path to test file test/test-segfault in builddir" ${TEST_PATH_FORCE}) -set(TEST_SLEEP_FOREVER_BINARY ${CMAKE_BINARY_DIR}/bin/${IDE_BIN}test-sleep-forever${EXT} CACHE STRING "Full path to test file test/test-sleep-forever in builddir" ${TEST_PATH_FORCE}) #### Find socket directories if (NOT $ENV{TMPDIR} STREQUAL "") @@ -478,10 +475,10 @@ add_definitions(${DBUS_BUS_CFLAGS}) if (DBUS_BUILD_TESTS) # set variables used for the .in files (substituted by configure_file) in test/data: + set(DBUS_TEST_EXEC ${EXECUTABLE_OUTPUT_PATH}${IDE_BIN}) set(DBUS_TEST_DATA ${CMAKE_BINARY_DIR}/test/data) set(TEST_SOCKET_DIR ${DBUS_SESSION_SOCKET_DIR} ) set(TEST_LAUNCH_HELPER_BINARY ${EXECUTABLE_OUTPUT_PATH}/dbus-daemon-launch-helper-test) - set(TEST_PRIVSERVER_BINARY ${EXECUTABLE_OUTPUT_PATH}/test-privserver) if (UNIX) set (TEST_LISTEN "debug-pipe:name=test-server</listen><listen>unix:tmpdir=${TEST_SOCKET_DIR}") set (TEST_CONNECTION "debug-pipe:name=test-server") diff --git a/cmake/config.h.cmake b/cmake/config.h.cmake index b4bfc802..768bf2db 100644 --- a/cmake/config.h.cmake +++ b/cmake/config.h.cmake @@ -33,18 +33,11 @@ #define TEST_CONNECTION "@TEST_CONNECTION@" // test binaries +#define DBUS_TEST_EXEC "@DBUS_TEST_EXEC@" +#define DBUS_EXEEXT "@EXEEXT@" + /* Full path to test file test/test-exit in builddir */ #define TEST_BUS_BINARY "@TEST_BUS_BINARY@" -/* Full path to test file test/test-exit in builddir */ -#define TEST_EXIT_BINARY "@TEST_EXIT_BINARY@" -/* Full path to test file test/test-segfault in builddir */ -#define TEST_SEGFAULT_BINARY "@TEST_SEGFAULT_BINARY@" -/* Full path to test file test/test-service in builddir */ -#define TEST_SERVICE_BINARY "@TEST_SERVICE_BINARY@" -/* Full path to test file test/test-shell-service in builddir */ -#define TEST_SHELL_SERVICE_BINARY "@TEST_SHELL_SERVICE_BINARY@" -/* Full path to test file test/test-sleep-forever in builddir */ -#define TEST_SLEEP_FOREVER_BINARY "@TEST_SLEEP_FOREVER_BINARY@" /* Some dbus features */ #cmakedefine DBUS_BUILD_TESTS 1 diff --git a/configure.ac b/configure.ac index 6c2e2b51..903a513b 100644 --- a/configure.ac +++ b/configure.ac @@ -1519,24 +1519,19 @@ DBUS_PWD=`pwd` # Useful in a cross-compilation environment, where the tests are run on the host system. AC_ARG_WITH(dbus-test-dir, AS_HELP_STRING([--with-dbus-test-dir=[dirname]],[path where the tests tools are available]), DBUS_PWD=$withval) -AC_DEFUN([TEST_PROG], [ -TEST_$1=${DBUS_PWD}/test/$2 -AC_DEFINE_UNQUOTED(TEST_$1, "$TEST_$1$EXEEXT", - [Full path to test file test/$2 in builddir]) -AC_SUBST(TEST_$1) -]) +DBUS_TEST_EXEC="$DBUS_PWD/test" DBUS_TEST_DATA="$DBUS_PWD/test/data" + AC_SUBST([DBUS_TEST_DATA]) +AC_SUBST([DBUS_TEST_EXEC]) -TEST_PROG(SERVICE_BINARY, test-service) -TEST_PROG(SHELL_SERVICE_BINARY, test-shell-service) -TEST_PROG(EXIT_BINARY, test-exit) -TEST_PROG(SEGFAULT_BINARY, test-segfault) -TEST_PROG(SLEEP_FOREVER_BINARY, test-sleep-forever) -TEST_PROG(PRIVSERVER_BINARY, name-test/test-privserver) +AC_DEFINE_UNQUOTED([DBUS_TEST_EXEC], ["$DBUS_TEST_EXEC"], + [Full path to the daemon in the builddir]) +AC_DEFINE_UNQUOTED([DBUS_EXEEXT], ["$EXEEXT"], + [Extension for executables, typically empty or .exe]) -AC_DEFINE_UNQUOTED(TEST_BUS_BINARY, "$DBUS_PWD/bus/dbus-daemon$EXEEXT", +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) diff --git a/dbus/dbus-spawn-win.c b/dbus/dbus-spawn-win.c index 36df388c..b0cf90f1 100644 --- a/dbus/dbus-spawn-win.c +++ b/dbus/dbus-spawn-win.c @@ -754,6 +754,30 @@ _dbus_babysitter_set_result_function (DBusBabysitter *sitter, #ifdef DBUS_BUILD_TESTS +static char * +get_test_exec (const char *exe, + DBusString *scratch_space) +{ + const char *dbus_test_exec; + + dbus_test_exec = _dbus_getenv ("DBUS_TEST_EXEC"); + + if (dbus_test_exec == NULL) + dbus_test_exec = DBUS_TEST_EXEC; + + if (!_dbus_string_init (scratch_space)) + return NULL; + + if (!_dbus_string_append_printf (scratch_space, "%s/%s%s", + dbus_test_exec, exe, DBUS_EXEEXT)) + { + _dbus_string_free (scratch_space); + return NULL; + } + + return _dbus_string_get_data (scratch_space); +} + #define LIVE_CHILDREN(sitter) ((sitter)->child_handle != NULL) static void @@ -816,6 +840,7 @@ check_spawn_segfault (void *data) char *argv[4] = { NULL, NULL, NULL, NULL }; DBusBabysitter *sitter; DBusError error; + DBusString argv0; sitter = NULL; @@ -823,7 +848,14 @@ check_spawn_segfault (void *data) /*** Test launching segfault binary */ - argv[0] = TEST_SEGFAULT_BINARY; + argv[0] = get_test_exec ("test-segfault", &argv0); + + if (argv[0] == NULL) + { + /* OOM was simulated, never mind */ + return TRUE; + } + if (_dbus_spawn_async_with_babysitter (&sitter, argv, NULL, NULL, NULL, &error)) @@ -832,6 +864,8 @@ check_spawn_segfault (void *data) _dbus_babysitter_set_child_exit_error (sitter, &error); } + _dbus_string_free (&argv0); + if (sitter) _dbus_babysitter_unref (sitter); @@ -861,6 +895,7 @@ check_spawn_exit (void *data) char *argv[4] = { NULL, NULL, NULL, NULL }; DBusBabysitter *sitter; DBusError error; + DBusString argv0; sitter = NULL; @@ -868,7 +903,14 @@ check_spawn_exit (void *data) /*** Test launching exit failure binary */ - argv[0] = TEST_EXIT_BINARY; + argv[0] = get_test_exec ("test-exit", &argv0); + + if (argv[0] == NULL) + { + /* OOM was simulated, never mind */ + return TRUE; + } + if (_dbus_spawn_async_with_babysitter (&sitter, argv, NULL, NULL, NULL, &error)) @@ -877,6 +919,8 @@ check_spawn_exit (void *data) _dbus_babysitter_set_child_exit_error (sitter, &error); } + _dbus_string_free (&argv0); + if (sitter) _dbus_babysitter_unref (sitter); @@ -906,6 +950,7 @@ check_spawn_and_kill (void *data) char *argv[4] = { NULL, NULL, NULL, NULL }; DBusBabysitter *sitter; DBusError error; + DBusString argv0; sitter = NULL; @@ -913,7 +958,14 @@ check_spawn_and_kill (void *data) /*** Test launching sleeping binary then killing it */ - argv[0] = TEST_SLEEP_FOREVER_BINARY; + argv[0] = get_test_exec ("test-sleep-forever", &argv0); + + if (argv[0] == NULL) + { + /* OOM was simulated, never mind */ + return TRUE; + } + if (_dbus_spawn_async_with_babysitter (&sitter, argv, NULL, NULL, NULL, &error)) @@ -925,6 +977,8 @@ check_spawn_and_kill (void *data) _dbus_babysitter_set_child_exit_error (sitter, &error); } + _dbus_string_free (&argv0); + if (sitter) _dbus_babysitter_unref (sitter); diff --git a/dbus/dbus-spawn.c b/dbus/dbus-spawn.c index 9f6be265..ef00801c 100644 --- a/dbus/dbus-spawn.c +++ b/dbus/dbus-spawn.c @@ -1323,6 +1323,30 @@ _dbus_babysitter_set_result_function (DBusBabysitter *sitter, #ifdef DBUS_BUILD_TESTS +static char * +get_test_exec (const char *exe, + DBusString *scratch_space) +{ + const char *dbus_test_exec; + + dbus_test_exec = _dbus_getenv ("DBUS_TEST_EXEC"); + + if (dbus_test_exec == NULL) + dbus_test_exec = DBUS_TEST_EXEC; + + if (!_dbus_string_init (scratch_space)) + return NULL; + + if (!_dbus_string_append_printf (scratch_space, "%s/%s%s", + dbus_test_exec, exe, DBUS_EXEEXT)) + { + _dbus_string_free (scratch_space); + return NULL; + } + + return _dbus_string_get_data (scratch_space); +} + static void _dbus_babysitter_block_for_child_exit (DBusBabysitter *sitter) { @@ -1377,10 +1401,18 @@ check_spawn_segfault (void *data) char *argv[4] = { NULL, NULL, NULL, NULL }; DBusBabysitter *sitter = NULL; DBusError error = DBUS_ERROR_INIT; + DBusString argv0; /*** Test launching segfault binary */ - - argv[0] = TEST_SEGFAULT_BINARY; + + argv[0] = get_test_exec ("test-segfault", &argv0); + + if (argv[0] == NULL) + { + /* OOM was simulated, never mind */ + return TRUE; + } + if (_dbus_spawn_async_with_babysitter (&sitter, argv, NULL, NULL, NULL, &error)) @@ -1389,6 +1421,8 @@ check_spawn_segfault (void *data) _dbus_babysitter_set_child_exit_error (sitter, &error); } + _dbus_string_free (&argv0); + if (sitter) _dbus_babysitter_unref (sitter); @@ -1418,10 +1452,18 @@ check_spawn_exit (void *data) char *argv[4] = { NULL, NULL, NULL, NULL }; DBusBabysitter *sitter = NULL; DBusError error = DBUS_ERROR_INIT; + DBusString argv0; /*** Test launching exit failure binary */ - - argv[0] = TEST_EXIT_BINARY; + + argv[0] = get_test_exec ("test-exit", &argv0); + + if (argv[0] == NULL) + { + /* OOM was simulated, never mind */ + return TRUE; + } + if (_dbus_spawn_async_with_babysitter (&sitter, argv, NULL, NULL, NULL, &error)) @@ -1430,6 +1472,8 @@ check_spawn_exit (void *data) _dbus_babysitter_set_child_exit_error (sitter, &error); } + _dbus_string_free (&argv0); + if (sitter) _dbus_babysitter_unref (sitter); @@ -1459,10 +1503,18 @@ check_spawn_and_kill (void *data) char *argv[4] = { NULL, NULL, NULL, NULL }; DBusBabysitter *sitter = NULL; DBusError error = DBUS_ERROR_INIT; + DBusString argv0; /*** Test launching sleeping binary then killing it */ - argv[0] = TEST_SLEEP_FOREVER_BINARY; + argv[0] = get_test_exec ("test-sleep-forever", &argv0); + + if (argv[0] == NULL) + { + /* OOM was simulated, never mind */ + return TRUE; + } + if (_dbus_spawn_async_with_babysitter (&sitter, argv, NULL, NULL, NULL, &error)) @@ -1474,6 +1526,8 @@ check_spawn_and_kill (void *data) _dbus_babysitter_set_child_exit_error (sitter, &error); } + _dbus_string_free (&argv0); + if (sitter) _dbus_babysitter_unref (sitter); diff --git a/test/data/invalid-service-files-system/org.freedesktop.DBus.TestSuiteNoService.service.in b/test/data/invalid-service-files-system/org.freedesktop.DBus.TestSuiteNoService.service.in index 16ace268..7822ffc4 100644 --- a/test/data/invalid-service-files-system/org.freedesktop.DBus.TestSuiteNoService.service.in +++ b/test/data/invalid-service-files-system/org.freedesktop.DBus.TestSuiteNoService.service.in @@ -1,4 +1,4 @@ [D-BUS Service] -Exec=@TEST_SERVICE_BINARY@ +Exec=@DBUS_TEST_EXEC@/test-service@EXEEXT@ User=anyrandomuser diff --git a/test/data/invalid-service-files-system/org.freedesktop.DBus.TestSuiteNoUser.service.in b/test/data/invalid-service-files-system/org.freedesktop.DBus.TestSuiteNoUser.service.in index 01b898cf..691e0096 100644 --- a/test/data/invalid-service-files-system/org.freedesktop.DBus.TestSuiteNoUser.service.in +++ b/test/data/invalid-service-files-system/org.freedesktop.DBus.TestSuiteNoUser.service.in @@ -1,4 +1,3 @@ [D-BUS Service] Name=org.freedesktop.DBus.TestSuiteNoUser -Exec=@TEST_SERVICE_BINARY@ - +Exec=@DBUS_TEST_EXEC@/test-service@EXEEXT@ diff --git a/test/data/valid-service-files-system/org.freedesktop.DBus.TestSuiteEchoService.service.in b/test/data/valid-service-files-system/org.freedesktop.DBus.TestSuiteEchoService.service.in index bd0e58e5..3076f3bf 100644 --- a/test/data/valid-service-files-system/org.freedesktop.DBus.TestSuiteEchoService.service.in +++ b/test/data/valid-service-files-system/org.freedesktop.DBus.TestSuiteEchoService.service.in @@ -1,5 +1,5 @@ [D-BUS Service] Name=org.freedesktop.DBus.TestSuiteEchoService -Exec=@TEST_SERVICE_BINARY@ +Exec=@DBUS_TEST_EXEC@/test-service@EXEEXT@ User=anyrandomuser diff --git a/test/data/valid-service-files-system/org.freedesktop.DBus.TestSuiteSegfaultService.service.in b/test/data/valid-service-files-system/org.freedesktop.DBus.TestSuiteSegfaultService.service.in index 18d16d1b..705d7148 100644 --- a/test/data/valid-service-files-system/org.freedesktop.DBus.TestSuiteSegfaultService.service.in +++ b/test/data/valid-service-files-system/org.freedesktop.DBus.TestSuiteSegfaultService.service.in @@ -1,5 +1,5 @@ [D-BUS Service] Name=org.freedesktop.DBus.TestSuiteSegfaultService -Exec=@TEST_SEGFAULT_BINARY@ +Exec=@DBUS_TEST_EXEC@/test-segfault@EXEEXT@ User=anyrandomuser diff --git a/test/data/valid-service-files-system/org.freedesktop.DBus.TestSuiteShellEchoServiceFail.service.in b/test/data/valid-service-files-system/org.freedesktop.DBus.TestSuiteShellEchoServiceFail.service.in index 9195e174..870835ea 100644 --- a/test/data/valid-service-files-system/org.freedesktop.DBus.TestSuiteShellEchoServiceFail.service.in +++ b/test/data/valid-service-files-system/org.freedesktop.DBus.TestSuiteShellEchoServiceFail.service.in @@ -1,5 +1,5 @@ [D-BUS Service] Name=org.freedesktop.DBus.TestSuiteShellEchoServiceFail -Exec=@TEST_SHELL_SERVICE_BINARY@ "this should 'fail' because of an unterminated quote +Exec=@DBUS_TEST_EXEC@/test-shell-service@EXEEXT@ "this should 'fail' because of an unterminated quote User=anyrandomuser diff --git a/test/data/valid-service-files-system/org.freedesktop.DBus.TestSuiteShellEchoServiceSuccess.service.in b/test/data/valid-service-files-system/org.freedesktop.DBus.TestSuiteShellEchoServiceSuccess.service.in index 2236ce55..66472614 100644 --- a/test/data/valid-service-files-system/org.freedesktop.DBus.TestSuiteShellEchoServiceSuccess.service.in +++ b/test/data/valid-service-files-system/org.freedesktop.DBus.TestSuiteShellEchoServiceSuccess.service.in @@ -1,5 +1,5 @@ [D-BUS Service] Name=org.freedesktop.DBus.TestSuiteShellEchoServiceSuccess -Exec=@TEST_SHELL_SERVICE_BINARY@ -test "that" 'we get' back --what "we put in" +Exec=@DBUS_TEST_EXEC@/test-shell-service@EXEEXT@ -test "that" 'we get' back --what "we put in" User=anyrandomuser diff --git a/test/data/valid-service-files/org.freedesktop.DBus.TestSuite.PrivServer.service.in b/test/data/valid-service-files/org.freedesktop.DBus.TestSuite.PrivServer.service.in index 2cbdaa8b..0fdfeade 100644 --- a/test/data/valid-service-files/org.freedesktop.DBus.TestSuite.PrivServer.service.in +++ b/test/data/valid-service-files/org.freedesktop.DBus.TestSuite.PrivServer.service.in @@ -1,4 +1,4 @@ [D-BUS Service] Name=org.freedesktop.DBus.TestSuite.PrivServer -Exec=@TEST_PRIVSERVER_BINARY@ +Exec=@DBUS_TEST_EXEC@/name-test/test-privserver@EXEEXT@ diff --git a/test/data/valid-service-files/org.freedesktop.DBus.TestSuiteEchoService.service.in b/test/data/valid-service-files/org.freedesktop.DBus.TestSuiteEchoService.service.in index 4202351d..a22a77d1 100644 --- a/test/data/valid-service-files/org.freedesktop.DBus.TestSuiteEchoService.service.in +++ b/test/data/valid-service-files/org.freedesktop.DBus.TestSuiteEchoService.service.in @@ -1,4 +1,3 @@ [D-BUS Service] Name=org.freedesktop.DBus.TestSuiteEchoService -Exec=@TEST_SERVICE_BINARY@ - +Exec=@DBUS_TEST_EXEC@/test-service@EXEEXT@ diff --git a/test/data/valid-service-files/org.freedesktop.DBus.TestSuiteForkingEchoService.service.in b/test/data/valid-service-files/org.freedesktop.DBus.TestSuiteForkingEchoService.service.in index 49fcac39..633862c7 100644 --- a/test/data/valid-service-files/org.freedesktop.DBus.TestSuiteForkingEchoService.service.in +++ b/test/data/valid-service-files/org.freedesktop.DBus.TestSuiteForkingEchoService.service.in @@ -1,3 +1,3 @@ [D-BUS Service] Name=org.freedesktop.DBus.TestSuiteForkingEchoService -Exec=@TEST_SERVICE_BINARY@ org.freedesktop.DBus.TestSuiteForkingEchoService fork +Exec=@DBUS_TEST_EXEC@/test-service@EXEEXT@ org.freedesktop.DBus.TestSuiteForkingEchoService fork diff --git a/test/data/valid-service-files/org.freedesktop.DBus.TestSuiteSegfaultService.service.in b/test/data/valid-service-files/org.freedesktop.DBus.TestSuiteSegfaultService.service.in index 73c7b55b..76254275 100644 --- a/test/data/valid-service-files/org.freedesktop.DBus.TestSuiteSegfaultService.service.in +++ b/test/data/valid-service-files/org.freedesktop.DBus.TestSuiteSegfaultService.service.in @@ -1,4 +1,4 @@ [D-BUS Service] Name=org.freedesktop.DBus.TestSuiteSegfaultService -Exec=@TEST_SEGFAULT_BINARY@ +Exec=@DBUS_TEST_EXEC@/test-segfault@EXEEXT@ diff --git a/test/data/valid-service-files/org.freedesktop.DBus.TestSuiteShellEchoServiceFail.service.in b/test/data/valid-service-files/org.freedesktop.DBus.TestSuiteShellEchoServiceFail.service.in index 4404c78e..8f5964a2 100644 --- a/test/data/valid-service-files/org.freedesktop.DBus.TestSuiteShellEchoServiceFail.service.in +++ b/test/data/valid-service-files/org.freedesktop.DBus.TestSuiteShellEchoServiceFail.service.in @@ -1,4 +1,3 @@ [D-BUS Service] Name=org.freedesktop.DBus.TestSuiteShellEchoServiceFail -Exec=@TEST_SHELL_SERVICE_BINARY@ "this should 'fail' because of an unterminated quote - +Exec=@DBUS_TEST_EXEC@/test-shell-service@EXEEXT@ "this should 'fail' because of an unterminated quote diff --git a/test/data/valid-service-files/org.freedesktop.DBus.TestSuiteShellEchoServiceSuccess.service.in b/test/data/valid-service-files/org.freedesktop.DBus.TestSuiteShellEchoServiceSuccess.service.in index e5688462..a52887e5 100644 --- a/test/data/valid-service-files/org.freedesktop.DBus.TestSuiteShellEchoServiceSuccess.service.in +++ b/test/data/valid-service-files/org.freedesktop.DBus.TestSuiteShellEchoServiceSuccess.service.in @@ -1,4 +1,4 @@ [D-BUS Service] Name=org.freedesktop.DBus.TestSuiteShellEchoServiceSuccess -Exec=@TEST_SHELL_SERVICE_BINARY@ -test "that" 'we get' back --what "we put in" +Exec=@DBUS_TEST_EXEC@/test-shell-service@EXEEXT@ -test "that" 'we get' back --what "we put in" |