[docs] Fix build-docs.sh
[llvm-project.git] / compiler-rt / test / tsan / CMakeLists.txt
blob25e95aa98cf9501109f41beb14f2343476ac9d69
1 set(TSAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
3 set(TSAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
4 if(${COMPILER_RT_DEFAULT_TARGET_ARCH} MATCHES "(x86_64|s390x)")
5   list(APPEND TSAN_TEST_DEPS GotsanRuntimeCheck)
6 endif()
7 if(NOT COMPILER_RT_STANDALONE_BUILD)
8   list(APPEND TSAN_TEST_DEPS tsan)
9 endif()
10 if(COMPILER_RT_LIBCXX_PATH AND
11    COMPILER_RT_LIBCXXABI_PATH AND
12    COMPILER_RT_TEST_COMPILER_ID STREQUAL "Clang"
13    AND NOT APPLE AND NOT ANDROID)
14   list(APPEND TSAN_TEST_DEPS libcxx_tsan)
15   set(TSAN_HAS_LIBCXX True)
16 else()
17   set(TSAN_HAS_LIBCXX False)
18 endif()
20 set(TSAN_DYNAMIC_TEST_DEPS ${TSAN_TEST_DEPS})
21 set(TSAN_TESTSUITES)
22 set(TSAN_DYNAMIC_TESTSUITES)
24 if (NOT DEFINED TSAN_TEST_DEFLAKE_THRESHOLD)
25   set(TSAN_TEST_DEFLAKE_THRESHOLD "10")
26 endif()
28 set(TSAN_TEST_ARCH ${TSAN_SUPPORTED_ARCH})
29 if(APPLE)
30   darwin_filter_host_archs(TSAN_SUPPORTED_ARCH TSAN_TEST_ARCH)
31 endif()
33 foreach(arch ${TSAN_TEST_ARCH})
34   set(TSAN_TEST_APPLE_PLATFORM "osx")
35   set(TSAN_TEST_MIN_DEPLOYMENT_TARGET_FLAG "${DARWIN_osx_MIN_VER_FLAG}")
37   set(TSAN_TEST_TARGET_ARCH ${arch})
38   string(TOLOWER "-${arch}" TSAN_TEST_CONFIG_SUFFIX)
39   get_test_cc_for_arch(${arch} TSAN_TEST_TARGET_CC TSAN_TEST_TARGET_CFLAGS)
41   string(REPLACE ";" " " LIBDISPATCH_CFLAGS_STRING " ${COMPILER_RT_TEST_LIBDISPATCH_CFLAGS}")
42   string(APPEND TSAN_TEST_TARGET_CFLAGS ${LIBDISPATCH_CFLAGS_STRING})
44   if (COMPILER_RT_HAS_MSSE4_2_FLAG)
45     string(APPEND TSAN_TEST_TARGET_CFLAGS " -msse4.2 ")
46   endif()
48   string(TOUPPER ${arch} ARCH_UPPER_CASE)
49   set(CONFIG_NAME ${ARCH_UPPER_CASE}Config)
51   configure_lit_site_cfg(
52     ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
53     ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py
54     MAIN_CONFIG
55     ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
56     )
57   list(APPEND TSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
59   if(COMPILER_RT_TSAN_HAS_STATIC_RUNTIME)
60     string(TOLOWER "-${arch}-${OS_NAME}-dynamic" TSAN_TEST_CONFIG_SUFFIX)
61     set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}DynamicConfig)
62     configure_lit_site_cfg(
63       ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
64       ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py
65       MAIN_CONFIG
66       ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
67       )
68     list(APPEND TSAN_DYNAMIC_TESTSUITES
69       ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
70   endif()
71 endforeach()
73 # iOS and iOS simulator test suites
74 # These are not added into "check-all", in order to run these tests, use
75 # "check-tsan-iossim-x86_64" and similar. They also require an extra environment
76 # variable to select which iOS device or simulator to use, e.g.:
77 # SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER="iPhone 6"
78 if(APPLE)
79   set(TSAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER})
80   set(TSAN_APPLE_PLATFORMS ${TSAN_SUPPORTED_OS})
81   foreach(platform ${TSAN_APPLE_PLATFORMS})
82     if ("${platform}" STREQUAL "osx")
83       # Skip macOS because it's handled by the code above that builds tests for the host machine.
84       continue()
85     endif()
86     list_intersect(
87       TSAN_TEST_${platform}_ARCHS
88       TSAN_SUPPORTED_ARCH
89       DARWIN_${platform}_ARCHS
90     )
91     foreach(arch ${TSAN_TEST_${platform}_ARCHS})
92       get_test_cflags_for_apple_platform(
93         "${platform}"
94         "${arch}"
95         TSAN_TEST_TARGET_CFLAGS
96         )
97       string(TOUPPER "${arch}" ARCH_UPPER_CASE)
98       get_capitalized_apple_platform("${platform}" PLATFORM_CAPITALIZED)
99       set(CONFIG_NAME "${PLATFORM_CAPITALIZED}${ARCH_UPPER_CASE}Config")
100       set(TSAN_TEST_CONFIG_SUFFIX "-${arch}-${platform}")
101       set(TSAN_TEST_APPLE_PLATFORM "${platform}")
102       set(TSAN_TEST_TARGET_ARCH "${arch}")
103       set(TSAN_TEST_MIN_DEPLOYMENT_TARGET_FLAG "${DARWIN_${platform}_MIN_VER_FLAG}")
104       configure_lit_site_cfg(
105         ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
106         ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py
107         )
108       add_lit_testsuite(check-tsan-${platform}-${arch} "ThreadSanitizer ${platform} ${arch} tests"
109         ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
110         EXCLUDE_FROM_CHECK_ALL
111         DEPENDS ${TSAN_TEST_DEPS})
112     endforeach()
113   endforeach()
114 endif()
116 if(COMPILER_RT_INCLUDE_TESTS)
117   configure_lit_site_cfg(
118     ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
119     ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg.py)
120   if(COMPILER_RT_TSAN_HAS_STATIC_RUNTIME)
121     configure_lit_site_cfg(
122       ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
123       ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic/lit.site.cfg.py)
124   endif()
125   list(APPEND TSAN_TEST_DEPS TsanUnitTests)
126   list(APPEND TSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit)
127   if(COMPILER_RT_TSAN_HAS_STATIC_RUNTIME)
128     list(APPEND TSAN_DYNAMIC_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic)
129   endif()
130 endif()
132 add_lit_testsuite(check-tsan "Running ThreadSanitizer tests"
133   ${TSAN_TESTSUITES}
134   DEPENDS ${TSAN_TEST_DEPS})
135 set_target_properties(check-tsan PROPERTIES FOLDER "Compiler-RT Tests")
137 if(COMPILER_RT_TSAN_HAS_STATIC_RUNTIME)
138   add_lit_testsuite(check-tsan-dynamic "Running the ThreadSanitizer tests with dynamic runtime"
139                     ${TSAN_DYNAMIC_TESTSUITES}
140                     EXCLUDE_FROM_CHECK_ALL
141                     DEPENDS ${TSAN_DYNAMIC_TEST_DEPS})
142   set_target_properties(check-tsan-dynamic PROPERTIES FOLDER "Compiler-RT Misc")
143 endif()