Commit 8e728f36 authored by Ralf Habacker's avatar Ralf Habacker

Use macros for test and helper executable targets on cmake build system.

The new macros add_test_executables and add helper_executables provides a
platform independent way for specifing dbus test and service applications.

On native Windows and Linux/UNIX systems the test applications are
directly runable.

When cross compiling for Windows on Linux test applications could be
executed on the Linux host system with the help of wine and activated
binfmt_misc support for wine.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=41252Reviewed-by: 's avatarSimon McVittie <simon.mcvittie@collabora.co.uk>
parent 79a7a30c
......@@ -106,10 +106,9 @@ if (DBUS_SERVICE)
endif (DBUS_SERVICE)
if (DBUS_ENABLE_EMBEDDED_TESTS)
add_executable(bus-test ${BUS_SOURCES} ${BUS_DIR}/test-main.c)
target_link_libraries(bus-test ${DBUS_INTERNAL_LIBRARIES} ${XML_LIBRARY})
set(SOURCES ${BUS_SOURCES} ${BUS_DIR}/test-main.c)
add_test_executable(bus-test "${SOURCES}" ${DBUS_INTERNAL_LIBRARIES} ${XML_LIBRARY})
set_target_properties(bus-test PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})
add_test(bus-test ${EXECUTABLE_OUTPUT_PATH}/bus-test ${CMAKE_BINARY_DIR}/test/data)
endif (DBUS_ENABLE_EMBEDDED_TESTS)
if(MSVC)
......@@ -146,11 +145,9 @@ if(NOT WIN32)
set_target_properties(dbus-daemon-launch-helper-test PROPERTIES COMPILE_FLAGS "-DACTIVATION_LAUNCHER_TEST")
target_link_libraries(dbus-daemon-launch-helper-test ${DBUS_INTERNAL_LIBRARIES} ${XML_LIBRARY} )
add_executable(bus-test-launch-helper ${LAUNCH_HELPER_SOURCES} ${BUS_DIR}/test-launch-helper.c)
set (SOURCES ${LAUNCH_HELPER_SOURCES} ${BUS_DIR}/test-launch-helper.c)
add_test_executable(bus-test-launch-helper "${SOURCES}" ${DBUS_INTERNAL_LIBRARIES} ${XML_LIBRARY})
set_target_properties(bus-test-launch-helper PROPERTIES COMPILE_FLAGS "-DACTIVATION_LAUNCHER_TEST -DACTIVATION_LAUNCHER_DO_OOM")
target_link_libraries(bus-test-launch-helper ${DBUS_INTERNAL_LIBRARIES} ${XML_LIBRARY} )
add_test(bus-test-launch-helper ${EXECUTABLE_OUTPUT_PATH}/bus-test-launch-helper )
endif(NOT WIN32)
#### Init scripts fun
......
......@@ -297,10 +297,7 @@ else(WIN32)
endif(WIN32)
if (DBUS_ENABLE_EMBEDDED_TESTS)
set (TESTS_ENVIRONMENT "DBUS_TEST_DATA=${CMAKE_SOURCE_DIR}/test/data DBUS_TEST_HOMEDIR=${CMAKE_BUILD_DIR}/dbus")
ADD_EXECUTABLE(dbus-test ${CMAKE_SOURCE_DIR}/../dbus/dbus-test-main.c)
target_link_libraries(dbus-test ${DBUS_INTERNAL_LIBRARIES})
add_test(dbus-test ${EXECUTABLE_OUTPUT_PATH}/dbus-test ${CMAKE_SOURCE_DIR}/../test/data)
add_test_executable(dbus-test ${CMAKE_SOURCE_DIR}/../dbus/dbus-test-main.c ${DBUS_INTERNAL_LIBRARIES})
set_target_properties(dbus-test PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})
ENDIF (DBUS_ENABLE_EMBEDDED_TESTS)
......
MACRO(TIMESTAMP RESULT)
if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
EXECUTE_PROCESS(COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE DATE)
......@@ -10,3 +9,29 @@ MACRO(TIMESTAMP RESULT)
EXECUTE_PROCESS(COMMAND "date" "+%Y%m%d%H%M" OUTPUT_VARIABLE ${RESULT})
endif ()
ENDMACRO()
macro(add_test_executable _target _source)
add_executable(${_target} ${_source})
target_link_libraries(${_target} ${ARGN})
if (CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
# run tests with binfmt_misc
set(PREFIX "z:")
set(_env "DBUS_TEST_DAEMON=${PREFIX}${CMAKE_BINARY_DIR}/bin/dbus-daemon${EXEEXT}")
add_test(NAME ${_target} COMMAND $<TARGET_FILE:${_target}>)
else()
set(PREFIX)
set(_env "DBUS_TEST_DAEMON=${CMAKE_BINARY_DIR}/bin/dbus-daemon${EXEEXT}")
add_test(NAME ${_target} COMMAND $<TARGET_FILE:${_target}>)
endif()
list(APPEND _env "DBUS_SESSION_BUS_ADDRESS=")
list(APPEND _env "DBUS_FATAL_WARNINGS=1")
list(APPEND _env "DBUS_BLOCK_ON_ABORT=1")
list(APPEND _env "DBUS_TEST_DATA=${PREFIX}${CMAKE_BINARY_DIR}/test/data")
list(APPEND _env "DBUS_TEST_HOMEDIR=${PREFIX}${CMAKE_BINARY_DIR}/dbus")
set_tests_properties(${_target} PROPERTIES ENVIRONMENT "${_env}")
endmacro(add_test_executable)
macro(add_helper_executable _target _source)
add_executable(${_target} ${_source})
target_link_libraries(${_target} ${ARGN})
endmacro(add_helper_executable)
......@@ -47,31 +47,15 @@ set (test-sleep-forever_SOURCES
${CMAKE_SOURCE_DIR}/../test/test-sleep-forever.c
)
add_executable(test-service ${test-service_SOURCES})
target_link_libraries(test-service dbus-testutils)
add_executable(test-names ${test-names_SOURCES})
target_link_libraries(test-names dbus-testutils)
add_executable(shell-test ${shell-test_SOURCES})
target_link_libraries(shell-test ${DBUS_INTERNAL_LIBRARIES})
ADD_TEST(shell-test ${EXECUTABLE_OUTPUT_PATH}/shell-test${EXEEXT})
add_executable(test-shell-service ${test-shell-service_SOURCES})
target_link_libraries(test-shell-service dbus-testutils)
add_executable(spawn-test ${spawn-test_SOURCES})
target_link_libraries(spawn-test ${DBUS_INTERNAL_LIBRARIES})
add_executable(test-exit ${test-exit_SOURCES})
target_link_libraries(test-exit ${DBUS_INTERNAL_LIBRARIES})
add_executable(test-segfault ${test-segfault_SOURCES})
target_link_libraries(test-segfault ${DBUS_INTERNAL_LIBRARIES})
add_executable(test-sleep-forever ${test-sleep-forever_SOURCES})
target_link_libraries(test-sleep-forever ${DBUS_INTERNAL_LIBRARIES})
add_helper_executable(test-service ${test-service_SOURCES} dbus-testutils)
add_helper_executable(test-names ${test-names_SOURCES} dbus-testutils)
add_test_executable(shell-test ${shell-test_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
add_test_executable(test-printf ${CMAKE_SOURCE_DIR}/../test/internals/printf.c dbus-testutils)
add_helper_executable(test-shell-service ${test-shell-service_SOURCES} dbus-testutils)
add_helper_executable(spawn-test ${spawn-test_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
add_helper_executable(test-exit ${test-exit_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
add_helper_executable(test-segfault ${test-segfault_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
add_helper_executable(test-sleep-forever ${test-sleep-forever_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
if(DBUS_WITH_GLIB)
message(STATUS "with glib test apps")
......@@ -84,37 +68,18 @@ if(DBUS_WITH_GLIB)
${GOBJECT_INCLUDE_DIR}
${CMAKE_SOURCE_DIR}/../test
)
set (TEST_LIBRARIES dbus-testutils ${GLIB2_LIBRARIES} ${GOBJECT_LIBRARIES})
add_executable(test-corrupt ${CMAKE_SOURCE_DIR}/../test/corrupt.c)
target_link_libraries(test-corrupt ${TEST_LIBRARIES})
add_executable(test-dbus-daemon ${CMAKE_SOURCE_DIR}/../test/dbus-daemon.c)
target_link_libraries(test-dbus-daemon ${TEST_LIBRARIES})
add_executable(test-dbus-daemon-eavesdrop ${CMAKE_SOURCE_DIR}/../test/dbus-daemon-eavesdrop.c)
target_link_libraries(test-dbus-daemon-eavesdrop ${TEST_LIBRARIES})
add_executable(test-loopback ${CMAKE_SOURCE_DIR}/../test/loopback.c)
target_link_libraries(test-loopback ${TEST_LIBRARIES})
add_executable(test-marshal ${CMAKE_SOURCE_DIR}/../test/marshal.c)
target_link_libraries(test-marshal ${TEST_LIBRARIES})
add_executable(test-refs ${CMAKE_SOURCE_DIR}/../test/internals/refs.c)
target_link_libraries(test-refs ${TEST_LIBRARIES})
add_executable(test-relay ${CMAKE_SOURCE_DIR}/../test/relay.c)
target_link_libraries(test-relay ${TEST_LIBRARIES})
add_executable(test-syntax ${CMAKE_SOURCE_DIR}/../test/syntax.c)
target_link_libraries(test-syntax ${TEST_LIBRARIES})
add_executable(test-syslog ${CMAKE_SOURCE_DIR}/../test/internals/syslog.c)
target_link_libraries(test-syslog ${TEST_LIBRARIES})
add_executable(manual-authz ${CMAKE_SOURCE_DIR}/../test/manual-authz.c)
target_link_libraries(manual-authz ${TEST_LIBRARIES})
set(TEST_LIBRARIES ${DBUS_INTERNAL_LIBRARIES} dbus-testutils ${GLIB2_LIBRARIES} ${GOBJECT_LIBRARIES})
add_test_executable(test-corrupt ${CMAKE_SOURCE_DIR}/../test/corrupt.c ${TEST_LIBRARIES})
add_test_executable(test-dbus-daemon ${CMAKE_SOURCE_DIR}/../test/dbus-daemon.c ${TEST_LIBRARIES})
add_test_executable(test-dbus-daemon-eavesdrop ${CMAKE_SOURCE_DIR}/../test/dbus-daemon-eavesdrop.c ${TEST_LIBRARIES})
add_test_executable(test-loopback ${CMAKE_SOURCE_DIR}/../test/loopback.c ${TEST_LIBRARIES})
add_test_executable(test-marshal ${CMAKE_SOURCE_DIR}/../test/marshal.c ${TEST_LIBRARIES})
add_test_executable(test-refs ${CMAKE_SOURCE_DIR}/../test/internals/refs.c ${TEST_LIBRARIES})
add_test_executable(test-relay ${CMAKE_SOURCE_DIR}/../test/relay.c ${TEST_LIBRARIES})
add_test_executable(test-syntax ${CMAKE_SOURCE_DIR}/../test/syntax.c ${TEST_LIBRARIES})
add_test_executable(test-syslog ${CMAKE_SOURCE_DIR}/../test/internals/syslog.c ${TEST_LIBRARIES})
add_helper_executable(manual-authz ${CMAKE_SOURCE_DIR}/../test/manual-authz.c ${TEST_LIBRARIES})
endif()
### keep these in creation order, i.e. uppermost dirs first
......@@ -210,4 +175,4 @@ add_custom_target(check
COMMAND ctest -R test-relay
COMMAND ctest -R test-syntax
COMMAND ctest -R test-syslog
)
\ No newline at end of file
)
......@@ -4,36 +4,12 @@ set (NAMEtest-DIR ../../../test/name-test)
add_definitions(${DBUS_INTERNAL_CLIENT_DEFINITIONS})
add_executable(test-pending-call-dispatch ${NAMEtest-DIR}/test-pending-call-dispatch.c)
target_link_libraries(test-pending-call-dispatch ${DBUS_INTERNAL_LIBRARIES})
ADD_TEST(test-pending-call-dispatch ${EXECUTABLE_OUTPUT_PATH}/test-pending-call-dispatch)
add_executable(test-pending-call-timeout ${NAMEtest-DIR}/test-pending-call-timeout.c)
target_link_libraries(test-pending-call-timeout ${DBUS_INTERNAL_LIBRARIES})
ADD_TEST(test-pending-call-timeout ${EXECUTABLE_OUTPUT_PATH}/test-pending-call-timeout)
add_executable(test-thread-init ${NAMEtest-DIR}/test-threads-init.c)
target_link_libraries(test-thread-init ${DBUS_INTERNAL_LIBRARIES})
ADD_TEST(test-thread-init ${EXECUTABLE_OUTPUT_PATH}/test-thread-init)
add_executable(test-ids ${NAMEtest-DIR}/test-ids.c)
target_link_libraries(test-ids ${DBUS_INTERNAL_LIBRARIES})
ADD_TEST(test-ids ${EXECUTABLE_OUTPUT_PATH}/test-ids)
add_executable(test-shutdown ${NAMEtest-DIR}/test-shutdown.c)
target_link_libraries(test-shutdown dbus-testutils)
ADD_TEST(test-shutdown ${EXECUTABLE_OUTPUT_PATH}/test-shutdown)
add_executable(test-privserver ${NAMEtest-DIR}/test-privserver.c)
target_link_libraries(test-privserver dbus-testutils)
ADD_TEST(test-privserver ${EXECUTABLE_OUTPUT_PATH}/test-privserver)
add_executable(test-privserver-client ${NAMEtest-DIR}/test-privserver-client.c)
target_link_libraries(test-privserver-client dbus-testutils)
ADD_TEST(test-privserver-client ${EXECUTABLE_OUTPUT_PATH}/test-privserver-client)
add_executable(test-autolaunch ${NAMEtest-DIR}/test-autolaunch.c)
target_link_libraries(test-autolaunch dbus-testutils)
ADD_TEST(test-autolaunch ${EXECUTABLE_OUTPUT_PATH}/test-autolaunch)
add_helper_executable(test-pending-call-dispatch ${NAMEtest-DIR}/test-pending-call-dispatch.c ${DBUS_INTERNAL_LIBRARIES})
add_helper_executable(test-pending-call-timeout ${NAMEtest-DIR}/test-pending-call-timeout.c ${DBUS_INTERNAL_LIBRARIES})
add_helper_executable(test-thread-init ${NAMEtest-DIR}/test-threads-init.c ${DBUS_INTERNAL_LIBRARIES})
add_helper_executable(test-ids ${NAMEtest-DIR}/test-ids.c ${DBUS_INTERNAL_LIBRARIES})
add_helper_executable(test-shutdown ${NAMEtest-DIR}/test-shutdown.c dbus-testutils)
add_helper_executable(test-privserver ${NAMEtest-DIR}/test-privserver.c dbus-testutils)
add_helper_executable(test-privserver-client ${NAMEtest-DIR}/test-privserver-client.c dbus-testutils)
add_helper_executable(test-autolaunch ${NAMEtest-DIR}/test-autolaunch.c dbus-testutils)
endif (DBUS_ENABLE_EMBEDDED_TESTS)
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