1 include_directories(..)
3 add_custom_target(ScudoUnitTests)
4 set_target_properties(ScudoUnitTests PROPERTIES
5 FOLDER "Compiler-RT Tests")
7 set(SCUDO_UNITTEST_CFLAGS
8 ${COMPILER_RT_UNITTEST_CFLAGS}
9 ${COMPILER_RT_GTEST_CFLAGS}
10 ${SANITIZER_TEST_CXX_CFLAGS}
11 -I${COMPILER_RT_SOURCE_DIR}/include
12 -I${COMPILER_RT_SOURCE_DIR}/lib
13 -I${COMPILER_RT_SOURCE_DIR}/lib/scudo/standalone
14 -I${COMPILER_RT_SOURCE_DIR}/lib/scudo/standalone/include
17 # Extra flags for the C++ tests
19 # TODO(kostyak): find a way to make -fsized-deallocation work
20 -Wno-mismatched-new-delete)
23 list(APPEND SCUDO_UNITTEST_CFLAGS -DSCUDO_DEBUG=1 -DSCUDO_ENABLE_HOOKS=1)
25 list(APPEND SCUDO_UNITTEST_CFLAGS -DSCUDO_ENABLE_HOOKS_TESTS=1)
30 list(APPEND SCUDO_UNITTEST_CFLAGS -fno-emulated-tls)
33 if (COMPILER_RT_HAS_GWP_ASAN)
34 list(APPEND SCUDO_UNITTEST_CFLAGS -DGWP_ASAN_HOOKS -fno-omit-frame-pointer
35 -mno-omit-leaf-frame-pointer)
38 append_list_if(COMPILER_RT_HAS_WTHREAD_SAFETY_FLAG -Werror=thread-safety
39 SCUDO_UNITTEST_CFLAGS)
41 set(SCUDO_TEST_ARCH ${SCUDO_STANDALONE_SUPPORTED_ARCH})
44 set(SCUDO_UNITTEST_LINK_FLAGS
45 ${COMPILER_RT_UNITTEST_LINK_FLAGS}
46 ${COMPILER_RT_UNWINDER_LINK_LIBS}
47 ${SANITIZER_TEST_CXX_LIBRARIES})
48 list(APPEND SCUDO_UNITTEST_LINK_FLAGS -pthread -no-pie)
49 # Linking against libatomic is required with some compilers
50 check_library_exists(atomic __atomic_load_8 "" COMPILER_RT_HAS_LIBATOMIC)
51 if (COMPILER_RT_HAS_LIBATOMIC)
52 list(APPEND SCUDO_UNITTEST_LINK_FLAGS -latomic)
55 set(SCUDO_TEST_HEADERS
58 foreach (header ${SCUDO_HEADERS})
59 list(APPEND SCUDO_TEST_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../${header})
62 macro(add_scudo_unittest testname)
63 cmake_parse_arguments(TEST "" "" "SOURCES;ADDITIONAL_RTOBJECTS" ${ARGN})
64 if (COMPILER_RT_HAS_GWP_ASAN)
65 list(APPEND TEST_ADDITIONAL_RTOBJECTS
66 RTGwpAsan RTGwpAsanBacktraceLibc RTGwpAsanSegvHandler)
69 if(COMPILER_RT_HAS_SCUDO_STANDALONE)
70 foreach(arch ${SCUDO_TEST_ARCH})
71 # Additional runtime objects get added along RTScudoStandalone
72 set(SCUDO_TEST_RTOBJECTS $<TARGET_OBJECTS:RTScudoStandalone.${arch}>)
73 foreach(rtobject ${TEST_ADDITIONAL_RTOBJECTS})
74 list(APPEND SCUDO_TEST_RTOBJECTS $<TARGET_OBJECTS:${rtobject}.${arch}>)
76 # Add the static runtime library made of all the runtime objects
77 set(RUNTIME RT${testname}.${arch})
78 add_library(${RUNTIME} STATIC ${SCUDO_TEST_RTOBJECTS})
79 set(ScudoUnitTestsObjects)
80 generate_compiler_rt_tests(ScudoUnitTestsObjects ScudoUnitTests
81 "${testname}-${arch}-Test" ${arch}
82 SOURCES ${TEST_SOURCES} ${COMPILER_RT_GTEST_SOURCE}
83 COMPILE_DEPS ${SCUDO_TEST_HEADERS}
84 DEPS llvm_gtest scudo_standalone
86 CFLAGS ${SCUDO_UNITTEST_CFLAGS}
87 LINK_FLAGS ${SCUDO_UNITTEST_LINK_FLAGS})
92 set(SCUDO_UNIT_TEST_SOURCES
99 condition_variable_test.cpp
110 size_class_map_test.cpp
116 scudo_unit_test_main.cpp
119 # Temporary hack until LLVM libc supports inttypes.h print format macros
120 # See: https://github.com/llvm/llvm-project/issues/63317#issuecomment-1591906241
121 if(LLVM_LIBC_INCLUDE_SCUDO)
122 list(REMOVE_ITEM SCUDO_UNIT_TEST_SOURCES timing_test.cpp)
125 add_scudo_unittest(ScudoUnitTest
126 SOURCES ${SCUDO_UNIT_TEST_SOURCES})
128 set(SCUDO_C_UNIT_TEST_SOURCES
130 scudo_unit_test_main.cpp
133 add_scudo_unittest(ScudoCUnitTest
134 SOURCES ${SCUDO_C_UNIT_TEST_SOURCES}
135 ADDITIONAL_RTOBJECTS RTScudoStandaloneCWrappers)
137 set(SCUDO_CXX_UNIT_TEST_SOURCES
138 wrappers_cpp_test.cpp
139 scudo_unit_test_main.cpp
142 add_scudo_unittest(ScudoCxxUnitTest
143 SOURCES ${SCUDO_CXX_UNIT_TEST_SOURCES}
144 ADDITIONAL_RTOBJECTS RTScudoStandaloneCWrappers RTScudoStandaloneCxxWrappers)