1# -*- Python -*- 2 3import json 4import os 5import platform 6import re 7import shutil 8import site 9import subprocess 10import sys 11 12import lit.formats 13from lit.llvm import llvm_config 14from lit.llvm.subst import FindTool 15from lit.llvm.subst import ToolSubst 16 17site.addsitedir(os.path.dirname(__file__)) 18from helper import toolchain 19 20# name: The name of this test suite. 21config.name = "lldb-shell" 22 23# testFormat: The test format to use to interpret tests. 24config.test_format = toolchain.ShTestLldb(not llvm_config.use_lit_shell) 25 26# suffixes: A list of file extensions to treat as test files. This is overriden 27# by individual lit.local.cfg files in the test subdirectories. 28config.suffixes = [".test", ".cpp", ".s", ".m"] 29 30# excludes: A list of directories to exclude from the testsuite. The 'Inputs' 31# subdirectories contain auxiliary inputs for various tests in their parent 32# directories. 33config.excludes = ["Inputs", "CMakeLists.txt", "README.txt", "LICENSE.txt"] 34 35# test_source_root: The root path where tests are located. 36config.test_source_root = os.path.dirname(__file__) 37 38# test_exec_root: The root path where tests should be run. 39config.test_exec_root = os.path.join(config.lldb_obj_root, "test", "Shell") 40 41# Propagate environment vars. 42llvm_config.with_system_environment( 43 [ 44 "FREEBSD_LEGACY_PLUGIN", 45 "HOME", 46 "TEMP", 47 "TMP", 48 "XDG_CACHE_HOME", 49 ] 50) 51 52# Enable sanitizer runtime flags. 53if config.llvm_use_sanitizer: 54 config.environment["ASAN_OPTIONS"] = "detect_stack_use_after_return=1" 55 config.environment["TSAN_OPTIONS"] = "halt_on_error=1" 56 config.environment["MallocNanoZone"] = "0" 57 58if config.lldb_platform_url and config.cmake_sysroot and config.enable_remote: 59 if re.match(r".*-linux.*", config.target_triple): 60 config.available_features.add("remote-linux") 61else: 62 # After this, enable_remote == True iff remote testing is going to be used. 63 config.enable_remote = False 64 65llvm_config.use_default_substitutions() 66toolchain.use_lldb_substitutions(config) 67toolchain.use_support_substitutions(config) 68 69if re.match(r"^arm(hf.*-linux)|(.*-linux-gnuabihf)", config.target_triple): 70 config.available_features.add("armhf-linux") 71 72if re.match(r".*-(windows|mingw32)", config.target_triple): 73 config.available_features.add("target-windows") 74 75if re.match(r".*-(windows-msvc)$", config.target_triple): 76 config.available_features.add("windows-msvc") 77 78if re.match(r".*-(windows-gnu|mingw32)$", config.target_triple): 79 config.available_features.add("windows-gnu") 80 81 82def calculate_arch_features(arch_string): 83 # This will add a feature such as x86, arm, mips, etc for each built 84 # target 85 features = [] 86 for arch in arch_string.split(): 87 features.append(arch.lower()) 88 return features 89 90 91# Run llvm-config and add automatically add features for whether we have 92# assertions enabled, whether we are in debug mode, and what targets we 93# are built for. 94llvm_config.feature_config( 95 [ 96 ("--assertion-mode", {"ON": "asserts"}), 97 ("--build-mode", {"DEBUG": "debug"}), 98 ("--targets-built", calculate_arch_features), 99 ] 100) 101 102# Clean the module caches in the test build directory. This is necessary in an 103# incremental build whenever clang changes underneath, so doing it once per 104# lit.py invocation is close enough. 105for cachedir in [config.clang_module_cache, config.lldb_module_cache]: 106 if os.path.isdir(cachedir): 107 lit_config.note("Deleting module cache at %s." % cachedir) 108 shutil.rmtree(cachedir) 109 110# Set a default per-test timeout of 10 minutes. Setting a timeout per test 111# requires that killProcessAndChildren() is supported on the platform and 112# lit complains if the value is set but it is not supported. 113supported, errormsg = lit_config.maxIndividualTestTimeIsSupported 114if supported: 115 lit_config.maxIndividualTestTime = 600 116else: 117 lit_config.warning("Could not set a default per-test timeout. " + errormsg) 118 119 120# If running tests natively, check for CPU features needed for some tests. 121 122if "native" in config.available_features: 123 cpuid_exe = lit.util.which("lit-cpuid", config.lldb_tools_dir) 124 if cpuid_exe is None: 125 lit_config.warning( 126 "lit-cpuid not found, tests requiring CPU extensions will be skipped" 127 ) 128 else: 129 out, err, exitcode = lit.util.executeCommand([cpuid_exe]) 130 if exitcode == 0: 131 for x in out.split(): 132 config.available_features.add("native-cpu-%s" % x) 133 else: 134 lit_config.warning("lit-cpuid failed: %s" % err) 135 136if config.lldb_enable_python: 137 config.available_features.add("python") 138 139if config.lldb_enable_lua: 140 config.available_features.add("lua") 141 142if config.lldb_enable_lzma: 143 config.available_features.add("lzma") 144 145if shutil.which("xz") is not None: 146 config.available_features.add("xz") 147 148if config.lldb_system_debugserver: 149 config.available_features.add("system-debugserver") 150 151if config.have_lldb_server: 152 config.available_features.add("lldb-server") 153 154if config.objc_gnustep_dir: 155 config.available_features.add("objc-gnustep") 156 if platform.system() == "Windows": 157 # objc.dll must be in PATH since Windows has no rpath 158 config.environment["PATH"] = os.path.pathsep.join( 159 ( 160 os.path.join(config.objc_gnustep_dir, "lib"), 161 config.environment.get("PATH", ""), 162 ) 163 ) 164 165# NetBSD permits setting dbregs either if one is root 166# or if user_set_dbregs is enabled 167can_set_dbregs = True 168if platform.system() == "NetBSD" and os.geteuid() != 0: 169 try: 170 output = ( 171 subprocess.check_output( 172 ["/sbin/sysctl", "-n", "security.models.extensions.user_set_dbregs"] 173 ) 174 .decode() 175 .strip() 176 ) 177 if output != "1": 178 can_set_dbregs = False 179 except subprocess.CalledProcessError: 180 can_set_dbregs = False 181if can_set_dbregs: 182 config.available_features.add("dbregs-set") 183 184if "LD_PRELOAD" in os.environ: 185 config.available_features.add("ld_preload-present") 186 187# Determine if a specific version of Xcode's linker contains a bug. We want to 188# skip affected tests if they contain this bug. 189if platform.system() == "Darwin": 190 try: 191 raw_version_details = subprocess.check_output( 192 ("xcrun", "ld", "-version_details") 193 ) 194 version_details = json.loads(raw_version_details) 195 version = version_details.get("version", "0") 196 version_tuple = tuple(int(x) for x in version.split(".")) 197 if (1000,) <= version_tuple <= (1109,): 198 config.available_features.add("ld_new-bug") 199 except: 200 pass 201