blob: 0eeec7908fe47e28535af050b6da6bf00b46a423 [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
Thomas Lively70620942022-03-17 15:22:17 -07006
7# TODO: LooseVersion is undocumented; use something else.
8from distutils.version import LooseVersion
Don Hinton3a58f672017-12-12 16:54:20 +00009
10import lit.formats
11import lit.util
12
13from lit.llvm import llvm_config
14from lit.llvm.subst import ToolSubst
Don Hinton3a58f672017-12-12 16:54:20 +000015
16# Configuration file for the 'lit' test runner.
17
18# name: The name of this test suite.
James Henderson24af0992021-02-11 15:41:32 +000019config.name = 'cross-project-tests'
Don Hinton3a58f672017-12-12 16:54:20 +000020
21# testFormat: The test format to use to interpret tests.
Don Hinton3a58f672017-12-12 16:54:20 +000022config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
23
24# suffixes: A list of file extensions to treat as test files.
25config.suffixes = ['.c', '.cpp', '.m']
26
27# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
28# subdirectories contain auxiliary inputs for various tests in their parent
29# directories.
30config.excludes = ['Inputs']
31
32# test_source_root: The root path where tests are located.
James Henderson24af0992021-02-11 15:41:32 +000033config.test_source_root = config.cross_project_tests_src_root
Don Hinton3a58f672017-12-12 16:54:20 +000034
35# test_exec_root: The root path where tests should be run.
James Henderson24af0992021-02-11 15:41:32 +000036config.test_exec_root = config.cross_project_tests_obj_root
Don Hinton3a58f672017-12-12 16:54:20 +000037
Jeremy Morse984fad22019-10-31 16:51:53 +000038llvm_config.use_default_substitutions()
39
Reid Kleckner75d38f12019-05-28 23:03:33 +000040tools = [
41 ToolSubst('%test_debuginfo', command=os.path.join(
James Henderson24af0992021-02-11 15:41:32 +000042 config.cross_project_tests_src_root, 'debuginfo-tests',
James Henderson13647502021-02-08 15:40:55 +000043 'llgdb-tests', 'test_debuginfo.pl')),
Christian Sigg60346bd2020-01-11 08:47:41 +010044 ToolSubst("%llvm_src_root", config.llvm_src_root),
45 ToolSubst("%llvm_tools_dir", config.llvm_tools_dir),
Reid Kleckner75d38f12019-05-28 23:03:33 +000046]
47
48def get_required_attr(config, attr_name):
49 attr_value = getattr(config, attr_name, None)
50 if attr_value == None:
51 lit_config.fatal(
52 "No attribute %r in test configuration! You may need to run "
53 "tests from your build directory or add this attribute "
54 "to lit.site.cfg " % attr_name)
55 return attr_value
56
57# If this is an MSVC environment, the tests at the root of the tree are
58# unsupported. The local win_cdb test suite, however, is supported.
59is_msvc = get_required_attr(config, "is_msvc")
60if is_msvc:
Jeremy Morse984fad22019-10-31 16:51:53 +000061 config.available_features.add('msvc')
Reid Kleckner75d38f12019-05-28 23:03:33 +000062 # FIXME: We should add some llvm lit utility code to find the Windows SDK
63 # and set up the environment appopriately.
64 win_sdk = 'C:/Program Files (x86)/Windows Kits/10/'
65 arch = 'x64'
Reid Kleckner75d38f12019-05-28 23:03:33 +000066 llvm_config.with_system_environment(['LIB', 'LIBPATH', 'INCLUDE'])
67 # Clear _NT_SYMBOL_PATH to prevent cdb from attempting to load symbols from
68 # the network.
69 llvm_config.with_environment('_NT_SYMBOL_PATH', '')
70 tools.append(ToolSubst('%cdb', '"%s"' % os.path.join(win_sdk, 'Debuggers',
71 arch, 'cdb.exe')))
72
James Henderson4446a722021-02-09 14:57:03 +000073# clang_src_dir and lld_src_dir are not used by these tests, but are required by
74# use_clang() and use_lld() respectively, so set them to "", if needed.
Don Hinton3a58f672017-12-12 16:54:20 +000075if not hasattr(config, 'clang_src_dir'):
76 config.clang_src_dir = ""
James Henderson38276002021-02-09 15:19:27 +000077llvm_config.use_clang(required=('clang' in config.llvm_enabled_projects))
78
James Henderson4446a722021-02-09 14:57:03 +000079if not hasattr(config, 'lld_src_dir'):
80 config.lld_src_dir = ""
81llvm_config.use_lld(required=('lld' in config.llvm_enabled_projects))
Don Hinton3a58f672017-12-12 16:54:20 +000082
OCHyamsac0f3292022-02-09 17:08:43 +000083if 'compiler-rt' in config.llvm_enabled_projects:
84 config.available_features.add('compiler-rt')
85
Don Hinton3a58f672017-12-12 16:54:20 +000086if config.llvm_use_sanitizer:
87 # Propagate path to symbolizer for ASan/MSan.
88 llvm_config.with_system_environment(
89 ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH'])
OCHyams52bc1c12021-02-24 11:09:18 +000090
OCHyams18ee8982021-12-16 13:41:29 +000091# Check which debuggers are available:
92lldb_path = llvm_config.use_llvm_tool('lldb', search_env='LLDB')
93
94if lldb_path is not None:
95 config.available_features.add('lldb')
96
97def configure_dexter_substitutions():
98 """Configure substitutions for host platform and return list of dependencies
99 """
100 # Produce dexter path, lldb path, and combine into the %dexter substitution
101 # for running a test.
102 dexter_path = os.path.join(config.cross_project_tests_src_root,
103 'debuginfo-tests', 'dexter', 'dexter.py')
104 dexter_test_cmd = '"{}" "{}" test'.format(sys.executable, dexter_path)
105 if lldb_path is not None:
106 dexter_test_cmd += ' --lldb-executable "{}"'.format(lldb_path)
107 tools.append(ToolSubst('%dexter', dexter_test_cmd))
108
109 # For testing other bits of dexter that aren't under the "test" subcommand,
110 # have a %dexter_base substitution.
111 dexter_base_cmd = '"{}" "{}"'.format(sys.executable, dexter_path)
112 tools.append(ToolSubst('%dexter_base', dexter_base_cmd))
113
114 # Set up commands for DexTer regression tests.
115 # Builder, debugger, optimisation level and several other flags differ
116 # depending on whether we're running a unix like or windows os.
117 if platform.system() == 'Windows':
118 # The Windows builder script uses lld.
119 dependencies = ['clang', 'lld-link']
OCHyamsde3f8152022-01-26 11:09:21 +0000120 dexter_regression_test_builder = 'clang-cl_vs2015'
121 dexter_regression_test_debugger = 'dbgeng'
122 dexter_regression_test_cflags = '/Zi /Od'
123 dexter_regression_test_ldflags = '/Zi'
OCHyams18ee8982021-12-16 13:41:29 +0000124 else:
125 # Use lldb as the debugger on non-Windows platforms.
126 dependencies = ['clang', 'lldb']
OCHyamsde3f8152022-01-26 11:09:21 +0000127 dexter_regression_test_builder = 'clang'
128 dexter_regression_test_debugger = 'lldb'
129 dexter_regression_test_cflags = '-O0 -glldb'
OCHyams18ee8982021-12-16 13:41:29 +0000130 dexter_regression_test_ldflags = ''
131
OCHyamsde3f8152022-01-26 11:09:21 +0000132 tools.append(ToolSubst('%dexter_regression_test_builder', dexter_regression_test_builder))
133 tools.append(ToolSubst('%dexter_regression_test_debugger', dexter_regression_test_debugger))
134 tools.append(ToolSubst('%dexter_regression_test_cflags', dexter_regression_test_cflags))
135 tools.append(ToolSubst('%dexter_regression_test_ldflags', dexter_regression_test_cflags))
136
OCHyams18ee8982021-12-16 13:41:29 +0000137 # Typical command would take the form:
138 # ./path_to_py/python.exe ./path_to_dex/dexter.py test --fail-lt 1.0 -w --builder clang --debugger lldb --cflags '-O0 -g'
139 # Exclude build flags for %dexter_regression_base.
140 dexter_regression_test_base = ' '.join(
141 # "python", "dexter.py", test, fail_mode, builder, debugger, cflags, ldflags
142 ['"{}"'.format(sys.executable),
143 '"{}"'.format(dexter_path),
144 'test',
145 '--fail-lt 1.0 -w',
OCHyamsde3f8152022-01-26 11:09:21 +0000146 '--debugger', dexter_regression_test_debugger])
OCHyams18ee8982021-12-16 13:41:29 +0000147 tools.append(ToolSubst('%dexter_regression_base', dexter_regression_test_base))
148
149 # Include build flags for %dexter_regression_test.
150 dexter_regression_test_build = ' '.join([
151 dexter_regression_test_base,
OCHyamsde3f8152022-01-26 11:09:21 +0000152 '--builder', dexter_regression_test_builder,
153 '--cflags "', dexter_regression_test_cflags + '"',
154 '--ldflags "', dexter_regression_test_ldflags + '"'])
OCHyams18ee8982021-12-16 13:41:29 +0000155 tools.append(ToolSubst('%dexter_regression_test', dexter_regression_test_build))
156 return dependencies
157
OCHyams52bc1c12021-02-24 11:09:18 +0000158def add_host_triple(clang):
159 return '{} --target={}'.format(clang, config.host_triple)
160
161# The set of arches we can build.
162targets = set(config.targets_to_build)
163# Add aliases to the target set.
164if 'AArch64' in targets:
165 targets.add('arm64')
166if 'ARM' in config.targets_to_build:
167 targets.add('thumbv7')
168
169def can_target_host():
170 # Check if the targets set contains anything that looks like our host arch.
171 # The arch name in the triple and targets set may be spelled differently
172 # (e.g. x86 vs X86).
173 return any(config.host_triple.lower().startswith(x.lower())
174 for x in targets)
175
176# Dexter tests run on the host machine. If the host arch is supported add
177# 'dexter' as an available feature and force the dexter tests to use the host
178# triple.
179if can_target_host():
OCHyams52bc1c12021-02-24 11:09:18 +0000180 if config.host_triple != config.target_triple:
181 print('Forcing dexter tests to use host triple {}.'.format(config.host_triple))
OCHyams18ee8982021-12-16 13:41:29 +0000182 dependencies = configure_dexter_substitutions()
183 if all(d in config.available_features for d in dependencies):
184 config.available_features.add('dexter')
185 llvm_config.with_environment('PATHTOCLANG',
186 add_host_triple(llvm_config.config.clang))
187 llvm_config.with_environment('PATHTOCLANGPP',
188 add_host_triple(llvm_config.use_llvm_tool('clang++')))
189 llvm_config.with_environment('PATHTOCLANGCL',
190 add_host_triple(llvm_config.use_llvm_tool('clang-cl')))
OCHyams52bc1c12021-02-24 11:09:18 +0000191else:
192 print('Host triple {} not supported. Skipping dexter tests in the '
193 'debuginfo-tests project.'.format(config.host_triple))
Jeremy Morse984fad22019-10-31 16:51:53 +0000194
Don Hinton3a58f672017-12-12 16:54:20 +0000195tool_dirs = [config.llvm_tools_dir]
196
Don Hinton3a58f672017-12-12 16:54:20 +0000197llvm_config.add_tool_substitutions(tools, tool_dirs)
198
199lit.util.usePlatformSdkOnDarwin(config, lit_config)
Vedant Kumarefab30c2018-08-04 00:02:48 +0000200
201if platform.system() == 'Darwin':
Jonas Devlieghere635eb802019-06-25 15:58:32 +0000202 xcode_lldb_vers = subprocess.check_output(['xcrun', 'lldb', '--version']).decode("utf-8")
Vedant Kumarefab30c2018-08-04 00:02:48 +0000203 match = re.search('lldb-(\d+)', xcode_lldb_vers)
204 if match:
205 apple_lldb_vers = int(match.group(1))
206 if apple_lldb_vers < 1000:
207 config.available_features.add('apple-lldb-pre-1000')
Jeremy Morse984fad22019-10-31 16:51:53 +0000208
OCHyams5257efd2022-02-09 10:47:07 +0000209def get_gdb_version_string():
210 """Return gdb's version string, or None if gdb cannot be found or the
211 --version output is formatted unexpectedly.
212 """
213 # See if we can get a gdb version, e.g.
214 # $ gdb --version
215 # GNU gdb (GDB) 10.2
216 # ...More stuff...
217 try:
218 gdb_vers_lines = subprocess.check_output(['gdb', '--version']).decode().splitlines()
219 except:
220 return None # We coudln't find gdb or something went wrong running it.
221 if len(gdb_vers_lines) < 1:
222 print("Unkown GDB version format (too few lines)", file=sys.stderr)
223 return None
OCHyams00b2a9c2022-02-09 11:32:29 +0000224 match = re.search('GNU gdb \(.*?\) ((\d|\.)+)', gdb_vers_lines[0].strip())
225 if match is None:
226 print(f"Unkown GDB version format: {gdb_vers_lines[0]}", file=sys.stderr)
OCHyams5257efd2022-02-09 10:47:07 +0000227 return None
OCHyams00b2a9c2022-02-09 11:32:29 +0000228 return match.group(1)
OCHyams5257efd2022-02-09 10:47:07 +0000229
230def get_clang_default_dwarf_version_string(triple):
231 """Return the default dwarf version string for clang on this (host) platform
232 or None if we can't work it out.
233 """
234 # Get the flags passed by the driver and look for -dwarf-version.
235 cmd = f'{llvm_config.use_llvm_tool("clang")} -g -xc -c - -v -### --target={triple}'
236 stderr = subprocess.run(cmd.split(), stderr=subprocess.PIPE).stderr.decode()
237 match = re.search('-dwarf-version=(\d+)', stderr)
238 if match is None:
239 print("Cannot determine default dwarf version", file=sys.stderr)
240 return None
241 return match.group(1)
242
243# Some cross-project-tests use gdb, but not all versions of gdb are compatible
244# with clang's dwarf. Add feature `gdb-clang-incompatibility` to signal that
245# there's an incompatibility between clang's default dwarf version for this
246# platform and the installed gdb version.
247dwarf_version_string = get_clang_default_dwarf_version_string(config.host_triple)
248gdb_version_string = get_gdb_version_string()
249if dwarf_version_string and gdb_version_string:
250 if int(dwarf_version_string) >= 5:
Thomas Lively70620942022-03-17 15:22:17 -0700251 if LooseVersion(gdb_version_string) < LooseVersion('10.1'):
OCHyams5257efd2022-02-09 10:47:07 +0000252 # Example for llgdb-tests, which use lldb on darwin but gdb elsewhere:
253 # XFAIL: !system-darwin && gdb-clang-incompatibility
254 config.available_features.add('gdb-clang-incompatibility')
255 print("XFAIL some tests: use gdb version >= 10.1 to restore test coverage", file=sys.stderr)
256
Christian Sigge9b38842020-09-29 15:19:54 +0200257llvm_config.feature_config(
258 [('--build-mode', {'Debug|RelWithDebInfo': 'debug-info'})]
259)
Thomas Lively70620942022-03-17 15:22:17 -0700260
261# Allow 'REQUIRES: XXX-registered-target' in tests.
262for arch in config.targets_to_build:
263 config.available_features.add(arch.lower() + '-registered-target')