xref: /llvm-project/lldb/test/API/CMakeLists.txt (revision b4c1f0cc492f1597397dcf0b06b816fa0a2135f1)
1add_custom_target(lldb-api-test-deps)
2set_target_properties(lldb-api-test-deps PROPERTIES FOLDER "LLDB/Tests")
3add_dependencies(lldb-api-test-deps lldb-test-depends)
4
5add_lit_testsuites(LLDB-API
6  ${CMAKE_CURRENT_SOURCE_DIR}
7  DEPENDS lldb-api-test-deps)
8
9function(add_python_test_target name test_script args comment)
10  set(PYTHON_TEST_COMMAND
11    ${Python3_EXECUTABLE}
12    ${test_script}
13    ${args}
14    )
15
16  add_custom_target(${name}
17    COMMAND ${PYTHON_TEST_COMMAND} ${ARG_DEFAULT_ARGS}
18    COMMENT "${comment}"
19    USES_TERMINAL
20    )
21  add_dependencies(${name} lldb-test-depends)
22endfunction()
23
24# The default architecture with which to compile test executables is the
25# default LLVM target architecture, which itself defaults to the host
26# architecture.
27if(NOT LLDB_DEFAULT_TEST_ARCH)
28  string(REGEX MATCH "^[^-]*" LLDB_DEFAULT_TEST_ARCH ${LLVM_HOST_TRIPLE})
29endif ()
30
31# Allow the user to override the default by setting LLDB_TEST_ARCH
32set(LLDB_TEST_ARCH
33  ${LLDB_DEFAULT_TEST_ARCH}
34  CACHE STRING "Specify the architecture to run LLDB tests as (x86|x64).  Determines whether tests are compiled with -m32 or -m64")
35
36# Users can override LLDB_TEST_USER_ARGS to specify arbitrary arguments to pass to the script
37set(LLDB_TEST_USER_ARGS
38  ""
39  CACHE STRING "Specify additional arguments to pass to test runner. Separate \
40items with \";\". For example: '-C;gcc;-C;clang;-A;i386;-A;x86_64'")
41
42set(LLDB_TEST_COMMON_ARGS_VAR
43  -u CXXFLAGS
44  -u CFLAGS
45  )
46
47# Set the path to the default lldb test executable.
48set(LLDB_DEFAULT_TEST_EXECUTABLE "${LLVM_RUNTIME_OUTPUT_INTDIR}/lldb${CMAKE_EXECUTABLE_SUFFIX}")
49
50set(LLDB_DEFAULT_TEST_DSYMUTIL "${LLVM_TOOLS_BINARY_DIR}/dsymutil${CMAKE_EXECUTABLE_SUFFIX}")
51
52if(LLDB_TEST_MAKE)
53  set(LLDB_DEFAULT_TEST_MAKE ${LLDB_TEST_MAKE})
54else()
55  # Prefer gmake as it will be a version of GNU make. 'make' could be GNU compatible or not.
56  set(MAKE_NAMES "gmake" "make")
57  find_program(LLDB_DEFAULT_TEST_MAKE NAMES ${MAKE_NAMES})
58  if(LLDB_DEFAULT_TEST_MAKE)
59    message(STATUS "Found make: ${LLDB_DEFAULT_TEST_MAKE}")
60    execute_process(COMMAND ${LLDB_DEFAULT_TEST_MAKE} --version OUTPUT_VARIABLE MAKE_VERSION
61           ERROR_QUIET)
62    if(NOT MAKE_VERSION MATCHES "^GNU Make")
63      message(WARNING "'make' tool ${LLDB_DEFAULT_TEST_MAKE} may not be GNU make compatible. "
64             "Some tests may fail to build. Provide a GNU compatible 'make' tool by setting "
65             "LLDB_TEST_MAKE.")
66    endif()
67  else()
68    list(JOIN "${MAKE_NAMES}" " " MAKE_NAMES_SPACES)
69    string(REPLACE ";" " " MAKE_NAMES_SPACES "${MAKE_NAMES}")
70    message(STATUS "Did not find one of: ${MAKE_NAMES_SPACES}")
71    message(WARNING
72          "Many LLDB API tests require a 'make' tool. Please provide it in Path "
73          "or pass via LLDB_TEST_MAKE.")
74  endif()
75endif()
76
77if (TARGET clang)
78  set(LLDB_DEFAULT_TEST_COMPILER "${LLVM_TOOLS_BINARY_DIR}/clang${CMAKE_EXECUTABLE_SUFFIX}")
79else()
80  set(LLDB_DEFAULT_TEST_COMPILER "")
81endif()
82
83set(LLDB_TEST_EXECUTABLE "${LLDB_DEFAULT_TEST_EXECUTABLE}" CACHE PATH "lldb executable used for testing")
84set(LLDB_TEST_COMPILER "${LLDB_DEFAULT_TEST_COMPILER}" CACHE PATH "C Compiler to use for building LLDB test inferiors")
85set(LLDB_TEST_DSYMUTIL "${LLDB_DEFAULT_TEST_DSYMUTIL}" CACHE PATH "dsymutil used for generating dSYM bundles")
86set(LLDB_TEST_MAKE "${LLDB_DEFAULT_TEST_MAKE}" CACHE PATH "make tool used for building test executables")
87
88if ("${LLDB_TEST_COMPILER}" STREQUAL "")
89  message(FATAL_ERROR "LLDB test compiler not specified. Tests will not run.")
90endif()
91
92if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
93  set(LLDB_TEST_DEBUG_TEST_CRASHES
94    0
95    CACHE BOOL "(Windows only) Enables debugging of tests in the test suite by showing the crash dialog when lldb crashes")
96
97  set(LLDB_TEST_HIDE_CONSOLE_WINDOWS
98    1
99    CACHE BOOL "(Windows only) Hides the console window for an inferior when it is launched through the test suite")
100
101  if (LLDB_TEST_DEBUG_TEST_CRASHES)
102    set(LLDB_TEST_COMMON_ARGS_VAR ${LLDB_TEST_COMMON_ARGS_VAR} --enable-crash-dialog)
103  endif()
104
105  if (NOT LLDB_TEST_HIDE_CONSOLE_WINDOWS)
106    set(LLDB_TEST_COMMON_ARGS_VAR ${LLDB_TEST_COMMON_ARGS_VAR} --show-inferior-console)
107  endif()
108endif()
109
110if (NOT "${LLDB_LIT_TOOLS_DIR}" STREQUAL "")
111  if (NOT EXISTS "${LLDB_LIT_TOOLS_DIR}")
112    message(WARNING "LLDB_LIT_TOOLS_DIR ${LLDB_LIT_TOOLS_DIR} does not exist.")
113  endif()
114endif()
115
116if(CMAKE_HOST_APPLE)
117  if(LLDB_BUILD_FRAMEWORK)
118    set(LLDB_FRAMEWORK_DIR ${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework)
119  endif()
120
121  if(LLDB_USE_SYSTEM_DEBUGSERVER)
122    lldb_find_system_debugserver(system_debugserver_path)
123    if(LLDB_BUILD_FRAMEWORK)
124      add_custom_target(debugserver
125        COMMAND ${CMAKE_COMMAND} -E copy_if_different
126        ${system_debugserver_path} $<TARGET_FILE_DIR:liblldb>/Resources
127        COMMENT "Copying the system debugserver to LLDB.framework's resource directory for testing.")
128    else()
129      add_custom_target(debugserver
130        COMMAND ${CMAKE_COMMAND} -E copy_if_different
131        ${system_debugserver_path} ${LLVM_RUNTIME_OUTPUT_INTDIR}
132        COMMENT "Copying the system debugserver to LLDB's binaries directory for testing.")
133    endif()
134    message(STATUS "LLDB tests use out-of-tree debugserver: ${system_debugserver_path}")
135    list(APPEND LLDB_TEST_COMMON_ARGS_VAR --out-of-tree-debugserver)
136    add_lldb_test_dependency(debugserver)
137  else()
138    message(STATUS "LLDB tests use just-built debug server")
139  endif()
140endif()
141
142set(dotest_args_replacement ${LLVM_BUILD_MODE})
143
144if(LLDB_BUILT_STANDALONE)
145  # In paths to our build-tree, replace CMAKE_CFG_INTDIR with our configuration name placeholder.
146  string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} config_runtime_output_dir ${LLVM_RUNTIME_OUTPUT_INTDIR})
147  string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_COMMON_ARGS_VAR "${LLDB_TEST_COMMON_ARGS_VAR}")
148  string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_USER_ARGS "${LLDB_TEST_USER_ARGS}")
149  string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_SOURCE_DIR "${LLDB_SOURCE_DIR}")
150  string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_FRAMEWORK_DIR "${LLDB_FRAMEWORK_DIR}")
151  string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_BUILD_DIRECTORY "${LLDB_TEST_BUILD_DIRECTORY}")
152  string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_EXECUTABLE "${LLDB_TEST_EXECUTABLE}")
153  string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_COMPILER "${LLDB_TEST_COMPILER}")
154  string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_DSYMUTIL "${LLDB_TEST_DSYMUTIL}")
155
156  # Remaining ones must be paths to the provided LLVM build-tree.
157  if(LLVM_CONFIGURATION_TYPES)
158    # LLDB uses single-config; LLVM multi-config; pick one and prefer Release types.
159    # Otherwise, if both use multi-config the default is fine.
160    if(NOT CMAKE_CONFIGURATION_TYPES)
161      if(RelWithDebInfo IN_LIST LLVM_CONFIGURATION_TYPES)
162        set(dotest_args_replacement RelWithDebInfo)
163      elseif(Release IN_LIST LLVM_CONFIGURATION_TYPES)
164        set(dotest_args_replacement Release)
165      else()
166        list(GET LLVM_CONFIGURATION_TYPES 0 dotest_args_replacement)
167      endif()
168    endif()
169  else()
170    # Common case: LLVM used a single-configuration generator like Ninja.
171    set(dotest_args_replacement ".")
172  endif()
173endif()
174
175string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_COMMON_ARGS_VAR "${LLDB_TEST_COMMON_ARGS_VAR}")
176string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_USER_ARGS "${LLDB_TEST_USER_ARGS}")
177string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_SOURCE_DIR "${LLDB_SOURCE_DIR}")
178string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_BUILD_DIRECTORY "${LLDB_TEST_BUILD_DIRECTORY}")
179string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_EXECUTABLE "${LLDB_TEST_EXECUTABLE}")
180string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_COMPILER "${LLDB_TEST_COMPILER}")
181string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_DSYMUTIL "${LLDB_TEST_DSYMUTIL}")
182
183set(LLDB_TEST_COMMON_ARGS ${LLDB_TEST_COMMON_ARGS_VAR} CACHE INTERNAL STRING)
184
185configure_lit_site_cfg(
186  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
187  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
188  MAIN_CONFIG
189  ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py)
190
191# Targets for running the test suite on the different Apple simulators.
192add_lit_testsuite(check-lldb-simulator-ios
193  "Running lldb test suite on the iOS simulator"
194  ${CMAKE_CURRENT_BINARY_DIR}
195  PARAMS "lldb-run-with-simulator=ios"
196  EXCLUDE_FROM_CHECK_ALL
197  DEPENDS lldb-api-test-deps)
198
199add_lit_testsuite(check-lldb-simulator-watchos
200  "Running lldb test suite on the watchOS simulator"
201  ${CMAKE_CURRENT_BINARY_DIR}
202  PARAMS "lldb-run-with-simulator=watchos"
203  EXCLUDE_FROM_CHECK_ALL
204  DEPENDS lldb-api-test-deps)
205
206add_lit_testsuite(check-lldb-simulator-tvos
207  "Running lldb test suite on the tvOS simulator"
208  ${CMAKE_CURRENT_BINARY_DIR}
209  PARAMS "lldb-run-with-simulator=tvos"
210  EXCLUDE_FROM_CHECK_ALL
211  DEPENDS lldb-api-test-deps)
212
213add_lit_testsuite(check-lldb-api "Running lldb api test suite"
214  ${CMAKE_CURRENT_BINARY_DIR}
215  EXCLUDE_FROM_CHECK_ALL
216  DEPENDS lldb-api-test-deps)
217