1set(SANITIZER_COMMON_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) 2 3set(SANITIZER_COMMON_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS}) 4 5if(CMAKE_HOST_UNIX) 6 list(APPEND SANITIZER_COMMON_TEST_DEPS SanitizerLintCheck) 7endif() 8 9set(SANITIZER_COMMON_TESTSUITES) 10 11# FIXME(dliew): We should switch to COMPILER_RT_SANITIZERS_TO_BUILD instead of 12# the hard coded `SUPPORTED_TOOLS_INIT` list once we know that the other 13# sanitizers work. 14set(SUPPORTED_TOOLS_INIT asan lsan msan tsan ubsan) 15set(SUPPORTED_TOOLS) 16 foreach(SANITIZER_TOOL ${SUPPORTED_TOOLS_INIT}) 17 string(TOUPPER ${SANITIZER_TOOL} SANITIZER_TOOL_UPPER) 18 if (COMPILER_RT_HAS_${SANITIZER_TOOL_UPPER}) 19 list(APPEND SUPPORTED_TOOLS ${SANITIZER_TOOL}) 20 endif() 21 endforeach() 22 23# FIXME(dliew): Remove this. 24# Temporary helper for https://reviews.llvm.org/D55740 25message( 26 STATUS 27 "Generated Sanitizer SUPPORTED_TOOLS list on \"${CMAKE_SYSTEM_NAME}\" is" 28 " \"${SUPPORTED_TOOLS}\"") 29 30# FIXME(dliew): These tests should be made to work on all platforms. 31# Use the legacy list for now. 32if (ANDROID OR WINDOWS) 33 set(OLD_SUPPORTED_TOOLS ${SUPPORTED_TOOLS}) 34 if (ANDROID) 35 set(SUPPORTED_TOOLS asan) 36 elseif (WINDOWS) 37 set(SUPPORTED_TOOLS "") 38 else() 39 message(FATAL_ERROR "Unhandled platform") 40 endif() 41 message( 42 AUTHOR_WARNING 43 "Replacing Sanitizer SUPPORTED_TOOLS list (${OLD_SUPPORTED_TOOLS}) with " 44 "\"${SUPPORTED_TOOLS}\"") 45 unset(OLD_SUPPORTED_TOOLS) 46endif() 47 48# FIXME(dliew): Remove this. 49# Temporary helper for https://reviews.llvm.org/D55740 50message( 51 STATUS 52 "sanitizer_common tests on \"${CMAKE_SYSTEM_NAME}\" will run against " 53 "\"${SUPPORTED_TOOLS}\"") 54 55# Create a separate config for each tool we support. 56foreach(tool ${SUPPORTED_TOOLS}) 57 string(TOUPPER ${tool} tool_toupper) 58 if(${tool_toupper}_SUPPORTED_ARCH AND NOT COMPILER_RT_STANDALONE_BUILD) 59 list(APPEND SANITIZER_COMMON_TEST_DEPS ${tool}) 60 endif() 61 set(TEST_ARCH ${${tool_toupper}_SUPPORTED_ARCH}) 62 if(APPLE) 63 darwin_filter_host_archs(${tool_toupper}_SUPPORTED_ARCH TEST_ARCH) 64 endif() 65 if(${tool} STREQUAL "asan") 66 list(REMOVE_ITEM TEST_ARCH sparc sparcv9) 67 endif() 68 if(OS_NAME MATCHES "SunOS" AND ${tool} STREQUAL "asan") 69 list(REMOVE_ITEM TEST_ARCH x86_64) 70 endif() 71 72 # TODO(dliew): We should iterate over the different 73 # Apple platforms, not just macOS. 74 foreach(arch ${TEST_ARCH}) 75 set(SANITIZER_COMMON_LIT_TEST_MODE ${tool}) 76 set(SANITIZER_COMMON_TEST_TARGET_ARCH ${arch}) 77 get_test_cc_for_arch(${arch} SANITIZER_COMMON_TEST_TARGET_CC SANITIZER_COMMON_TEST_TARGET_CFLAGS) 78 set(CONFIG_NAME ${tool}-${arch}-${OS_NAME}) 79 configure_lit_site_cfg( 80 ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in 81 ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py) 82 # FIXME(dliew): LSan i386 on Darwin is completly broken right now. 83 # so don't run the tests by default. 84 if (NOT (CMAKE_SYSTEM_NAME MATCHES "Darwin" AND 85 ${tool} STREQUAL "lsan" AND 86 ${arch} STREQUAL "i386")) 87 list(APPEND SANITIZER_COMMON_TESTSUITES 88 ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}) 89 endif() 90 endforeach() 91endforeach() 92 93# Unit tests. 94if(COMPILER_RT_INCLUDE_TESTS) 95 configure_lit_site_cfg( 96 ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in 97 ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg.py) 98 # FIXME: support unit test in the android test runner 99 if (NOT ANDROID) 100 list(APPEND SANITIZER_COMMON_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit) 101 list(APPEND SANITIZER_COMMON_TEST_DEPS SanitizerUnitTests) 102 endif() 103endif() 104 105if(SANITIZER_COMMON_TESTSUITES) 106 add_lit_testsuite(check-sanitizer "Running sanitizer_common tests" 107 ${SANITIZER_COMMON_TESTSUITES} 108 DEPENDS ${SANITIZER_COMMON_TEST_DEPS}) 109 set_target_properties(check-sanitizer PROPERTIES FOLDER 110 "Compiler-RT Misc") 111endif() 112