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 -s 40 ${CMAKE_BINARY_DIR}/lldb-test-traces 41 -S nm 42 -u CXXFLAGS 43 -u CFLAGS 44 ) 45 46# Set the path to the default lldb test executable. 47set(LLDB_DEFAULT_TEST_EXECUTABLE "${LLVM_RUNTIME_OUTPUT_INTDIR}/lldb${CMAKE_EXECUTABLE_SUFFIX}") 48 49# Set the paths to default llvm tools. 50set(LLDB_DEFAULT_TEST_DSYMUTIL "${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/dsymutil${CMAKE_EXECUTABLE_SUFFIX}") 51set(LLDB_DEFAULT_TEST_FILECHECK "${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/FileCheck${CMAKE_EXECUTABLE_SUFFIX}") 52set(LLDB_DEFAULT_TEST_YAML2OBJ "${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/yaml2obj${CMAKE_EXECUTABLE_SUFFIX}") 53 54if (TARGET clang) 55 set(LLDB_DEFAULT_TEST_COMPILER "${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/clang${CMAKE_EXECUTABLE_SUFFIX}") 56else() 57 set(LLDB_DEFAULT_TEST_COMPILER "") 58endif() 59 60set(LLDB_TEST_EXECUTABLE "${LLDB_DEFAULT_TEST_EXECUTABLE}" CACHE PATH "lldb executable used for testing") 61set(LLDB_TEST_COMPILER "${LLDB_DEFAULT_TEST_COMPILER}" CACHE PATH "C Compiler to use for building LLDB test inferiors") 62set(LLDB_TEST_DSYMUTIL "${LLDB_DEFAULT_TEST_DSYMUTIL}" CACHE PATH "dsymutil used for generating dSYM bundles") 63set(LLDB_TEST_FILECHECK "${LLDB_DEFAULT_TEST_FILECHECK}" CACHE PATH "FileCheck used for testing purposes") 64set(LLDB_TEST_YAML2OBJ "${LLDB_DEFAULT_TEST_YAML2OBJ}" CACHE PATH "yaml2obj used for testing purposes") 65 66if ("${LLDB_TEST_COMPILER}" STREQUAL "") 67 message(FATAL_ERROR "LLDB test compiler not specified. Tests will not run.") 68endif() 69 70if ( CMAKE_SYSTEM_NAME MATCHES "Windows" ) 71 set(LLDB_TEST_DEBUG_TEST_CRASHES 72 0 73 CACHE BOOL "(Windows only) Enables debugging of tests in the test suite by showing the crash dialog when lldb crashes") 74 75 set(LLDB_TEST_HIDE_CONSOLE_WINDOWS 76 1 77 CACHE BOOL "(Windows only) Hides the console window for an inferior when it is launched through the test suite") 78 79 if (LLDB_TEST_DEBUG_TEST_CRASHES) 80 set(LLDB_TEST_COMMON_ARGS ${LLDB_TEST_COMMON_ARGS} --enable-crash-dialog) 81 endif() 82 83 if (NOT LLDB_TEST_HIDE_CONSOLE_WINDOWS) 84 set(LLDB_TEST_COMMON_ARGS ${LLDB_TEST_COMMON_ARGS} --show-inferior-console) 85 endif() 86endif() 87 88if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows|Darwin") 89 list(APPEND LLDB_TEST_COMMON_ARGS 90 --env ARCHIVER=${CMAKE_AR} --env OBJCOPY=${CMAKE_OBJCOPY}) 91endif() 92 93if (NOT "${LLDB_LIT_TOOLS_DIR}" STREQUAL "") 94 if (NOT EXISTS "${LLDB_LIT_TOOLS_DIR}") 95 message(WARNING "LLDB_LIT_TOOLS_DIR ${LLDB_LIT_TOOLS_DIR} does not exist.") 96 endif() 97endif() 98 99if(CMAKE_HOST_APPLE) 100 if(LLDB_BUILD_FRAMEWORK) 101 list(APPEND LLDB_TEST_COMMON_ARGS --framework ${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework) 102 endif() 103 104 # Use the same identity for testing 105 get_property(code_sign_identity_used GLOBAL PROPERTY LLDB_DEBUGSERVER_CODESIGN_IDENTITY) 106 if(code_sign_identity_used) 107 list(APPEND LLDB_TEST_COMMON_ARGS --codesign-identity "${code_sign_identity_used}") 108 endif() 109 110 if(LLDB_USE_SYSTEM_DEBUGSERVER) 111 lldb_find_system_debugserver(system_debugserver_path) 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 message(STATUS "LLDB tests use out-of-tree debugserver: ${system_debugserver_path}") 117 list(APPEND LLDB_TEST_COMMON_ARGS --out-of-tree-debugserver) 118 add_lldb_test_dependency(debugserver) 119 elseif(TARGET debugserver) 120 set(debugserver_path ${LLVM_RUNTIME_OUTPUT_INTDIR}/debugserver) 121 message(STATUS "LLDB Tests use just-built debugserver: ${debugserver_path}") 122 list(APPEND LLDB_TEST_COMMON_ARGS --server ${debugserver_path}) 123 add_lldb_test_dependency(debugserver) 124 elseif(TARGET lldb-server) 125 set(lldb_server_path ${LLVM_RUNTIME_OUTPUT_INTDIR}/lldb-server) 126 message(STATUS "LLDB Tests use just-built lldb-server: ${lldb_server_path}") 127 list(APPEND LLDB_TEST_COMMON_ARGS --server ${lldb_server_path}) 128 add_lldb_test_dependency(lldb-server) 129 else() 130 message(WARNING "LLDB Tests enabled, but no server available") 131 endif() 132endif() 133 134set(LLDB_DOTEST_ARGS ${LLDB_TEST_COMMON_ARGS};${LLDB_TEST_USER_ARGS} CACHE INTERNAL STRING) 135set(dotest_args_replacement ${LLVM_BUILD_MODE}) 136 137if(LLDB_BUILT_STANDALONE) 138 # In paths to our build-tree, replace CMAKE_CFG_INTDIR with our configuration name placeholder. 139 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} config_runtime_output_dir ${LLVM_RUNTIME_OUTPUT_INTDIR}) 140 string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_DOTEST_ARGS "${LLDB_DOTEST_ARGS}") 141 string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_SOURCE_DIR "${LLDB_SOURCE_DIR}") 142 string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_BUILD_DIRECTORY "${LLDB_TEST_BUILD_DIRECTORY}") 143 string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_EXECUTABLE "${LLDB_TEST_EXECUTABLE}") 144 string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_COMPILER "${LLDB_TEST_COMPILER}") 145 string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_DSYMUTIL "${LLDB_TEST_DSYMUTIL}") 146 string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_FILECHECK "${LLDB_TEST_FILECHECK}") 147 string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_YAML2OBJ "${LLDB_TEST_YAML2OBJ}") 148 149 # Remaining ones must be paths to the provided LLVM build-tree. 150 if(LLVM_CONFIGURATION_TYPES) 151 # LLDB uses single-config; LLVM multi-config; pick one and prefer Release types. 152 # Otherwise, if both use multi-config the default is fine. 153 if(NOT CMAKE_CONFIGURATION_TYPES) 154 if(RelWithDebInfo IN_LIST LLVM_CONFIGURATION_TYPES) 155 set(dotest_args_replacement RelWithDebInfo) 156 elseif(Release IN_LIST LLVM_CONFIGURATION_TYPES) 157 set(dotest_args_replacement Release) 158 else() 159 list(GET LLVM_CONFIGURATION_TYPES 0 dotest_args_replacement) 160 endif() 161 endif() 162 else() 163 # Common case: LLVM used a single-configuration generator like Ninja. 164 set(dotest_args_replacement ".") 165 endif() 166endif() 167 168string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_DOTEST_ARGS "${LLDB_DOTEST_ARGS}") 169string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_SOURCE_DIR "${LLDB_SOURCE_DIR}") 170string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_BUILD_DIRECTORY "${LLDB_TEST_BUILD_DIRECTORY}") 171string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_EXECUTABLE "${LLDB_TEST_EXECUTABLE}") 172string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_COMPILER "${LLDB_TEST_COMPILER}") 173string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_DSYMUTIL "${LLDB_TEST_DSYMUTIL}") 174string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_FILECHECK "${LLDB_TEST_FILECHECK}") 175string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_YAML2OBJ "${LLDB_TEST_YAML2OBJ}") 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