Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / lib / scudo / standalone / tests / CMakeLists.txt
blobc6b6a1cb57ceea68d55ac6c9181c88028d2630f2
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
15   -DGTEST_HAS_RTTI=0
16   -g
17   # Extra flags for the C++ tests
18   -Wconversion
19   # TODO(kostyak): find a way to make -fsized-deallocation work
20   -Wno-mismatched-new-delete)
22 if(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()
27 endif()
29 if(ANDROID)
30   list(APPEND SCUDO_UNITTEST_CFLAGS -fno-emulated-tls)
31 endif()
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)
36 endif()
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})
43 # gtests requires c++
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)
53 endif()
55 set(SCUDO_TEST_HEADERS
56   scudo_unit_test.h
57   )
58 foreach (header ${SCUDO_HEADERS})
59   list(APPEND SCUDO_TEST_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../${header})
60 endforeach()
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)
67   endif()
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}>)
75       endforeach()
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
85         RUNTIME ${RUNTIME}
86         CFLAGS ${SCUDO_UNITTEST_CFLAGS}
87         LINK_FLAGS ${SCUDO_UNITTEST_LINK_FLAGS})
88     endforeach()
89   endif()
90 endmacro()
92 set(SCUDO_UNIT_TEST_SOURCES
93   atomic_test.cpp
94   bytemap_test.cpp
95   checksum_test.cpp
96   chunk_test.cpp
97   combined_test.cpp
98   common_test.cpp
99   condition_variable_test.cpp
100   flags_test.cpp
101   list_test.cpp
102   map_test.cpp
103   memtag_test.cpp
104   mutex_test.cpp
105   primary_test.cpp
106   quarantine_test.cpp
107   release_test.cpp
108   report_test.cpp
109   secondary_test.cpp
110   size_class_map_test.cpp
111   stats_test.cpp
112   strings_test.cpp
113   timing_test.cpp
114   tsd_test.cpp
115   vector_test.cpp
116   scudo_unit_test_main.cpp
117   )
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)
123 endif()
125 add_scudo_unittest(ScudoUnitTest
126   SOURCES ${SCUDO_UNIT_TEST_SOURCES})
128 set(SCUDO_C_UNIT_TEST_SOURCES
129   wrappers_c_test.cpp
130   scudo_unit_test_main.cpp
131   )
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
140   )
142 add_scudo_unittest(ScudoCxxUnitTest
143   SOURCES ${SCUDO_CXX_UNIT_TEST_SOURCES}
144   ADDITIONAL_RTOBJECTS RTScudoStandaloneCWrappers RTScudoStandaloneCxxWrappers)