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 # Lit requires a Python3 interpreter, let's be careful and fail early if it's
5 if (NOT DEFINED Python3_EXECUTABLE)
7 "LLDB test suite requires a Python3 interpreter but none "
8 "was found. Please install Python3 or disable tests with "
9 "`LLDB_INCLUDE_TESTS=OFF`.")
12 if(LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS)
13 message(STATUS "Enforcing strict test requirements for LLDB")
14 set(useful_python_modules
15 psutil # Lit uses psutil to do per-test timeouts.
17 foreach(module ${useful_python_modules})
18 lldb_find_python_module(${module})
19 if (NOT PY_${module}_FOUND)
21 "Python module '${module}' not found. Please install it via pip or via "
22 "your operating system's package manager. Alternatively, disable "
23 "strict testing requirements with "
24 "`LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS=OFF`")
29 if(LLDB_BUILT_STANDALONE)
30 # In order to run check-lldb-* we need the correct map_config directives in
31 # llvm-lit. Because this is a standalone build, LLVM doesn't know about LLDB,
32 # and the lldb mappings are missing. We build our own llvm-lit, and tell LLVM
33 # to use the llvm-lit in the lldb build directory.
34 if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/llvm-lit)
35 set(LLVM_EXTERNAL_LIT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/llvm-lit)
39 # Configure the build directory.
40 # The .noindex suffix is a marker for Spotlight to never index the
41 # build directory. LLDB queries Spotlight to locate .dSYM bundles
42 # based on the UUID embedded in a binary, and because the UUID is a
43 # hash of filename and .text section, there *will* be conflicts inside
44 # the build directory.
45 set(LLDB_TEST_BUILD_DIRECTORY "${PROJECT_BINARY_DIR}/lldb-test-build.noindex" CACHE PATH "The build root for building tests.")
47 # Configure and create module cache directories.
48 set(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.")
49 set(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.")
50 file(MAKE_DIRECTORY ${LLDB_TEST_MODULE_CACHE_LLDB})
51 file(MAKE_DIRECTORY ${LLDB_TEST_MODULE_CACHE_CLANG})
53 # Windows and Linux have no built-in ObjC runtime. Turn this on in order to run tests with GNUstep.
54 option(LLDB_TEST_OBJC_GNUSTEP "Enable ObjC tests with GNUstep libobjc2 on non-Apple platforms" Off)
55 set(LLDB_TEST_OBJC_GNUSTEP_DIR "" CACHE PATH "Custom path to the GNUstep shared library")
57 if (LLDB_TEST_OBJC_GNUSTEP)
58 if (LLDB_TEST_OBJC_GNUSTEP_DIR)
59 set(GNUstepObjC_DIR ${LLDB_TEST_OBJC_GNUSTEP_DIR})
61 find_package(GNUstepObjC)
62 if (NOT GNUstepObjC_FOUND)
63 if (LLDB_TEST_OBJC_GNUSTEP_DIR)
64 message(FATAL_ERROR "Failed to find GNUstep libobjc2 in ${LLDB_TEST_OBJC_GNUSTEP_DIR}. "
65 "Please check LLDB_TEST_OBJC_GNUSTEP_DIR or turn off LLDB_TEST_OBJC_GNUSTEP.")
67 message(FATAL_ERROR "Failed to find GNUstep libobjc2. "
68 "Please set LLDB_TEST_OBJC_GNUSTEP_DIR or turn off LLDB_TEST_OBJC_GNUSTEP.")
71 set(LLDB_TEST_OBJC_GNUSTEP_DIR ${GNUstepObjC_DIR})
72 elseif (LLDB_TEST_OBJC_GNUSTEP_DIR)
73 message(STATUS "Reset LLDB_TEST_OBJC_GNUSTEP_DIR since LLDB_TEST_OBJC_GNUSTEP is off")
74 set(LLDB_TEST_OBJC_GNUSTEP_DIR "" CACHE PATH "Custom path to the GNUstep shared library" FORCE)
77 # LLVM_BUILD_MODE is used in lit.site.cfg
78 if (CMAKE_CFG_INTDIR STREQUAL ".")
79 set(LLVM_BUILD_MODE ".")
81 set(LLVM_BUILD_MODE "%(build_mode)s")
84 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLDB_LIBS_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
85 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLDB_TOOLS_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
87 # Create a custom target to track test dependencies.
88 add_custom_target(lldb-test-depends)
89 set_target_properties(lldb-test-depends PROPERTIES FOLDER "lldb misc")
91 # Create an alias for the legacy name of lldb-test-depends
92 add_custom_target(lldb-test-deps)
93 add_dependencies(lldb-test-deps lldb-test-depends)
95 function(add_lldb_test_dependency)
96 foreach(dependency ${ARGN})
97 add_dependencies(lldb-test-depends ${dependency})
99 endfunction(add_lldb_test_dependency)
101 # lldb itself and lldb-test is an hard dependency for the testsuites.
102 add_lldb_test_dependency(lldb)
103 add_lldb_test_dependency(lldb-test)
105 # On Darwin, darwin-debug is an hard dependency for the testsuites.
106 if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
107 add_lldb_test_dependency(darwin-debug)
110 if(TARGET debugserver)
111 add_lldb_test_dependency(debugserver)
113 if(TARGET lldb-server)
114 add_lldb_test_dependency(lldb-server)
117 if(TARGET lldb-vscode)
118 add_lldb_test_dependency(lldb-vscode)
122 add_lldb_test_dependency(liblldb)
125 if(TARGET lldb-framework)
126 add_lldb_test_dependency(lldb-framework)
129 # Add dependencies that are not exported targets when building standalone.
130 if(NOT LLDB_BUILT_STANDALONE)
131 add_lldb_test_dependency(
142 # Add dependencies if we test with the in-tree clang.
143 # This works with standalone builds as they import the clang target.
145 add_lldb_test_dependency(clang)
147 # TestFullLtoStepping depends on LTO, and only runs when the compiler is clang.
148 add_lldb_test_dependency(LTO)
150 if (TARGET libcxx OR ("libcxx" IN_LIST LLVM_ENABLE_RUNTIMES))
151 set(LLDB_HAS_LIBCXX ON)
152 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
153 set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
154 set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
155 set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1")
157 set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
158 set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1")
160 add_lldb_test_dependency(cxx)
163 if (TARGET compiler-rt OR "compiler-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
164 set(LLDB_HAS_COMPILER_RT ON)
165 add_lldb_test_dependency(compiler-rt)
168 if(APPLE AND NOT LLVM_TARGET_IS_CROSSCOMPILE_HOST)
169 # FIXME: Standalone builds should import the cxx target as well.
170 if(LLDB_BUILT_STANDALONE)
171 # For now check that the include directory exists.
172 set(cxx_dir "${LLDB_TEST_LIBCXX_ROOT_DIR}/include/c++")
173 if(EXISTS ${cxx_dir})
174 # These variables make sure the API tests can run against a custom
175 # build of libcxx even for standalone builds.
176 set(LLDB_HAS_LIBCXX ON)
177 set(LIBCXX_LIBRARY_DIR "${LLDB_TEST_LIBCXX_ROOT_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}")
178 set(LIBCXX_GENERATED_INCLUDE_DIR "${LLDB_TEST_LIBCXX_ROOT_DIR}/include/c++/v1")
181 "Couldn't find libcxx build in '${LLDB_TEST_LIBCXX_ROOT_DIR}'. To run the "
182 "test-suite for a standalone LLDB build please build libcxx and point "
183 "LLDB_TEST_LIBCXX_ROOT_DIR to it.")
186 # We require libcxx for the test suite, so if we aren't building it,
187 # provide a helpful error about how to resolve the situation.
188 if(NOT LLDB_HAS_LIBCXX)
190 "LLDB test suite requires libc++, but it is currently disabled. "
191 "Please add `libcxx` to `LLVM_ENABLE_RUNTIMES` or disable tests via "
192 "`LLDB_INCLUDE_TESTS=OFF`.")
198 if (LLDB_BUILT_STANDALONE)
199 set(LLVM_HOST_TRIPLE ${LLVM_TARGET_TRIPLE})
202 add_lldb_test_dependency(
218 add_lldb_test_dependency(lld)
220 # LLD is required to link test executables on Windows.
221 if (CMAKE_SYSTEM_NAME MATCHES "Windows")
222 message(WARNING "lld required to test LLDB on Windows")
226 if (CMAKE_SIZEOF_VOID_P EQUAL 8)
227 set(LLDB_IS_64_BITS 1)
230 # These values are not canonicalized within LLVM.
231 llvm_canonicalize_cmake_booleans(
237 LLVM_ENABLE_SHARED_LIBS
239 LLDB_TOOL_LLDB_SERVER_BUILD
240 LLDB_USE_SYSTEM_DEBUGSERVER
243 # Configure the individual test suites.
244 add_subdirectory(API)
245 add_subdirectory(Shell)
246 add_subdirectory(Unit)
248 # Configure the top level test suite.
249 configure_lit_site_cfg(
250 ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
251 ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
253 ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py)
255 add_lit_testsuite(check-lldb "Running lldb lit test suite"
256 ${CMAKE_CURRENT_BINARY_DIR}
261 set_target_properties(check-lldb PROPERTIES FOLDER "lldb tests")
263 if(LLDB_BUILT_STANDALONE)
264 # This has to happen *AFTER* add_lit_testsuite.
265 if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/llvm-lit)
266 # LLVM's make_paths_relative uses Python3_EXECUTABLE which isn't set in a
267 # standalone LLDB build.
268 set(Python3_EXECUTABLE ${Python3_EXECUTABLE})
269 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit ${CMAKE_CURRENT_BINARY_DIR}/llvm-lit)