xref: /openbsd-src/gnu/llvm/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt (revision 810390e339a5425391477d5d41c78d7cab2424ac)
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  ${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  # TODO(kostyak): find a way to make -fsized-deallocation work
19  -Wno-mismatched-new-delete)
20
21if(COMPILER_RT_DEBUG)
22  list(APPEND SCUDO_UNITTEST_CFLAGS -DSCUDO_DEBUG=1)
23endif()
24
25if(ANDROID)
26  list(APPEND SCUDO_UNITTEST_CFLAGS -fno-emulated-tls)
27endif()
28
29if (COMPILER_RT_HAS_GWP_ASAN)
30  list(APPEND SCUDO_UNITTEST_CFLAGS -DGWP_ASAN_HOOKS -fno-omit-frame-pointer
31       -mno-omit-leaf-frame-pointer)
32endif()
33
34set(SCUDO_TEST_ARCH ${SCUDO_STANDALONE_SUPPORTED_ARCH})
35
36# gtests requires c++
37set(SCUDO_UNITTEST_LINK_FLAGS
38  ${COMPILER_RT_UNITTEST_LINK_FLAGS}
39  ${COMPILER_RT_UNWINDER_LINK_LIBS}
40  ${SANITIZER_TEST_CXX_LIBRARIES})
41list(APPEND SCUDO_UNITTEST_LINK_FLAGS -pthread -no-pie)
42# Linking against libatomic is required with some compilers
43check_library_exists(atomic __atomic_load_8 "" COMPILER_RT_HAS_LIBATOMIC)
44if (COMPILER_RT_HAS_LIBATOMIC)
45  list(APPEND SCUDO_UNITTEST_LINK_FLAGS -latomic)
46endif()
47
48set(SCUDO_TEST_HEADERS
49  scudo_unit_test.h
50  )
51foreach (header ${SCUDO_HEADERS})
52  list(APPEND SCUDO_TEST_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../${header})
53endforeach()
54
55macro(add_scudo_unittest testname)
56  cmake_parse_arguments(TEST "" "" "SOURCES;ADDITIONAL_RTOBJECTS" ${ARGN})
57  if (COMPILER_RT_HAS_GWP_ASAN)
58    list(APPEND TEST_ADDITIONAL_RTOBJECTS
59         RTGwpAsan RTGwpAsanBacktraceLibc RTGwpAsanSegvHandler)
60  endif()
61
62  if(COMPILER_RT_HAS_SCUDO_STANDALONE)
63    foreach(arch ${SCUDO_TEST_ARCH})
64      # Additional runtime objects get added along RTScudoStandalone
65      set(SCUDO_TEST_RTOBJECTS $<TARGET_OBJECTS:RTScudoStandalone.${arch}>)
66      foreach(rtobject ${TEST_ADDITIONAL_RTOBJECTS})
67        list(APPEND SCUDO_TEST_RTOBJECTS $<TARGET_OBJECTS:${rtobject}.${arch}>)
68      endforeach()
69      # Add the static runtime library made of all the runtime objects
70      set(RUNTIME RT${testname}.${arch})
71      add_library(${RUNTIME} STATIC ${SCUDO_TEST_RTOBJECTS})
72      set(ScudoUnitTestsObjects)
73      generate_compiler_rt_tests(ScudoUnitTestsObjects ScudoUnitTests
74        "${testname}-${arch}-Test" ${arch}
75        SOURCES ${TEST_SOURCES} ${COMPILER_RT_GTEST_SOURCE}
76        COMPILE_DEPS ${SCUDO_TEST_HEADERS}
77        DEPS llvm_gtest scudo_standalone
78        RUNTIME ${RUNTIME}
79        CFLAGS ${SCUDO_UNITTEST_CFLAGS}
80        LINK_FLAGS ${SCUDO_UNITTEST_LINK_FLAGS})
81    endforeach()
82  endif()
83endmacro()
84
85set(SCUDO_UNIT_TEST_SOURCES
86  atomic_test.cpp
87  bytemap_test.cpp
88  checksum_test.cpp
89  chunk_test.cpp
90  combined_test.cpp
91  common_test.cpp
92  flags_test.cpp
93  list_test.cpp
94  map_test.cpp
95  memtag_test.cpp
96  mutex_test.cpp
97  primary_test.cpp
98  quarantine_test.cpp
99  release_test.cpp
100  report_test.cpp
101  secondary_test.cpp
102  size_class_map_test.cpp
103  stats_test.cpp
104  strings_test.cpp
105  tsd_test.cpp
106  vector_test.cpp
107  scudo_unit_test_main.cpp
108  )
109
110add_scudo_unittest(ScudoUnitTest
111  SOURCES ${SCUDO_UNIT_TEST_SOURCES})
112
113set(SCUDO_C_UNIT_TEST_SOURCES
114  wrappers_c_test.cpp
115  scudo_unit_test_main.cpp
116  )
117
118add_scudo_unittest(ScudoCUnitTest
119  SOURCES ${SCUDO_C_UNIT_TEST_SOURCES}
120  ADDITIONAL_RTOBJECTS RTScudoStandaloneCWrappers)
121
122set(SCUDO_CXX_UNIT_TEST_SOURCES
123  wrappers_cpp_test.cpp
124  scudo_unit_test_main.cpp
125  )
126
127add_scudo_unittest(ScudoCxxUnitTest
128  SOURCES ${SCUDO_CXX_UNIT_TEST_SOURCES}
129  ADDITIONAL_RTOBJECTS RTScudoStandaloneCWrappers RTScudoStandaloneCxxWrappers)
130