Home | History | Annotate | Download | only in asan
      1 set(ASAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
      2 
      3 set(ASAN_TESTSUITES)
      4 set(ASAN_DYNAMIC_TESTSUITES)
      5 
      6 # TODO(wwchrome): Re-enable Win64 asan tests when ready.
      7 # Disable tests for asan Win64 temporarily.
      8 if(OS_NAME MATCHES "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 8)
      9   set(EXCLUDE_FROM_ALL TRUE)
     10 endif()
     11 
     12 macro(get_bits_for_arch arch bits)
     13   if (${arch} MATCHES "i386|i686|arm|mips|mipsel")
     14     set(${bits} 32)
     15   elseif (${arch} MATCHES "x86_64|powerpc64|powerpc64le|aarch64|mips64|mips64el|s390x")
     16     set(${bits} 64)
     17   else()
     18     message(FATAL_ERROR "Unknown target architecture: ${arch}")
     19   endif()
     20 endmacro()
     21 
     22 set(ASAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
     23 if(NOT COMPILER_RT_STANDALONE_BUILD)
     24   list(APPEND ASAN_TEST_DEPS asan)
     25   if(WIN32 AND COMPILER_RT_HAS_LLD_SOURCES)
     26     list(APPEND ASAN_TEST_DEPS
     27       lld
     28     )
     29   endif()
     30 endif()
     31 set(ASAN_DYNAMIC_TEST_DEPS ${ASAN_TEST_DEPS})
     32 
     33 set(ASAN_TEST_ARCH ${ASAN_SUPPORTED_ARCH})
     34 if(APPLE)
     35   darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH)
     36 endif()
     37 
     38 foreach(arch ${ASAN_TEST_ARCH})
     39   if(ANDROID)
     40     set(ASAN_TEST_TARGET_ARCH ${arch}-android)
     41   else()
     42     set(ASAN_TEST_TARGET_ARCH ${arch})
     43   endif()
     44   string(TOLOWER "-${arch}-${OS_NAME}" ASAN_TEST_CONFIG_SUFFIX)
     45   get_bits_for_arch(${arch} ASAN_TEST_BITS)
     46   if(ANDROID OR ${arch} MATCHES "arm|aarch64")
     47     # This is only true if we are cross-compiling.
     48     # Build all tests with host compiler and use host tools.
     49     set(ASAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER})
     50     set(ASAN_TEST_TARGET_CFLAGS ${COMPILER_RT_TEST_COMPILER_CFLAGS})
     51   else()
     52     get_target_flags_for_arch(${arch} ASAN_TEST_TARGET_CFLAGS)
     53     string(REPLACE ";" " " ASAN_TEST_TARGET_CFLAGS "${ASAN_TEST_TARGET_CFLAGS}")
     54   endif()
     55   if(ANDROID)
     56     set(ASAN_TEST_DYNAMIC True)
     57   else()
     58     set(ASAN_TEST_DYNAMIC False)
     59   endif()
     60   string(TOUPPER ${arch} ARCH_UPPER_CASE)
     61   set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)
     62   configure_lit_site_cfg(
     63     ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
     64     ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg
     65     )
     66   list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
     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.in
     74       ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg)
     75     list(APPEND ASAN_DYNAMIC_TESTSUITES
     76       ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
     77   endif()
     78 endforeach()
     79 
     80 # Add unit tests.
     81 if(COMPILER_RT_INCLUDE_TESTS)
     82   set(ASAN_TEST_DYNAMIC False)
     83   configure_lit_site_cfg(
     84     ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in
     85     ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg)
     86   if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME)
     87     set(ASAN_TEST_DYNAMIC True)
     88     configure_lit_site_cfg(
     89       ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in
     90       ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic/lit.site.cfg)
     91   endif()
     92   # FIXME: support unit test in the android test runner
     93   if (NOT ANDROID)
     94     list(APPEND ASAN_TEST_DEPS AsanUnitTests)
     95     list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit)
     96     if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME)
     97       list(APPEND ASAN_DYNAMIC_TEST_DEPS AsanDynamicUnitTests)
     98       list(APPEND ASAN_DYNAMIC_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic)
     99     endif()
    100   endif()
    101 endif()
    102 
    103 set(LIT_ARGS)
    104 if(ANDROID)
    105   set(LIT_ARGS -j5)
    106 endif()
    107 
    108 add_lit_testsuite(check-asan "Running the AddressSanitizer tests"
    109   ${ASAN_TESTSUITES}
    110   DEPENDS ${ASAN_TEST_DEPS}
    111   ARGS ${LIT_ARGS})
    112 set_target_properties(check-asan PROPERTIES FOLDER "Compiler-RT Misc")
    113 
    114 if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME)
    115   # Add check-dynamic-asan target. It is a part of check-all only on Windows,
    116   # where we want to always test both dynamic and static runtime.
    117 
    118   if(NOT OS_NAME MATCHES "Windows")
    119     set(EXCLUDE_FROM_ALL TRUE)
    120   endif()
    121   add_lit_testsuite(check-asan-dynamic
    122                     "Running the AddressSanitizer tests with dynamic runtime"
    123                     ${ASAN_DYNAMIC_TESTSUITES}
    124                     DEPENDS ${ASAN_DYNAMIC_TEST_DEPS})
    125   set_target_properties(check-asan-dynamic
    126                         PROPERTIES FOLDER "Compiler-RT Misc")
    127   if(NOT OS_NAME MATCHES "Windows")
    128     set(EXCLUDE_FROM_ALL FALSE)
    129   endif()
    130 endif()
    131 
    132 # TODO(wwchrome): Re-enable the tests for asan Win64 when ready.
    133 if(OS_NAME MATCHES "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 8)
    134   set(EXCLUDE_FROM_ALL FALSE)
    135 endif()
    136