brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.3 KiB · cdc0cfe Raw
220 lines · python
1# -*- Python -*-2 3import json4import os5import platform6import re7import shutil8import site9import subprocess10import sys11 12import lit.formats13from lit.llvm import llvm_config14from lit.llvm.subst import FindTool15from lit.llvm.subst import ToolSubst16 17site.addsitedir(os.path.dirname(__file__))18from helper import toolchain19 20# name: The name of this test suite.21config.name = "lldb-shell"22 23# testFormat: The test format to use to interpret tests.24# We prefer the lit internal shell which provides a better user experience on25# failures and is faster unless the user explicitly disables it with26# LIT_USE_INTERNAL_SHELL=0 env var.27use_lit_shell = True28lit_shell_env = os.environ.get("LIT_USE_INTERNAL_SHELL")29if lit_shell_env:30    use_lit_shell = lit.util.pythonize_bool(lit_shell_env)31 32config.test_format = toolchain.ShTestLldb(not use_lit_shell)33 34# suffixes: A list of file extensions to treat as test files. This is overriden35# by individual lit.local.cfg files in the test subdirectories.36config.suffixes = [".test", ".cpp", ".s", ".m", ".ll", ".c"]37 38# excludes: A list of directories to exclude from the testsuite. The 'Inputs'39# subdirectories contain auxiliary inputs for various tests in their parent40# directories.41config.excludes = ["Inputs", "CMakeLists.txt", "README.txt", "LICENSE.txt"]42 43# test_source_root: The root path where tests are located.44config.test_source_root = os.path.dirname(__file__)45 46# test_exec_root: The root path where tests should be run.47config.test_exec_root = os.path.join(config.lldb_obj_root, "test", "Shell")48 49# Propagate environment vars.50llvm_config.with_system_environment(51    [52        "FREEBSD_LEGACY_PLUGIN",53        "HOME",54        "TEMP",55        "TMP",56        "XDG_CACHE_HOME",57    ]58)59 60# Enable sanitizer runtime flags.61if config.llvm_use_sanitizer:62    config.environment["ASAN_OPTIONS"] = "detect_stack_use_after_return=1"63    config.environment["TSAN_OPTIONS"] = "halt_on_error=1"64    config.environment["MallocNanoZone"] = "0"65 66if config.lldb_platform_url and config.cmake_sysroot and config.enable_remote:67    if re.match(r".*-linux.*", config.target_triple):68        config.available_features.add("remote-linux")69else:70    # After this, enable_remote == True iff remote testing is going to be used.71    config.enable_remote = False72 73llvm_config.use_default_substitutions()74toolchain.use_lldb_substitutions(config)75toolchain.use_support_substitutions(config)76 77if re.match(r"^arm(hf.*-linux)|(.*-linux-gnuabihf)", config.target_triple):78    config.available_features.add("armhf-linux")79 80if re.match(r".*-(windows|mingw32)", config.target_triple):81    config.available_features.add("target-windows")82 83if re.match(r".*-(windows-msvc)$", config.target_triple):84    config.available_features.add("windows-msvc")85 86if re.match(r".*-(windows-gnu|mingw32)$", config.target_triple):87    config.available_features.add("windows-gnu")88 89 90def calculate_arch_features(arch_string):91    # This will add a feature such as x86, arm, mips, etc for each built92    # target93    features = []94    for arch in arch_string.split():95        features.append(arch.lower())96    return features97 98 99# Run llvm-config and add automatically add features for whether we have100# assertions enabled, whether we are in debug mode, and what targets we101# are built for.102llvm_config.feature_config(103    [104        ("--assertion-mode", {"ON": "asserts"}),105        ("--build-mode", {"DEBUG": "debug"}),106        ("--targets-built", calculate_arch_features),107    ]108)109 110# Clean the module caches in the test build directory. This is necessary in an111# incremental build whenever clang changes underneath, so doing it once per112# lit.py invocation is close enough.113for cachedir in [config.clang_module_cache, config.lldb_module_cache]:114    if os.path.isdir(cachedir):115        lit_config.note("Deleting module cache at %s." % cachedir)116        shutil.rmtree(cachedir)117 118# Set a default per-test timeout of 10 minutes. Setting a timeout per test119# requires that killProcessAndChildren() is supported on the platform and120# lit complains if the value is set but it is not supported.121supported, errormsg = lit_config.maxIndividualTestTimeIsSupported122if supported:123    lit_config.maxIndividualTestTime = 600124else:125    lit_config.warning("Could not set a default per-test timeout. " + errormsg)126 127 128# If running tests natively, check for CPU features needed for some tests.129 130if "native" in config.available_features:131    cpuid_exe = lit.util.which("lit-cpuid", config.lldb_tools_dir)132    if cpuid_exe is None:133        lit_config.warning(134            "lit-cpuid not found, tests requiring CPU extensions will be skipped"135        )136    else:137        out, err, exitcode = lit.util.executeCommand([cpuid_exe])138        if exitcode == 0:139            for x in out.split():140                config.available_features.add("native-cpu-%s" % x)141        else:142            lit_config.warning("lit-cpuid failed: %s" % err)143 144if config.lldb_enable_python:145    config.available_features.add("python")146 147if config.lldb_enable_lua:148    config.available_features.add("lua")149 150if config.lldb_enable_lzma:151    config.available_features.add("lzma")152 153if shutil.which("xz") is not None:154    config.available_features.add("xz")155 156if config.lldb_system_debugserver:157    config.available_features.add("system-debugserver")158 159if config.have_lldb_server:160    config.available_features.add("lldb-server")161 162if config.objc_gnustep_dir:163    config.available_features.add("objc-gnustep")164    if platform.system() == "Windows":165        # objc.dll must be in PATH since Windows has no rpath166        config.environment["PATH"] = os.path.pathsep.join(167            (168                os.path.join(config.objc_gnustep_dir, "lib"),169                config.environment.get("PATH", ""),170            )171        )172 173if config.have_dia_sdk:174    config.available_features.add("diasdk")175 176# NetBSD permits setting dbregs either if one is root177# or if user_set_dbregs is enabled178can_set_dbregs = True179if platform.system() == "NetBSD" and os.geteuid() != 0:180    try:181        output = (182            subprocess.check_output(183                ["/sbin/sysctl", "-n", "security.models.extensions.user_set_dbregs"]184            )185            .decode()186            .strip()187        )188        if output != "1":189            can_set_dbregs = False190    except subprocess.CalledProcessError:191        can_set_dbregs = False192if can_set_dbregs:193    config.available_features.add("dbregs-set")194 195if "LD_PRELOAD" in os.environ:196    config.available_features.add("ld_preload-present")197 198# Determine if a specific version of Xcode's linker contains a bug. We want to199# skip affected tests if they contain this bug.200if platform.system() == "Darwin":201    try:202        raw_version_details = subprocess.check_output(203            ("xcrun", "ld", "-version_details")204        )205        version_details = json.loads(raw_version_details)206        version = version_details.get("version", "0")207        version_tuple = tuple(int(x) for x in version.split("."))208        if (1000,) <= version_tuple <= (1109,):209            config.available_features.add("ld_new-bug")210    except:211        pass212 213# Some shell tests dynamically link with python.dll and need to know the214# location of the Python libraries. This ensures that we use the same215# version of Python that was used to build lldb to run our tests.216config.environment["PYTHONHOME"] = config.python_root_dir217config.environment["PATH"] = os.path.pathsep.join(218    (config.python_root_dir, config.environment.get("PATH", ""))219)220