6 from distutils
.version
import StrictVersion
11 from lit
.llvm
import llvm_config
12 from lit
.llvm
.subst
import ToolSubst
14 # Configuration file for the 'lit' test runner.
16 # name: The name of this test suite.
17 config
.name
= 'cross-project-tests'
19 # testFormat: The test format to use to interpret tests.
20 config
.test_format
= lit
.formats
.ShTest(not llvm_config
.use_lit_shell
)
22 # suffixes: A list of file extensions to treat as test files.
23 config
.suffixes
= ['.c', '.cpp', '.m']
25 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
26 # subdirectories contain auxiliary inputs for various tests in their parent
28 config
.excludes
= ['Inputs']
30 # test_source_root: The root path where tests are located.
31 config
.test_source_root
= config
.cross_project_tests_src_root
33 # test_exec_root: The root path where tests should be run.
34 config
.test_exec_root
= config
.cross_project_tests_obj_root
36 llvm_config
.use_default_substitutions()
39 ToolSubst('%test_debuginfo', command
=os
.path
.join(
40 config
.cross_project_tests_src_root
, 'debuginfo-tests',
41 'llgdb-tests', 'test_debuginfo.pl')),
42 ToolSubst("%llvm_src_root", config
.llvm_src_root
),
43 ToolSubst("%llvm_tools_dir", config
.llvm_tools_dir
),
46 def get_required_attr(config
, attr_name
):
47 attr_value
= getattr(config
, attr_name
, None)
48 if attr_value
== None:
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
)
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.
57 is_msvc
= get_required_attr(config
, "is_msvc")
59 config
.available_features
.add('msvc')
60 # 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/'
64 llvm_config
.with_system_environment(['LIB', 'LIBPATH', 'INCLUDE'])
65 # Clear _NT_SYMBOL_PATH to prevent cdb from attempting to load symbols from
67 llvm_config
.with_environment('_NT_SYMBOL_PATH', '')
68 tools
.append(ToolSubst('%cdb', '"%s"' % os
.path
.join(win_sdk
, 'Debuggers',
71 # 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.
73 if not hasattr(config
, 'clang_src_dir'):
74 config
.clang_src_dir
= ""
75 llvm_config
.use_clang(required
=('clang' in config
.llvm_enabled_projects
))
77 if not hasattr(config
, 'lld_src_dir'):
78 config
.lld_src_dir
= ""
79 llvm_config
.use_lld(required
=('lld' in config
.llvm_enabled_projects
))
81 if 'compiler-rt' in config
.llvm_enabled_projects
:
82 config
.available_features
.add('compiler-rt')
84 if 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'])
89 # Check which debuggers are available:
90 lldb_path
= llvm_config
.use_llvm_tool('lldb', search_env
='LLDB')
92 if lldb_path
is not None:
93 config
.available_features
.add('lldb')
95 def configure_dexter_substitutions():
96 """Configure substitutions for host platform and return list of dependencies
98 # Produce dexter path, lldb path, and combine into the %dexter substitution
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
))
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
))
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']
118 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'
123 # Use lldb as the debugger on non-Windows platforms.
124 dependencies
= ['clang', 'lldb']
125 dexter_regression_test_builder
= 'clang'
126 dexter_regression_test_debugger
= 'lldb'
127 dexter_regression_test_cflags
= '-O0 -glldb'
128 dexter_regression_test_ldflags
= ''
130 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
))
135 # 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
),
144 '--debugger', dexter_regression_test_debugger
])
145 tools
.append(ToolSubst('%dexter_regression_base', dexter_regression_test_base
))
147 # Include build flags for %dexter_regression_test.
148 dexter_regression_test_build
= ' '.join([
149 dexter_regression_test_base
,
150 '--builder', dexter_regression_test_builder
,
151 '--cflags "', dexter_regression_test_cflags
+ '"',
152 '--ldflags "', dexter_regression_test_ldflags
+ '"'])
153 tools
.append(ToolSubst('%dexter_regression_test', dexter_regression_test_build
))
156 def add_host_triple(clang
):
157 return '{} --target={}'.format(clang
, config
.host_triple
)
159 # The set of arches we can build.
160 targets
= set(config
.targets_to_build
)
161 # Add aliases to the target set.
162 if 'AArch64' in targets
:
164 if 'ARM' in config
.targets_to_build
:
165 targets
.add('thumbv7')
167 def 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
171 return any(config
.host_triple
.lower().startswith(x
.lower())
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
177 if can_target_host():
178 if config
.host_triple
!= config
.target_triple
:
179 print('Forcing dexter tests to use host triple {}.'.format(config
.host_triple
))
180 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')))
190 print('Host triple {} not supported. Skipping dexter tests in the '
191 'debuginfo-tests project.'.format(config
.host_triple
))
193 tool_dirs
= [config
.llvm_tools_dir
]
195 llvm_config
.add_tool_substitutions(tools
, tool_dirs
)
197 lit
.util
.usePlatformSdkOnDarwin(config
, lit_config
)
199 if platform
.system() == 'Darwin':
200 xcode_lldb_vers
= subprocess
.check_output(['xcrun', 'lldb', '--version']).decode("utf-8")
201 match
= re
.search('lldb-(\d+)', xcode_lldb_vers
)
203 apple_lldb_vers
= int(match
.group(1))
204 if apple_lldb_vers
< 1000:
205 config
.available_features
.add('apple-lldb-pre-1000')
207 def 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.
211 # See if we can get a gdb version, e.g.
216 gdb_vers_lines
= subprocess
.check_output(['gdb', '--version']).decode().splitlines()
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
)
222 match
= re
.search('GNU gdb \(.*?\) ((\d|\.)+)', gdb_vers_lines
[0].strip())
224 print(f
"Unkown GDB version format: {gdb_vers_lines[0]}", file=sys
.stderr
)
226 return match
.group(1)
228 def 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.
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
)
237 print("Cannot determine default dwarf version", file=sys
.stderr
)
239 return match
.group(1)
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.
245 dwarf_version_string
= get_clang_default_dwarf_version_string(config
.host_triple
)
246 gdb_version_string
= get_gdb_version_string()
247 if 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
)
255 llvm_config
.feature_config(
256 [('--build-mode', {'Debug|RelWithDebInfo': 'debug-info'})]