12 from lit.llvm import llvm_config
13 from lit.llvm.subst import FindTool
14 from lit.llvm.subst import ToolSubst
15 from distutils.spawn import find_executable
17 site.addsitedir(os.path.dirname(__file__))
18 from helper import toolchain
20 # name: The name of this test suite.
21 config.name = 'lldb-shell'
23 # testFormat: The test format to use to interpret tests.
24 config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
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.
28 config.suffixes = ['.test', '.cpp', '.s']
30 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
31 # subdirectories contain auxiliary inputs for various tests in their parent
33 config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt']
35 # test_source_root: The root path where tests are located.
36 config.test_source_root = os.path.dirname(__file__)
38 # test_exec_root: The root path where tests should be run.
39 config.test_exec_root = os.path.join(config.lldb_obj_root, 'test')
41 # Propagate reproducer environment vars.
42 if 'LLDB_CAPTURE_REPRODUCER' in os.environ:
43 config.environment['LLDB_CAPTURE_REPRODUCER'] = os.environ[
44 'LLDB_CAPTURE_REPRODUCER']
46 # Support running the test suite under the lldb-repro wrapper. This makes it
47 # possible to capture a test suite run and then rerun all the test from the
48 # just captured reproducer.
49 lldb_repro_mode = lit_config.params.get('lldb-run-with-repro', None)
51 config.skip_reproducer_test = True
52 lit_config.note("Running Shell test with lldb-repo in {} mode.".format(lldb_repro_mode))
53 toolchain.use_lldb_repro_substitutions(config, lldb_repro_mode)
55 llvm_config.use_default_substitutions()
56 toolchain.use_lldb_substitutions(config)
57 toolchain.use_support_substitutions(config)
59 if re.match(r'^arm(hf.*-linux)|(.*-linux-gnuabihf)', config.target_triple):
60 config.available_features.add("armhf-linux")
62 def calculate_arch_features(arch_string):
63 # This will add a feature such as x86, arm, mips, etc for each built
66 for arch in arch_string.split():
67 features.append(arch.lower())
70 # Run llvm-config and add automatically add features for whether we have
71 # assertions enabled, whether we are in debug mode, and what targets we
73 llvm_config.feature_config(
74 [('--assertion-mode', {'ON': 'asserts'}),
75 ('--build-mode', {'DEBUG': 'debug'}),
76 ('--targets-built', calculate_arch_features)
79 # Clean the module caches in the test build directory. This is necessary in an
80 # incremental build whenever clang changes underneath, so doing it once per
81 # lit.py invocation is close enough.
82 for cachedir in [config.clang_module_cache, config.lldb_module_cache]:
83 if os.path.isdir(cachedir):
84 print("Deleting module cache at %s."%cachedir)
85 shutil.rmtree(cachedir)
87 # Set a default per-test timeout of 10 minutes. Setting a timeout per test
88 # requires that killProcessAndChildren() is supported on the platform and
89 # lit complains if the value is set but it is not supported.
90 supported, errormsg = lit_config.maxIndividualTestTimeIsSupported
92 lit_config.maxIndividualTestTime = 600
94 lit_config.warning("Could not set a default per-test timeout. " + errormsg)
97 # If running tests natively, check for CPU features needed for some tests.
99 if 'native' in config.available_features:
100 cpuid_exe = lit.util.which('lit-cpuid', config.lldb_tools_dir)
101 if cpuid_exe is None:
102 lit_config.warning("lit-cpuid not found, tests requiring CPU extensions will be skipped")
104 out, err, exitcode = lit.util.executeCommand([cpuid_exe])
106 for x in out.split():
107 config.available_features.add('native-cpu-%s' % x)
109 lit_config.warning("lit-cpuid failed: %s" % err)
111 if config.lldb_enable_python:
112 config.available_features.add('python')
114 if config.lldb_enable_lua:
115 config.available_features.add('lua')
117 if config.lldb_enable_lzma:
118 config.available_features.add('lzma')
120 if find_executable('xz') != None:
121 config.available_features.add('xz')
123 # NetBSD permits setting dbregs either if one is root
124 # or if user_set_dbregs is enabled
125 can_set_dbregs = True
126 if platform.system() == 'NetBSD' and os.geteuid() != 0:
128 output = subprocess.check_output(["/sbin/sysctl", "-n",
129 "security.models.extensions.user_set_dbregs"]).decode().strip()
131 can_set_dbregs = False
132 except subprocess.CalledProcessError:
133 can_set_dbregs = False
135 config.available_features.add('dbregs-set')