1include_directories(..) 2 3add_custom_target(ScudoUnitTests) 4set_target_properties(ScudoUnitTests PROPERTIES 5 FOLDER "Compiler-RT Tests") 6 7set(SCUDO_UNITTEST_CFLAGS 8 ${COMPILER_RT_UNITTEST_CFLAGS} 9 ${COMPILER_RT_GTEST_CFLAGS} 10 -I${COMPILER_RT_SOURCE_DIR}/include 11 -I${COMPILER_RT_SOURCE_DIR}/lib 12 -I${COMPILER_RT_SOURCE_DIR}/lib/scudo/standalone 13 -I${COMPILER_RT_SOURCE_DIR}/lib/scudo/standalone/include 14 -DGTEST_HAS_RTTI=0 15 -DSCUDO_DEBUG=1 16 # Extra flags for the C++ tests 17 # TODO(kostyak): find a way to make -fsized-deallocation work 18 -Wno-mismatched-new-delete) 19 20if(ANDROID) 21 list(APPEND SCUDO_UNITTEST_CFLAGS -fno-emulated-tls) 22endif() 23 24if (COMPILER_RT_HAS_GWP_ASAN) 25 list(APPEND SCUDO_UNITTEST_CFLAGS -DGWP_ASAN_HOOKS) 26endif() 27 28set(SCUDO_TEST_ARCH ${SCUDO_STANDALONE_SUPPORTED_ARCH}) 29 30# gtests requires c++ 31set(LINK_FLAGS ${COMPILER_RT_UNITTEST_LINK_FLAGS}) 32foreach(lib ${SANITIZER_TEST_CXX_LIBRARIES}) 33 list(APPEND LINK_FLAGS -l${lib}) 34endforeach() 35list(APPEND LINK_FLAGS -pthread) 36# Linking against libatomic is required with some compilers 37list(APPEND LINK_FLAGS -latomic) 38 39set(SCUDO_TEST_HEADERS) 40foreach (header ${SCUDO_HEADERS}) 41 list(APPEND SCUDO_TEST_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../${header}) 42endforeach() 43 44macro(add_scudo_unittest testname) 45 cmake_parse_arguments(TEST "" "" "SOURCES;ADDITIONAL_RTOBJECTS" ${ARGN}) 46 if (COMPILER_RT_HAS_GWP_ASAN) 47 list(APPEND TEST_ADDITIONAL_RTOBJECTS 48 RTGwpAsan RTGwpAsanBacktraceLibc RTGwpAsanSegvHandler) 49 endif() 50 51 if(COMPILER_RT_HAS_SCUDO_STANDALONE) 52 foreach(arch ${SCUDO_TEST_ARCH}) 53 # Additional runtime objects get added along RTScudoStandalone 54 set(SCUDO_TEST_RTOBJECTS $<TARGET_OBJECTS:RTScudoStandalone.${arch}>) 55 foreach(rtobject ${TEST_ADDITIONAL_RTOBJECTS}) 56 list(APPEND SCUDO_TEST_RTOBJECTS $<TARGET_OBJECTS:${rtobject}.${arch}>) 57 endforeach() 58 # Add the static runtime library made of all the runtime objects 59 set(RUNTIME RT${testname}.${arch}) 60 add_library(${RUNTIME} STATIC ${SCUDO_TEST_RTOBJECTS}) 61 set(ScudoUnitTestsObjects) 62 generate_compiler_rt_tests(ScudoUnitTestsObjects ScudoUnitTests 63 "${testname}-${arch}-Test" ${arch} 64 SOURCES ${TEST_SOURCES} ${COMPILER_RT_GTEST_SOURCE} 65 COMPILE_DEPS ${SCUDO_TEST_HEADERS} 66 DEPS gtest scudo_standalone 67 RUNTIME ${RUNTIME} 68 CFLAGS ${SCUDO_UNITTEST_CFLAGS} 69 LINK_FLAGS ${LINK_FLAGS}) 70 endforeach() 71 endif() 72endmacro() 73 74set(SCUDO_UNIT_TEST_SOURCES 75 atomic_test.cpp 76 bytemap_test.cpp 77 checksum_test.cpp 78 chunk_test.cpp 79 combined_test.cpp 80 flags_test.cpp 81 list_test.cpp 82 map_test.cpp 83 mutex_test.cpp 84 primary_test.cpp 85 quarantine_test.cpp 86 release_test.cpp 87 report_test.cpp 88 secondary_test.cpp 89 size_class_map_test.cpp 90 stats_test.cpp 91 strings_test.cpp 92 tsd_test.cpp 93 vector_test.cpp 94 scudo_unit_test_main.cpp 95 ) 96 97add_scudo_unittest(ScudoUnitTest 98 SOURCES ${SCUDO_UNIT_TEST_SOURCES}) 99 100set(SCUDO_C_UNIT_TEST_SOURCES 101 wrappers_c_test.cpp 102 scudo_unit_test_main.cpp 103 ) 104 105add_scudo_unittest(ScudoCUnitTest 106 SOURCES ${SCUDO_C_UNIT_TEST_SOURCES} 107 ADDITIONAL_RTOBJECTS RTScudoStandaloneCWrappers) 108 109set(SCUDO_CXX_UNIT_TEST_SOURCES 110 wrappers_cpp_test.cpp 111 scudo_unit_test_main.cpp 112 ) 113 114add_scudo_unittest(ScudoCxxUnitTest 115 SOURCES ${SCUDO_CXX_UNIT_TEST_SOURCES} 116 ADDITIONAL_RTOBJECTS RTScudoStandaloneCWrappers RTScudoStandaloneCxxWrappers) 117