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