blob: ffa208ffc3b938039081deb98f74d6402ed63aa6 [file] [log] [blame]
Don Hinton3a58f672017-12-12 16:54:20 +00001import os
2import platform
3import re
4import subprocess
Jeremy Morse984fad22019-10-31 16:51:53 +00005import sys
OCHyams5257efd2022-02-09 10:47:07 +00006from distutils.version import StrictVersion
Don Hinton3a58f672017-12-12 16:54:20 +00007
8import lit.formats
9import lit.util
10
11from lit.llvm import llvm_config
12from lit.llvm.subst import ToolSubst
Don Hinton3a58f672017-12-12 16:54:20 +000013
14# Configuration file for the 'lit' test runner.
15
16# name: The name of this test suite.
James Henderson24af0992021-02-11 15:41:32 +000017config.name = 'cross-project-tests'
Don Hinton3a58f672017-12-12 16:54:20 +000018
19# testFormat: The test format to use to interpret tests.
Don Hinton3a58f672017-12-12 16:54:20 +000020config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
21
22# suffixes: A list of file extensions to treat as test files.
23config.suffixes = ['.c', '.cpp', '.m']
24
25# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
26# subdirectories contain auxiliary inputs for various tests in their parent
27# directories.
28config.excludes = ['Inputs']
29
30# test_source_root: The root path where tests are located.
James Henderson24af0992021-02-11 15:41:32 +000031config.test_source_root = config.cross_project_tests_src_root
Don Hinton3a58f672017-12-12 16:54:20 +000032
33# test_exec_root: The root path where tests should be run.
James Henderson24af0992021-02-11 15:41:32 +000034config.test_exec_root = config.cross_project_tests_obj_root
Don Hinton3a58f672017-12-12 16:54:20 +000035
Jeremy Morse984fad22019-10-31 16:51:53 +000036llvm_config.use_default_substitutions()
37
Reid Kleckner75d38f12019-05-28 23:03:33 +000038tools = [
39 ToolSubst('%test_debuginfo', command=os.path.join(
James Henderson24af0992021-02-11 15:41:32 +000040 config.cross_project_tests_src_root, 'debuginfo-tests',
James Henderson13647502021-02-08 15:40:55 +000041 'llgdb-tests', 'test_debuginfo.pl')),
Christian Sigg60346bd2020-01-11 08:47:41 +010042 ToolSubst("%llvm_src_root", config.llvm_src_root),
43 ToolSubst("%llvm_tools_dir", config.llvm_tools_dir),
Reid Kleckner75d38f12019-05-28 23:03:33 +000044]
45
46def get_required_attr(config, attr_name):
47 attr_value = getattr(config, attr_name, None)
48 if attr_value == None:
49 lit_config.fatal(
50 "No attribute %r in test configuration! You may need to run "
51 "tests from your build directory or add this attribute "
52 "to lit.site.cfg " % attr_name)
53 return attr_value
54
55# If this is an MSVC environment, the tests at the root of the tree are
56# unsupported. The local win_cdb test suite, however, is supported.
57is_msvc = get_required_attr(config, "is_msvc")
58if is_msvc:
Jeremy Morse984fad22019-10-31 16:51:53 +000059 config.available_features.add('msvc')
Reid Kleckner75d38f12019-05-28 23:03:33 +000060 # FIXME: We should add some llvm lit utility code to find the Windows SDK
61 # and set up the environment appopriately.
62 win_sdk = 'C:/Program Files (x86)/Windows Kits/10/'
63 arch = 'x64'
Reid Kleckner75d38f12019-05-28 23:03:33 +000064 llvm_config.with_system_environment(['LIB', 'LIBPATH', 'INCLUDE'])
65 # Clear _NT_SYMBOL_PATH to prevent cdb from attempting to load symbols from
66 # the network.
67 llvm_config.with_environment('_NT_SYMBOL_PATH', '')
68 tools.append(ToolSubst('%cdb', '"%s"' % os.path.join(win_sdk, 'Debuggers',
69 arch, 'cdb.exe')))
70
James Henderson4446a722021-02-09 14:57:03 +000071# clang_src_dir and lld_src_dir are not used by these tests, but are required by
72# use_clang() and use_lld() respectively, so set them to "", if needed.
Don Hinton3a58f672017-12-12 16:54:20 +000073if not hasattr(config, 'clang_src_dir'):
74 config.clang_src_dir = ""
James Henderson38276002021-02-09 15:19:27 +000075llvm_config.use_clang(required=('clang' in config.llvm_enabled_projects))
76
James Henderson4446a722021-02-09 14:57:03 +000077if not hasattr(config, 'lld_src_dir'):
78 config.lld_src_dir = ""
79llvm_config.use_lld(required=('lld' in config.llvm_enabled_projects))
Don Hinton3a58f672017-12-12 16:54:20 +000080
81if config.llvm_use_sanitizer:
82 # Propagate path to symbolizer for ASan/MSan.
83 llvm_config.with_system_environment(
84 ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH'])
OCHyams52bc1c12021-02-24 11:09:18 +000085
OCHyams18ee8982021-12-16 13:41:29 +000086# Check which debuggers are available:
87lldb_path = llvm_config.use_llvm_tool('lldb', search_env='LLDB')
88
89if lldb_path is not None:
90 config.available_features.add('lldb')
91
92def configure_dexter_substitutions():
93 """Configure substitutions for host platform and return list of dependencies
94 """
95 # Produce dexter path, lldb path, and combine into the %dexter substitution
96 # for running a test.
97 dexter_path = os.path.join(config.cross_project_tests_src_root,
98 'debuginfo-tests', 'dexter', 'dexter.py')
99 dexter_test_cmd = '"{}" "{}" test'.format(sys.executable, dexter_path)
100 if lldb_path is not None:
101 dexter_test_cmd += ' --lldb-executable "{}"'.format(lldb_path)
102 tools.append(ToolSubst('%dexter', dexter_test_cmd))
103
104 # For testing other bits of dexter that aren't under the "test" subcommand,
105 # have a %dexter_base substitution.
106 dexter_base_cmd = '"{}" "{}"'.format(sys.executable, dexter_path)
107 tools.append(ToolSubst('%dexter_base', dexter_base_cmd))
108
109 # Set up commands for DexTer regression tests.
110 # Builder, debugger, optimisation level and several other flags differ
111 # depending on whether we're running a unix like or windows os.
112 if platform.system() == 'Windows':
113 # The Windows builder script uses lld.
114 dependencies = ['clang', 'lld-link']
OCHyamsde3f8152022-01-26 11:09:21 +0000115 dexter_regression_test_builder = 'clang-cl_vs2015'
116 dexter_regression_test_debugger = 'dbgeng'
117 dexter_regression_test_cflags = '/Zi /Od'
118 dexter_regression_test_ldflags = '/Zi'
OCHyams18ee8982021-12-16 13:41:29 +0000119 else:
120 # Use lldb as the debugger on non-Windows platforms.
121 dependencies = ['clang', 'lldb']
OCHyamsde3f8152022-01-26 11:09:21 +0000122 dexter_regression_test_builder = 'clang'
123 dexter_regression_test_debugger = 'lldb'
124 dexter_regression_test_cflags = '-O0 -glldb'
OCHyams18ee8982021-12-16 13:41:29 +0000125 dexter_regression_test_ldflags = ''
126
OCHyamsde3f8152022-01-26 11:09:21 +0000127 tools.append(ToolSubst('%dexter_regression_test_builder', dexter_regression_test_builder))
128 tools.append(ToolSubst('%dexter_regression_test_debugger', dexter_regression_test_debugger))
129 tools.append(ToolSubst('%dexter_regression_test_cflags', dexter_regression_test_cflags))
130 tools.append(ToolSubst('%dexter_regression_test_ldflags', dexter_regression_test_cflags))
131
OCHyams18ee8982021-12-16 13:41:29 +0000132 # Typical command would take the form:
133 # ./path_to_py/python.exe ./path_to_dex/dexter.py test --fail-lt 1.0 -w --builder clang --debugger lldb --cflags '-O0 -g'
134 # Exclude build flags for %dexter_regression_base.
135 dexter_regression_test_base = ' '.join(
136 # "python", "dexter.py", test, fail_mode, builder, debugger, cflags, ldflags
137 ['"{}"'.format(sys.executable),
138 '"{}"'.format(dexter_path),
139 'test',
140 '--fail-lt 1.0 -w',
OCHyamsde3f8152022-01-26 11:09:21 +0000141 '--debugger', dexter_regression_test_debugger])
OCHyams18ee8982021-12-16 13:41:29 +0000142 tools.append(ToolSubst('%dexter_regression_base', dexter_regression_test_base))
143
144 # Include build flags for %dexter_regression_test.
145 dexter_regression_test_build = ' '.join([
146 dexter_regression_test_base,
OCHyamsde3f8152022-01-26 11:09:21 +0000147 '--builder', dexter_regression_test_builder,
148 '--cflags "', dexter_regression_test_cflags + '"',
149 '--ldflags "', dexter_regression_test_ldflags + '"'])
OCHyams18ee8982021-12-16 13:41:29 +0000150 tools.append(ToolSubst('%dexter_regression_test', dexter_regression_test_build))
151 return dependencies
152
OCHyams52bc1c12021-02-24 11:09:18 +0000153def add_host_triple(clang):
154 return '{} --target={}'.format(clang, config.host_triple)
155
156# The set of arches we can build.
157targets = set(config.targets_to_build)
158# Add aliases to the target set.
159if 'AArch64' in targets:
160 targets.add('arm64')
161if 'ARM' in config.targets_to_build:
162 targets.add('thumbv7')
163
164def can_target_host():
165 # Check if the targets set contains anything that looks like our host arch.
166 # The arch name in the triple and targets set may be spelled differently
167 # (e.g. x86 vs X86).
168 return any(config.host_triple.lower().startswith(x.lower())
169 for x in targets)
170
171# Dexter tests run on the host machine. If the host arch is supported add
172# 'dexter' as an available feature and force the dexter tests to use the host
173# triple.
174if can_target_host():
OCHyams52bc1c12021-02-24 11:09:18 +0000175 if config.host_triple != config.target_triple:
176 print('Forcing dexter tests to use host triple {}.'.format(config.host_triple))
OCHyams18ee8982021-12-16 13:41:29 +0000177 dependencies = configure_dexter_substitutions()
178 if all(d in config.available_features for d in dependencies):
179 config.available_features.add('dexter')
180 llvm_config.with_environment('PATHTOCLANG',
181 add_host_triple(llvm_config.config.clang))
182 llvm_config.with_environment('PATHTOCLANGPP',
183 add_host_triple(llvm_config.use_llvm_tool('clang++')))
184 llvm_config.with_environment('PATHTOCLANGCL',
185 add_host_triple(llvm_config.use_llvm_tool('clang-cl')))
OCHyams52bc1c12021-02-24 11:09:18 +0000186else:
187 print('Host triple {} not supported. Skipping dexter tests in the '
188 'debuginfo-tests project.'.format(config.host_triple))
Jeremy Morse984fad22019-10-31 16:51:53 +0000189
Don Hinton3a58f672017-12-12 16:54:20 +0000190tool_dirs = [config.llvm_tools_dir]
191
Don Hinton3a58f672017-12-12 16:54:20 +0000192llvm_config.add_tool_substitutions(tools, tool_dirs)
193
194lit.util.usePlatformSdkOnDarwin(config, lit_config)
Vedant Kumarefab30c2018-08-04 00:02:48 +0000195
196if platform.system() == 'Darwin':
Jonas Devlieghere635eb802019-06-25 15:58:32 +0000197 xcode_lldb_vers = subprocess.check_output(['xcrun', 'lldb', '--version']).decode("utf-8")
Vedant Kumarefab30c2018-08-04 00:02:48 +0000198 match = re.search('lldb-(\d+)', xcode_lldb_vers)
199 if match:
200 apple_lldb_vers = int(match.group(1))
201 if apple_lldb_vers < 1000:
202 config.available_features.add('apple-lldb-pre-1000')
Jeremy Morse984fad22019-10-31 16:51:53 +0000203
OCHyams5257efd2022-02-09 10:47:07 +0000204def get_gdb_version_string():
205 """Return gdb's version string, or None if gdb cannot be found or the
206 --version output is formatted unexpectedly.
207 """
208 # See if we can get a gdb version, e.g.
209 # $ gdb --version
210 # GNU gdb (GDB) 10.2
211 # ...More stuff...
212 try:
213 gdb_vers_lines = subprocess.check_output(['gdb', '--version']).decode().splitlines()
214 except:
215 return None # We coudln't find gdb or something went wrong running it.
216 if len(gdb_vers_lines) < 1:
217 print("Unkown GDB version format (too few lines)", file=sys.stderr)
218 return None
OCHyams00b2a9c2022-02-09 11:32:29 +0000219 match = re.search('GNU gdb \(.*?\) ((\d|\.)+)', gdb_vers_lines[0].strip())
220 if match is None:
221 print(f"Unkown GDB version format: {gdb_vers_lines[0]}", file=sys.stderr)
OCHyams5257efd2022-02-09 10:47:07 +0000222 return None
OCHyams00b2a9c2022-02-09 11:32:29 +0000223 return match.group(1)
OCHyams5257efd2022-02-09 10:47:07 +0000224
225def get_clang_default_dwarf_version_string(triple):
226 """Return the default dwarf version string for clang on this (host) platform
227 or None if we can't work it out.
228 """
229 # Get the flags passed by the driver and look for -dwarf-version.
230 cmd = f'{llvm_config.use_llvm_tool("clang")} -g -xc -c - -v -### --target={triple}'
231 stderr = subprocess.run(cmd.split(), stderr=subprocess.PIPE).stderr.decode()
232 match = re.search('-dwarf-version=(\d+)', stderr)
233 if match is None:
234 print("Cannot determine default dwarf version", file=sys.stderr)
235 return None
236 return match.group(1)
237
238# Some cross-project-tests use gdb, but not all versions of gdb are compatible
239# with clang's dwarf. Add feature `gdb-clang-incompatibility` to signal that
240# there's an incompatibility between clang's default dwarf version for this
241# platform and the installed gdb version.
242dwarf_version_string = get_clang_default_dwarf_version_string(config.host_triple)
243gdb_version_string = get_gdb_version_string()
244if dwarf_version_string and gdb_version_string:
245 if int(dwarf_version_string) >= 5:
246 if StrictVersion(gdb_version_string) < StrictVersion('10.1'):
247 # Example for llgdb-tests, which use lldb on darwin but gdb elsewhere:
248 # XFAIL: !system-darwin && gdb-clang-incompatibility
249 config.available_features.add('gdb-clang-incompatibility')
250 print("XFAIL some tests: use gdb version >= 10.1 to restore test coverage", file=sys.stderr)
251
Christian Sigge9b38842020-09-29 15:19:54 +0200252llvm_config.feature_config(
253 [('--build-mode', {'Debug|RelWithDebInfo': 'debug-info'})]
254)