7 # TODO: LooseVersion is undocumented; use something else.
8 from distutils
.version
import LooseVersion
13 from lit
.llvm
import llvm_config
14 from lit
.llvm
.subst
import ToolSubst
16 # Configuration file for the 'lit' test runner.
18 # name: The name of this test suite.
19 config
.name
= "cross-project-tests"
21 # testFormat: The test format to use to interpret tests.
22 config
.test_format
= lit
.formats
.ShTest(not llvm_config
.use_lit_shell
)
24 # suffixes: A list of file extensions to treat as test files.
25 config
.suffixes
= [".c", ".cl", ".cpp", ".m"]
27 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
28 # subdirectories contain auxiliary inputs for various tests in their parent
30 config
.excludes
= ["Inputs"]
32 # test_source_root: The root path where tests are located.
33 config
.test_source_root
= config
.cross_project_tests_src_root
35 # test_exec_root: The root path where tests should be run.
36 config
.test_exec_root
= config
.cross_project_tests_obj_root
38 llvm_config
.use_default_substitutions()
44 config
.cross_project_tests_src_root
,
50 ToolSubst("%llvm_src_root", config
.llvm_src_root
),
51 ToolSubst("%llvm_tools_dir", config
.llvm_tools_dir
),
55 def get_required_attr(config
, attr_name
):
56 attr_value
= getattr(config
, attr_name
, None)
57 if attr_value
== None:
59 "No attribute %r in test configuration! You may need to run "
60 "tests from your build directory or add this attribute "
61 "to lit.site.cfg " % attr_name
66 # If this is an MSVC environment, the tests at the root of the tree are
67 # unsupported. The local win_cdb test suite, however, is supported.
68 is_msvc
= get_required_attr(config
, "is_msvc")
70 config
.available_features
.add("msvc")
71 # FIXME: We should add some llvm lit utility code to find the Windows SDK
72 # and set up the environment appopriately.
73 win_sdk
= "C:/Program Files (x86)/Windows Kits/10/"
75 llvm_config
.with_system_environment(["LIB", "LIBPATH", "INCLUDE"])
76 # Clear _NT_SYMBOL_PATH to prevent cdb from attempting to load symbols from
78 llvm_config
.with_environment("_NT_SYMBOL_PATH", "")
80 ToolSubst("%cdb", '"%s"' % os
.path
.join(win_sdk
, "Debuggers", arch
, "cdb.exe"))
83 # clang_src_dir and lld_src_dir are not used by these tests, but are required by
84 # use_clang() and use_lld() respectively, so set them to "", if needed.
85 if not hasattr(config
, "clang_src_dir"):
86 config
.clang_src_dir
= ""
87 llvm_config
.use_clang(required
=("clang" in config
.llvm_enabled_projects
))
89 if not hasattr(config
, "lld_src_dir"):
90 config
.lld_src_dir
= ""
91 llvm_config
.use_lld(required
=("lld" in config
.llvm_enabled_projects
))
93 if "compiler-rt" in config
.llvm_enabled_projects
:
94 config
.available_features
.add("compiler-rt")
96 # Check which debuggers are available:
97 lldb_path
= llvm_config
.use_llvm_tool("lldb", search_env
="LLDB")
99 if lldb_path
is not None:
100 config
.available_features
.add("lldb")
103 def configure_dexter_substitutions():
104 """Configure substitutions for host platform and return list of dependencies"""
105 # Produce dexter path, lldb path, and combine into the %dexter substitution
106 # for running a test.
107 dexter_path
= os
.path
.join(
108 config
.cross_project_tests_src_root
, "debuginfo-tests", "dexter", "dexter.py"
110 dexter_test_cmd
= '"{}" "{}" test'.format(sys
.executable
, dexter_path
)
111 if lldb_path
is not None:
112 dexter_test_cmd
+= ' --lldb-executable "{}"'.format(lldb_path
)
113 tools
.append(ToolSubst("%dexter", dexter_test_cmd
))
115 # For testing other bits of dexter that aren't under the "test" subcommand,
116 # have a %dexter_base substitution.
117 dexter_base_cmd
= '"{}" "{}"'.format(sys
.executable
, dexter_path
)
118 tools
.append(ToolSubst("%dexter_base", dexter_base_cmd
))
120 # Set up commands for DexTer regression tests.
121 # Builder, debugger, optimisation level and several other flags differ
122 # depending on whether we're running a unix like or windows os.
123 if platform
.system() == "Windows":
124 # The Windows builder script uses lld.
125 dependencies
= ["clang", "lld-link"]
126 dexter_regression_test_builder
= "clang-cl"
127 dexter_regression_test_debugger
= "dbgeng"
128 dexter_regression_test_flags
= "/Zi /Od"
130 # Use lldb as the debugger on non-Windows platforms.
131 dependencies
= ["clang", "lldb"]
132 dexter_regression_test_builder
= "clang++"
133 dexter_regression_test_debugger
= "lldb"
134 dexter_regression_test_flags
= "-O0 -glldb -std=gnu++11"
137 ToolSubst("%dexter_regression_test_builder", dexter_regression_test_builder
)
140 ToolSubst("%dexter_regression_test_debugger", dexter_regression_test_debugger
)
142 # We don't need to distinguish cflags and ldflags because for Dexter
143 # regression tests we use clang to drive the linker, and so all flags will be
144 # passed in a single command.
146 ToolSubst("%dexter_regression_test_flags", dexter_regression_test_flags
)
149 # Typical command would take the form:
150 # ./path_to_py/python.exe ./path_to_dex/dexter.py test --fail-lt 1.0 -w --binary %t --debugger lldb --cflags '-O0 -g'
151 dexter_regression_test_run
= " ".join(
152 # "python", "dexter.py", test, fail_mode, builder, debugger, cflags, ldflags
154 '"{}"'.format(sys
.executable
),
155 '"{}"'.format(dexter_path
),
159 dexter_regression_test_debugger
,
162 tools
.append(ToolSubst("%dexter_regression_test_run", dexter_regression_test_run
))
164 # Include build flags for %dexter_regression_test.
165 dexter_regression_test_build
= " ".join(
167 dexter_regression_test_builder
,
168 dexter_regression_test_flags
,
171 tools
.append(ToolSubst("%dexter_regression_test_build", dexter_regression_test_build
))
175 def add_host_triple(clang
):
176 return "{} --target={}".format(clang
, config
.host_triple
)
179 # The set of arches we can build.
180 targets
= set(config
.targets_to_build
)
181 # Add aliases to the target set.
182 if "AArch64" in targets
:
184 if "ARM" in config
.targets_to_build
:
185 targets
.add("thumbv7")
188 def can_target_host():
189 # Check if the targets set contains anything that looks like our host arch.
190 # The arch name in the triple and targets set may be spelled differently
192 return any(config
.host_triple
.lower().startswith(x
.lower()) for x
in targets
)
195 # Dexter tests run on the host machine. If the host arch is supported add
196 # 'dexter' as an available feature and force the dexter tests to use the host
198 if can_target_host():
199 if config
.host_triple
!= config
.target_triple
:
200 print("Forcing dexter tests to use host triple {}.".format(config
.host_triple
))
201 dependencies
= configure_dexter_substitutions()
202 if all(d
in config
.available_features
for d
in dependencies
):
203 config
.available_features
.add("dexter")
204 llvm_config
.with_environment(
205 "PATHTOCLANG", add_host_triple(llvm_config
.config
.clang
)
207 llvm_config
.with_environment(
208 "PATHTOCLANGPP", add_host_triple(llvm_config
.use_llvm_tool("clang++"))
210 llvm_config
.with_environment(
211 "PATHTOCLANGCL", add_host_triple(llvm_config
.use_llvm_tool("clang-cl"))
215 "Host triple {} not supported. Skipping dexter tests in the "
216 "debuginfo-tests project.".format(config
.host_triple
)
219 tool_dirs
= [config
.llvm_tools_dir
]
221 llvm_config
.add_tool_substitutions(tools
, tool_dirs
)
223 lit
.util
.usePlatformSdkOnDarwin(config
, lit_config
)
225 if platform
.system() == "Darwin":
226 xcode_lldb_vers
= subprocess
.check_output(["xcrun", "lldb", "--version"]).decode(
229 match
= re
.search("lldb-(\d+)", xcode_lldb_vers
)
231 apple_lldb_vers
= int(match
.group(1))
232 if apple_lldb_vers
< 1000:
233 config
.available_features
.add("apple-lldb-pre-1000")
236 def get_gdb_version_string():
237 """Return gdb's version string, or None if gdb cannot be found or the
238 --version output is formatted unexpectedly.
240 # See if we can get a gdb version, e.g.
246 subprocess
.check_output(["gdb", "--version"]).decode().splitlines()
249 return None # We coudln't find gdb or something went wrong running it.
250 if len(gdb_vers_lines
) < 1:
251 print("Unkown GDB version format (too few lines)", file=sys
.stderr
)
253 match
= re
.search("GNU gdb \(.*?\) ((\d|\.)+)", gdb_vers_lines
[0].strip())
255 print(f
"Unkown GDB version format: {gdb_vers_lines[0]}", file=sys
.stderr
)
257 return match
.group(1)
260 def get_clang_default_dwarf_version_string(triple
):
261 """Return the default dwarf version string for clang on this (host) platform
262 or None if we can't work it out.
264 # Get the flags passed by the driver and look for -dwarf-version.
265 cmd
= f
'{llvm_config.use_llvm_tool("clang")} -g -xc -c - -v -### --target={triple}'
266 stderr
= subprocess
.run(cmd
.split(), stderr
=subprocess
.PIPE
).stderr
.decode()
267 match
= re
.search("-dwarf-version=(\d+)", stderr
)
269 print("Cannot determine default dwarf version", file=sys
.stderr
)
271 return match
.group(1)
274 # Some cross-project-tests use gdb, but not all versions of gdb are compatible
275 # with clang's dwarf. Add feature `gdb-clang-incompatibility` to signal that
276 # there's an incompatibility between clang's default dwarf version for this
277 # platform and the installed gdb version.
278 dwarf_version_string
= get_clang_default_dwarf_version_string(config
.host_triple
)
279 gdb_version_string
= get_gdb_version_string()
280 if dwarf_version_string
and gdb_version_string
:
281 if int(dwarf_version_string
) >= 5:
282 if LooseVersion(gdb_version_string
) < LooseVersion("10.1"):
283 # Example for llgdb-tests, which use lldb on darwin but gdb elsewhere:
284 # XFAIL: !system-darwin && gdb-clang-incompatibility
285 config
.available_features
.add("gdb-clang-incompatibility")
287 "XFAIL some tests: use gdb version >= 10.1 to restore test coverage",
291 llvm_config
.feature_config([("--build-mode", {"Debug|RelWithDebInfo": "debug-info"})])
293 # Allow 'REQUIRES: XXX-registered-target' in tests.
294 for arch
in config
.targets_to_build
:
295 config
.available_features
.add(arch
.lower() + "-registered-target")