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_prerun_command(export ASAN_OPTIONS=malloc_context_size=0) + add_test_prerun_command(export LSAN_OPTIONS=suppressions=${SAN_SUPP_DIR}/lsan) + endif() + if("thread" IN_LIST ARGN) + add_test_prerun_command(export TSAN_OPTIONS=suppressions=${SAN_SUPP_DIR}/tsan) + endif() + if("undefined" IN_LIST ARGN) + add_test_prerun_command(export 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,19 @@ # Allow to easily build test suites +macro(add_test_prerun_command) + set_property(GLOBAL APPEND PROPERTY TEST_PRERUN_COMMANDS COMMAND ${ARGN}) +endmacro() + +function(add_test_custom_target TARGET) + get_property(TEST_PRERUN_COMMANDS GLOBAL PROPERTY TEST_PRERUN_COMMANDS) + + add_custom_target(${TARGET} + ${TEST_PRERUN_COMMANDS} + ${ARGN} + VERBATIM + ) +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,7 +51,7 @@ get_target_from_suite(${SUITE} SUITE_TARGET) set(TARGET "${SUITE_TARGET}-${NAME}") - add_custom_target(${TARGET} + add_test_custom_target(${TARGET} COMMAND "${CMAKE_SOURCE_DIR}/cmake/utils/test_wrapper.sh" "$" "${NAME}.log" ${ARGN} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -52,8 +52,9 @@ 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} + add_test_custom_target(${TARGET} COMMENT "${COMMENT}" COMMAND "${Python_EXECUTABLE}" @@ -97,7 +98,7 @@ add_dependencies(check-upgrade-activated-extended check-functional-upgrade-activated-extended) if(BUILD_BITCOIN_TX) - add_custom_target(check-bitcoin-util + add_test_custom_target(check-bitcoin-util COMMENT "Test Bitcoin utilities..." COMMAND "${Python_EXECUTABLE}"