• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1set(UBSAN_LIT_TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
2
3set(UBSAN_TESTSUITES)
4set(UBSAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
5
6macro(add_ubsan_testsuite test_mode sanitizer arch)
7  set(UBSAN_LIT_TEST_MODE "${test_mode}")
8  set(CONFIG_NAME ${UBSAN_LIT_TEST_MODE}-${arch})
9  configure_lit_site_cfg(
10    ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
11    ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg)
12  list(APPEND UBSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
13  if(NOT COMPILER_RT_STANDALONE_BUILD)
14    list(APPEND UBSAN_TEST_DEPS ${sanitizer})
15  endif()
16endmacro()
17
18set(UBSAN_TEST_ARCH ${UBSAN_SUPPORTED_ARCH})
19if(APPLE)
20  darwin_filter_host_archs(UBSAN_SUPPORTED_ARCH UBSAN_TEST_ARCH)
21endif()
22
23foreach(arch ${UBSAN_TEST_ARCH})
24  set(UBSAN_TEST_TARGET_ARCH ${arch})
25  if(${arch} MATCHES "arm|aarch64")
26    # This is only true if we're cross-compiling.
27    set(UBSAN_TEST_TARGET_CFLAGS ${COMPILER_RT_TEST_COMPILER_CFLAGS})
28  else()
29    get_target_flags_for_arch(${arch} UBSAN_TEST_TARGET_CFLAGS)
30    string(REPLACE ";" " " UBSAN_TEST_TARGET_CFLAGS "${UBSAN_TEST_TARGET_CFLAGS}")
31  endif()
32  add_ubsan_testsuite("Standalone" ubsan ${arch})
33
34  if(COMPILER_RT_HAS_ASAN AND ";${ASAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
35    add_ubsan_testsuite("AddressSanitizer" asan ${arch})
36  endif()
37  if(COMPILER_RT_HAS_MSAN AND ";${MSAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
38    add_ubsan_testsuite("MemorySanitizer" msan ${arch})
39  endif()
40  if(COMPILER_RT_HAS_TSAN AND ";${TSAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
41    add_ubsan_testsuite("ThreadSanitizer" tsan ${arch})
42  endif()
43endforeach()
44
45add_lit_testsuite(check-ubsan "Running UndefinedBehaviorSanitizer tests"
46  ${UBSAN_TESTSUITES}
47  DEPENDS ${UBSAN_TEST_DEPS})
48set_target_properties(check-ubsan PROPERTIES FOLDER "UBSan tests")
49