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 # Lit uses psutil to do per-test timeouts.
15 set(useful_python_modules psutil)
18 # We no longer vendor pexpect and it is not used on Windows.
22 foreach(module ${useful_python_modules})
23 lldb_find_python_module(${module})
24 if (NOT PY_${module}_FOUND)
26 "Python module '${module}' not found. Please install it via pip or via "
27 "your operating system's package manager. Alternatively, disable "
28 "strict testing requirements with "
29 "`LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS=OFF`")
34 if(LLDB_BUILT_STANDALONE)
35 # In order to run check-lldb-* we need the correct map_config directives in
36 # llvm-lit. Because this is a standalone build, LLVM doesn't know about LLDB,
37 # and the lldb mappings are missing. We build our own llvm-lit, and tell LLVM
38 # to use the llvm-lit in the lldb build directory.
39 if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/llvm-lit)
40 set(LLVM_EXTERNAL_LIT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/llvm-lit)
44 # Configure the build directory.
45 # The .noindex suffix is a marker for Spotlight to never index the
46 # build directory. LLDB queries Spotlight to locate .dSYM bundles
47 # based on the UUID embedded in a binary, and because the UUID is a
48 # hash of filename and .text section, there *will* be conflicts inside
49 # the build directory.
50 set(LLDB_TEST_BUILD_DIRECTORY "${PROJECT_BINARY_DIR}/lldb-test-build.noindex" CACHE PATH "The build root for building tests.")
52 # Configure and create module cache directories.
53 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.")
54 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.")
55 file(MAKE_DIRECTORY ${LLDB_TEST_MODULE_CACHE_LLDB})
56 file(MAKE_DIRECTORY ${LLDB_TEST_MODULE_CACHE_CLANG})
58 # Windows and Linux have no built-in ObjC runtime. Turn this on in order to run tests with GNUstep.
59 option(LLDB_TEST_OBJC_GNUSTEP "Enable ObjC tests with GNUstep libobjc2 on non-Apple platforms" Off)
60 set(LLDB_TEST_OBJC_GNUSTEP_DIR "" CACHE PATH "Custom path to the GNUstep shared library")
62 if (LLDB_TEST_OBJC_GNUSTEP)
63 if (LLDB_TEST_OBJC_GNUSTEP_DIR)
64 set(GNUstepObjC_DIR ${LLDB_TEST_OBJC_GNUSTEP_DIR})
66 find_package(GNUstepObjC)
67 if (NOT GNUstepObjC_FOUND)
68 if (LLDB_TEST_OBJC_GNUSTEP_DIR)
69 message(FATAL_ERROR "Failed to find GNUstep libobjc2 in ${LLDB_TEST_OBJC_GNUSTEP_DIR}. "
70 "Please check LLDB_TEST_OBJC_GNUSTEP_DIR or turn off LLDB_TEST_OBJC_GNUSTEP.")
72 message(FATAL_ERROR "Failed to find GNUstep libobjc2. "
73 "Please set LLDB_TEST_OBJC_GNUSTEP_DIR or turn off LLDB_TEST_OBJC_GNUSTEP.")
76 set(LLDB_TEST_OBJC_GNUSTEP_DIR ${GNUstepObjC_DIR})
77 elseif (LLDB_TEST_OBJC_GNUSTEP_DIR)
78 message(STATUS "Reset LLDB_TEST_OBJC_GNUSTEP_DIR since LLDB_TEST_OBJC_GNUSTEP is off")
79 set(LLDB_TEST_OBJC_GNUSTEP_DIR "" CACHE PATH "Custom path to the GNUstep shared library" FORCE)
82 # LLVM_BUILD_MODE is used in lit.site.cfg
83 if (CMAKE_CFG_INTDIR STREQUAL ".")
84 set(LLVM_BUILD_MODE ".")
86 set(LLVM_BUILD_MODE "%(build_mode)s")
89 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLDB_LIBS_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
90 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLDB_TOOLS_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
92 # Create a custom target to track test dependencies.
93 add_custom_target(lldb-test-depends)
94 set_target_properties(lldb-test-depends PROPERTIES FOLDER "LLDB/Tests")
96 # Create an alias for the legacy name of lldb-test-depends
97 add_custom_target(lldb-test-deps)
98 set_target_properties(lldb-test-deps PROPERTIES FOLDER "LLDB/Tests")
99 add_dependencies(lldb-test-deps lldb-test-depends)
101 function(add_lldb_test_dependency)
102 foreach(dependency ${ARGN})
103 add_dependencies(lldb-test-depends ${dependency})
105 endfunction(add_lldb_test_dependency)
107 # lldb itself and lldb-test is an hard dependency for the testsuites.
108 add_lldb_test_dependency(lldb)
109 add_lldb_test_dependency(lldb-test)
111 # On Darwin, darwin-debug is an hard dependency for the testsuites.
112 if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
113 add_lldb_test_dependency(darwin-debug)
116 if(TARGET debugserver)
117 add_lldb_test_dependency(debugserver)
119 if(TARGET lldb-server)
120 add_lldb_test_dependency(lldb-server)
124 add_lldb_test_dependency(lldb-dap)
128 add_lldb_test_dependency(liblldb)
131 if(TARGET lldb-framework)
132 add_lldb_test_dependency(lldb-framework)
135 # Add dependencies that are not exported targets when building standalone.
136 if(NOT LLDB_BUILT_STANDALONE)
137 add_lldb_test_dependency(
148 if (LLVM_ENABLE_RUNTIMES)
149 add_lldb_test_dependency(runtimes)
152 # Add dependencies if we test with the in-tree clang.
153 # This works with standalone builds as they import the clang target.
155 add_lldb_test_dependency(clang)
157 # TestFullLtoStepping depends on LTO, and only runs when the compiler is clang.
158 add_lldb_test_dependency(LTO)
160 if (TARGET libcxx OR ("libcxx" IN_LIST LLVM_ENABLE_RUNTIMES))
161 set(LLDB_HAS_LIBCXX ON)
162 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
163 set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
164 set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
165 set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1")
167 set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
168 set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1")
172 if (TARGET compiler-rt OR "compiler-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
173 set(LLDB_HAS_COMPILER_RT ON)
176 if(APPLE AND NOT LLVM_TARGET_IS_CROSSCOMPILE_HOST)
177 # FIXME: Standalone builds should import the cxx target as well.
178 if(LLDB_BUILT_STANDALONE)
179 # For now check that the include directory exists.
180 set(cxx_dir "${LLDB_TEST_LIBCXX_ROOT_DIR}/include/c++")
181 if(EXISTS ${cxx_dir})
182 # These variables make sure the API tests can run against a custom
183 # build of libcxx even for standalone builds.
184 set(LLDB_HAS_LIBCXX ON)
185 set(LIBCXX_LIBRARY_DIR "${LLDB_TEST_LIBCXX_ROOT_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}")
186 set(LIBCXX_GENERATED_INCLUDE_DIR "${LLDB_TEST_LIBCXX_ROOT_DIR}/include/c++/v1")
189 "Couldn't find libcxx build in '${LLDB_TEST_LIBCXX_ROOT_DIR}'. To run the "
190 "test-suite for a standalone LLDB build please build libcxx and point "
191 "LLDB_TEST_LIBCXX_ROOT_DIR to it.")
194 # We require libcxx for the test suite, so if we aren't building it,
195 # provide a helpful error about how to resolve the situation.
196 if(NOT LLDB_HAS_LIBCXX)
198 "LLDB test suite requires libc++, but it is currently disabled. "
199 "Please add `libcxx` to `LLVM_ENABLE_RUNTIMES` or disable tests via "
200 "`LLDB_INCLUDE_TESTS=OFF`.")
206 if (LLDB_BUILT_STANDALONE)
207 set(LLVM_HOST_TRIPLE ${LLVM_TARGET_TRIPLE})
210 add_lldb_test_dependency(
226 add_lldb_test_dependency(lld)
228 # LLD is required to link test executables on Windows.
229 if (CMAKE_SYSTEM_NAME MATCHES "Windows")
230 message(WARNING "lld required to test LLDB on Windows")
234 if (CMAKE_SIZEOF_VOID_P EQUAL 8)
235 set(LLDB_IS_64_BITS 1)
238 # These values are not canonicalized within LLVM.
239 llvm_canonicalize_cmake_booleans(
245 LLVM_ENABLE_SHARED_LIBS
247 LLDB_TOOL_LLDB_SERVER_BUILD
248 LLDB_USE_SYSTEM_DEBUGSERVER
251 # Configure the individual test suites.
252 add_subdirectory(API)
253 add_subdirectory(Shell)
254 add_subdirectory(Unit)
256 # Configure the top level test suite.
257 configure_lit_site_cfg(
258 ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
259 ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
261 ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py)
263 add_lit_testsuite(check-lldb "Running lldb lit test suite"
264 ${CMAKE_CURRENT_BINARY_DIR}
270 if(LLDB_BUILT_STANDALONE)
271 # This has to happen *AFTER* add_lit_testsuite.
272 if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/llvm-lit)
273 # LLVM's make_paths_relative uses Python3_EXECUTABLE which isn't set in a
274 # standalone LLDB build.
275 set(Python3_EXECUTABLE ${Python3_EXECUTABLE})
276 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit ${CMAKE_CURRENT_BINARY_DIR}/llvm-lit)