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