Chandler Carruth | 821f21b | 2012-06-25 12:57:43 +0000 | [diff] [blame] | 1 | # Testing rules for AddressSanitizer. |
| 2 | # |
| 3 | # These are broken into two buckets. One set of tests directly interacts with |
| 4 | # the runtime library and checks its functionality. These are the |
| 5 | # no-instrumentation tests. |
| 6 | # |
| 7 | # Another group of tests relies upon the ability to compile the test with |
| 8 | # address sanitizer instrumentation pass. These tests form "integration" tests |
| 9 | # and have some elements of version skew -- they test the *host* compiler's |
| 10 | # instrumentation against the just-built runtime library. |
| 11 | |
| 12 | include(CheckCXXCompilerFlag) |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 13 | include(CompilerRTCompile) |
Chandler Carruth | 821f21b | 2012-06-25 12:57:43 +0000 | [diff] [blame] | 14 | |
| 15 | include_directories(..) |
| 16 | include_directories(../..) |
| 17 | |
Alexey Samsonov | 032e833 | 2012-12-21 14:04:52 +0000 | [diff] [blame] | 18 | set(ASAN_UNITTEST_HEADERS |
| 19 | asan_mac_test.h |
| 20 | asan_test_config.h |
| 21 | asan_test_utils.h) |
| 22 | |
Alexey Samsonov | d00ecb6 | 2012-06-28 13:12:07 +0000 | [diff] [blame] | 23 | set(ASAN_UNITTEST_COMMON_CFLAGS |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 24 | ${COMPILER_RT_TEST_CFLAGS} |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 25 | ${COMPILER_RT_GTEST_CFLAGS} |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 26 | -I${COMPILER_RT_SOURCE_DIR}/include |
| 27 | -I${COMPILER_RT_SOURCE_DIR}/lib |
| 28 | -I${COMPILER_RT_SOURCE_DIR}/lib/asan |
Kostya Serebryany | c74b2cc | 2013-02-14 08:12:26 +0000 | [diff] [blame] | 29 | -I${COMPILER_RT_SOURCE_DIR}/lib/sanitizer_common/tests |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 30 | -fno-rtti |
| 31 | -O2 |
Alexey Samsonov | d00ecb6 | 2012-06-28 13:12:07 +0000 | [diff] [blame] | 32 | -Wno-format |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 33 | -Werror=sign-compare |
| 34 | -Wno-non-virtual-dtor) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 35 | append_list_if(COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG -Wno-variadic-macros ASAN_UNITTEST_COMMON_CFLAGS) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 36 | |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 37 | # -gline-tables-only must be enough for ASan, so use it if possible. |
| 38 | if(COMPILER_RT_TEST_COMPILER_ID MATCHES "Clang") |
| 39 | list(APPEND ASAN_UNITTEST_COMMON_CFLAGS -gline-tables-only) |
| 40 | else() |
| 41 | list(APPEND ASAN_UNITTEST_COMMON_CFLAGS -g) |
Alexey Samsonov | 76e8428 | 2012-09-12 12:07:36 +0000 | [diff] [blame] | 42 | endif() |
| 43 | |
Evgeniy Stepanov | 34fc56c | 2012-09-11 11:55:45 +0000 | [diff] [blame] | 44 | # Use -D instead of definitions to please custom compile command. |
Alexey Samsonov | ee485d4 | 2013-01-21 10:51:18 +0000 | [diff] [blame] | 45 | list(APPEND ASAN_UNITTEST_COMMON_CFLAGS |
Alexey Samsonov | ee485d4 | 2013-01-21 10:51:18 +0000 | [diff] [blame] | 46 | -DASAN_HAS_BLACKLIST=1 |
| 47 | -DASAN_HAS_EXCEPTIONS=1 |
| 48 | -DASAN_UAR=0) |
Evgeniy Stepanov | 34fc56c | 2012-09-11 11:55:45 +0000 | [diff] [blame] | 49 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 50 | if(APPLE) |
| 51 | list(APPEND ASAN_UNITTEST_COMMON_CFLAGS ${DARWIN_osx_CFLAGS}) |
| 52 | list(APPEND ASAN_UNITTEST_COMMON_LINKFLAGS ${DARWIN_osx_LINKFLAGS}) |
| 53 | endif() |
| 54 | |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 55 | if(MSVC) |
| 56 | # Disable exceptions on Windows until they work reliably. |
| 57 | list(APPEND ASAN_UNITTEST_COMMON_CFLAGS -fno-exceptions -DGTEST_HAS_SEH=0) |
| 58 | endif() |
| 59 | |
Alexey Samsonov | 7a89732 | 2012-10-19 15:18:14 +0000 | [diff] [blame] | 60 | set(ASAN_BLACKLIST_FILE "${CMAKE_CURRENT_SOURCE_DIR}/asan_test.ignore") |
Alexey Samsonov | 2084543 | 2012-06-29 10:23:31 +0000 | [diff] [blame] | 61 | set(ASAN_UNITTEST_INSTRUMENTED_CFLAGS |
| 62 | ${ASAN_UNITTEST_COMMON_CFLAGS} |
Richard Smith | f10a79a | 2012-11-06 02:31:42 +0000 | [diff] [blame] | 63 | -fsanitize=address |
Alexey Samsonov | 3b9e668 | 2013-01-22 10:30:17 +0000 | [diff] [blame] | 64 | "-fsanitize-blacklist=${ASAN_BLACKLIST_FILE}" |
Alexey Samsonov | 2084543 | 2012-06-29 10:23:31 +0000 | [diff] [blame] | 65 | ) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 66 | if(CAN_TARGET_x86_64 OR CAN_TARGET_i386) |
| 67 | list(APPEND ASAN_UNITTEST_INSTRUMENTED_CFLAGS -mllvm -asan-instrument-assembly) |
| 68 | endif() |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 69 | |
| 70 | if(NOT MSVC) |
| 71 | list(APPEND ASAN_UNITTEST_COMMON_LINKFLAGS --driver-mode=g++) |
Alexey Samsonov | ee485d4 | 2013-01-21 10:51:18 +0000 | [diff] [blame] | 72 | endif() |
Alexey Samsonov | 2084543 | 2012-06-29 10:23:31 +0000 | [diff] [blame] | 73 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 74 | # x86_64 FreeBSD 9.2 additionally requires libc++ to build the tests. |
| 75 | if(CMAKE_SYSTEM MATCHES "FreeBSD-9.2-RELEASE") |
| 76 | list(APPEND ASAN_UNITTEST_COMMON_LINKFLAGS "-lc++") |
| 77 | endif() |
| 78 | |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 79 | # Unit tests on Mac depend on Foundation. |
| 80 | if(APPLE) |
| 81 | list(APPEND ASAN_UNITTEST_COMMON_LINKFLAGS -framework Foundation) |
| 82 | endif() |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 83 | if(ANDROID) |
Alexey Samsonov | 5d9d807 | 2013-09-17 07:50:12 +0000 | [diff] [blame] | 84 | list(APPEND ASAN_UNITTEST_COMMON_LINKFLAGS -pie) |
| 85 | endif() |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 86 | |
| 87 | set(ASAN_UNITTEST_INSTRUMENTED_LINKFLAGS |
| 88 | ${ASAN_UNITTEST_COMMON_LINKFLAGS}) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 89 | list(APPEND ASAN_UNITTEST_INSTRUMENTED_LINKFLAGS -fsanitize=address) |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 90 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 91 | set(ASAN_DYNAMIC_UNITTEST_INSTRUMENTED_LINKFLAGS |
| 92 | ${ASAN_UNITTEST_INSTRUMENTED_LINKFLAGS} |
| 93 | -shared-libasan) |
| 94 | |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 95 | set(ASAN_UNITTEST_INSTRUMENTED_LIBS) |
| 96 | # NDK r10 requires -latomic almost always. |
| 97 | append_list_if(ANDROID atomic ASAN_UNITTEST_INSTRUMENTED_LIBS) |
| 98 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 99 | set(ASAN_UNITTEST_NOINST_LINKFLAGS ${ASAN_UNITTEST_COMMON_LINKFLAGS}) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 100 | append_list_if(COMPILER_RT_HAS_LIBM -lm ASAN_UNITTEST_NOINST_LINKFLAGS) |
| 101 | append_list_if(COMPILER_RT_HAS_LIBDL -ldl ASAN_UNITTEST_NOINST_LINKFLAGS) |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 102 | append_list_if(COMPILER_RT_HAS_LIBRT -lrt ASAN_UNITTEST_NOINST_LINKFLAGS) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 103 | append_list_if(COMPILER_RT_HAS_LIBPTHREAD -pthread ASAN_UNITTEST_NOINST_LINKFLAGS) |
| 104 | append_list_if(COMPILER_RT_HAS_LIBPTHREAD -pthread |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 105 | ASAN_DYNAMIC_UNITTEST_INSTRUMENTED_LINKFLAGS) |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 106 | |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 107 | # TODO(eugenis): move all -l flags above to _LIBS? |
| 108 | set(ASAN_UNITTEST_NOINST_LIBS) |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 109 | append_list_if(COMPILER_RT_HAS_LIBLOG log ASAN_UNITTEST_NOINST_LIBS) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 110 | # NDK r10 requires -latomic almost always. |
| 111 | append_list_if(ANDROID atomic ASAN_UNITTEST_NOINST_LIBS) |
| 112 | |
Alexey Samsonov | bf23186 | 2012-12-19 15:17:23 +0000 | [diff] [blame] | 113 | # Compile source for the given architecture, using compiler |
| 114 | # options in ${ARGN}, and add it to the object list. |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 115 | macro(asan_compile obj_list source arch kind) |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 116 | get_filename_component(basename ${source} NAME) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 117 | set(output_obj "${obj_list}.${basename}.${arch}${kind}.o") |
Alexey Samsonov | bf23186 | 2012-12-19 15:17:23 +0000 | [diff] [blame] | 118 | get_target_flags_for_arch(${arch} TARGET_CFLAGS) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 119 | set(COMPILE_DEPS ${ASAN_UNITTEST_HEADERS} ${ASAN_BLACKLIST_FILE}) |
| 120 | if(NOT COMPILER_RT_STANDALONE_BUILD) |
| 121 | list(APPEND COMPILE_DEPS gtest asan) |
| 122 | endif() |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 123 | clang_compile(${output_obj} ${source} |
Alexey Samsonov | bf23186 | 2012-12-19 15:17:23 +0000 | [diff] [blame] | 124 | CFLAGS ${ARGN} ${TARGET_CFLAGS} |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 125 | DEPS ${COMPILE_DEPS}) |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 126 | list(APPEND ${obj_list} ${output_obj}) |
| 127 | endmacro() |
Chandler Carruth | 821f21b | 2012-06-25 12:57:43 +0000 | [diff] [blame] | 128 | |
Alexey Samsonov | bf23186 | 2012-12-19 15:17:23 +0000 | [diff] [blame] | 129 | # Link ASan unit test for a given architecture from a set |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 130 | # of objects in with given linker flags. |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 131 | macro(add_asan_test test_suite test_name arch kind) |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 132 | cmake_parse_arguments(TEST "WITH_TEST_RUNTIME" "" "OBJECTS;LINKFLAGS;SUBDIR" ${ARGN}) |
Alexey Samsonov | bf23186 | 2012-12-19 15:17:23 +0000 | [diff] [blame] | 133 | get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 134 | set(TEST_DEPS ${TEST_OBJECTS}) |
| 135 | if(NOT COMPILER_RT_STANDALONE_BUILD) |
| 136 | list(APPEND TEST_DEPS asan) |
| 137 | endif() |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 138 | if(TEST_WITH_TEST_RUNTIME) |
| 139 | list(APPEND TEST_DEPS ${ASAN_TEST_RUNTIME}) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 140 | if(NOT MSVC) |
| 141 | list(APPEND TEST_OBJECTS lib${ASAN_TEST_RUNTIME}.a) |
| 142 | else() |
| 143 | list(APPEND TEST_OBJECTS ${ASAN_TEST_RUNTIME}.lib) |
| 144 | endif() |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 145 | endif() |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 146 | add_compiler_rt_test(${test_suite} ${test_name} |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 147 | SUBDIR ${TEST_SUBDIR} |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 148 | OBJECTS ${TEST_OBJECTS} |
| 149 | DEPS ${TEST_DEPS} |
| 150 | LINK_FLAGS ${TEST_LINKFLAGS} |
Alexey Samsonov | bf23186 | 2012-12-19 15:17:23 +0000 | [diff] [blame] | 151 | ${TARGET_LINK_FLAGS}) |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 152 | endmacro() |
Alexey Samsonov | 37dd1d7 | 2012-06-28 12:19:52 +0000 | [diff] [blame] | 153 | |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 154 | # Main AddressSanitizer unit tests. |
| 155 | add_custom_target(AsanUnitTests) |
| 156 | set_target_properties(AsanUnitTests PROPERTIES FOLDER "ASan unit tests") |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 157 | # AddressSanitizer unit tests with dynamic runtime (on platforms where it's |
| 158 | # not the default). |
| 159 | add_custom_target(AsanDynamicUnitTests) |
| 160 | set_target_properties(AsanDynamicUnitTests |
| 161 | PROPERTIES FOLDER "ASan unit tests with dynamic runtime") |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 162 | # ASan benchmarks (not actively used now). |
| 163 | add_custom_target(AsanBenchmarks) |
| 164 | set_target_properties(AsanBenchmarks PROPERTIES FOLDER "Asan benchmarks") |
Alexey Samsonov | 1a7741b | 2012-07-24 08:26:19 +0000 | [diff] [blame] | 165 | |
Alexey Samsonov | c92a421 | 2013-01-22 07:31:28 +0000 | [diff] [blame] | 166 | set(ASAN_NOINST_TEST_SOURCES |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 167 | ${COMPILER_RT_GTEST_SOURCE} |
Alexey Samsonov | 4681781 | 2013-09-17 08:40:32 +0000 | [diff] [blame] | 168 | asan_fake_stack_test.cc |
Alexey Samsonov | c92a421 | 2013-01-22 07:31:28 +0000 | [diff] [blame] | 169 | asan_noinst_test.cc |
| 170 | asan_test_main.cc) |
Alexander Potapenko | bdd9545 | 2013-09-12 09:46:56 +0000 | [diff] [blame] | 171 | |
Alexey Samsonov | c92a421 | 2013-01-22 07:31:28 +0000 | [diff] [blame] | 172 | set(ASAN_INST_TEST_SOURCES |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 173 | ${COMPILER_RT_GTEST_SOURCE} |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 174 | asan_asm_test.cc |
Alexey Samsonov | c92a421 | 2013-01-22 07:31:28 +0000 | [diff] [blame] | 175 | asan_globals_test.cc |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 176 | asan_interface_test.cc |
Alexey Samsonov | c92a421 | 2013-01-22 07:31:28 +0000 | [diff] [blame] | 177 | asan_test.cc |
| 178 | asan_oob_test.cc |
| 179 | asan_mem_test.cc |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 180 | asan_str_test.cc |
| 181 | asan_test_main.cc) |
| 182 | if(APPLE) |
| 183 | list(APPEND ASAN_INST_TEST_SOURCES asan_mac_test.cc) |
| 184 | endif() |
| 185 | |
| 186 | set(ASAN_BENCHMARKS_SOURCES |
| 187 | ${COMPILER_RT_GTEST_SOURCE} |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 188 | asan_benchmarks_test.cc) |
Alexey Samsonov | c92a421 | 2013-01-22 07:31:28 +0000 | [diff] [blame] | 189 | |
Alexey Samsonov | bf23186 | 2012-12-19 15:17:23 +0000 | [diff] [blame] | 190 | # Adds ASan unit tests and benchmarks for architecture. |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 191 | macro(add_asan_tests_for_arch_and_kind arch kind) |
Alexey Samsonov | bf23186 | 2012-12-19 15:17:23 +0000 | [diff] [blame] | 192 | # Instrumented tests. |
| 193 | set(ASAN_INST_TEST_OBJECTS) |
Alexey Samsonov | c92a421 | 2013-01-22 07:31:28 +0000 | [diff] [blame] | 194 | foreach(src ${ASAN_INST_TEST_SOURCES}) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 195 | asan_compile(ASAN_INST_TEST_OBJECTS ${src} ${arch} ${kind} |
| 196 | ${ASAN_UNITTEST_INSTRUMENTED_CFLAGS} ${ARGN}) |
Alexey Samsonov | c92a421 | 2013-01-22 07:31:28 +0000 | [diff] [blame] | 197 | endforeach() |
Alexey Samsonov | bf23186 | 2012-12-19 15:17:23 +0000 | [diff] [blame] | 198 | if (APPLE) |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 199 | # Add Mac-specific helper. |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 200 | asan_compile(ASAN_INST_TEST_OBJECTS asan_mac_test_helpers.mm ${arch} ${kind} |
| 201 | ${ASAN_UNITTEST_INSTRUMENTED_CFLAGS} -ObjC ${ARGN}) |
Alexey Samsonov | bf23186 | 2012-12-19 15:17:23 +0000 | [diff] [blame] | 202 | endif() |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 203 | file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/default") |
| 204 | add_asan_test(AsanUnitTests "Asan-${arch}${kind}-Test" |
| 205 | ${arch} ${kind} SUBDIR "default" |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 206 | OBJECTS ${ASAN_INST_TEST_OBJECTS} |
| 207 | LINKFLAGS ${ASAN_UNITTEST_INSTRUMENTED_LINKFLAGS}) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 208 | if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME) |
| 209 | file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/dynamic") |
| 210 | add_asan_test(AsanDynamicUnitTests "Asan-${arch}${kind}-Dynamic-Test" |
| 211 | ${arch} ${kind} SUBDIR "dynamic" |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 212 | OBJECTS ${ASAN_INST_TEST_OBJECTS} |
| 213 | LINKFLAGS ${ASAN_DYNAMIC_UNITTEST_INSTRUMENTED_LINKFLAGS}) |
| 214 | endif() |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 215 | |
| 216 | # Add static ASan runtime that will be linked with uninstrumented tests. |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 217 | set(ASAN_TEST_RUNTIME RTAsanTest.${arch}${kind}) |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 218 | if(APPLE) |
| 219 | set(ASAN_TEST_RUNTIME_OBJECTS |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 220 | $<TARGET_OBJECTS:RTAsan_dynamic.osx> |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 221 | $<TARGET_OBJECTS:RTInterception.osx> |
| 222 | $<TARGET_OBJECTS:RTSanitizerCommon.osx> |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 223 | $<TARGET_OBJECTS:RTSanitizerCommonLibc.osx> |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 224 | $<TARGET_OBJECTS:RTLSanCommon.osx> |
| 225 | $<TARGET_OBJECTS:RTUbsan.osx>) |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 226 | else() |
| 227 | set(ASAN_TEST_RUNTIME_OBJECTS |
| 228 | $<TARGET_OBJECTS:RTAsan.${arch}> |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 229 | $<TARGET_OBJECTS:RTAsan_cxx.${arch}> |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 230 | $<TARGET_OBJECTS:RTInterception.${arch}> |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 231 | $<TARGET_OBJECTS:RTSanitizerCommon.${arch}> |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 232 | $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}> |
| 233 | $<TARGET_OBJECTS:RTLSanCommon.${arch}> |
| 234 | $<TARGET_OBJECTS:RTUbsan.${arch}> |
| 235 | $<TARGET_OBJECTS:RTUbsan_cxx.${arch}>) |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 236 | endif() |
| 237 | add_library(${ASAN_TEST_RUNTIME} STATIC ${ASAN_TEST_RUNTIME_OBJECTS}) |
| 238 | set_target_properties(${ASAN_TEST_RUNTIME} PROPERTIES |
| 239 | ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) |
Alexey Samsonov | bf23186 | 2012-12-19 15:17:23 +0000 | [diff] [blame] | 240 | # Uninstrumented tests. |
| 241 | set(ASAN_NOINST_TEST_OBJECTS) |
Alexey Samsonov | c92a421 | 2013-01-22 07:31:28 +0000 | [diff] [blame] | 242 | foreach(src ${ASAN_NOINST_TEST_SOURCES}) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 243 | asan_compile(ASAN_NOINST_TEST_OBJECTS ${src} ${arch} ${kind} |
| 244 | ${ASAN_UNITTEST_COMMON_CFLAGS} ${ARGN}) |
Alexey Samsonov | c92a421 | 2013-01-22 07:31:28 +0000 | [diff] [blame] | 245 | endforeach() |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 246 | add_asan_test(AsanUnitTests "Asan-${arch}${kind}-Noinst-Test" |
| 247 | ${arch} ${kind} SUBDIR "default" |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 248 | OBJECTS ${ASAN_NOINST_TEST_OBJECTS} |
| 249 | LINKFLAGS ${ASAN_UNITTEST_NOINST_LINKFLAGS} |
| 250 | WITH_TEST_RUNTIME) |
Alexey Samsonov | bf23186 | 2012-12-19 15:17:23 +0000 | [diff] [blame] | 251 | |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 252 | # Benchmarks. |
Alexey Samsonov | bf23186 | 2012-12-19 15:17:23 +0000 | [diff] [blame] | 253 | set(ASAN_BENCHMARKS_OBJECTS) |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 254 | foreach(src ${ASAN_BENCHMARKS_SOURCES}) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 255 | asan_compile(ASAN_BENCHMARKS_OBJECTS ${src} ${arch} ${kind} |
| 256 | ${ASAN_UNITTEST_INSTRUMENTED_CFLAGS} ${ARGN}) |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 257 | endforeach() |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 258 | add_asan_test(AsanBenchmarks "Asan-${arch}${kind}-Benchmark" |
| 259 | ${arch} ${kind} SUBDIR "default" |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 260 | OBJECTS ${ASAN_BENCHMARKS_OBJECTS} |
| 261 | LINKFLAGS ${ASAN_UNITTEST_INSTRUMENTED_LINKFLAGS}) |
Alexey Samsonov | bf23186 | 2012-12-19 15:17:23 +0000 | [diff] [blame] | 262 | endmacro() |
| 263 | |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 264 | if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT ANDROID) |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 265 | set(ASAN_TEST_ARCH ${ASAN_SUPPORTED_ARCH}) |
| 266 | if(APPLE) |
| 267 | darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH) |
| 268 | endif() |
| 269 | foreach(arch ${ASAN_TEST_ARCH}) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 270 | add_asan_tests_for_arch_and_kind(${arch} "-inline") |
| 271 | add_asan_tests_for_arch_and_kind(${arch} "-with-calls" |
| 272 | -mllvm -asan-instrumentation-with-call-threshold=0) |
Alexey Samsonov | d0b1d46 | 2013-01-21 14:31:45 +0000 | [diff] [blame] | 273 | endforeach() |
Chandler Carruth | 984f6cf | 2012-06-27 09:01:24 +0000 | [diff] [blame] | 274 | endif() |
Alexey Samsonov | 2084543 | 2012-06-29 10:23:31 +0000 | [diff] [blame] | 275 | |
Evgeniy Stepanov | 34fc56c | 2012-09-11 11:55:45 +0000 | [diff] [blame] | 276 | if(ANDROID) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 277 | foreach(arch ${ASAN_SUPPORTED_ARCH}) |
| 278 | # Test w/o ASan instrumentation. Link it with ASan statically. |
| 279 | add_executable(AsanNoinstTest # FIXME: .arch? |
| 280 | $<TARGET_OBJECTS:RTAsan.${arch}> |
| 281 | $<TARGET_OBJECTS:RTInterception.${arch}> |
| 282 | $<TARGET_OBJECTS:RTSanitizerCommon.${arch}> |
| 283 | $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}> |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 284 | $<TARGET_OBJECTS:RTUbsan.${arch}> |
| 285 | $<TARGET_OBJECTS:RTUbsan_cxx.${arch}> |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 286 | ${COMPILER_RT_GTEST_SOURCE} |
| 287 | ${ASAN_NOINST_TEST_SOURCES}) |
| 288 | set_target_compile_flags(AsanNoinstTest ${ASAN_UNITTEST_COMMON_CFLAGS}) |
| 289 | set_target_link_flags(AsanNoinstTest ${ASAN_UNITTEST_NOINST_LINKFLAGS}) |
| 290 | target_link_libraries(AsanNoinstTest ${ASAN_UNITTEST_NOINST_LIBS}) |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 291 | |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 292 | # Test with ASan instrumentation. Link with ASan dynamic runtime. |
| 293 | add_executable(AsanTest |
| 294 | ${COMPILER_RT_GTEST_SOURCE} |
| 295 | ${ASAN_INST_TEST_SOURCES}) |
| 296 | set_target_compile_flags(AsanTest ${ASAN_UNITTEST_INSTRUMENTED_CFLAGS}) |
| 297 | set_target_link_flags(AsanTest ${ASAN_UNITTEST_INSTRUMENTED_LINKFLAGS}) |
| 298 | target_link_libraries(AsanTest ${ASAN_UNITTEST_INSTRUMENTED_LIBS}) |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 299 | |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 300 | # Setup correct output directory and link flags. |
| 301 | set_target_properties(AsanNoinstTest AsanTest PROPERTIES |
| 302 | RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) |
| 303 | # Add unit tests to the test suite. |
| 304 | add_dependencies(AsanUnitTests AsanNoinstTest AsanTest) |
| 305 | endforeach() |
Evgeniy Stepanov | 34fc56c | 2012-09-11 11:55:45 +0000 | [diff] [blame] | 306 | endif() |