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 15from distutils.spawn import find_executable 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 = lit.formats.ShTest(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'] 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 'FREEBSD_LEGACY_PLUGIN', 44 'HOME', 45 'TEMP', 46 'TMP', 47 'XDG_CACHE_HOME', 48]) 49 50# Support running the test suite under the lldb-repro wrapper. This makes it 51# possible to capture a test suite run and then rerun all the test from the 52# just captured reproducer. 53lldb_repro_mode = lit_config.params.get('lldb-run-with-repro', None) 54if lldb_repro_mode: 55 config.available_features.add('lldb-repro') 56 lit_config.note("Running Shell tests in {} mode.".format(lldb_repro_mode)) 57 toolchain.use_lldb_repro_substitutions(config, lldb_repro_mode) 58 59llvm_config.use_default_substitutions() 60toolchain.use_lldb_substitutions(config) 61toolchain.use_support_substitutions(config) 62 63if re.match(r'^arm(hf.*-linux)|(.*-linux-gnuabihf)', config.target_triple): 64 config.available_features.add("armhf-linux") 65 66def calculate_arch_features(arch_string): 67 # This will add a feature such as x86, arm, mips, etc for each built 68 # target 69 features = [] 70 for arch in arch_string.split(): 71 features.append(arch.lower()) 72 return features 73 74# Run llvm-config and add automatically add features for whether we have 75# assertions enabled, whether we are in debug mode, and what targets we 76# are built for. 77llvm_config.feature_config( 78 [('--assertion-mode', {'ON': 'asserts'}), 79 ('--build-mode', {'DEBUG': 'debug'}), 80 ('--targets-built', calculate_arch_features) 81 ]) 82 83# Clean the module caches in the test build directory. This is necessary in an 84# incremental build whenever clang changes underneath, so doing it once per 85# lit.py invocation is close enough. 86for cachedir in [config.clang_module_cache, config.lldb_module_cache]: 87 if os.path.isdir(cachedir): 88 lit_config.note("Deleting module cache at %s."%cachedir) 89 shutil.rmtree(cachedir) 90 91# Set a default per-test timeout of 10 minutes. Setting a timeout per test 92# requires that killProcessAndChildren() is supported on the platform and 93# lit complains if the value is set but it is not supported. 94supported, errormsg = lit_config.maxIndividualTestTimeIsSupported 95if supported: 96 lit_config.maxIndividualTestTime = 600 97else: 98 lit_config.warning("Could not set a default per-test timeout. " + errormsg) 99 100 101# If running tests natively, check for CPU features needed for some tests. 102 103if 'native' in config.available_features: 104 cpuid_exe = lit.util.which('lit-cpuid', config.lldb_tools_dir) 105 if cpuid_exe is None: 106 lit_config.warning("lit-cpuid not found, tests requiring CPU extensions will be skipped") 107 else: 108 out, err, exitcode = lit.util.executeCommand([cpuid_exe]) 109 if exitcode == 0: 110 for x in out.split(): 111 config.available_features.add('native-cpu-%s' % x) 112 else: 113 lit_config.warning("lit-cpuid failed: %s" % err) 114 115if config.lldb_enable_python: 116 config.available_features.add('python') 117 118if config.lldb_enable_lua: 119 config.available_features.add('lua') 120 121if config.lldb_enable_lzma: 122 config.available_features.add('lzma') 123 124if find_executable('xz') != None: 125 config.available_features.add('xz') 126 127if config.lldb_system_debugserver: 128 config.available_features.add('system-debugserver') 129 130# NetBSD permits setting dbregs either if one is root 131# or if user_set_dbregs is enabled 132can_set_dbregs = True 133if platform.system() == 'NetBSD' and os.geteuid() != 0: 134 try: 135 output = subprocess.check_output(["/sbin/sysctl", "-n", 136 "security.models.extensions.user_set_dbregs"]).decode().strip() 137 if output != "1": 138 can_set_dbregs = False 139 except subprocess.CalledProcessError: 140 can_set_dbregs = False 141if can_set_dbregs: 142 config.available_features.add('dbregs-set') 143 144if 'LD_PRELOAD' in os.environ: 145 config.available_features.add('ld_preload-present') 146