Run ThreadSanitizer tests without ASLR
Co-authored-by: Andrew Kesterson <andrew@aklabs.net>
This commit is contained in:
@@ -107,6 +107,19 @@ if(AKERR_SANITIZE AND NOT CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
|
|||||||
"AKERR_SANITIZE requires GCC or Clang, not ${CMAKE_C_COMPILER_ID}")
|
"AKERR_SANITIZE requires GCC or Clang, not ${CMAKE_C_COMPILER_ID}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(AKERR_SANITIZE STREQUAL "thread" AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||||
|
# ThreadSanitizer reserves a fixed, very large virtual-address range. Linux
|
||||||
|
# ASLR can put a loader mapping inside it before the runtime starts, which
|
||||||
|
# makes every test fail with "unexpected memory mapping" before main().
|
||||||
|
# Run the instrumented tests under the normal util-linux ASLR wrapper.
|
||||||
|
find_program(AKERR_SETARCH_EXECUTABLE setarch)
|
||||||
|
if(NOT AKERR_SETARCH_EXECUTABLE)
|
||||||
|
message(FATAL_ERROR
|
||||||
|
"AKERR_SANITIZE=thread on Linux requires setarch (util-linux) to "
|
||||||
|
"start tests with ASLR disabled.")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
function(akerr_instrument_for_sanitizers _target)
|
function(akerr_instrument_for_sanitizers _target)
|
||||||
if(AKERR_SANITIZE)
|
if(AKERR_SANITIZE)
|
||||||
target_compile_options(${_target} PRIVATE
|
target_compile_options(${_target} PRIVATE
|
||||||
@@ -252,7 +265,13 @@ foreach(_test IN LISTS AKERR_TESTS)
|
|||||||
target_link_libraries(test_${_test} PRIVATE Threads::Threads)
|
target_link_libraries(test_${_test} PRIVATE Threads::Threads)
|
||||||
endif()
|
endif()
|
||||||
akerr_instrument_for_sanitizers(test_${_test})
|
akerr_instrument_for_sanitizers(test_${_test})
|
||||||
add_test(NAME ${_test} COMMAND test_${_test})
|
if(AKERR_SANITIZE STREQUAL "thread" AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||||
|
add_test(NAME ${_test}
|
||||||
|
COMMAND ${AKERR_SETARCH_EXECUTABLE} ${CMAKE_SYSTEM_PROCESSOR}
|
||||||
|
-R $<TARGET_FILE:test_${_test}>)
|
||||||
|
else()
|
||||||
|
add_test(NAME ${_test} COMMAND test_${_test})
|
||||||
|
endif()
|
||||||
# A sanitizer report is a test failure. Without halt_on_error the runtime
|
# A sanitizer report is a test failure. Without halt_on_error the runtime
|
||||||
# prints and continues, which leaves a race to be noticed in the log by
|
# prints and continues, which leaves a race to be noticed in the log by
|
||||||
# somebody reading it -- and under a race storm the reporting itself is slow
|
# somebody reading it -- and under a race storm the reporting itself is slow
|
||||||
|
|||||||
Reference in New Issue
Block a user