Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 1 | set(ASAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 2 | |
| 3 | set(ASAN_TESTSUITES) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 4 | set(ASAN_DYNAMIC_TESTSUITES) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 5 | |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 6 | macro(get_bits_for_arch arch bits) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 7 | if (${arch} MATCHES "i386|i686|arm|mips|mipsel") |
Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 8 | set(${bits} 32) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 9 | elseif (${arch} MATCHES "x86_64|powerpc64|powerpc64le|aarch64|mips64|mips64el") |
Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 10 | set(${bits} 64) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 11 | else() |
| 12 | message(FATAL_ERROR "Unknown target architecture: ${arch}") |
| 13 | endif() |
| 14 | endmacro() |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 15 | |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 16 | set(ASAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS}) |
| 17 | if(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() |
| 24 | endif() |
| 25 | set(ASAN_DYNAMIC_TEST_DEPS ${ASAN_TEST_DEPS}) |
| 26 | |
| 27 | set(ASAN_TEST_ARCH ${ASAN_SUPPORTED_ARCH}) |
| 28 | if(APPLE) |
| 29 | darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH) |
| 30 | endif() |
| 31 | |
| 32 | foreach(arch ${ASAN_TEST_ARCH}) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 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}) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 44 | set(ASAN_TEST_TARGET_CFLAGS ${COMPILER_RT_TEST_COMPILER_CFLAGS}) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 45 | else() |
| 46 | get_target_flags_for_arch(${arch} ASAN_TEST_TARGET_CFLAGS) |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 47 | string(REPLACE ";" " " ASAN_TEST_TARGET_CFLAGS "${ASAN_TEST_TARGET_CFLAGS}") |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 48 | endif() |
| 49 | if(ANDROID) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 50 | set(ASAN_TEST_DYNAMIC True) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 51 | else() |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 52 | set(ASAN_TEST_DYNAMIC False) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 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) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 66 | configure_lit_site_cfg( |
| 67 | ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 68 | ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg) |
| 69 | list(APPEND ASAN_DYNAMIC_TESTSUITES |
| 70 | ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 71 | endif() |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 72 | endforeach() |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 73 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 74 | # Add unit tests. |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 75 | if(COMPILER_RT_INCLUDE_TESTS) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 76 | set(ASAN_TEST_DYNAMIC False) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 77 | configure_lit_site_cfg( |
| 78 | ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in |
| 79 | ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 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() |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 95 | endif() |
| 96 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 97 | add_lit_testsuite(check-asan "Running the AddressSanitizer tests" |
| 98 | ${ASAN_TESTSUITES} |
| 99 | DEPENDS ${ASAN_TEST_DEPS}) |
| 100 | set_target_properties(check-asan PROPERTIES FOLDER "ASan tests") |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 101 | |
| 102 | if(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() |
| 117 | endif() |