blob: ae4b7c20651f23acaf3a448561a9151cae518126 [file] [log] [blame]
Don Hinton3a58f672017-12-12 16:54:201import os
2import platform
3import re
4import subprocess
Jeremy Morse984fad22019-10-31 16:51:535import sys
OCHyams5257efd2022-02-09 10:47:076from distutils.version import StrictVersion
Don Hinton3a58f672017-12-12 16:54:207
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:2013
14# Configuration file for the 'lit' test runner.
15
16# name: The name of this test suite.
James Henderson24af0992021-02-11 15:41:3217config.name = 'cross-project-tests'
Don Hinton3a58f672017-12-12 16:54:2018
19# testFormat: The test format to use to interpret tests.
Don Hinton3a58f672017-12-12 16:54:2020config.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:3231config.test_source_root = config.cross_project_tests_src_root
Don Hinton3a58f672017-12-12 16:54:2032
33# test_exec_root: The root path where tests should be run.
James Henderson24af0992021-02-11 15:41:3234config.test_exec_root = config.cross_project_tests_obj_root
Don Hinton3a58f672017-12-12 16:54:2035
Jeremy Morse984fad22019-10-31 16:51:5336llvm_config.use_default_substitutions()
37
Reid Kleckner75d38f12019-05-28 23:03:3338tools = [
39 ToolSubst('%test_debuginfo', command=os.path.join(
James Henderson24af0992021-02-11 15:41:3240 config.cross_project_tests_src_root, 'debuginfo-tests',
James Henderson13647502021-02-08 15:40:5541 'llgdb-tests', 'test_debuginfo.pl')),
Christian Sigg60346bd2020-01-11 07:47:4142 ToolSubst("%llvm_src_root", config.llvm_src_root),
43 ToolSubst("%llvm_tools_dir", config.llvm_tools_dir),
Reid Kleckner75d38f12019-05-28 23:03:3344]
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:5359 config.available_features.add('msvc')
Reid Kleckner75d38f12019-05-28 23:03:3360 # 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:3364 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:0371# 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:2073if not hasattr(config, 'clang_src_dir'):
74 config.clang_src_dir = ""
James Henderson38276002021-02-09 15:19:2775llvm_config.use_clang(required=('clang' in config.llvm_enabled_projects))
76
James Henderson4446a722021-02-09 14:57:0377if 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:2080
OCHyamsac0f3292022-02-09 17:08:4381if 'compiler-rt' in config.llvm_enabled_projects:
82 config.available_features.add('compiler-rt')
83
Don Hinton3a58f672017-12-12 16:54:2084if config.llvm_use_sanitizer:
85 # Propagate path to symbolizer for ASan/MSan.
86 llvm_config.with_system_environment(
87 ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH'])
OCHyams52bc1c12021-02-24 11:09:1888
OCHyams18ee8982021-12-16 13:41:2989# Check which debuggers are available:
90lldb_path = llvm_config.use_llvm_tool('lldb', search_env='LLDB')
91
92if lldb_path is not None:
93 config.available_features.add('lldb')
94
95def configure_dexter_substitutions():
96 """Configure substitutions for host platform and return list of dependencies
97 """
98 # Produce dexter path, lldb path, and combine into the %dexter substitution
99 # for running a test.
100 dexter_path = os.path.join(config.cross_project_tests_src_root,
101 'debuginfo-tests', 'dexter', 'dexter.py')
102 dexter_test_cmd = '"{}" "{}" test'.format(sys.executable, dexter_path)
103 if lldb_path is not None:
104 dexter_test_cmd += ' --lldb-executable "{}"'.format(lldb_path)
105 tools.append(ToolSubst('%dexter', dexter_test_cmd))
106
107 # For testing other bits of dexter that aren't under the "test" subcommand,
108 # have a %dexter_base substitution.
109 dexter_base_cmd = '"{}" "{}"'.format(sys.executable, dexter_path)
110 tools.append(ToolSubst('%dexter_base', dexter_base_cmd))
111
112 # Set up commands for DexTer regression tests.
113 # Builder, debugger, optimisation level and several other flags differ
114 # depending on whether we're running a unix like or windows os.
115 if platform.system() == 'Windows':
116 # The Windows builder script uses lld.
117 dependencies = ['clang', 'lld-link']
OCHyamsde3f8152022-01-26 11:09:21118 dexter_regression_test_builder = 'clang-cl_vs2015'
119 dexter_regression_test_debugger = 'dbgeng'
120 dexter_regression_test_cflags = '/Zi /Od'
121 dexter_regression_test_ldflags = '/Zi'
OCHyams18ee8982021-12-16 13:41:29122 else:
123 # Use lldb as the debugger on non-Windows platforms.
124 dependencies = ['clang', 'lldb']
OCHyamsde3f8152022-01-26 11:09:21125 dexter_regression_test_builder = 'clang'
126 dexter_regression_test_debugger = 'lldb'
127 dexter_regression_test_cflags = '-O0 -glldb'
OCHyams18ee8982021-12-16 13:41:29128 dexter_regression_test_ldflags = ''
129
OCHyamsde3f8152022-01-26 11:09:21130 tools.append(ToolSubst('%dexter_regression_test_builder', dexter_regression_test_builder))
131 tools.append(ToolSubst('%dexter_regression_test_debugger', dexter_regression_test_debugger))
132 tools.append(ToolSubst('%dexter_regression_test_cflags', dexter_regression_test_cflags))
133 tools.append(ToolSubst('%dexter_regression_test_ldflags', dexter_regression_test_cflags))
134
OCHyams18ee8982021-12-16 13:41:29135 # Typical command would take the form:
136 # ./path_to_py/python.exe ./path_to_dex/dexter.py test --fail-lt 1.0 -w --builder clang --debugger lldb --cflags '-O0 -g'
137 # Exclude build flags for %dexter_regression_base.
138 dexter_regression_test_base = ' '.join(
139 # "python", "dexter.py", test, fail_mode, builder, debugger, cflags, ldflags
140 ['"{}"'.format(sys.executable),
141 '"{}"'.format(dexter_path),
142 'test',
143 '--fail-lt 1.0 -w',
OCHyamsde3f8152022-01-26 11:09:21144 '--debugger', dexter_regression_test_debugger])
OCHyams18ee8982021-12-16 13:41:29145 tools.append(ToolSubst('%dexter_regression_base', dexter_regression_test_base))
146
147 # Include build flags for %dexter_regression_test.
148 dexter_regression_test_build = ' '.join([
149 dexter_regression_test_base,
OCHyamsde3f8152022-01-26 11:09:21150 '--builder', dexter_regression_test_builder,
151 '--cflags "', dexter_regression_test_cflags + '"',
152 '--ldflags "', dexter_regression_test_ldflags + '"'])
OCHyams18ee8982021-12-16 13:41:29153 tools.append(ToolSubst('%dexter_regression_test', dexter_regression_test_build))
154 return dependencies
155
OCHyams52bc1c12021-02-24 11:09:18156def add_host_triple(clang):
157 return '{} --target={}'.format(clang, config.host_triple)
158
159# The set of arches we can build.
160targets = set(config.targets_to_build)
161# Add aliases to the target set.
162if 'AArch64' in targets:
163 targets.add('arm64')
164if 'ARM' in config.targets_to_build:
165 targets.add('thumbv7')
166
167def can_target_host():
168 # Check if the targets set contains anything that looks like our host arch.
169 # The arch name in the triple and targets set may be spelled differently
170 # (e.g. x86 vs X86).
171 return any(config.host_triple.lower().startswith(x.lower())
172 for x in targets)
173
174# Dexter tests run on the host machine. If the host arch is supported add
175# 'dexter' as an available feature and force the dexter tests to use the host
176# triple.
177if can_target_host():
OCHyams52bc1c12021-02-24 11:09:18178 if config.host_triple != config.target_triple:
179 print('Forcing dexter tests to use host triple {}.'.format(config.host_triple))
OCHyams18ee8982021-12-16 13:41:29180 dependencies = configure_dexter_substitutions()
181 if all(d in config.available_features for d in dependencies):
182 config.available_features.add('dexter')
183 llvm_config.with_environment('PATHTOCLANG',
184 add_host_triple(llvm_config.config.clang))
185 llvm_config.with_environment('PATHTOCLANGPP',
186 add_host_triple(llvm_config.use_llvm_tool('clang++')))
187 llvm_config.with_environment('PATHTOCLANGCL',
188 add_host_triple(llvm_config.use_llvm_tool('clang-cl')))
OCHyams52bc1c12021-02-24 11:09:18189else:
190 print('Host triple {} not supported. Skipping dexter tests in the '
191 'debuginfo-tests project.'.format(config.host_triple))
Jeremy Morse984fad22019-10-31 16:51:53192
Don Hinton3a58f672017-12-12 16:54:20193tool_dirs = [config.llvm_tools_dir]
194
Don Hinton3a58f672017-12-12 16:54:20195llvm_config.add_tool_substitutions(tools, tool_dirs)
196
197lit.util.usePlatformSdkOnDarwin(config, lit_config)
Vedant Kumarefab30c2018-08-04 00:02:48198
199if platform.system() == 'Darwin':
Jonas Devlieghere635eb802019-06-25 15:58:32200 xcode_lldb_vers = subprocess.check_output(['xcrun', 'lldb', '--version']).decode("utf-8")
Vedant Kumarefab30c2018-08-04 00:02:48201 match = re.search('lldb-(\d+)', xcode_lldb_vers)
202 if match:
203 apple_lldb_vers = int(match.group(1))
204 if apple_lldb_vers < 1000:
205 config.available_features.add('apple-lldb-pre-1000')
Jeremy Morse984fad22019-10-31 16:51:53206
OCHyams5257efd2022-02-09 10:47:07207def get_gdb_version_string():
208 """Return gdb's version string, or None if gdb cannot be found or the
209 --version output is formatted unexpectedly.
210 """
211 # See if we can get a gdb version, e.g.
212 # $ gdb --version
213 # GNU gdb (GDB) 10.2
214 # ...More stuff...
215 try:
216 gdb_vers_lines = subprocess.check_output(['gdb', '--version']).decode().splitlines()
217 except:
218 return None # We coudln't find gdb or something went wrong running it.
219 if len(gdb_vers_lines) < 1:
220 print("Unkown GDB version format (too few lines)", file=sys.stderr)
221 return None
OCHyams00b2a9c2022-02-09 11:32:29222 match = re.search('GNU gdb \(.*?\) ((\d|\.)+)', gdb_vers_lines[0].strip())
223 if match is None:
224 print(f"Unkown GDB version format: {gdb_vers_lines[0]}", file=sys.stderr)
OCHyams5257efd2022-02-09 10:47:07225 return None
OCHyams00b2a9c2022-02-09 11:32:29226 return match.group(1)
OCHyams5257efd2022-02-09 10:47:07227
228def get_clang_default_dwarf_version_string(triple):
229 """Return the default dwarf version string for clang on this (host) platform
230 or None if we can't work it out.
231 """
232 # Get the flags passed by the driver and look for -dwarf-version.
233 cmd = f'{llvm_config.use_llvm_tool("clang")} -g -xc -c - -v -### --target={triple}'
234 stderr = subprocess.run(cmd.split(), stderr=subprocess.PIPE).stderr.decode()
235 match = re.search('-dwarf-version=(\d+)', stderr)
236 if match is None:
237 print("Cannot determine default dwarf version", file=sys.stderr)
238 return None
239 return match.group(1)
240
241# Some cross-project-tests use gdb, but not all versions of gdb are compatible
242# with clang's dwarf. Add feature `gdb-clang-incompatibility` to signal that
243# there's an incompatibility between clang's default dwarf version for this
244# platform and the installed gdb version.
245dwarf_version_string = get_clang_default_dwarf_version_string(config.host_triple)
246gdb_version_string = get_gdb_version_string()
247if dwarf_version_string and gdb_version_string:
248 if int(dwarf_version_string) >= 5:
249 if StrictVersion(gdb_version_string) < StrictVersion('10.1'):
250 # Example for llgdb-tests, which use lldb on darwin but gdb elsewhere:
251 # XFAIL: !system-darwin && gdb-clang-incompatibility
252 config.available_features.add('gdb-clang-incompatibility')
253 print("XFAIL some tests: use gdb version >= 10.1 to restore test coverage", file=sys.stderr)
254
Christian Sigge9b38842020-09-29 13:19:54255llvm_config.feature_config(
256 [('--build-mode', {'Debug|RelWithDebInfo': 'debug-info'})]
257)