diff --git a/cmake/modules/Sanitizers.cmake b/cmake/modules/Sanitizers.cmake --- a/cmake/modules/Sanitizers.cmake +++ b/cmake/modules/Sanitizers.cmake @@ -36,4 +36,17 @@ add_compile_options(${_fsanitize_option}) add_link_options(${_fsanitize_option}) + + include(TestSuite) + set(SAN_SUPP_DIR "${CMAKE_SOURCE_DIR}/test/sanitizer_suppressions") + if("address" IN_LIST ARGN) + add_test_environment(ASAN_OPTIONS malloc_context_size=0) + add_test_environment(LSAN_OPTIONS "suppressions=${SAN_SUPP_DIR}/lsan") + endif() + if("thread" IN_LIST ARGN) + add_test_environment(TSAN_OPTIONS "suppressions=${SAN_SUPP_DIR}/tsan") + endif() + if("undefined" IN_LIST ARGN) + add_test_environment(UBSAN_OPTIONS "suppressions=${SAN_SUPP_DIR}/ubsan:print_stacktrace=1:halt_on_error=1") + endif() endfunction() diff --git a/cmake/modules/TestSuite.cmake b/cmake/modules/TestSuite.cmake --- a/cmake/modules/TestSuite.cmake +++ b/cmake/modules/TestSuite.cmake @@ -1,5 +1,20 @@ # Allow to easily build test suites +macro(add_test_environment VARIABLE VALUE) + set_property(GLOBAL APPEND PROPERTY TEST_ENVIRONMENT "${VARIABLE}=${VALUE}") +endmacro() + +function(add_test_custom_target TARGET) + cmake_parse_arguments(ARG "" "" "CUSTOM_TARGET_ARGS;TEST_COMMAND" ${ARGN}) + + get_property(TEST_ENVIRONMENT GLOBAL PROPERTY TEST_ENVIRONMENT) + + add_custom_target(${TARGET} + ${ARG_CUSTOM_TARGET_ARGS} + COMMAND ${CMAKE_COMMAND} -E env ${TEST_ENVIRONMENT} ${ARG_TEST_COMMAND} + ) +endfunction() + # Define a new target property to hold the list of tests associated with a test # suite. This property is named UNIT_TESTS to avoid confusion with the directory # level property TESTS. @@ -37,13 +52,14 @@ get_target_from_suite(${SUITE} SUITE_TARGET) set(TARGET "${SUITE_TARGET}-${NAME}") - add_custom_target(${TARGET} - COMMAND + add_test_custom_target(${TARGET} + TEST_COMMAND "${CMAKE_SOURCE_DIR}/cmake/utils/test_wrapper.sh" "$" "${NAME}.log" ${ARGN} - COMMENT "${SUITE}: testing ${NAME}" - DEPENDS ${EXECUTABLE} - VERBATIM + CUSTOM_TARGET_ARGS + COMMENT "${SUITE}: testing ${NAME}" + DEPENDS ${EXECUTABLE} + VERBATIM ) add_dependencies(${SUITE_TARGET} ${TARGET}) endfunction() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -52,19 +52,21 @@ make_link(util/rpcauth-test.py) make_link(fuzz/test_runner.py) +include(TestSuite) macro(add_functional_test_check TARGET COMMENT) - add_custom_target(${TARGET} - COMMENT "${COMMENT}" - COMMAND + add_test_custom_target(${TARGET} + TEST_COMMAND "${Python_EXECUTABLE}" ./functional/test_runner.py ${ARGN} - DEPENDS - bitcoind - bitcoin-cli - ${CMAKE_CURRENT_BINARY_DIR}/functional/test_runner.py - USES_TERMINAL - VERBATIM + CUSTOM_TARGET_ARGS + COMMENT "${COMMENT}" + DEPENDS + bitcoind + bitcoin-cli + ${CMAKE_CURRENT_BINARY_DIR}/functional/test_runner.py + USES_TERMINAL + VERBATIM ) endmacro() @@ -97,14 +99,15 @@ add_dependencies(check-upgrade-activated-extended check-functional-upgrade-activated-extended) if(BUILD_BITCOIN_TX) - add_custom_target(check-bitcoin-util - COMMENT "Test Bitcoin utilities..." - COMMAND + add_test_custom_target(check-bitcoin-util + TEST_COMMAND "${Python_EXECUTABLE}" ./util/bitcoin-util-test.py - DEPENDS - bitcoin-tx - ${CMAKE_CURRENT_BINARY_DIR}/util/bitcoin-util-test.py + CUSTOM_TARGET_ARGS + COMMENT "Test Bitcoin utilities..." + DEPENDS + bitcoin-tx + ${CMAKE_CURRENT_BINARY_DIR}/util/bitcoin-util-test.py ) add_dependencies(check check-bitcoin-util)