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 65if re.match(r'.*-(windows-msvc)$', config.target_triple): 66 config.available_features.add("windows-msvc") 67 68if re.match(r'.*-(windows-gnu|mingw32)$', config.target_triple): 69 config.available_features.add("windows-gnu") 70 71def calculate_arch_features(arch_string): 72 # This will add a feature such as x86, arm, mips, etc for each built 73 # target 74 features = [] 75 for arch in arch_string.split(): 76 features.append(arch.lower()) 77 return features 78 79# Run llvm-config and add automatically add features for whether we have 80# assertions enabled, whether we are in debug mode, and what targets we 81# are built for. 82llvm_config.feature_config( 83 [('--assertion-mode', {'ON': 'asserts'}), 84 ('--build-mode', {'DEBUG': 'debug'}), 85 ('--targets-built', calculate_arch_features) 86 ]) 87 88# Clean the module caches in the test build directory. This is necessary in an 89# incremental build whenever clang changes underneath, so doing it once per 90# lit.py invocation is close enough. 91for cachedir in [config.clang_module_cache, config.lldb_module_cache]: 92 if os.path.isdir(cachedir): 93 lit_config.note("Deleting module cache at %s."%cachedir) 94 shutil.rmtree(cachedir) 95 96# Set a default per-test timeout of 10 minutes. Setting a timeout per test 97# requires that killProcessAndChildren() is supported on the platform and 98# lit complains if the value is set but it is not supported. 99supported, errormsg = lit_config.maxIndividualTestTimeIsSupported 100if supported: 101 lit_config.maxIndividualTestTime = 600 102else: 103 lit_config.warning("Could not set a default per-test timeout. " + errormsg) 104 105 106# If running tests natively, check for CPU features needed for some tests. 107 108if 'native' in config.available_features: 109 cpuid_exe = lit.util.which('lit-cpuid', config.lldb_tools_dir) 110 if cpuid_exe is None: 111 lit_config.warning("lit-cpuid not found, tests requiring CPU extensions will be skipped") 112 else: 113 out, err, exitcode = lit.util.executeCommand([cpuid_exe]) 114 if exitcode == 0: 115 for x in out.split(): 116 config.available_features.add('native-cpu-%s' % x) 117 else: 118 lit_config.warning("lit-cpuid failed: %s" % err) 119 120if config.lldb_enable_python: 121 config.available_features.add('python') 122 123if config.lldb_enable_lua: 124 config.available_features.add('lua') 125 126if config.lldb_enable_lzma: 127 config.available_features.add('lzma') 128 129if shutil.which('xz') != None: 130 config.available_features.add('xz') 131 132if config.lldb_system_debugserver: 133 config.available_features.add('system-debugserver') 134 135# NetBSD permits setting dbregs either if one is root 136# or if user_set_dbregs is enabled 137can_set_dbregs = True 138if platform.system() == 'NetBSD' and os.geteuid() != 0: 139 try: 140 output = subprocess.check_output(["/sbin/sysctl", "-n", 141 "security.models.extensions.user_set_dbregs"]).decode().strip() 142 if output != "1": 143 can_set_dbregs = False 144 except subprocess.CalledProcessError: 145 can_set_dbregs = False 146if can_set_dbregs: 147 config.available_features.add('dbregs-set') 148 149if 'LD_PRELOAD' in os.environ: 150 config.available_features.add('ld_preload-present') 151