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