CMakeLists.txt revision 821f21b7cdd0bcc91102f08c8ee0773fd9273046
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 12include(CheckCXXCompilerFlag) 13 14include_directories(..) 15include_directories(../..) 16 17add_custom_target(AsanTests) 18set_target_properties(AsanTests PROPERTIES FOLDER "ASan tests") 19function(add_asan_test testname) 20 add_unittest(AsanTests ${testname} ${ARGN}) 21 if(CMAKE_SIZEOF_VOID_P EQUAL 4) 22 target_link_libraries(${testname} clang_rt.asan-i386) 23 else() 24 target_link_libraries(${testname} clang_rt.asan-x86_64) 25 endif() 26endfunction() 27 28add_asan_test(AsanNoInstrumentationTests 29 asan_noinst_test.cc 30 asan_break_optimization.cc 31 ) 32 33# FIXME: Currently, this detection isn't working. Assume we're doing 34# a bootstrap build for now. 35set(HOST_HAS_ASAN on) 36#check_cxx_compiler_flag("-faddress-sanitizer" HOST_HAS_ASAN) 37 38if(HOST_HAS_ASAN) 39 add_asan_test(AsanInstrumentationTests 40 asan_globals_test.cc 41 asan_interface_test.cc 42 asan_test.cc 43 asan_break_optimization.cc 44 ) 45 set_property(TARGET AsanInstrumentationTests APPEND_STRING PROPERTY COMPILE_FLAGS 46 " -faddress-sanitizer ${ASAN_CFLAGS}") 47 set_property(TARGET AsanInstrumentationTests APPEND_STRING PROPERTY COMPILE_FLAGS 48 " -mllvm -asan-blacklist=${CMAKE_CURRENT_SOURCE_DIR}/asan_test.ignore") 49 set_property(TARGET AsanInstrumentationTests APPEND PROPERTY COMPILE_DEFINITIONS 50 ASAN_HAS_BLACKLIST=1 51 ASAN_HAS_EXCEPTIONS=1 52 ASAN_NEEDS_SEGV=1 53 ASAN_UAR=0 54 ) 55endif() 56 57