1 set(ASAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) 2 3 set(ASAN_TESTSUITES) 4 set(ASAN_DYNAMIC_TESTSUITES) 5 6 macro(get_bits_for_arch arch bits) 7 if (${arch} MATCHES "i386|i686|arm|mips|mipsel") 8 set(${bits} 32) 9 elseif (${arch} MATCHES "x86_64|powerpc64|powerpc64le|aarch64|mips64|mips64el") 10 set(${bits} 64) 11 else() 12 message(FATAL_ERROR "Unknown target architecture: ${arch}") 13 endif() 14 endmacro() 15 16 foreach(arch ${ASAN_SUPPORTED_ARCH}) 17 if(ANDROID) 18 set(ASAN_TEST_TARGET_ARCH ${arch}-android) 19 else() 20 set(ASAN_TEST_TARGET_ARCH ${arch}) 21 endif() 22 string(TOLOWER "-${arch}-${OS_NAME}" ASAN_TEST_CONFIG_SUFFIX) 23 get_bits_for_arch(${arch} ASAN_TEST_BITS) 24 if(ANDROID OR ${arch} MATCHES "arm|aarch64") 25 # This is only true if we are cross-compiling. 26 # Build all tests with host compiler and use host tools. 27 set(ASAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER}) 28 set(ASAN_TEST_TARGET_CFLAGS ${COMPILER_RT_TEST_COMPILER_CFLAGS}) 29 else() 30 get_target_flags_for_arch(${arch} ASAN_TEST_TARGET_CFLAGS) 31 endif() 32 if(ANDROID) 33 set(ASAN_TEST_DYNAMIC True) 34 else() 35 set(ASAN_TEST_DYNAMIC False) 36 endif() 37 string(TOUPPER ${arch} ARCH_UPPER_CASE) 38 set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config) 39 configure_lit_site_cfg( 40 ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in 41 ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg 42 ) 43 list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}) 44 45 if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME) 46 string(TOLOWER "-${arch}-${OS_NAME}-dynamic" ASAN_TEST_CONFIG_SUFFIX) 47 set(ASAN_TEST_DYNAMIC True) 48 set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}DynamicConfig) 49 configure_lit_site_cfg( 50 ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in 51 ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg) 52 list(APPEND ASAN_DYNAMIC_TESTSUITES 53 ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}) 54 endif() 55 endforeach() 56 57 set(ASAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS}) 58 if(NOT COMPILER_RT_STANDALONE_BUILD) 59 list(APPEND ASAN_TEST_DEPS asan) 60 endif() 61 set(ASAN_DYNAMIC_TEST_DEPS ${ASAN_TEST_DEPS}) 62 63 # Add unit tests. 64 if(COMPILER_RT_INCLUDE_TESTS) 65 set(ASAN_TEST_DYNAMIC False) 66 configure_lit_site_cfg( 67 ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in 68 ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg) 69 if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME) 70 set(ASAN_TEST_DYNAMIC True) 71 configure_lit_site_cfg( 72 ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in 73 ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic/lit.site.cfg) 74 endif() 75 # FIXME: support unit test in the android test runner 76 if (NOT ANDROID) 77 list(APPEND ASAN_TEST_DEPS AsanUnitTests) 78 list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit) 79 if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME) 80 list(APPEND ASAN_DYNAMIC_TEST_DEPS AsanDynamicUnitTests) 81 list(APPEND ASAN_DYNAMIC_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic) 82 endif() 83 endif() 84 endif() 85 86 add_lit_testsuite(check-asan "Running the AddressSanitizer tests" 87 ${ASAN_TESTSUITES} 88 DEPENDS ${ASAN_TEST_DEPS}) 89 set_target_properties(check-asan PROPERTIES FOLDER "ASan tests") 90 91 if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME) 92 # Add check-dynamic-asan target. It is a part of check-all only on Windows, 93 # where we want to always test both dynamic and static runtime. 94 if(NOT OS_NAME MATCHES "Windows") 95 set(EXCLUDE_FROM_ALL TRUE) 96 endif() 97 add_lit_testsuite(check-asan-dynamic 98 "Running the AddressSanitizer tests with dynamic runtime" 99 ${ASAN_DYNAMIC_TESTSUITES} 100 DEPENDS ${ASAN_DYNAMIC_TEST_DEPS}) 101 set_target_properties(check-asan-dynamic 102 PROPERTIES FOLDER "ASan dynamic tests") 103 if(NOT OS_NAME MATCHES "Windows") 104 set(EXCLUDE_FROM_ALL FALSE) 105 endif() 106 endif() 107