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_vs2015"
127 dexter_regression_test_debugger
= "dbgeng"
128 dexter_regression_test_cflags
= "/Zi /Od"
129 dexter_regression_test_ldflags
= "/Zi"
131 # Use lldb as the debugger on non-Windows platforms.
132 dependencies
= ["clang", "lldb"]
133 dexter_regression_test_builder
= "clang"
134 dexter_regression_test_debugger
= "lldb"
135 dexter_regression_test_cflags
= "-O0 -glldb"
136 dexter_regression_test_ldflags
= ""
139 ToolSubst("%dexter_regression_test_builder", dexter_regression_test_builder
)
142 ToolSubst("%dexter_regression_test_debugger", dexter_regression_test_debugger
)
145 ToolSubst("%dexter_regression_test_cflags", dexter_regression_test_cflags
)
148 ToolSubst("%dexter_regression_test_ldflags", dexter_regression_test_cflags
)
151 # Typical command would take the form:
152 # ./path_to_py/python.exe ./path_to_dex/dexter.py test --fail-lt 1.0 -w --builder clang --debugger lldb --cflags '-O0 -g'
153 # Exclude build flags for %dexter_regression_base.
154 dexter_regression_test_base
= " ".join(
155 # "python", "dexter.py", test, fail_mode, builder, debugger, cflags, ldflags
157 '"{}"'.format(sys
.executable
),
158 '"{}"'.format(dexter_path
),
162 dexter_regression_test_debugger
,
165 tools
.append(ToolSubst("%dexter_regression_base", dexter_regression_test_base
))
167 # Include build flags for %dexter_regression_test.
168 dexter_regression_test_build
= " ".join(
170 dexter_regression_test_base
,
172 dexter_regression_test_builder
,
174 dexter_regression_test_cflags
+ '"',
176 dexter_regression_test_ldflags
+ '"',
179 tools
.append(ToolSubst("%dexter_regression_test", dexter_regression_test_build
))
183 def add_host_triple(clang
):
184 return "{} --target={}".format(clang
, config
.host_triple
)
187 # The set of arches we can build.
188 targets
= set(config
.targets_to_build
)
189 # Add aliases to the target set.
190 if "AArch64" in targets
:
192 if "ARM" in config
.targets_to_build
:
193 targets
.add("thumbv7")
196 def can_target_host():
197 # Check if the targets set contains anything that looks like our host arch.
198 # The arch name in the triple and targets set may be spelled differently
200 return any(config
.host_triple
.lower().startswith(x
.lower()) for x
in targets
)
203 # Dexter tests run on the host machine. If the host arch is supported add
204 # 'dexter' as an available feature and force the dexter tests to use the host
206 if can_target_host():
207 if config
.host_triple
!= config
.target_triple
:
208 print("Forcing dexter tests to use host triple {}.".format(config
.host_triple
))
209 dependencies
= configure_dexter_substitutions()
210 if all(d
in config
.available_features
for d
in dependencies
):
211 config
.available_features
.add("dexter")
212 llvm_config
.with_environment(
213 "PATHTOCLANG", add_host_triple(llvm_config
.config
.clang
)
215 llvm_config
.with_environment(
216 "PATHTOCLANGPP", add_host_triple(llvm_config
.use_llvm_tool("clang++"))
218 llvm_config
.with_environment(
219 "PATHTOCLANGCL", add_host_triple(llvm_config
.use_llvm_tool("clang-cl"))
223 "Host triple {} not supported. Skipping dexter tests in the "
224 "debuginfo-tests project.".format(config
.host_triple
)
227 tool_dirs
= [config
.llvm_tools_dir
]
229 llvm_config
.add_tool_substitutions(tools
, tool_dirs
)
231 lit
.util
.usePlatformSdkOnDarwin(config
, lit_config
)
233 if platform
.system() == "Darwin":
234 xcode_lldb_vers
= subprocess
.check_output(["xcrun", "lldb", "--version"]).decode(
237 match
= re
.search("lldb-(\d+)", xcode_lldb_vers
)
239 apple_lldb_vers
= int(match
.group(1))
240 if apple_lldb_vers
< 1000:
241 config
.available_features
.add("apple-lldb-pre-1000")
244 def get_gdb_version_string():
245 """Return gdb's version string, or None if gdb cannot be found or the
246 --version output is formatted unexpectedly.
248 # See if we can get a gdb version, e.g.
254 subprocess
.check_output(["gdb", "--version"]).decode().splitlines()
257 return None # We coudln't find gdb or something went wrong running it.
258 if len(gdb_vers_lines
) < 1:
259 print("Unkown GDB version format (too few lines)", file=sys
.stderr
)
261 match
= re
.search("GNU gdb \(.*?\) ((\d|\.)+)", gdb_vers_lines
[0].strip())
263 print(f
"Unkown GDB version format: {gdb_vers_lines[0]}", file=sys
.stderr
)
265 return match
.group(1)
268 def get_clang_default_dwarf_version_string(triple
):
269 """Return the default dwarf version string for clang on this (host) platform
270 or None if we can't work it out.
272 # Get the flags passed by the driver and look for -dwarf-version.
273 cmd
= f
'{llvm_config.use_llvm_tool("clang")} -g -xc -c - -v -### --target={triple}'
274 stderr
= subprocess
.run(cmd
.split(), stderr
=subprocess
.PIPE
).stderr
.decode()
275 match
= re
.search("-dwarf-version=(\d+)", stderr
)
277 print("Cannot determine default dwarf version", file=sys
.stderr
)
279 return match
.group(1)
282 # Some cross-project-tests use gdb, but not all versions of gdb are compatible
283 # with clang's dwarf. Add feature `gdb-clang-incompatibility` to signal that
284 # there's an incompatibility between clang's default dwarf version for this
285 # platform and the installed gdb version.
286 dwarf_version_string
= get_clang_default_dwarf_version_string(config
.host_triple
)
287 gdb_version_string
= get_gdb_version_string()
288 if dwarf_version_string
and gdb_version_string
:
289 if int(dwarf_version_string
) >= 5:
290 if LooseVersion(gdb_version_string
) < LooseVersion("10.1"):
291 # Example for llgdb-tests, which use lldb on darwin but gdb elsewhere:
292 # XFAIL: !system-darwin && gdb-clang-incompatibility
293 config
.available_features
.add("gdb-clang-incompatibility")
295 "XFAIL some tests: use gdb version >= 10.1 to restore test coverage",
299 llvm_config
.feature_config([("--build-mode", {"Debug|RelWithDebInfo": "debug-info"})])
301 # Allow 'REQUIRES: XXX-registered-target' in tests.
302 for arch
in config
.targets_to_build
:
303 config
.available_features
.add(arch
.lower() + "-registered-target")