141 lines · plain
1include_directories(..)2 3add_custom_target(ScudoUnitTests)4set_target_properties(ScudoUnitTests PROPERTIES5 FOLDER "Compiler-RT Tests")6 7set(SCUDO_UNITTEST_CFLAGS8 ${COMPILER_RT_UNITTEST_CFLAGS}9 ${COMPILER_RT_GTEST_CFLAGS}10 ${SANITIZER_TEST_CXX_CFLAGS}11 -I${COMPILER_RT_SOURCE_DIR}/include12 -I${COMPILER_RT_SOURCE_DIR}/lib13 -I${COMPILER_RT_SOURCE_DIR}/lib/scudo/standalone14 -I${COMPILER_RT_SOURCE_DIR}/lib/scudo/standalone/include15 -DGTEST_HAS_RTTI=016 -g17 # Extra flags for the C++ tests18 -Wconversion19 # TODO(kostyak): find a way to make -fsized-deallocation work20 -Wno-mismatched-new-delete)21 22if(COMPILER_RT_DEBUG)23 list(APPEND SCUDO_UNITTEST_CFLAGS -DSCUDO_DEBUG=1 -DSCUDO_ENABLE_HOOKS=1)24 if (NOT FUCHSIA)25 list(APPEND SCUDO_UNITTEST_CFLAGS -DSCUDO_ENABLE_HOOKS_TESTS=1)26 endif()27endif()28 29if(ANDROID)30 list(APPEND SCUDO_UNITTEST_CFLAGS -fno-emulated-tls)31endif()32 33if (COMPILER_RT_HAS_GWP_ASAN)34 list(APPEND SCUDO_UNITTEST_CFLAGS -DGWP_ASAN_HOOKS -fno-omit-frame-pointer35 -mno-omit-leaf-frame-pointer)36endif()37 38append_list_if(COMPILER_RT_HAS_WTHREAD_SAFETY_FLAG -Werror=thread-safety39 SCUDO_UNITTEST_CFLAGS)40 41set(SCUDO_TEST_ARCH ${SCUDO_STANDALONE_SUPPORTED_ARCH})42 43# gtests requires c++44set(SCUDO_UNITTEST_LINK_FLAGS45 ${COMPILER_RT_UNITTEST_LINK_FLAGS}46 ${COMPILER_RT_UNWINDER_LINK_LIBS}47 ${SANITIZER_TEST_CXX_LIBRARIES})48list(APPEND SCUDO_UNITTEST_LINK_FLAGS -pthread -no-pie)49 50append_list_if(COMPILER_RT_HAS_LIBATOMIC -latomic SCUDO_UNITTEST_LINK_FLAGS)51 52set(SCUDO_TEST_HEADERS53 scudo_unit_test.h54 )55foreach (header ${SCUDO_HEADERS})56 list(APPEND SCUDO_TEST_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../${header})57endforeach()58 59macro(add_scudo_unittest testname)60 cmake_parse_arguments(TEST "" "" "SOURCES;ADDITIONAL_RTOBJECTS" ${ARGN})61 if (COMPILER_RT_HAS_GWP_ASAN)62 list(APPEND TEST_ADDITIONAL_RTOBJECTS63 RTGwpAsan RTGwpAsanBacktraceLibc RTGwpAsanSegvHandler)64 endif()65 66 foreach(arch ${SCUDO_TEST_ARCH})67 # Additional runtime objects get added along RTScudoStandalone68 set(SCUDO_TEST_RTOBJECTS $<TARGET_OBJECTS:RTScudoStandalone.${arch}>)69 foreach(rtobject ${TEST_ADDITIONAL_RTOBJECTS})70 list(APPEND SCUDO_TEST_RTOBJECTS $<TARGET_OBJECTS:${rtobject}.${arch}>)71 endforeach()72 # Add the static runtime library made of all the runtime objects73 set(RUNTIME RT${testname}.${arch})74 add_library(${RUNTIME} STATIC ${SCUDO_TEST_RTOBJECTS})75 set(ScudoUnitTestsObjects)76 generate_compiler_rt_tests(ScudoUnitTestsObjects ScudoUnitTests77 "${testname}-${arch}-Test" ${arch}78 SOURCES ${TEST_SOURCES} ${COMPILER_RT_GTEST_SOURCE}79 COMPILE_DEPS ${SCUDO_TEST_HEADERS}80 DEPS scudo_standalone81 RUNTIME ${RUNTIME}82 CFLAGS ${SCUDO_UNITTEST_CFLAGS}83 LINK_FLAGS ${SCUDO_UNITTEST_LINK_FLAGS})84 endforeach()85endmacro()86 87set(SCUDO_UNIT_TEST_SOURCES88 allocator_config_test.cpp89 atomic_test.cpp90 bytemap_test.cpp91 checksum_test.cpp92 chunk_test.cpp93 combined_test.cpp94 common_test.cpp95 condition_variable_test.cpp96 flags_test.cpp97 list_test.cpp98 map_test.cpp99 memtag_test.cpp100 mutex_test.cpp101 primary_test.cpp102 quarantine_test.cpp103 release_test.cpp104 report_test.cpp105 secondary_test.cpp106 size_class_map_test.cpp107 stats_test.cpp108 strings_test.cpp109 timing_test.cpp110 tsd_test.cpp111 vector_test.cpp112 scudo_unit_test_main.cpp113 )114 115# Temporary hack until LLVM libc supports inttypes.h print format macros116# See: https://github.com/llvm/llvm-project/issues/63317#issuecomment-1591906241117if(LLVM_LIBC_INCLUDE_SCUDO)118 list(REMOVE_ITEM SCUDO_UNIT_TEST_SOURCES timing_test.cpp)119endif()120 121add_scudo_unittest(ScudoUnitTest122 SOURCES ${SCUDO_UNIT_TEST_SOURCES})123 124set(SCUDO_C_UNIT_TEST_SOURCES125 wrappers_c_test.cpp126 scudo_unit_test_main.cpp127 )128 129add_scudo_unittest(ScudoCUnitTest130 SOURCES ${SCUDO_C_UNIT_TEST_SOURCES}131 ADDITIONAL_RTOBJECTS RTScudoStandaloneCWrappers)132 133set(SCUDO_CXX_UNIT_TEST_SOURCES134 wrappers_cpp_test.cpp135 scudo_unit_test_main.cpp136 )137 138add_scudo_unittest(ScudoCxxUnitTest139 SOURCES ${SCUDO_CXX_UNIT_TEST_SOURCES}140 ADDITIONAL_RTOBJECTS RTScudoStandaloneCWrappers RTScudoStandaloneCxxWrappers)141