• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Test runner infrastructure for LLDB. This configures the LLDB test trees
2# for use by Lit, and delegates to LLVM's lit test handlers.
3
4if(LLDB_BUILT_STANDALONE)
5  # In order to run check-lldb-* we need the correct map_config directives in
6  # llvm-lit. Because this is a standalone build, LLVM doesn't know about LLDB,
7  # and the lldb mappings are missing. We build our own llvm-lit, and tell LLVM
8  # to use the llvm-lit in the lldb build directory.
9  if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/llvm-lit)
10    set(LLVM_EXTERNAL_LIT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/llvm-lit)
11  endif()
12endif()
13
14# Configure the build directory.
15set(LLDB_TEST_BUILD_DIRECTORY "${PROJECT_BINARY_DIR}/lldb-test-build.noindex" CACHE PATH "The build root for building tests.")
16
17# Configure and create module cache directories.
18set(LLDB_TEST_MODULE_CACHE_LLDB "${LLDB_TEST_BUILD_DIRECTORY}/module-cache-lldb" CACHE PATH "The Clang module cache used by the Clang embedded in LLDB while running tests.")
19set(LLDB_TEST_MODULE_CACHE_CLANG "${LLDB_TEST_BUILD_DIRECTORY}/module-cache-clang" CACHE PATH "The Clang module cache used by the Clang while building tests.")
20file(MAKE_DIRECTORY ${LLDB_TEST_MODULE_CACHE_LLDB})
21file(MAKE_DIRECTORY ${LLDB_TEST_MODULE_CACHE_CLANG})
22
23# LLVM_BUILD_MODE is used in lit.site.cfg
24if (CMAKE_CFG_INTDIR STREQUAL ".")
25  set(LLVM_BUILD_MODE ".")
26else ()
27  set(LLVM_BUILD_MODE "%(build_mode)s")
28endif ()
29
30string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLDB_LIBS_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
31string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLDB_TOOLS_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
32
33# Create a custom target to track test dependencies.
34add_custom_target(lldb-test-deps)
35set_target_properties(lldb-test-deps PROPERTIES FOLDER "lldb misc")
36
37function(add_lldb_test_dependency)
38  foreach(dependency ${ARGN})
39    add_dependencies(lldb-test-deps ${dependency})
40  endforeach()
41endfunction(add_lldb_test_dependency)
42
43# lldb itself and lldb-test is an hard dependency for the testsuites.
44add_lldb_test_dependency(lldb)
45add_lldb_test_dependency(lldb-test)
46
47# On Darwin, darwin-debug is an hard dependency for the testsuites.
48if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
49  add_lldb_test_dependency(darwin-debug)
50endif()
51
52if(TARGET lldb-server)
53  add_lldb_test_dependency(lldb-server)
54endif()
55
56if(TARGET lldb-vscode)
57  add_lldb_test_dependency(lldb-vscode)
58endif()
59
60if(TARGET lldb-instr)
61  add_lldb_test_dependency(lldb-instr)
62endif()
63
64if(TARGET liblldb)
65  add_lldb_test_dependency(liblldb)
66endif()
67
68if(TARGET lldb-framework)
69  add_lldb_test_dependency(lldb-framework)
70endif()
71
72# Add dependencies that are not exported targets when building standalone.
73if(NOT LLDB_BUILT_STANDALONE)
74  add_lldb_test_dependency(
75    FileCheck
76    count
77    dsymutil
78    llvm-strip
79    not
80    split-file
81    yaml2obj
82  )
83endif()
84
85# Add dependencies if we test with the in-tree clang.
86# This works with standalone builds as they import the clang target.
87if(TARGET clang)
88  add_lldb_test_dependency(clang)
89
90  if(TARGET asan)
91    add_lldb_test_dependency(asan)
92  endif()
93
94  if(TARGET tsan)
95    add_lldb_test_dependency(tsan)
96  endif()
97
98  if(APPLE)
99    # FIXME: Standalone builds should import the cxx target as well.
100    if(LLDB_BUILT_STANDALONE)
101      # For now check that the include directory exists.
102      set(cxx_dir "${LLVM_BINARY_DIR}/include/c++")
103      if(NOT EXISTS ${cxx_dir})
104        message(WARNING "LLDB test suite requires libc++ in llvm/projects/libcxx or an existing build symlinked to ${cxx_dir}")
105      endif()
106    else()
107      # We require libcxx for the test suite, so if we aren't building it,
108      # try to provide a helpful error about how to resolve the situation.
109      if(NOT TARGET cxx)
110        if(LLVM_ENABLE_PROJECTS STREQUAL "")
111          # If `LLVM_ENABLE_PROJECTS` is not being used (implying that we are
112          # using the old layout), suggest checking it out.
113          message(FATAL_ERROR
114            "LLDB test suite requires libc++, but it is currently disabled. "
115            "Please checkout `libcxx` in `llvm/projects` or disable tests "
116            "via `LLDB_INCLUDE_TESTS=OFF`.")
117        else()
118          # If `LLVM_ENABLE_PROJECTS` is being used, suggest adding it.
119          message(FATAL_ERROR
120            "LLDB test suite requires libc++, but it is currently disabled. "
121            "Please add `libcxx` to `LLVM_ENABLE_PROJECTS` or disable tests "
122            "via `LLDB_INCLUDE_TESTS=OFF`.")
123        endif()
124      endif()
125      add_lldb_test_dependency(cxx)
126    endif()
127  endif()
128endif()
129
130if (LLDB_BUILT_STANDALONE)
131  set(LLVM_HOST_TRIPLE ${TARGET_TRIPLE})
132endif()
133
134add_lldb_test_dependency(
135  lit-cpuid
136  llc
137  lli
138  llvm-config
139  llvm-dwarfdump
140  llvm-dwp
141  llvm-nm
142  llvm-mc
143  llvm-objcopy
144  llvm-pdbutil
145  llvm-readobj
146  )
147
148if(TARGET lld)
149  add_lldb_test_dependency(lld)
150else()
151  # LLD is required to link test executables on Windows.
152  if (CMAKE_SYSTEM_NAME MATCHES "Windows")
153    message(WARNING "lld required to test LLDB on Windows")
154  endif()
155endif()
156
157if (CMAKE_SIZEOF_VOID_P EQUAL 8)
158  set(LLDB_IS_64_BITS 1)
159endif()
160
161# These values are not canonicalized within LLVM.
162llvm_canonicalize_cmake_booleans(
163  LLDB_BUILD_INTEL_PT
164  LLDB_ENABLE_PYTHON
165  LLDB_ENABLE_LUA
166  LLDB_ENABLE_LZMA
167  LLVM_ENABLE_ZLIB
168  LLVM_ENABLE_SHARED_LIBS
169  LLDB_IS_64_BITS)
170
171# Configure the individual test suites.
172add_subdirectory(API)
173add_subdirectory(Shell)
174add_subdirectory(Unit)
175
176# Configure the top level test suite.
177configure_lit_site_cfg(
178  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
179  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
180  MAIN_CONFIG
181  ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py)
182
183add_lit_testsuites(LLDB
184  ${CMAKE_CURRENT_SOURCE_DIR}
185  DEPENDS lldb-test-deps)
186
187add_lit_testsuite(check-lldb-lit "Running lldb lit test suite"
188  ${CMAKE_CURRENT_BINARY_DIR}
189  DEPENDS lldb-test-deps)
190set_target_properties(check-lldb-lit PROPERTIES FOLDER "lldb tests")
191
192add_custom_target(check-lldb)
193add_dependencies(check-lldb lldb-test-deps)
194set_target_properties(check-lldb PROPERTIES FOLDER "lldb misc")
195add_dependencies(check-lldb check-lldb-lit)
196
197# Add a lit test suite that runs the API & shell test while capturing a
198# reproducer.
199add_lit_testsuite(check-lldb-reproducers-capture
200  "Running lldb test suite with reproducer capture"
201  ${CMAKE_CURRENT_BINARY_DIR}/API
202  ${CMAKE_CURRENT_BINARY_DIR}/Shell
203  PARAMS "lldb-run-with-repro=capture"
204  EXCLUDE_FROM_CHECK_ALL
205  DEPENDS lldb-test-deps)
206
207# Add a lit test suite that runs the API & shell test by replaying a
208# reproducer.
209add_lit_testsuite(check-lldb-reproducers
210  "Running lldb test suite with reproducer replay"
211  ${CMAKE_CURRENT_BINARY_DIR}/API
212  ${CMAKE_CURRENT_BINARY_DIR}/Shell
213  PARAMS "lldb-run-with-repro=replay"
214  EXCLUDE_FROM_CHECK_ALL
215  DEPENDS lldb-test-deps)
216add_dependencies(check-lldb-reproducers check-lldb-reproducers-capture)
217
218# Targets for running the test suite on the different Apple simulators.
219add_lit_testsuite(check-lldb-simulator-ios
220  "Running lldb test suite on the iOS simulator"
221  ${CMAKE_CURRENT_BINARY_DIR}/API
222  PARAMS "lldb-run-with-simulator=ios"
223  EXCLUDE_FROM_CHECK_ALL
224  DEPENDS lldb-test-deps)
225
226add_lit_testsuite(check-lldb-simulator-watchos
227  "Running lldb test suite on the watchOS simulator"
228  ${CMAKE_CURRENT_BINARY_DIR}/API
229  PARAMS "lldb-run-with-simulator=watchos"
230  EXCLUDE_FROM_CHECK_ALL
231  DEPENDS lldb-test-deps)
232
233add_lit_testsuite(check-lldb-simulator-tvos
234  "Running lldb test suite on the tvOS simulator"
235  ${CMAKE_CURRENT_BINARY_DIR}/API
236  PARAMS "lldb-run-with-simulator=tvos"
237  EXCLUDE_FROM_CHECK_ALL
238  DEPENDS lldb-test-deps)
239
240
241if(LLDB_BUILT_STANDALONE)
242  # This has to happen *AFTER* add_lit_testsuite.
243  if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/llvm-lit)
244    # LLVM's make_paths_relative uses Python3_EXECUTABLE which isn't set in a
245    # standalone LLDB build.
246    set(Python3_EXECUTABLE ${Python3_EXECUTABLE})
247    add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit ${CMAKE_CURRENT_BINARY_DIR}/llvm-lit)
248  endif()
249endif()
250