Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / lit.cfg.py
blob60843ef8a1420485c6505d53da32b2985d0b3aa9
1 # -*- Python -*-
3 import os
4 import platform
5 import re
6 import subprocess
7 import tempfile
9 import lit.formats
10 import lit.util
12 from lit.llvm import llvm_config
13 from lit.llvm.subst import ToolSubst
14 from lit.llvm.subst import FindTool
16 # Configuration file for the 'lit' test runner.
18 # name: The name of this test suite.
19 config.name = "Clang"
21 # testFormat: The test format to use to interpret tests.
23 # For now we require '&&' between commands, until they get globally killed and
24 # the test runner updated.
25 config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
27 # suffixes: A list of file extensions to treat as test files.
28 config.suffixes = [
29 ".c",
30 ".cpp",
31 ".i",
32 ".cppm",
33 ".m",
34 ".mm",
35 ".cu",
36 ".hip",
37 ".hlsl",
38 ".ll",
39 ".cl",
40 ".clcpp",
41 ".s",
42 ".S",
43 ".modulemap",
44 ".test",
45 ".rs",
46 ".ifs",
47 ".rc",
50 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
51 # subdirectories contain auxiliary inputs for various tests in their parent
52 # directories.
53 config.excludes = [
54 "Inputs",
55 "CMakeLists.txt",
56 "README.txt",
57 "LICENSE.txt",
58 "debuginfo-tests",
61 # test_source_root: The root path where tests are located.
62 config.test_source_root = os.path.dirname(__file__)
64 # test_exec_root: The root path where tests should be run.
65 config.test_exec_root = os.path.join(config.clang_obj_root, "test")
67 llvm_config.use_default_substitutions()
69 llvm_config.use_clang()
71 config.substitutions.append(("%src_include_dir", config.clang_src_dir + "/include"))
73 config.substitutions.append(("%target_triple", config.target_triple))
75 config.substitutions.append(("%PATH%", config.environment["PATH"]))
78 # For each occurrence of a clang tool name, replace it with the full path to
79 # the build directory holding that tool. We explicitly specify the directories
80 # to search to ensure that we get the tools just built and not some random
81 # tools that might happen to be in the user's PATH.
82 tool_dirs = [config.clang_tools_dir, config.llvm_tools_dir]
84 tools = [
85 "apinotes-test",
86 "c-index-test",
87 "clang-diff",
88 "clang-format",
89 "clang-repl",
90 "clang-offload-packager",
91 "clang-tblgen",
92 "clang-scan-deps",
93 "opt",
94 "llvm-ifs",
95 "yaml2obj",
96 "clang-linker-wrapper",
97 "llvm-lto",
98 "llvm-lto2",
99 "llvm-profdata",
100 ToolSubst(
101 "%clang_extdef_map",
102 command=FindTool("clang-extdef-mapping"),
103 unresolved="ignore",
107 if config.clang_examples:
108 config.available_features.add("examples")
111 def have_host_jit_feature_support(feature_name):
112 clang_repl_exe = lit.util.which("clang-repl", config.clang_tools_dir)
114 if not clang_repl_exe:
115 return False
117 try:
118 clang_repl_cmd = subprocess.Popen(
119 [clang_repl_exe, "--host-supports-" + feature_name], stdout=subprocess.PIPE
121 except OSError:
122 print("could not exec clang-repl")
123 return False
125 clang_repl_out = clang_repl_cmd.stdout.read().decode("ascii")
126 clang_repl_cmd.wait()
128 return "true" in clang_repl_out
130 def have_host_clang_repl_cuda():
131 clang_repl_exe = lit.util.which('clang-repl', config.clang_tools_dir)
133 if not clang_repl_exe:
134 return False
136 testcode = b'\n'.join([
137 b"__global__ void test_func() {}",
138 b"test_func<<<1,1>>>();",
139 b"extern \"C\" int puts(const char *s);",
140 b"puts(cudaGetLastError() ? \"failure\" : \"success\");",
141 b"%quit"
143 try:
144 clang_repl_cmd = subprocess.run([clang_repl_exe, '--cuda'],
145 stdout=subprocess.PIPE,
146 stderr=subprocess.PIPE,
147 input=testcode)
148 except OSError:
149 return False
151 if clang_repl_cmd.returncode == 0:
152 if clang_repl_cmd.stdout.find(b"success") != -1:
153 return True
155 return False
157 if have_host_jit_feature_support('jit'):
158 config.available_features.add('host-supports-jit')
160 if have_host_clang_repl_cuda():
161 config.available_features.add('host-supports-cuda')
163 if config.clang_staticanalyzer:
164 config.available_features.add("staticanalyzer")
165 tools.append("clang-check")
167 if config.clang_staticanalyzer_z3:
168 config.available_features.add("z3")
169 else:
170 config.available_features.add("no-z3")
172 check_analyzer_fixit_path = os.path.join(
173 config.test_source_root, "Analysis", "check-analyzer-fixit.py"
175 config.substitutions.append(
177 "%check_analyzer_fixit",
178 '"%s" %s' % (config.python_executable, check_analyzer_fixit_path),
182 llvm_config.add_tool_substitutions(tools, tool_dirs)
184 config.substitutions.append(
186 "%hmaptool",
187 "'%s' %s"
189 config.python_executable,
190 os.path.join(config.clang_src_dir, "utils", "hmaptool", "hmaptool"),
195 config.substitutions.append(
197 "%deps-to-rsp",
198 '"%s" %s'
200 config.python_executable,
201 os.path.join(config.clang_src_dir, "utils", "module-deps-to-rsp.py"),
206 config.substitutions.append(("%host_cc", config.host_cc))
207 config.substitutions.append(("%host_cxx", config.host_cxx))
210 # Plugins (loadable modules)
211 if config.has_plugins and config.llvm_plugin_ext:
212 config.available_features.add("plugins")
214 if config.clang_default_pie_on_linux:
215 config.available_features.add("default-pie-on-linux")
217 # Set available features we allow tests to conditionalize on.
219 if config.clang_default_cxx_stdlib != "":
220 config.available_features.add(
221 "default-cxx-stdlib={}".format(config.clang_default_cxx_stdlib)
224 # As of 2011.08, crash-recovery tests still do not pass on FreeBSD.
225 if platform.system() not in ["FreeBSD"]:
226 config.available_features.add("crash-recovery")
228 # ANSI escape sequences in non-dumb terminal
229 if platform.system() not in ["Windows"]:
230 config.available_features.add("ansi-escape-sequences")
232 # Capability to print utf8 to the terminal.
233 # Windows expects codepage, unless Wide API.
234 if platform.system() not in ["Windows"]:
235 config.available_features.add("utf8-capable-terminal")
237 # Support for libgcc runtime. Used to rule out tests that require
238 # clang to run with -rtlib=libgcc.
239 if platform.system() not in ["Darwin", "Fuchsia"]:
240 config.available_features.add("libgcc")
242 # Case-insensitive file system
245 def is_filesystem_case_insensitive():
246 handle, path = tempfile.mkstemp(prefix="case-test", dir=config.test_exec_root)
247 isInsensitive = os.path.exists(
248 os.path.join(os.path.dirname(path), os.path.basename(path).upper())
250 os.close(handle)
251 os.remove(path)
252 return isInsensitive
255 if is_filesystem_case_insensitive():
256 config.available_features.add("case-insensitive-filesystem")
258 # Tests that require the /dev/fd filesystem.
259 if os.path.exists("/dev/fd/0") and sys.platform not in ["cygwin"]:
260 config.available_features.add("dev-fd-fs")
262 # Set on native MS environment.
263 if re.match(r".*-(windows-msvc)$", config.target_triple):
264 config.available_features.add("ms-sdk")
266 # [PR8833] LLP64-incompatible tests
267 if not re.match(
268 r"^(aarch64|x86_64).*-(windows-msvc|windows-gnu)$", config.target_triple
270 config.available_features.add("LP64")
272 # Tests that are specific to the Apple Silicon macOS.
273 if re.match(r"^arm64(e)?-apple-(macos|darwin)", config.target_triple):
274 config.available_features.add("apple-silicon-mac")
276 # [PR18856] Depends to remove opened file. On win32, a file could be removed
277 # only if all handles were closed.
278 if platform.system() not in ["Windows"]:
279 config.available_features.add("can-remove-opened-file")
281 # Features
282 known_arches = ["x86_64", "mips64", "ppc64", "aarch64"]
283 if any(config.target_triple.startswith(x) for x in known_arches):
284 config.available_features.add("clang-target-64-bits")
287 def calculate_arch_features(arch_string):
288 features = []
289 for arch in arch_string.split():
290 features.append(arch.lower() + "-registered-target")
291 return features
294 llvm_config.feature_config(
296 ("--assertion-mode", {"ON": "asserts"}),
297 ("--cxxflags", {r"-D_GLIBCXX_DEBUG\b": "libstdcxx-safe-mode"}),
298 ("--targets-built", calculate_arch_features),
302 if lit.util.which("xmllint"):
303 config.available_features.add("xmllint")
305 if config.enable_backtrace:
306 config.available_features.add("backtrace")
308 if config.enable_threads:
309 config.available_features.add("thread_support")
311 # Check if we should allow outputs to console.
312 run_console_tests = int(lit_config.params.get("enable_console", "0"))
313 if run_console_tests != 0:
314 config.available_features.add("console")
316 lit.util.usePlatformSdkOnDarwin(config, lit_config)
317 macOSSDKVersion = lit.util.findPlatformSdkVersionOnMacOS(config, lit_config)
318 if macOSSDKVersion is not None:
319 config.available_features.add("macos-sdk-" + str(macOSSDKVersion))
321 if os.path.exists("/etc/gentoo-release"):
322 config.available_features.add("gentoo")
324 if config.enable_shared:
325 config.available_features.add("enable_shared")
327 # Add a vendor-specific feature.
328 if config.clang_vendor_uti:
329 config.available_features.add("clang-vendor=" + config.clang_vendor_uti)
331 if config.have_llvm_driver:
332 config.available_features.add("llvm-driver")
335 def exclude_unsupported_files_for_aix(dirname):
336 for filename in os.listdir(dirname):
337 source_path = os.path.join(dirname, filename)
338 if os.path.isdir(source_path):
339 continue
340 f = open(source_path, "r", encoding="ISO-8859-1")
341 try:
342 data = f.read()
343 # 64-bit object files are not supported on AIX, so exclude the tests.
344 if (
345 any(
346 option in data
347 for option in (
348 "-emit-obj",
349 "-fmodule-format=obj",
350 "-fintegrated-as",
353 and "64" in config.target_triple
355 config.excludes += [filename]
356 finally:
357 f.close()
360 if "aix" in config.target_triple:
361 for directory in (
362 "/CodeGenCXX",
363 "/Misc",
364 "/Modules",
365 "/PCH",
366 "/Driver",
367 "/ASTMerge/anonymous-fields",
368 "/ASTMerge/injected-class-name-decl",
370 exclude_unsupported_files_for_aix(config.test_source_root + directory)
372 # Some tests perform deep recursion, which requires a larger pthread stack size
373 # than the relatively low default of 192 KiB for 64-bit processes on AIX. The
374 # `AIXTHREAD_STK` environment variable provides a non-intrusive way to request
375 # a larger pthread stack size for the tests. Various applications and runtime
376 # libraries on AIX use a default pthread stack size of 4 MiB, so we will use
377 # that as a default value here.
378 if "AIXTHREAD_STK" in os.environ:
379 config.environment["AIXTHREAD_STK"] = os.environ["AIXTHREAD_STK"]
380 elif platform.system() == "AIX":
381 config.environment["AIXTHREAD_STK"] = "4194304"
383 # Some tools support an environment variable "OBJECT_MODE" on AIX OS, which
384 # controls the kind of objects they will support. If there is no "OBJECT_MODE"
385 # environment variable specified, the default behaviour is to support 32-bit
386 # objects only. In order to not affect most test cases, which expect to support
387 # 32-bit and 64-bit objects by default, set the environment variable
388 # "OBJECT_MODE" to "any" by default on AIX OS.
390 if "system-aix" in config.available_features:
391 config.substitutions.append(("llvm-nm", "env OBJECT_MODE=any llvm-nm"))
392 config.substitutions.append(("llvm-ar", "env OBJECT_MODE=any llvm-ar"))
393 config.substitutions.append(("llvm-ranlib", "env OBJECT_MODE=any llvm-ranlib"))
395 # It is not realistically possible to account for all options that could
396 # possibly be present in system and user configuration files, so disable
397 # default configs for the test runs.
398 config.environment["CLANG_NO_DEFAULT_CONFIG"] = "1"