xref: /llvm-project/compiler-rt/test/CMakeLists.txt (revision a14a83d9a102253eca7c02ff4c35a2ce3f7de6e5)
1# Needed for lit support in standalone builds.
2include(AddLLVM)
3
4pythonize_bool(COMPILER_RT_TEST_STANDALONE_BUILD_LIBS)
5
6pythonize_bool(LLVM_ENABLE_EXPENSIVE_CHECKS)
7
8pythonize_bool(ZLIB_FOUND)
9pythonize_bool(COMPILER_RT_BUILD_STANDALONE_LIBATOMIC)
10
11pythonize_bool(COMPILER_RT_ENABLE_INTERNAL_SYMBOLIZER)
12
13pythonize_bool(COMPILER_RT_HAS_AARCH64_SME)
14
15pythonize_bool(COMPILER_RT_HAS_NO_DEFAULT_CONFIG_FLAG)
16
17configure_compiler_rt_lit_site_cfg(
18  ${CMAKE_CURRENT_SOURCE_DIR}/lit.common.configured.in
19  ${CMAKE_CURRENT_BINARY_DIR}/lit.common.configured)
20
21# BlocksRuntime (and most of builtins) testsuites are not yet ported to lit.
22# add_subdirectory(BlocksRuntime)
23
24set(SANITIZER_COMMON_LIT_TEST_DEPS)
25
26if(COMPILER_RT_BUILD_PROFILE AND COMPILER_RT_HAS_PROFILE)
27  list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS profile)
28endif()
29
30# When ANDROID, we build tests with the host compiler (i.e. CMAKE_C_COMPILER),
31# and run tests with tools from the host toolchain.
32if(NOT ANDROID)
33  if(NOT COMPILER_RT_STANDALONE_BUILD AND NOT LLVM_RUNTIMES_BUILD)
34    # Use LLVM utils and Clang from the same build tree.
35    list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS
36      clang clang-resource-headers FileCheck count not llvm-config llvm-nm
37      llvm-objdump llvm-readelf llvm-readobj llvm-size llvm-symbolizer
38      compiler-rt-headers sancov split-file llvm-strip)
39    if (WIN32)
40      list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS KillTheDoctor)
41    endif()
42  endif()
43  # Tests use C++ standard library headers.
44  if (TARGET cxx-headers OR HAVE_LIBCXX)
45    list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS cxx-headers)
46  endif()
47endif()
48
49umbrella_lit_testsuite_begin(check-compiler-rt)
50
51function(compiler_rt_test_runtime runtime)
52  string(TOUPPER ${runtime} runtime_uppercase)
53  if(COMPILER_RT_HAS_${runtime_uppercase} AND COMPILER_RT_INCLUDE_TESTS)
54    if (${runtime} STREQUAL cfi AND NOT COMPILER_RT_HAS_UBSAN)
55      # CFI tests require diagnostic mode, which is implemented in UBSan.
56    elseif (${runtime} STREQUAL scudo_standalone)
57      add_subdirectory(scudo/standalone)
58    else()
59      add_subdirectory(${runtime})
60    endif()
61  endif()
62endfunction()
63
64# Run sanitizer tests only if we're sure that clang would produce
65# working binaries.
66if(COMPILER_RT_CAN_EXECUTE_TESTS)
67  if(COMPILER_RT_BUILD_BUILTINS)
68    add_subdirectory(builtins)
69  endif()
70  if(COMPILER_RT_BUILD_SANITIZERS)
71    compiler_rt_test_runtime(interception)
72
73    compiler_rt_test_runtime(lsan)
74    compiler_rt_test_runtime(ubsan)
75    compiler_rt_test_runtime(sanitizer_common)
76
77    # OpenBSD not supporting asan, cannot run the tests
78    if(COMPILER_RT_BUILD_LIBFUZZER AND NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "OpenBSD" AND NOT ANDROID)
79      compiler_rt_test_runtime(fuzzer)
80
81      # These tests don't need an additional runtime but use asan runtime.
82      add_subdirectory(metadata)
83    endif()
84
85    foreach(sanitizer ${COMPILER_RT_SANITIZERS_TO_BUILD})
86      compiler_rt_test_runtime(${sanitizer})
87    endforeach()
88  endif()
89  if(COMPILER_RT_BUILD_PROFILE AND COMPILER_RT_HAS_PROFILE)
90    compiler_rt_test_runtime(profile)
91  endif()
92  if(COMPILER_RT_BUILD_CTX_PROFILE)
93    compiler_rt_test_runtime(ctx_profile)
94  endif()
95  if(COMPILER_RT_BUILD_MEMPROF)
96    compiler_rt_test_runtime(memprof)
97  endif()
98  if(COMPILER_RT_BUILD_XRAY)
99    compiler_rt_test_runtime(xray)
100  endif()
101  if(COMPILER_RT_BUILD_ORC)
102    compiler_rt_Test_runtime(orc)
103  endif()
104  # ShadowCallStack does not yet provide a runtime with compiler-rt, the tests
105  # include their own minimal runtime
106  add_subdirectory(shadowcallstack)
107endif()
108
109# Now that we've traversed all the directories and know all the lit testsuites,
110# introduce a rule to run to run all of them.
111get_property(LLVM_COMPILER_RT_LIT_DEPENDS GLOBAL PROPERTY LLVM_COMPILER_RT_LIT_DEPENDS)
112add_custom_target(compiler-rt-test-depends)
113set_target_properties(compiler-rt-test-depends PROPERTIES FOLDER "Compiler-RT/Tests")
114if(LLVM_COMPILER_RT_LIT_DEPENDS)
115  add_dependencies(compiler-rt-test-depends ${LLVM_COMPILER_RT_LIT_DEPENDS})
116endif()
117umbrella_lit_testsuite_end(check-compiler-rt)
118
119if(COMPILER_RT_STANDALONE_BUILD)
120  if(NOT TARGET check-all)
121    add_custom_target(check-all)
122  endif()
123  add_dependencies(check-all check-compiler-rt)
124endif()
125