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)
118 add_lldb_test_dependency(lldb-dap)
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 if (LLVM_ENABLE_RUNTIMES)
143 add_lldb_test_dependency(runtimes)
146 # Add dependencies if we test with the in-tree clang.
147 # This works with standalone builds as they import the clang target.
149 add_lldb_test_dependency(clang)
151 # TestFullLtoStepping depends on LTO, and only runs when the compiler is clang.
152 add_lldb_test_dependency(LTO)
154 if (TARGET libcxx OR ("libcxx" IN_LIST LLVM_ENABLE_RUNTIMES))
155 set(LLDB_HAS_LIBCXX ON)
156 if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
157 set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
158 set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")
159 set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1")
161 set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})
162 set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1")
166 if (TARGET compiler-rt OR "compiler-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
167 set(LLDB_HAS_COMPILER_RT ON)
170 if(APPLE AND NOT LLVM_TARGET_IS_CROSSCOMPILE_HOST)
171 # FIXME: Standalone builds should import the cxx target as well.
172 if(LLDB_BUILT_STANDALONE)
173 # For now check that the include directory exists.
174 set(cxx_dir "${LLDB_TEST_LIBCXX_ROOT_DIR}/include/c++")
175 if(EXISTS ${cxx_dir})
176 # These variables make sure the API tests can run against a custom
177 # build of libcxx even for standalone builds.
178 set(LLDB_HAS_LIBCXX ON)
179 set(LIBCXX_LIBRARY_DIR "${LLDB_TEST_LIBCXX_ROOT_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}")
180 set(LIBCXX_GENERATED_INCLUDE_DIR "${LLDB_TEST_LIBCXX_ROOT_DIR}/include/c++/v1")
183 "Couldn't find libcxx build in '${LLDB_TEST_LIBCXX_ROOT_DIR}'. To run the "
184 "test-suite for a standalone LLDB build please build libcxx and point "
185 "LLDB_TEST_LIBCXX_ROOT_DIR to it.")
188 # We require libcxx for the test suite, so if we aren't building it,
189 # provide a helpful error about how to resolve the situation.
190 if(NOT LLDB_HAS_LIBCXX)
192 "LLDB test suite requires libc++, but it is currently disabled. "
193 "Please add `libcxx` to `LLVM_ENABLE_RUNTIMES` or disable tests via "
194 "`LLDB_INCLUDE_TESTS=OFF`.")
200 if (LLDB_BUILT_STANDALONE)
201 set(LLVM_HOST_TRIPLE ${LLVM_TARGET_TRIPLE})
204 add_lldb_test_dependency(
220 add_lldb_test_dependency(lld)
222 # LLD is required to link test executables on Windows.
223 if (CMAKE_SYSTEM_NAME MATCHES "Windows")
224 message(WARNING "lld required to test LLDB on Windows")
228 if (CMAKE_SIZEOF_VOID_P EQUAL 8)
229 set(LLDB_IS_64_BITS 1)
232 # These values are not canonicalized within LLVM.
233 llvm_canonicalize_cmake_booleans(
239 LLVM_ENABLE_SHARED_LIBS
241 LLDB_TOOL_LLDB_SERVER_BUILD
242 LLDB_USE_SYSTEM_DEBUGSERVER
245 # Configure the individual test suites.
246 add_subdirectory(API)
247 add_subdirectory(Shell)
248 add_subdirectory(Unit)
250 # Configure the top level test suite.
251 configure_lit_site_cfg(
252 ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
253 ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
255 ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py)
257 add_lit_testsuite(check-lldb "Running lldb lit test suite"
258 ${CMAKE_CURRENT_BINARY_DIR}
263 set_target_properties(check-lldb PROPERTIES FOLDER "lldb tests")
265 if(LLDB_BUILT_STANDALONE)
266 # This has to happen *AFTER* add_lit_testsuite.
267 if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/llvm-lit)
268 # LLVM's make_paths_relative uses Python3_EXECUTABLE which isn't set in a
269 # standalone LLDB build.
270 set(Python3_EXECUTABLE ${Python3_EXECUTABLE})
271 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit ${CMAKE_CURRENT_BINARY_DIR}/llvm-lit)