brintos

brintos / llvm-project-archived public Read only

0
0
Text · 10.1 KiB · 818dff5 Raw
294 lines · plain
1# Test runner infrastructure for LLDB. This configures the LLDB test trees2# 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's4# not present.5if (NOT DEFINED Python3_EXECUTABLE)6  message(SEND_ERROR7    "LLDB test suite requires a Python3 interpreter but none "8    "was found. Please install Python3 or disable tests with "9    "`LLDB_INCLUDE_TESTS=OFF`.")10endif()11 12if(LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS)13  message(STATUS "Enforcing strict test requirements for LLDB")14  # Lit uses psutil to do per-test timeouts.15  set(useful_python_modules psutil packaging)16 17  if(NOT WIN32)18    # We no longer vendor pexpect and it is not used on Windows.19    list(APPEND pexpect)20  endif()21 22  foreach(module ${useful_python_modules})23    lldb_find_python_module(${module})24    if (NOT PY_${module}_FOUND)25      message(SEND_ERROR26        "Python module '${module}' not found. Please install it via pip or via "27        "your operating system's package manager. Alternatively, disable "28        "strict testing requirements with "29        "`LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS=OFF`")30    endif()31  endforeach()32endif()33 34if(LLDB_BUILT_STANDALONE)35  # In order to run check-lldb-* we need the correct map_config directives in36  # llvm-lit. Because this is a standalone build, LLVM doesn't know about LLDB,37  # and the lldb mappings are missing. We build our own llvm-lit, and tell LLVM38  # to use the llvm-lit in the lldb build directory.39  if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/llvm-lit)40    set(LLVM_EXTERNAL_LIT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/llvm-lit)41  endif()42endif()43 44# Configure the build directory.45# The .noindex suffix is a marker for Spotlight to never index the46# build directory.  LLDB queries Spotlight to locate .dSYM bundles47# based on the UUID embedded in a binary, and because the UUID is a48# hash of filename and .text section, there *will* be conflicts inside49# the build directory.50set(LLDB_TEST_BUILD_DIRECTORY "${PROJECT_BINARY_DIR}/lldb-test-build.noindex" CACHE PATH "The build root for building tests.")51 52# Configure and create module cache directories.53set(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.")54set(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.")55file(MAKE_DIRECTORY ${LLDB_TEST_MODULE_CACHE_LLDB})56file(MAKE_DIRECTORY ${LLDB_TEST_MODULE_CACHE_CLANG})57 58# Windows and Linux have no built-in ObjC runtime. Turn this on in order to run tests with GNUstep.59option(LLDB_TEST_OBJC_GNUSTEP "Enable ObjC tests with GNUstep libobjc2 on non-Apple platforms" Off)60set(LLDB_TEST_OBJC_GNUSTEP_DIR "" CACHE PATH "Custom path to the GNUstep shared library")61 62if (LLDB_TEST_OBJC_GNUSTEP)63  if (LLDB_TEST_OBJC_GNUSTEP_DIR)64    set(GNUstepObjC_DIR ${LLDB_TEST_OBJC_GNUSTEP_DIR})65  endif()66  find_package(GNUstepObjC)67  if (NOT GNUstepObjC_FOUND)68    if (LLDB_TEST_OBJC_GNUSTEP_DIR)69      message(SEND_ERROR "Failed to find GNUstep libobjc2 in ${LLDB_TEST_OBJC_GNUSTEP_DIR}. "70                          "Please check LLDB_TEST_OBJC_GNUSTEP_DIR or turn off LLDB_TEST_OBJC_GNUSTEP.")71    else()72      message(SEND_ERROR "Failed to find GNUstep libobjc2. "73                          "Please set LLDB_TEST_OBJC_GNUSTEP_DIR or turn off LLDB_TEST_OBJC_GNUSTEP.")74    endif()75  endif()76  set(LLDB_TEST_OBJC_GNUSTEP_DIR ${GNUstepObjC_DIR})77elseif (LLDB_TEST_OBJC_GNUSTEP_DIR)78  message(STATUS "Reset LLDB_TEST_OBJC_GNUSTEP_DIR since LLDB_TEST_OBJC_GNUSTEP is off")79  set(LLDB_TEST_OBJC_GNUSTEP_DIR "" CACHE PATH "Custom path to the GNUstep shared library" FORCE)80endif()81 82# LLVM_BUILD_MODE is used in lit.site.cfg83if (CMAKE_CFG_INTDIR STREQUAL ".")84  set(LLVM_BUILD_MODE ".")85else ()86  set(LLVM_BUILD_MODE "%(build_mode)s")87endif ()88 89string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLDB_LIBS_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})90string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLDB_TOOLS_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR})91 92# Create a custom target to track test dependencies.93add_custom_target(lldb-test-depends)94set_target_properties(lldb-test-depends PROPERTIES FOLDER "LLDB/Tests")95 96# Create an alias for the legacy name of lldb-test-depends97add_custom_target(lldb-test-deps)98set_target_properties(lldb-test-deps PROPERTIES FOLDER "LLDB/Tests")99add_dependencies(lldb-test-deps lldb-test-depends)100 101function(add_lldb_test_dependency)102  foreach(dependency ${ARGN})103    add_dependencies(lldb-test-depends ${dependency})104  endforeach()105endfunction(add_lldb_test_dependency)106 107# lldb itself and lldb-test is an hard dependency for the testsuites.108add_lldb_test_dependency(lldb)109add_lldb_test_dependency(lldb-test)110 111# On Darwin, darwin-debug is an hard dependency for the testsuites.112if (CMAKE_SYSTEM_NAME MATCHES "Darwin")113  add_lldb_test_dependency(darwin-debug)114endif()115 116if(TARGET debugserver)117  add_lldb_test_dependency(debugserver)118endif()119if(TARGET lldb-server)120  add_lldb_test_dependency(lldb-server)121endif()122 123if(TARGET lldb-dap)124  add_lldb_test_dependency(lldb-dap)125endif()126 127if(TARGET liblldb)128  add_lldb_test_dependency(liblldb)129endif()130 131if(TARGET lldb-framework)132  add_lldb_test_dependency(lldb-framework)133endif()134 135if (LLDB_CAN_USE_LLDB_RPC_SERVER)136  add_lldb_test_dependency(lldb-rpc-generate-sources)137endif()138 139# Add dependencies that are not exported targets when building standalone.140if(NOT LLDB_BUILT_STANDALONE)141  add_lldb_test_dependency(142    FileCheck143    count144    dsymutil145    llvm-strip146    not147    split-file148    yaml2obj149  )150endif()151 152if (LLVM_ENABLE_RUNTIMES)153  add_lldb_test_dependency(runtimes)154endif()155 156# Add dependencies if we test with the in-tree clang.157# This works with standalone builds as they import the clang target.158if(TARGET clang)159  add_lldb_test_dependency(clang)160 161  # TestFullLtoStepping depends on LTO, and only runs when the compiler is clang.162  add_lldb_test_dependency(LTO)163 164  if (TARGET libcxx OR ("libcxx" IN_LIST LLVM_ENABLE_RUNTIMES))165    set(LLDB_HAS_LIBCXX ON)166    if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)167      set(LIBCXX_TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE})168      if(LIBCXX_LIBDIR_SUBDIR)169        string(APPEND LIBCXX_TARGET_SUBDIR /${LIBCXX_LIBDIR_SUBDIR})170      endif()171      cmake_path(NORMAL_PATH LIBCXX_TARGET_SUBDIR)172      set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LIBCXX_TARGET_SUBDIR})173      set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1")174      set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LIBCXX_TARGET_SUBDIR}/c++/v1")175    else()176      set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX})177      set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1")178    endif()179  endif()180 181  if (TARGET compiler-rt OR "compiler-rt" IN_LIST LLVM_ENABLE_RUNTIMES)182    set(LLDB_HAS_COMPILER_RT ON)183  endif()184 185  if(APPLE AND NOT LLVM_TARGET_IS_CROSSCOMPILE_HOST)186    # FIXME: Standalone builds should import the cxx target as well.187    if(LLDB_BUILT_STANDALONE)188      # For now check that the include directory exists.189      set(cxx_dir "${LLDB_TEST_LIBCXX_ROOT_DIR}/include/c++")190      if(EXISTS ${cxx_dir})191        # These variables make sure the API tests can run against a custom192        # build of libcxx even for standalone builds.193        set(LLDB_HAS_LIBCXX ON)194        set(LIBCXX_LIBRARY_DIR "${LLDB_TEST_LIBCXX_ROOT_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}")195        set(LIBCXX_GENERATED_INCLUDE_DIR "${LLDB_TEST_LIBCXX_ROOT_DIR}/include/c++/v1")196      else()197        message(SEND_ERROR198            "Couldn't find libcxx build in '${LLDB_TEST_LIBCXX_ROOT_DIR}'. To run the "199            "test-suite for a standalone LLDB build please build libcxx and point "200            "LLDB_TEST_LIBCXX_ROOT_DIR to it.")201      endif()202    else()203      # We require libcxx for the test suite, so if we aren't building it,204      # provide a helpful error about how to resolve the situation.205      if(LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS AND NOT LLDB_HAS_LIBCXX)206        message(SEND_ERROR207          "LLDB test suite requires libc++, but it is currently disabled. "208          "Please add `libcxx` to `LLVM_ENABLE_RUNTIMES` or disable tests via "209          "`LLDB_INCLUDE_TESTS=OFF`.")210      endif()211    endif()212  endif()213endif()214 215if (LLDB_BUILT_STANDALONE)216  set(LLVM_HOST_TRIPLE ${LLVM_TARGET_TRIPLE})217endif()218 219add_lldb_test_dependency(220  lit-cpuid221  llc222  lli223  llvm-config224  llvm-dwarfdump225  llvm-dwp226  llvm-nm227  llvm-mc228  llvm-objcopy229  llvm-pdbutil230  llvm-readobj231  llvm-ar232  yaml2macho-core233  )234 235if(TARGET lld)236  add_lldb_test_dependency(lld)237else()238  # LLD is required to link test executables on Windows.239  if (CMAKE_SYSTEM_NAME MATCHES "Windows")240    message(WARNING "lld required to test LLDB on Windows")241  endif()242endif()243 244if (CMAKE_SIZEOF_VOID_P EQUAL 8)245  set(LLDB_IS_64_BITS 1)246endif()247 248set(LLDB_TEST_SHELL_DISABLE_REMOTE OFF CACHE BOOL "Disable remote Shell tests execution")249 250# These values are not canonicalized within LLVM.251llvm_canonicalize_cmake_booleans(252  LLDB_BUILD_INTEL_PT253  LLDB_ENABLE_PYTHON254  LLDB_ENABLE_LUA255  LLDB_ENABLE_LZMA256  LLVM_ENABLE_ZLIB257  LLVM_ENABLE_SHARED_LIBS258  LLVM_ENABLE_DIA_SDK259  LLDB_HAS_LIBCXX260  LLDB_TEST_SHELL_DISABLE_REMOTE261  LLDB_TOOL_LLDB_SERVER_BUILD262  LLDB_USE_SYSTEM_DEBUGSERVER263  LLDB_IS_64_BITS264  LLDB_BUILD_LLDBRPC)265 266# Configure the individual test suites.267add_subdirectory(API)268add_subdirectory(Shell)269add_subdirectory(Unit)270 271# Configure the top level test suite.272configure_lit_site_cfg(273  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in274  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py275  MAIN_CONFIG276  ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py)277 278add_lit_testsuite(check-lldb "Running lldb lit test suite"279  ${CMAKE_CURRENT_BINARY_DIR}280  DEPENDS281    lldb-api-test-deps282    lldb-shell-test-deps283    lldb-unit-test-deps)284 285if(LLDB_BUILT_STANDALONE)286  # This has to happen *AFTER* add_lit_testsuite.287  if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/llvm-lit)288    # LLVM's make_paths_relative uses Python3_EXECUTABLE which isn't set in a289    # standalone LLDB build.290    set(Python3_EXECUTABLE ${Python3_EXECUTABLE})291    add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit ${CMAKE_CURRENT_BINARY_DIR}/llvm-lit)292  endif()293endif()294