1# -*- Python -*- 2 3import os 4import platform 5import re 6import shutil 7import site 8import subprocess 9import sys 10 11import lit.formats 12from lit.llvm import llvm_config 13from lit.llvm.subst import FindTool 14from lit.llvm.subst import ToolSubst 15 16site.addsitedir(os.path.dirname(__file__)) 17from helper import toolchain 18 19# name: The name of this test suite. 20config.name = 'lldb-shell' 21 22# testFormat: The test format to use to interpret tests. 23config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) 24 25# suffixes: A list of file extensions to treat as test files. This is overriden 26# by individual lit.local.cfg files in the test subdirectories. 27config.suffixes = ['.test', '.cpp', '.s'] 28 29# excludes: A list of directories to exclude from the testsuite. The 'Inputs' 30# subdirectories contain auxiliary inputs for various tests in their parent 31# directories. 32config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt'] 33 34# test_source_root: The root path where tests are located. 35config.test_source_root = os.path.dirname(__file__) 36 37# test_exec_root: The root path where tests should be run. 38config.test_exec_root = os.path.join(config.lldb_obj_root, 'test', 'Shell') 39 40# Propagate environment vars. 41llvm_config.with_system_environment([ 42 'FREEBSD_LEGACY_PLUGIN', 43 'HOME', 44 'TEMP', 45 'TMP', 46 'XDG_CACHE_HOME', 47]) 48 49# Support running the test suite under the lldb-repro wrapper. This makes it 50# possible to capture a test suite run and then rerun all the test from the 51# just captured reproducer. 52lldb_repro_mode = lit_config.params.get('lldb-run-with-repro', None) 53if lldb_repro_mode: 54 config.available_features.add('lldb-repro') 55 lit_config.note("Running Shell tests in {} mode.".format(lldb_repro_mode)) 56 toolchain.use_lldb_repro_substitutions(config, lldb_repro_mode) 57 58llvm_config.use_default_substitutions() 59toolchain.use_lldb_substitutions(config) 60toolchain.use_support_substitutions(config) 61 62if re.match(r'^arm(hf.*-linux)|(.*-linux-gnuabihf)', config.target_triple): 63 config.available_features.add("armhf-linux") 64 65def calculate_arch_features(arch_string): 66 # This will add a feature such as x86, arm, mips, etc for each built 67 # target 68 features = [] 69 for arch in arch_string.split(): 70 features.append(arch.lower()) 71 return features 72 73# Run llvm-config and add automatically add features for whether we have 74# assertions enabled, whether we are in debug mode, and what targets we 75# are built for. 76llvm_config.feature_config( 77 [('--assertion-mode', {'ON': 'asserts'}), 78 ('--build-mode', {'DEBUG': 'debug'}), 79 ('--targets-built', calculate_arch_features) 80 ]) 81 82# Clean the module caches in the test build directory. This is necessary in an 83# incremental build whenever clang changes underneath, so doing it once per 84# lit.py invocation is close enough. 85for cachedir in [config.clang_module_cache, config.lldb_module_cache]: 86 if os.path.isdir(cachedir): 87 lit_config.note("Deleting module cache at %s."%cachedir) 88 shutil.rmtree(cachedir) 89 90# Set a default per-test timeout of 10 minutes. Setting a timeout per test 91# requires that killProcessAndChildren() is supported on the platform and 92# lit complains if the value is set but it is not supported. 93supported, errormsg = lit_config.maxIndividualTestTimeIsSupported 94if supported: 95 lit_config.maxIndividualTestTime = 600 96else: 97 lit_config.warning("Could not set a default per-test timeout. " + errormsg) 98 99 100# If running tests natively, check for CPU features needed for some tests. 101 102if 'native' in config.available_features: 103 cpuid_exe = lit.util.which('lit-cpuid', config.lldb_tools_dir) 104 if cpuid_exe is None: 105 lit_config.warning("lit-cpuid not found, tests requiring CPU extensions will be skipped") 106 else: 107 out, err, exitcode = lit.util.executeCommand([cpuid_exe]) 108 if exitcode == 0: 109 for x in out.split(): 110 config.available_features.add('native-cpu-%s' % x) 111 else: 112 lit_config.warning("lit-cpuid failed: %s" % err) 113 114if config.lldb_enable_python: 115 config.available_features.add('python') 116 117if config.lldb_enable_lua: 118 config.available_features.add('lua') 119 120if config.lldb_enable_lzma: 121 config.available_features.add('lzma') 122 123if shutil.which('xz') != None: 124 config.available_features.add('xz') 125 126if config.lldb_system_debugserver: 127 config.available_features.add('system-debugserver') 128 129# NetBSD permits setting dbregs either if one is root 130# or if user_set_dbregs is enabled 131can_set_dbregs = True 132if platform.system() == 'NetBSD' and os.geteuid() != 0: 133 try: 134 output = subprocess.check_output(["/sbin/sysctl", "-n", 135 "security.models.extensions.user_set_dbregs"]).decode().strip() 136 if output != "1": 137 can_set_dbregs = False 138 except subprocess.CalledProcessError: 139 can_set_dbregs = False 140if can_set_dbregs: 141 config.available_features.add('dbregs-set') 142 143if 'LD_PRELOAD' in os.environ: 144 config.available_features.add('ld_preload-present') 145