From 885f8c15fe94cbfe39398c9badd25b484addc9a8 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Thu, 10 Oct 2013 23:42:57 +0200 Subject: [PATCH 1/2] 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 running dbus test applications. On native Windows and linux/UNIX systems the test applications are directly runable. When cross compiling for Windows on linux we are using wine to run test executables. Because wine is mandatory for running test, it's presence is verified on cmake run. The configuring process will be aborted if wine has not been found. Running wine executables directly would also be possible with the help of the binfmt_misc support of the linux kernel. We choosed to not support this at now, because it would limit cross compiling to linux os only. Also binfmt_misc support needs to be configured by root, which would add an additional dependency to dbus compiling. --- cmake/bus/CMakeLists.txt | 11 ++--- cmake/dbus/CMakeLists.txt | 5 +-- cmake/modules/Macros.cmake | 34 ++++++++++++++++ cmake/test/CMakeLists.txt | 77 ++++++++++------------------------- cmake/test/name-test/CMakeLists.txt | 40 ++++-------------- 5 Dateien geändert, 68 Zeilen hinzugefügt(+), 99 Zeilen entfernt(-) diff --git a/cmake/bus/CMakeLists.txt b/cmake/bus/CMakeLists.txt index 9943584..c344dc6 100644 --- a/cmake/bus/CMakeLists.txt +++ b/cmake/bus/CMakeLists.txt @@ -108,10 +108,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) @@ -148,11 +147,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 diff --git a/cmake/dbus/CMakeLists.txt b/cmake/dbus/CMakeLists.txt index 0205f85..ad57382 100644 --- a/cmake/dbus/CMakeLists.txt +++ b/cmake/dbus/CMakeLists.txt @@ -299,10 +299,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) diff --git a/cmake/modules/Macros.cmake b/cmake/modules/Macros.cmake index adb34b5..36f4940 100644 --- a/cmake/modules/Macros.cmake +++ b/cmake/modules/Macros.cmake @@ -1,3 +1,11 @@ +if (DBUS_BUILD_TESTS AND CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME STREQUAL "Windows") + find_file(WINE_EXECUTABLE wine) + if (NOT WINE_EXECUTABLE) + message(FATAL_ERROR "ERROR: Could not find wine executable to run tests") + else() + message(STATUS "Using ${WINE_EXECUTABLE} to run test applications") + endif() +endif() MACRO(TIMESTAMP RESULT) if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") @@ -10,3 +18,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 wine + set(PREFIX "z:") + set(_env "DBUS_TEST_DAEMON=${WINE_EXECUTABLE} ${PREFIX}${CMAKE_BINARY_DIR}/bin/dbus-daemon${EXEEXT}") + add_test(NAME ${_target} COMMAND ${WINE_EXECUTABLE} ${PREFIX}$) + else() + set(PREFIX) + set(_env "DBUS_TEST_DAEMON=${CMAKE_BINARY_DIR}/bin/dbus-daemon${EXEEXT}") + add_test(NAME ${_target} COMMAND $) + 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) diff --git a/cmake/test/CMakeLists.txt b/cmake/test/CMakeLists.txt index c726596..c083f75 100644 --- a/cmake/test/CMakeLists.txt +++ b/cmake/test/CMakeLists.txt @@ -46,31 +46,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") @@ -83,37 +67,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 diff --git a/cmake/test/name-test/CMakeLists.txt b/cmake/test/name-test/CMakeLists.txt index bf096ba..befb28f 100644 --- a/cmake/test/name-test/CMakeLists.txt +++ b/cmake/test/name-test/CMakeLists.txt @@ -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) -- 1.7.10.4