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