Commit 33c43947 authored by Simon McVittie's avatar Simon McVittie

Simplify substitution of test executables to use fewer variables

Also use EXEEXT in all the service files, even in the automake build
system.
Signed-off-by: default avatarSimon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Ralf Habacker's avatarRalf Habacker <ralf.habacker@freenet.de>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=41222
parent 6934bc69
......@@ -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")
......
......@@ -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
......
......@@ -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)
......
......@@ -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);
......
......@@ -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);
......
[D-BUS Service]
Exec=@TEST_SERVICE_BINARY@
Exec=@DBUS_TEST_EXEC@/test-service@EXEEXT@
User=anyrandomuser
[D-BUS Service]
Name=org.freedesktop.DBus.TestSuiteNoUser
Exec=@TEST_SERVICE_BINARY@
Exec=@DBUS_TEST_EXEC@/test-service@EXEEXT@
[D-BUS Service]
Name=org.freedesktop.DBus.TestSuiteEchoService
Exec=@TEST_SERVICE_BINARY@
Exec=@DBUS_TEST_EXEC@/test-service@EXEEXT@
User=anyrandomuser
[D-BUS Service]
Name=org.freedesktop.DBus.TestSuiteSegfaultService
Exec=@TEST_SEGFAULT_BINARY@
Exec=@DBUS_TEST_EXEC@/test-segfault@EXEEXT@
User=anyrandomuser
[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
[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
[D-BUS Service]
Name=org.freedesktop.DBus.TestSuite.PrivServer
Exec=@TEST_PRIVSERVER_BINARY@
Exec=@DBUS_TEST_EXEC@/name-test/test-privserver@EXEEXT@
[D-BUS Service]
Name=org.freedesktop.DBus.TestSuiteEchoService
Exec=@TEST_SERVICE_BINARY@
Exec=@DBUS_TEST_EXEC@/test-service@EXEEXT@
[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
[D-BUS Service]
Name=org.freedesktop.DBus.TestSuiteSegfaultService
Exec=@TEST_SEGFAULT_BINARY@
Exec=@DBUS_TEST_EXEC@/test-segfault@EXEEXT@
[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
[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"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment