• 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 lld thinlto)
7  set(UBSAN_LIT_TEST_MODE "${test_mode}")
8  set(CONFIG_NAME ${UBSAN_LIT_TEST_MODE})
9  if (${lld})
10    set(CONFIG_NAME ${CONFIG_NAME}-lld)
11    if (TARGET lld)
12      list(APPEND UBSAN_TEST_DEPS lld)
13    endif()
14  endif()
15  if (${thinlto})
16    set(CONFIG_NAME ${CONFIG_NAME}-thinlto)
17    list(APPEND UBSAN_TEST_DEPS LTO)
18  endif()
19  set(UBSAN_TEST_USE_LLD ${lld})
20  set(UBSAN_TEST_USE_THINLTO ${thinlto})
21  set(CONFIG_NAME ${CONFIG_NAME}-${arch})
22  configure_lit_site_cfg(
23    ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
24    ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py)
25  list(APPEND UBSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
26  if(NOT COMPILER_RT_STANDALONE_BUILD)
27    list(APPEND UBSAN_TEST_DEPS ${sanitizer})
28  endif()
29endmacro()
30
31macro(add_ubsan_testsuites test_mode sanitizer arch)
32  add_ubsan_testsuite(${test_mode} ${sanitizer} ${arch} False False)
33
34  if(COMPILER_RT_HAS_LLD AND arch STREQUAL "x86_64" AND NOT (APPLE OR WIN32))
35    add_ubsan_testsuite(${test_mode} ${sanitizer} ${arch} True False)
36  endif()
37endmacro()
38
39set(UBSAN_TEST_ARCH ${UBSAN_SUPPORTED_ARCH})
40if(APPLE)
41  darwin_filter_host_archs(UBSAN_SUPPORTED_ARCH UBSAN_TEST_ARCH)
42endif()
43
44foreach(arch ${UBSAN_TEST_ARCH})
45  set(UBSAN_TEST_TARGET_ARCH ${arch})
46  if (APPLE)
47    set(UBSAN_TEST_APPLE_PLATFORM "osx")
48    set(UBSAN_TEST_MIN_DEPLOYMENT_TARGET_FLAG "${DARWIN_osx_MIN_VER_FLAG}")
49  endif()
50  get_test_cc_for_arch(${arch} UBSAN_TEST_TARGET_CC UBSAN_TEST_TARGET_CFLAGS)
51  add_ubsan_testsuites("Standalone" ubsan ${arch})
52
53  if(COMPILER_RT_HAS_ASAN AND ";${ASAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
54    # TODO(wwchrome): Re-enable ubsan for asan win 64-bit when ready.
55    # Disable ubsan with AddressSanitizer tests for Windows 64-bit,
56    # 64-bit Solaris/x86, and SPARC.
57    if((NOT (OS_NAME MATCHES "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 8)) AND
58       (NOT (OS_NAME MATCHES "SunOS" AND ${arch} MATCHES x86_64)) AND
59       (NOT ${arch} MATCHES sparc))
60      add_ubsan_testsuites("AddressSanitizer" asan ${arch})
61    endif()
62  endif()
63  if(COMPILER_RT_HAS_MSAN AND ";${MSAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
64    add_ubsan_testsuites("MemorySanitizer" msan ${arch})
65  endif()
66  if(COMPILER_RT_HAS_TSAN AND ";${TSAN_SUPPORTED_ARCH};" MATCHES ";${arch};" AND NOT ANDROID)
67    add_ubsan_testsuites("ThreadSanitizer" tsan ${arch})
68  endif()
69endforeach()
70
71macro(add_ubsan_device_testsuite test_mode sanitizer platform arch)
72  # Note we expect the caller to have already set UBSAN_TEST_TARGET_CFLAGS
73  set(UBSAN_LIT_TEST_MODE "${test_mode}")
74  set(CONFIG_NAME ${UBSAN_LIT_TEST_MODE}-${platform}-${arch})
75  set(UBSAN_TEST_TARGET_ARCH ${arch})
76  set(UBSAN_TEST_USE_LLD "False")
77  set(UBSAN_TEST_USE_THINLTO "False")
78  if (APPLE)
79    set(UBSAN_TEST_APPLE_PLATFORM "${platform}")
80    set(UBSAN_TEST_MIN_DEPLOYMENT_TARGET_FLAG "${DARWIN_${platform}_MIN_VER_FLAG}")
81  else()
82    unset(UBSAN_TEST_APPLE_PLATFORM)
83    unset(UBSAN_TEST_MIN_DEPLOYMENT_TARGET_FLAG)
84  endif()
85  configure_lit_site_cfg(
86    ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
87    ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py)
88  #list(APPEND UBSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
89  if(NOT COMPILER_RT_STANDALONE_BUILD)
90    list(APPEND UBSAN_TEST_DEPS ${sanitizer})
91  endif()
92  add_lit_testsuite(check-ubsan-${test_mode}-${platform}-${arch}
93    "UBSan ${CONFIG_NAME} tests"
94    ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
95    EXCLUDE_FROM_CHECK_ALL
96    DEPENDS ${UBSAN_TEST_DEPS})
97endmacro()
98
99if(APPLE)
100  foreach(arch ${UBSAN_TEST_ARCH})
101    set(UBSAN_TEST_TARGET_ARCH ${arch})
102    get_test_cc_for_arch(${arch} UBSAN_TEST_TARGET_CC UBSAN_TEST_TARGET_CFLAGS)
103    set(UBSAN_TEST_TARGET_CFLAGS "${UBSAN_TEST_TARGET_CFLAGS} -lc++abi")
104    add_ubsan_testsuites("StandaloneStatic" ubsan ${arch})
105  endforeach()
106
107  # Device and simulator test suites.
108  # These are not added into "check-all", in order to run these tests, use
109  # "check-asan-iossim-x86_64" and similar. They also require that an extra env
110  # variable to select which iOS device or simulator to use, e.g.:
111  # SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER="iPhone 6"
112  set(UBSAN_APPLE_PLATFORMS ${SANITIZER_COMMON_SUPPORTED_OS})
113  foreach(platform ${UBSAN_APPLE_PLATFORMS})
114    list_intersect(
115      UBSAN_TEST_${platform}_ARCHS
116      UBSAN_SUPPORTED_ARCH
117      DARWIN_${platform}_ARCHS
118      )
119    foreach(arch ${UBSAN_TEST_${platform}_ARCHS})
120      get_test_cflags_for_apple_platform(
121        "${platform}"
122        "${arch}"
123        UBSAN_TEST_TARGET_CFLAGS
124      )
125      add_ubsan_device_testsuite("Standalone" ubsan ${platform} ${arch})
126
127      if(COMPILER_RT_HAS_ASAN AND ";${ASAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
128        add_ubsan_device_testsuite("AddressSanitizer" asan ${platform} ${arch})
129      endif()
130
131      if(COMPILER_RT_HAS_TSAN AND ";${TSAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
132        add_ubsan_device_testsuite("ThreadSanitizer" tsan ${platform} ${arch})
133      endif()
134    endforeach()
135  endforeach()
136endif()
137
138add_lit_testsuite(check-ubsan "Running UndefinedBehaviorSanitizer tests"
139  ${UBSAN_TESTSUITES}
140  DEPENDS ${UBSAN_TEST_DEPS})
141set_target_properties(check-ubsan PROPERTIES FOLDER "Compiler-RT Misc")
142
143