1 set(ASAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
4 set(ASAN_DYNAMIC_TESTSUITES)
6 # Before Windows 8 (CMAKE_SYSTEM_VERSION 6.2), reserving large regions of shadow
7 # memory allocated physical memory for page tables, which made it very
8 # unreliable. Remove the asan tests from check-all in this configuration.
9 set(SHADOW_MAPPING_UNRELIABLE FALSE)
10 if(OS_NAME MATCHES "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 8 AND
11 CMAKE_SYSTEM_VERSION LESS 6.2)
12 set(SHADOW_MAPPING_UNRELIABLE TRUE)
13 message(WARNING "Disabling ASan tests because they are unreliable on Windows 7 and earlier")
16 macro(get_bits_for_arch arch bits)
17 if (${arch} MATCHES "x86_64|powerpc64|powerpc64le|aarch64|arm64|mips64|mips64el|s390x|sparcv9|riscv64|loongarch64")
19 elseif (${arch} MATCHES "i386|arm|mips|mipsel|sparc")
22 message(FATAL_ERROR "Unknown target architecture: ${arch}")
26 set(ASAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
27 list(APPEND ASAN_TEST_DEPS asan)
28 if(NOT COMPILER_RT_STANDALONE_BUILD)
29 if(NOT APPLE AND COMPILER_RT_HAS_LLD AND "lld" IN_LIST LLVM_ENABLE_PROJECTS)
30 list(APPEND ASAN_TEST_DEPS lld)
33 set(ASAN_DYNAMIC_TEST_DEPS ${ASAN_TEST_DEPS})
35 set(ASAN_TEST_ARCH ${ASAN_SUPPORTED_ARCH})
37 darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH)
39 list(REMOVE_ITEM ASAN_TEST_ARCH sparc sparcv9)
40 if(OS_NAME MATCHES "SunOS")
41 list(REMOVE_ITEM ASAN_TEST_ARCH x86_64)
44 foreach(arch ${ASAN_TEST_ARCH})
45 set(ASAN_TEST_TARGET_ARCH ${arch})
46 set(ASAN_TEST_APPLE_PLATFORM "osx")
47 set(ASAN_TEST_MIN_DEPLOYMENT_TARGET_FLAG "${DARWIN_osx_MIN_VER_FLAG}")
48 string(TOLOWER "-${arch}-${OS_NAME}" ASAN_TEST_CONFIG_SUFFIX)
49 get_bits_for_arch(${arch} ASAN_TEST_BITS)
50 get_test_cc_for_arch(${arch} ASAN_TEST_TARGET_CC ASAN_TEST_TARGET_CFLAGS)
52 set(ASAN_TEST_DYNAMIC True)
54 set(ASAN_TEST_DYNAMIC False)
56 string(TOUPPER ${arch} ARCH_UPPER_CASE)
57 set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)
59 # MinGW environments don't provide a statically linked CRT, so only the
60 # dynamic asan test configuration can be expected to work.
61 configure_lit_site_cfg(
62 ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
63 ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py
65 list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
68 if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME)
69 string(TOLOWER "-${arch}-${OS_NAME}-dynamic" ASAN_TEST_CONFIG_SUFFIX)
70 set(ASAN_TEST_DYNAMIC True)
71 set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}DynamicConfig)
72 configure_lit_site_cfg(
73 ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
74 ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py)
75 list(APPEND ASAN_DYNAMIC_TESTSUITES
76 ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
79 # ARM on Linux may include thumb code, where fast unwinding does not work.
80 # Enable unwind tables so that we do not end up falling back to it in tests.
81 if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND NOT ANDROID AND ${arch} MATCHES "arm")
82 set(ASAN_TEST_TARGET_CFLAGS "${ASAN_TEST_TARGET_CFLAGS} -funwind-tables")
86 # iOS and iOS simulator test suites
87 # These are not added into "check-all", in order to run these tests, use
88 # "check-asan-iossim-x86_64" and similar. They also require that an extra env
89 # variable to select which iOS device or simulator to use, e.g.:
90 # SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER="iPhone 6"
92 set(ASAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER})
93 set(ASAN_TEST_DYNAMIC True)
94 set(ASAN_APPLE_PLATFORMS ${SANITIZER_COMMON_SUPPORTED_OS})
96 foreach(platform ${ASAN_APPLE_PLATFORMS})
97 if ("${platform}" STREQUAL "osx")
98 # Skip macOS because it's handled by the code above that builds tests for the host machine.
102 ASAN_TEST_${platform}_ARCHS
104 DARWIN_${platform}_ARCHS
106 foreach(arch ${ASAN_TEST_${platform}_ARCHS})
107 get_test_cflags_for_apple_platform(
110 ASAN_TEST_TARGET_CFLAGS
112 string(TOUPPER "${arch}" ARCH_UPPER_CASE)
113 get_capitalized_apple_platform("${platform}" PLATFORM_CAPITALIZED)
114 set(CONFIG_NAME "${PLATFORM_CAPITALIZED}${ARCH_UPPER_CASE}Config")
115 set(ASAN_TEST_CONFIG_SUFFIX "-${arch}-${platform}")
116 set(ASAN_TEST_APPLE_PLATFORM "${platform}")
117 set(ASAN_TEST_TARGET_ARCH "${arch}")
118 set(ASAN_TEST_MIN_DEPLOYMENT_TARGET_FLAG "${DARWIN_${platform}_MIN_VER_FLAG}")
119 get_bits_for_arch(${arch} ASAN_TEST_BITS)
120 configure_lit_site_cfg(
121 ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
122 ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py
124 add_lit_testsuite(check-asan-${platform}-${arch} "AddressSanitizer ${platform} ${arch} tests"
125 ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
126 EXCLUDE_FROM_CHECK_ALL
127 DEPENDS ${ASAN_TEST_DEPS})
133 if(COMPILER_RT_INCLUDE_TESTS)
134 foreach(arch ${ASAN_TEST_ARCH})
135 string(TOUPPER ${arch} ARCH_UPPER_CASE)
136 set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)
137 set(CONFIG_NAME_DYNAMIC ${ARCH_UPPER_CASE}${OS_NAME}DynamicConfig)
140 # MinGW environments don't provide a statically linked CRT, so only the
141 # dynamic asan test configuration can be expected to work.
142 set(ASAN_TEST_DYNAMIC False)
143 configure_lit_site_cfg(
144 ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
145 ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME}/lit.site.cfg.py)
147 if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME)
148 set(ASAN_TEST_DYNAMIC True)
149 configure_lit_site_cfg(
150 ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
151 ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME_DYNAMIC}/lit.site.cfg.py)
153 # FIXME: support unit test in the android test runner
156 list(APPEND ASAN_TEST_DEPS AsanUnitTests)
157 list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME})
159 if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME)
160 list(APPEND ASAN_DYNAMIC_TEST_DEPS AsanDynamicUnitTests)
161 list(APPEND ASAN_DYNAMIC_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME_DYNAMIC})
167 if (SHADOW_MAPPING_UNRELIABLE)
168 set(exclude_from_check_all.g "EXCLUDE_FROM_CHECK_ALL")
170 set(exclude_from_check_all.g "")
173 add_lit_testsuite(check-asan "Running the AddressSanitizer tests"
175 ${exclude_from_check_all}
176 DEPENDS ${ASAN_TEST_DEPS})
177 set_target_properties(check-asan PROPERTIES FOLDER "Compiler-RT Misc")
179 if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME)
180 add_lit_testsuite(check-asan-dynamic
181 "Running the AddressSanitizer tests with dynamic runtime"
182 ${ASAN_DYNAMIC_TESTSUITES}
183 ${exclude_from_check_all.g}
184 DEPENDS ${ASAN_DYNAMIC_TEST_DEPS})
185 set_target_properties(check-asan-dynamic
186 PROPERTIES FOLDER "Compiler-RT Misc")