diff options
Diffstat (limited to 'lib/tsan/tests/CMakeLists.txt')
-rw-r--r-- | lib/tsan/tests/CMakeLists.txt | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/lib/tsan/tests/CMakeLists.txt b/lib/tsan/tests/CMakeLists.txt index 1c3f98f3f0bc..51181bab3a79 100644 --- a/lib/tsan/tests/CMakeLists.txt +++ b/lib/tsan/tests/CMakeLists.txt @@ -33,9 +33,12 @@ macro(tsan_compile obj_list source arch) endmacro() macro(add_tsan_unittest testname) - # Build unit tests only for 64-bit Linux. - if(UNIX AND NOT APPLE) - foreach(arch ${TSAN_SUPPORTED_ARCH}) + set(TSAN_TEST_ARCH ${TSAN_SUPPORTED_ARCH}) + if(APPLE) + darwin_filter_host_archs(TSAN_SUPPORTED_ARCH TSAN_TEST_ARCH) + endif() + if(UNIX) + foreach(arch ${TSAN_TEST_ARCH}) cmake_parse_arguments(TEST "" "" "SOURCES;HEADERS" ${ARGN}) set(TEST_OBJECTS) foreach(SOURCE ${TEST_SOURCES} ${COMPILER_RT_GTEST_SOURCE}) @@ -46,15 +49,38 @@ macro(add_tsan_unittest testname) if(NOT COMPILER_RT_STANDALONE_BUILD) list(APPEND TEST_DEPS tsan) endif() - # FIXME: Looks like we should link TSan with just-built runtime, - # and not rely on -fsanitize=thread, as these tests are essentially - # unit tests. - add_compiler_rt_test(TsanUnitTests ${testname} - OBJECTS ${TEST_OBJECTS} - DEPS ${TEST_DEPS} - LINK_FLAGS ${TARGET_LINK_FLAGS} - -fsanitize=thread - -lstdc++ -lm) + if(NOT APPLE) + # FIXME: Looks like we should link TSan with just-built runtime, + # and not rely on -fsanitize=thread, as these tests are essentially + # unit tests. + add_compiler_rt_test(TsanUnitTests ${testname} + OBJECTS ${TEST_OBJECTS} + DEPS ${TEST_DEPS} + LINK_FLAGS ${TARGET_LINK_FLAGS} + -fsanitize=thread + -lstdc++ -lm) + else() + set(TSAN_TEST_RUNTIME_OBJECTS + $<TARGET_OBJECTS:RTTsan_dynamic.osx> + $<TARGET_OBJECTS:RTInterception.osx> + $<TARGET_OBJECTS:RTSanitizerCommon.osx> + $<TARGET_OBJECTS:RTSanitizerCommonLibc.osx> + $<TARGET_OBJECTS:RTUbsan.osx>) + set(TSAN_TEST_RUNTIME RTTsanTest.${testname}.${arch}) + add_library(${TSAN_TEST_RUNTIME} STATIC ${TSAN_TEST_RUNTIME_OBJECTS}) + set_target_properties(${TSAN_TEST_RUNTIME} PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + list(APPEND TEST_OBJECTS lib${TSAN_TEST_RUNTIME}.a) + list(APPEND TEST_DEPS ${TSAN_TEST_RUNTIME}) + # Intentionally do *not* link with `-fsanitize=thread`. We already link + # against a static version of the runtime, and we don't want the dynamic + # one. + add_compiler_rt_test(TsanUnitTests "${testname}-${arch}-Test" + OBJECTS ${TEST_OBJECTS} + DEPS ${TEST_DEPS} + LINK_FLAGS ${TARGET_LINK_FLAGS} + -lc++) + endif() endforeach() endif() endmacro() |