From 92a575b5465f3873ab2151b7abf63b28381a0c2b Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Thu, 10 Oct 2013 23:42:57 +0200 Subject: [PATCH 3/8] Use macro add_test_executable to add test executables and add_service_executable for test helper executables. --- cmake/bus/CMakeLists.txt | 11 ++--- cmake/dbus/CMakeLists.txt | 5 +-- cmake/modules/Macros.cmake | 29 +++++++++++++ cmake/test/CMakeLists.txt | 79 ++++++++++------------------------- cmake/test/name-test/CMakeLists.txt | 40 ++++-------------- 5 Dateien geändert, 63 Zeilen hinzugefügt(+), 101 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..1bcad3c 100644 --- a/cmake/modules/Macros.cmake +++ b/cmake/modules/Macros.cmake @@ -10,3 +10,32 @@ 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}) + # require binfmt + set(_env "DBUS_TEST_DAEMON=${CMAKE_BINARY_DIR}/bin/dbus-daemon.exe") + list(APPEND _env "DBUS_SESSION_BUS_ADDRESS=") + list(APPEND _env "DBUS_BLOCK_ON_ABORT=1") + list(APPEND _env "DBUS_FATAL_WARNINGS=1") + if (CMAKE_CROSSCOMPILING) + set(PREFIX "z:") + set(EXT ".exe") + # run with wine + add_test(${_target} wine ${PREFIX}${EXECUTABLE_OUTPUT_PATH}/${_target}${EXT}) + else() + set(PREFIX) + set(EXT) + add_test(NAME ${_target} COMMAND $) + endif() + list(APPEND _env "DBUS_TEST_DAEMON=${CMAKE_BINARY_DIR}/bin/dbus-daemon${EXT}") + 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_service_executable _target _source) + add_executable(${_target} ${_source}) + target_link_libraries(${_target} ${ARGN}) +endmacro(add_service_executable) diff --git a/cmake/test/CMakeLists.txt b/cmake/test/CMakeLists.txt index 8a5cab4..343f445 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_service_executable(test-service ${test-service_SOURCES} dbus-testutils) +add_service_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_service_executable(test-shell-service ${test-shell-service_SOURCES} dbus-testutils) +add_service_executable(spawn-test ${spawn-test_SOURCES} ${DBUS_INTERNAL_LIBRARIES}) +add_service_executable(test-exit ${test-exit_SOURCES} ${DBUS_INTERNAL_LIBRARIES}) +add_service_executable(test-segfault ${test-segfault_SOURCES} ${DBUS_INTERNAL_LIBRARIES}) +add_service_executable(test-sleep-forever ${test-sleep-forever_SOURCES} ${DBUS_INTERNAL_LIBRARIES}) if(DBUS_WITH_GLIB) message(STATUS "with glib test apps") @@ -78,42 +62,23 @@ if(DBUS_WITH_GLIB) ${GLIB2_DEFINITIONS} ${GOBJECT_DEFINITIONS} ) include_directories( ${GLIB2_INCLUDE_DIR} ${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_service_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..3257aa4 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_service_executable(test-pending-call-dispatch ${NAMEtest-DIR}/test-pending-call-dispatch.c ${DBUS_INTERNAL_LIBRARIES}) +add_service_executable(test-pending-call-timeout ${NAMEtest-DIR}/test-pending-call-timeout.c ${DBUS_INTERNAL_LIBRARIES}) +add_service_executable(test-thread-init ${NAMEtest-DIR}/test-threads-init.c ${DBUS_INTERNAL_LIBRARIES}) +add_service_executable(test-ids ${NAMEtest-DIR}/test-ids.c ${DBUS_INTERNAL_LIBRARIES}) +add_service_executable(test-shutdown ${NAMEtest-DIR}/test-shutdown.c dbus-testutils) +add_service_executable(test-privserver ${NAMEtest-DIR}/test-privserver.c dbus-testutils) +add_service_executable(test-privserver-client ${NAMEtest-DIR}/test-privserver-client.c dbus-testutils) +add_service_executable(test-autolaunch ${NAMEtest-DIR}/test-autolaunch.c dbus-testutils) endif (DBUS_ENABLE_EMBEDDED_TESTS) -- 1.7.10.4