From 1727ebcf8f21ab0245008ad8cae338d32e9198d5 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Thu, 11 Feb 2016 03:30:34 +0100 Subject: [PATCH 2/2] Add cmake support for running testcases in test/name-test on linux. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=93976 Signed-off-by: Ralf Habacker --- cmake/CMakeLists.txt | 5 +-- cmake/bus/CMakeLists.txt | 3 ++ cmake/modules/Macros.cmake | 72 +++++++++++++++++++++++++++++-------- cmake/test/name-test/CMakeLists.txt | 38 ++++++++++++++++---- 4 files changed, 95 insertions(+), 23 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index fef731c..7f86cdd 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -13,7 +13,8 @@ if(COMMAND cmake_policy) endif(COMMAND cmake_policy) if(CMAKE_MAJOR_VERSION GREATER 2) - cmake_policy(SET CMP0026 NEW) + # support LOCATION property of get_target_property + cmake_policy(SET CMP0026 OLD) if (CMAKE_MAJOR_VERSION GREATER 4 OR CMAKE_MINOR_VERSION GREATER 1) cmake_policy(SET CMP0053 NEW) cmake_policy(SET CMP0054 NEW) @@ -517,13 +518,13 @@ add_definitions(-DHAVE_CONFIG_H=1) add_subdirectory( dbus ) add_subdirectory( bus ) +add_subdirectory( tools ) if (DBUS_BUILD_TESTS) add_subdirectory( test ) add_custom_target(check COMMAND ctest -R ^test-.* ) endif (DBUS_BUILD_TESTS) -add_subdirectory( tools ) add_subdirectory( doc ) diff --git a/cmake/bus/CMakeLists.txt b/cmake/bus/CMakeLists.txt index 0dcae65..3a2ebea 100644 --- a/cmake/bus/CMakeLists.txt +++ b/cmake/bus/CMakeLists.txt @@ -94,6 +94,9 @@ target_link_libraries(dbus-daemon ${DBUS_INTERNAL_LIBRARIES} ${XML_LIBRARY}) set_target_properties(dbus-daemon PROPERTIES OUTPUT_NAME ${DBUS_DAEMON_NAME}) set_target_properties(dbus-daemon PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS}) +get_target_property(DBUS_TEST_DAEMON dbus-daemon LOCATION) +set(DBUS_TEST_DAEMON ${DBUS_TEST_DAEMON} PARENT_SCOPE) + install_targets(/bin dbus-daemon) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/session.conf DESTINATION share/dbus-1) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/legacy-config/session.conf DESTINATION etc/dbus-1) diff --git a/cmake/modules/Macros.cmake b/cmake/modules/Macros.cmake index 24e7762..e53f9af 100644 --- a/cmake/modules/Macros.cmake +++ b/cmake/modules/Macros.cmake @@ -1,5 +1,8 @@ +set(PATH_PREFIX) + if(DBUS_BUILD_TESTS AND CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME STREQUAL "Windows") if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") + set(PATH_PREFIX "z:") find_file(WINE_EXECUTABLE NAMES wine PATHS /usr/bin /usr/local/bin @@ -42,32 +45,73 @@ MACRO(TIMESTAMP RESULT) endif () ENDMACRO() -macro(add_test_executable _target _source) +macro(_add_test_executable _target _source _wrapper _args) 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}") - if(HAVE_BINFMT_WINE_SUPPORT) - add_test(NAME ${_target} COMMAND $ --tap) - else() - add_test(NAME ${_target} COMMAND ${WINE_EXECUTABLE} ${PREFIX}$ --tap) + if(NOT HAVE_BINFMT_WINE_SUPPORT) + set(DBUS_TEST_DAEMON_WRAPPER ${WINE_EXECUTABLE}) + set(_args "${_wrapper} ${_args}") + set(_wrapper ${DBUS_TEST_DAEMON_WRAPPER}) + list(APPEND _env "DBUS_TEST_DAEMON_WRAPPER=${DBUS_TEST_DAEMON_WRAPPER}") endif() + endif() + if(_wrapper) + add_test(NAME ${_target} COMMAND ${_wrapper} ${_args} $ --tap) else() - set(PREFIX) - set(_env "DBUS_TEST_DAEMON=${CMAKE_BINARY_DIR}/bin/dbus-daemon${EXEEXT}") add_test(NAME ${_target} COMMAND $ --tap) endif() + + list(APPEND _env "DBUS_TEST_DAEMON=${DBUS_TEST_DAEMON}") list(APPEND _env "DBUS_SESSION_BUS_ADDRESS=") - list(APPEND _env "DBUS_FATAL_WARNINGS=1") - list(APPEND _env "DBUS_TEST_DATA=${PREFIX}${CMAKE_BINARY_DIR}/test/data") - list(APPEND _env "DBUS_TEST_DBUS_LAUNCH=${PREFIX}${CMAKE_BINARY_DIR}/bin/dbus-launch${EXEEXT}") - list(APPEND _env "DBUS_TEST_HOMEDIR=${PREFIX}${CMAKE_BINARY_DIR}/dbus") + list(APPEND _env "DBUS_FATAL_WARNINGS=0") + list(APPEND _env "DBUS_TEST_DATA=${PATH_PREFIX}${CMAKE_BINARY_DIR}/test/data") + list(APPEND _env "DBUS_TEST_DBUS_LAUNCH=${PATH_PREFIX}${CMAKE_BINARY_DIR}/bin/dbus-launch${EXEEXT}") + list(APPEND _env "DBUS_TEST_HOMEDIR=${PATH_PREFIX}${CMAKE_BINARY_DIR}/dbus") + list(APPEND _env "DBUS_TEST_EXEC=${PATH_PREFIX}${CMAKE_BINARY_DIR}/bin") set_tests_properties(${_target} PROPERTIES ENVIRONMENT "${_env}") +endmacro(_add_test_executable) + +# +# add_test_executable +# _target cmake target +# _source source files to build targets +# optional libraries +# +macro(add_test_executable _target _source) + _add_test_executable(${_target} "${_source}" "" "" ${ARGN}) endmacro(add_test_executable) +macro(add_session_test_executable _target _source) +if(NOT WIN32) + set(_wrapper ${DBUS_RUN_SESSION}) + set(_args) + list(APPEND _args "--dbus-daemon=${DBUS_TEST_DAEMON}") + list(APPEND _args "--config-file=${PATH_PREFIX}${add_session_test_executable_session_conf}") + _add_test_executable(${_target} ${_source} "${_wrapper}" "${_args}" ${ARGN}) +else() + add_helper_executable(${_target} ${_source}) +endif() +endmacro(add_session_test_executable) + macro(add_helper_executable _target _source) add_executable(${_target} ${_source}) target_link_libraries(${_target} ${ARGN}) endmacro(add_helper_executable) + +# +# read in file 'in, replace a line containing 'search' +# with 'replace' and save the output into file 'out' +# +macro(file_replace_line in out search replace) + file(STRINGS ${in} var) + set(content) + foreach(line ${var}) + if(line MATCHES ".*${search}.*") + set(content "${content}\n ${replace}") + else() + set(content "${content}\n${line}") + endif() + endforeach() + file(WRITE ${out} ${content}) +endmacro() diff --git a/cmake/test/name-test/CMakeLists.txt b/cmake/test/name-test/CMakeLists.txt index befb28f..1e6d88b 100644 --- a/cmake/test/name-test/CMakeLists.txt +++ b/cmake/test/name-test/CMakeLists.txt @@ -1,15 +1,39 @@ if (DBUS_ENABLE_EMBEDDED_TESTS) +set(TMP_SESSION_CONF_IN ${CMAKE_SOURCE_DIR}/../test/name-test/tmp-session-like-system.conf) +set(TMP_SESSION_CONF ${CMAKE_BINARY_DIR}/test/name-test/tmp-session-like-system.conf) +set(SERVICE_DIR ${CMAKE_BINARY_DIR}/test/data/valid-service-files) + +# create temporary session conf file +file_replace_line( + ${TMP_SESSION_CONF_IN} ${TMP_SESSION_CONF}.tmp + "${SERVICE_DIR}" +) +file_replace_line( + ${TMP_SESSION_CONF}.tmp ${TMP_SESSION_CONF} + "