1 set(SANITIZER_COMMON_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
3 set(SANITIZER_COMMON_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
5 set(SANITIZER_COMMON_TESTSUITES)
7 # FIXME(dliew): We should switch to COMPILER_RT_SANITIZERS_TO_BUILD instead of
8 # the hard coded `SUPPORTED_TOOLS_INIT` list once we know that the other
10 set(SUPPORTED_TOOLS_INIT asan lsan hwasan msan tsan ubsan)
12 foreach(SANITIZER_TOOL ${SUPPORTED_TOOLS_INIT})
13 string(TOUPPER ${SANITIZER_TOOL} SANITIZER_TOOL_UPPER)
14 if (COMPILER_RT_HAS_${SANITIZER_TOOL_UPPER})
15 list(APPEND SUPPORTED_TOOLS ${SANITIZER_TOOL})
19 # FIXME(dliew): Remove this.
20 # Temporary helper for https://reviews.llvm.org/D55740
23 "Generated Sanitizer SUPPORTED_TOOLS list on \"${CMAKE_SYSTEM_NAME}\" is"
24 " \"${SUPPORTED_TOOLS}\"")
26 # FIXME(dliew): These tests should be made to work on all platforms.
27 # Use the legacy list for now.
28 if (ANDROID OR WINDOWS)
29 set(OLD_SUPPORTED_TOOLS ${SUPPORTED_TOOLS})
31 set(SUPPORTED_TOOLS asan)
33 set(SUPPORTED_TOOLS "")
35 message(FATAL_ERROR "Unhandled platform")
39 "Replacing Sanitizer SUPPORTED_TOOLS list (${OLD_SUPPORTED_TOOLS}) with "
40 "\"${SUPPORTED_TOOLS}\"")
41 unset(OLD_SUPPORTED_TOOLS)
44 # FIXME(dliew): Remove this.
45 # Temporary helper for https://reviews.llvm.org/D55740
48 "sanitizer_common tests on \"${CMAKE_SYSTEM_NAME}\" will run against "
49 "\"${SUPPORTED_TOOLS}\"")
51 # Create a separate config for each tool we support.
52 foreach(tool ${SUPPORTED_TOOLS})
53 string(TOUPPER ${tool} tool_toupper)
54 if(${tool_toupper}_SUPPORTED_ARCH AND NOT COMPILER_RT_STANDALONE_BUILD)
55 list(APPEND SANITIZER_COMMON_TEST_DEPS ${tool})
57 set(TEST_ARCH ${${tool_toupper}_SUPPORTED_ARCH})
59 darwin_filter_host_archs(${tool_toupper}_SUPPORTED_ARCH TEST_ARCH)
61 if(${tool} STREQUAL "asan")
62 list(REMOVE_ITEM TEST_ARCH sparc sparcv9)
64 if(OS_NAME MATCHES "SunOS" AND ${tool} STREQUAL "asan")
65 list(REMOVE_ITEM TEST_ARCH x86_64)
68 # TODO(dliew): We should iterate over the different
69 # Apple platforms, not just macOS.
70 foreach(arch ${TEST_ARCH})
71 set(SANITIZER_COMMON_LIT_TEST_MODE ${tool})
72 set(SANITIZER_COMMON_TEST_TARGET_ARCH ${arch})
73 get_test_cc_for_arch(${arch} SANITIZER_COMMON_TEST_TARGET_CC SANITIZER_COMMON_TEST_TARGET_CFLAGS)
74 set(CONFIG_NAME ${tool}-${arch}-${OS_NAME})
76 # ARM on Linux might use the slow unwinder as default and the unwind table is
77 # required to get a complete stacktrace.
78 if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND NOT ANDROID)
79 list(APPEND SANITIZER_COMMON_TEST_TARGET_CFLAGS -funwind-tables)
81 list(APPEND SANITIZER_COMMON_TEST_TARGET_CFLAGS "--sysroot=${CMAKE_SYSROOT}")
83 string(REPLACE ";" " " SANITIZER_COMMON_TEST_TARGET_CFLAGS
84 "${SANITIZER_COMMON_TEST_TARGET_CFLAGS}")
87 configure_lit_site_cfg(
88 ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
89 ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py)
90 # FIXME(dliew): LSan i386 on Darwin is completely broken right now.
91 # so don't run the tests by default.
92 if (NOT (CMAKE_SYSTEM_NAME MATCHES "Darwin" AND
93 ${tool} STREQUAL "lsan" AND
94 ${arch} STREQUAL "i386"))
95 list(APPEND SANITIZER_COMMON_TESTSUITES
96 ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
102 if(COMPILER_RT_INCLUDE_TESTS)
103 configure_lit_site_cfg(
104 ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
105 ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg.py)
106 # FIXME: support unit test in the android test runner
108 list(APPEND SANITIZER_COMMON_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit)
109 list(APPEND SANITIZER_COMMON_TEST_DEPS SanitizerUnitTests)
113 if(SANITIZER_COMMON_TESTSUITES)
114 add_lit_testsuite(check-sanitizer "Running sanitizer_common tests"
115 ${SANITIZER_COMMON_TESTSUITES}
116 DEPENDS ${SANITIZER_COMMON_TEST_DEPS})
117 set_target_properties(check-sanitizer PROPERTIES FOLDER