183 lines · plain
1set(ASAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})2 3set(ASAN_TESTSUITES)4set(ASAN_DYNAMIC_TESTSUITES)5 6# Before Windows 8 (CMAKE_SYSTEM_VERSION 6.2), reserving large regions of shadow7# memory allocated physical memory for page tables, which made it very8# unreliable. Remove the asan tests from check-all in this configuration.9set(SHADOW_MAPPING_UNRELIABLE FALSE)10if(OS_NAME MATCHES "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 8 AND11 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")14endif()15 16macro(get_bits_for_arch arch bits)17 if (${arch} MATCHES "x86_64|powerpc64|powerpc64le|aarch64|arm64|mips64|mips64el|s390x|sparcv9|riscv64|loongarch64")18 set(${bits} 64)19 elseif (${arch} MATCHES "i386|arm|mips|mipsel|sparc")20 set(${bits} 32)21 else()22 message(FATAL_ERROR "Unknown target architecture: ${arch}")23 endif()24endmacro()25 26set(ASAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})27list(APPEND ASAN_TEST_DEPS asan)28if(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)31 endif()32endif()33set(ASAN_DYNAMIC_TEST_DEPS ${ASAN_TEST_DEPS})34 35set(ASAN_TEST_ARCH ${ASAN_SUPPORTED_ARCH})36if(APPLE)37 darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH)38endif()39list(REMOVE_ITEM ASAN_TEST_ARCH sparcv9)40if(OS_NAME MATCHES "SunOS")41 list(REMOVE_ITEM ASAN_TEST_ARCH x86_64)42endif()43 44foreach(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)51 if(ANDROID OR APPLE)52 set(ASAN_TEST_DYNAMIC True)53 else()54 set(ASAN_TEST_DYNAMIC False)55 endif()56 string(TOUPPER ${arch} ARCH_UPPER_CASE)57 set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)58 if(NOT MINGW)59 # MinGW environments don't provide a statically linked CRT, so only the60 # dynamic asan test configuration can be expected to work.61 configure_lit_site_cfg(62 ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in63 ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py64 )65 list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})66 endif()67 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.in74 ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py)75 list(APPEND ASAN_DYNAMIC_TESTSUITES76 ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})77 endif()78 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")83 endif()84endforeach()85 86# iOS and iOS simulator test suites87# These are not added into "check-all", in order to run these tests, use88# "check-asan-iossim-x86_64" and similar. They also require that an extra env89# variable to select which iOS device or simulator to use, e.g.:90# SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER="iPhone 6"91if(APPLE)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})95 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.99 continue()100 endif()101 list_intersect(102 ASAN_TEST_${platform}_ARCHS103 ASAN_SUPPORTED_ARCH104 DARWIN_${platform}_ARCHS105 )106 foreach(arch ${ASAN_TEST_${platform}_ARCHS})107 get_test_cflags_for_apple_platform(108 "${platform}"109 "${arch}"110 ASAN_TEST_TARGET_CFLAGS111 )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.in122 ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py123 )124 add_lit_testsuite(check-asan-${platform}-${arch} "AddressSanitizer ${platform} ${arch} tests"125 ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/126 EXCLUDE_FROM_CHECK_ALL127 DEPENDS ${ASAN_TEST_DEPS})128 endforeach()129 endforeach()130endif()131 132# Add unit tests.133foreach(arch ${ASAN_TEST_ARCH})134 string(TOUPPER ${arch} ARCH_UPPER_CASE)135 set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)136 set(CONFIG_NAME_DYNAMIC ${ARCH_UPPER_CASE}${OS_NAME}DynamicConfig)137 138 if(NOT MINGW)139 # MinGW environments don't provide a statically linked CRT, so only the140 # dynamic asan test configuration can be expected to work.141 set(ASAN_TEST_DYNAMIC False)142 configure_lit_site_cfg(143 ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in144 ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME}/lit.site.cfg.py)145 endif()146 if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME)147 set(ASAN_TEST_DYNAMIC True)148 configure_lit_site_cfg(149 ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in150 ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME_DYNAMIC}/lit.site.cfg.py)151 endif()152 # FIXME: support unit test in the android test runner153 if (NOT ANDROID)154 if (NOT MINGW)155 list(APPEND ASAN_TEST_DEPS AsanUnitTests)156 list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME})157 endif()158 if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME)159 list(APPEND ASAN_DYNAMIC_TEST_DEPS AsanDynamicUnitTests)160 list(APPEND ASAN_DYNAMIC_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/${CONFIG_NAME_DYNAMIC})161 endif()162 endif()163endforeach()164 165if (SHADOW_MAPPING_UNRELIABLE)166 set(exclude_from_check_all.g "EXCLUDE_FROM_CHECK_ALL")167else()168 set(exclude_from_check_all.g "")169endif()170 171add_lit_testsuite(check-asan "Running the AddressSanitizer tests"172 ${ASAN_TESTSUITES}173 ${exclude_from_check_all}174 DEPENDS ${ASAN_TEST_DEPS})175 176if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME)177 add_lit_testsuite(check-asan-dynamic178 "Running the AddressSanitizer tests with dynamic runtime"179 ${ASAN_DYNAMIC_TESTSUITES}180 ${exclude_from_check_all.g}181 DEPENDS ${ASAN_DYNAMIC_TEST_DEPS})182endif()183