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