[Github] Label lldb-dap PRs (#125139)
[llvm-project.git] / clang / test / lit.cfg.py
blobe4b39c4f715971b68e7a2b4eea87c36786cee24b
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 ".cuh",
37 ".hip",
38 ".hlsl",
39 ".ll",
40 ".cl",
41 ".clcpp",
42 ".s",
43 ".S",
44 ".modulemap",
45 ".test",
46 ".rs",
47 ".ifs",
48 ".rc",
51 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
52 # subdirectories contain auxiliary inputs for various tests in their parent
53 # directories.
54 config.excludes = [
55 "Inputs",
56 "CMakeLists.txt",
57 "README.txt",
58 "LICENSE.txt",
59 "debuginfo-tests",
62 # test_source_root: The root path where tests are located.
63 config.test_source_root = os.path.dirname(__file__)
65 # test_exec_root: The root path where tests should be run.
66 config.test_exec_root = os.path.join(config.clang_obj_root, "test")
68 llvm_config.use_default_substitutions()
70 llvm_config.use_clang()
72 config.substitutions.append(("%src_include_dir", config.clang_src_dir + "/include"))
74 config.substitutions.append(("%target_triple", config.target_triple))
76 config.substitutions.append(("%PATH%", config.environment["PATH"]))
79 # For each occurrence of a clang tool name, replace it with the full path to
80 # the build directory holding that tool. We explicitly specify the directories
81 # to search to ensure that we get the tools just built and not some random
82 # tools that might happen to be in the user's PATH.
83 tool_dirs = [config.clang_tools_dir, config.llvm_tools_dir]
85 tools = [
86 "apinotes-test",
87 "c-index-test",
88 "clang-diff",
89 "clang-format",
90 "clang-repl",
91 "clang-offload-packager",
92 "clang-tblgen",
93 "clang-scan-deps",
94 "clang-installapi",
95 "opt",
96 "llvm-ifs",
97 "yaml2obj",
98 "clang-linker-wrapper",
99 "clang-nvlink-wrapper",
100 "clang-sycl-linker",
101 "llvm-lto",
102 "llvm-lto2",
103 "llvm-profdata",
104 "llvm-readtapi",
105 ToolSubst(
106 "%clang_extdef_map",
107 command=FindTool("clang-extdef-mapping"),
108 unresolved="ignore",
112 if config.clang_examples:
113 config.available_features.add("examples")
116 def have_host_jit_feature_support(feature_name):
117 clang_repl_exe = lit.util.which("clang-repl", config.clang_tools_dir)
119 if not clang_repl_exe:
120 return False
122 try:
123 clang_repl_cmd = subprocess.Popen(
124 [clang_repl_exe, "--host-supports-" + feature_name], stdout=subprocess.PIPE
126 except OSError:
127 print("could not exec clang-repl")
128 return False
130 clang_repl_out = clang_repl_cmd.stdout.read().decode("ascii")
131 clang_repl_cmd.wait()
133 return "true" in clang_repl_out
135 def have_host_clang_repl_cuda():
136 clang_repl_exe = lit.util.which('clang-repl', config.clang_tools_dir)
138 if not clang_repl_exe:
139 return False
141 testcode = b'\n'.join([
142 b"__global__ void test_func() {}",
143 b"test_func<<<1,1>>>();",
144 b"extern \"C\" int puts(const char *s);",
145 b"puts(cudaGetLastError() ? \"failure\" : \"success\");",
146 b"%quit"
148 try:
149 clang_repl_cmd = subprocess.run([clang_repl_exe, '--cuda'],
150 stdout=subprocess.PIPE,
151 stderr=subprocess.PIPE,
152 input=testcode)
153 except OSError:
154 return False
156 if clang_repl_cmd.returncode == 0:
157 if clang_repl_cmd.stdout.find(b"success") != -1:
158 return True
160 return False
162 if have_host_jit_feature_support('jit'):
163 config.available_features.add('host-supports-jit')
165 if have_host_clang_repl_cuda():
166 config.available_features.add('host-supports-cuda')
168 if config.clang_staticanalyzer:
169 config.available_features.add("staticanalyzer")
170 tools.append("clang-check")
172 if config.clang_staticanalyzer_z3:
173 config.available_features.add("z3")
174 else:
175 config.available_features.add("no-z3")
177 check_analyzer_fixit_path = os.path.join(
178 config.test_source_root, "Analysis", "check-analyzer-fixit.py"
180 config.substitutions.append(
182 "%check_analyzer_fixit",
183 '"%s" %s' % (config.python_executable, check_analyzer_fixit_path),
187 llvm_config.add_tool_substitutions(tools, tool_dirs)
189 config.substitutions.append(
191 "%hmaptool",
192 "'%s' %s"
194 config.python_executable,
195 os.path.join(config.clang_src_dir, "utils", "hmaptool", "hmaptool"),
200 config.substitutions.append(
202 "%deps-to-rsp",
203 '"%s" %s'
205 config.python_executable,
206 os.path.join(config.clang_src_dir, "utils", "module-deps-to-rsp.py"),
211 config.substitutions.append(("%host_cc", config.host_cc))
212 config.substitutions.append(("%host_cxx", config.host_cxx))
214 # Determine whether the test target is compatible with execution on the host.
215 if "aarch64" in config.host_arch:
216 config.available_features.add("aarch64-host")
218 # Plugins (loadable modules)
219 if config.has_plugins and config.llvm_plugin_ext:
220 config.available_features.add("plugins")
222 if config.clang_default_pie_on_linux:
223 config.available_features.add("default-pie-on-linux")
225 # Set available features we allow tests to conditionalize on.
227 if config.clang_default_cxx_stdlib != "":
228 config.available_features.add(
229 "default-cxx-stdlib={}".format(config.clang_default_cxx_stdlib)
232 # As of 2011.08, crash-recovery tests still do not pass on FreeBSD.
233 if platform.system() not in ["FreeBSD"]:
234 config.available_features.add("crash-recovery")
236 # ANSI escape sequences in non-dumb terminal
237 if platform.system() not in ["Windows"]:
238 config.available_features.add("ansi-escape-sequences")
240 # Capability to print utf8 to the terminal.
241 # Windows expects codepage, unless Wide API.
242 if platform.system() not in ["Windows"]:
243 config.available_features.add("utf8-capable-terminal")
245 # Support for libgcc runtime. Used to rule out tests that require
246 # clang to run with -rtlib=libgcc.
247 if platform.system() not in ["Darwin", "Fuchsia"]:
248 config.available_features.add("libgcc")
250 # Case-insensitive file system
253 def is_filesystem_case_insensitive():
254 handle, path = tempfile.mkstemp(prefix="case-test", dir=config.test_exec_root)
255 isInsensitive = os.path.exists(
256 os.path.join(os.path.dirname(path), os.path.basename(path).upper())
258 os.close(handle)
259 os.remove(path)
260 return isInsensitive
263 if is_filesystem_case_insensitive():
264 config.available_features.add("case-insensitive-filesystem")
266 # Tests that require the /dev/fd filesystem.
267 if os.path.exists("/dev/fd/0") and sys.platform not in ["cygwin"]:
268 config.available_features.add("dev-fd-fs")
270 # Set on native MS environment.
271 if re.match(r".*-(windows-msvc)$", config.target_triple):
272 config.available_features.add("ms-sdk")
274 # [PR8833] LLP64-incompatible tests
275 if not re.match(
276 r"^(aarch64|x86_64).*-(windows-msvc|windows-gnu)$", config.target_triple
278 config.available_features.add("LP64")
280 # Tests that are specific to the Apple Silicon macOS.
281 if re.match(r"^arm64(e)?-apple-(macos|darwin)", config.target_triple):
282 config.available_features.add("apple-silicon-mac")
284 # [PR18856] Depends to remove opened file. On win32, a file could be removed
285 # only if all handles were closed.
286 if platform.system() not in ["Windows"]:
287 config.available_features.add("can-remove-opened-file")
289 # Features
290 known_arches = ["x86_64", "mips64", "ppc64", "aarch64"]
291 if any(config.target_triple.startswith(x) for x in known_arches):
292 config.available_features.add("clang-target-64-bits")
295 def calculate_arch_features(arch_string):
296 features = []
297 for arch in arch_string.split():
298 features.append(arch.lower() + "-registered-target")
299 return features
302 llvm_config.feature_config(
304 ("--assertion-mode", {"ON": "asserts"}),
305 ("--cxxflags", {r"-D_GLIBCXX_DEBUG\b": "libstdcxx-safe-mode"}),
306 ("--targets-built", calculate_arch_features),
310 if lit.util.which("xmllint"):
311 config.available_features.add("xmllint")
313 if config.enable_backtrace:
314 config.available_features.add("backtrace")
316 if config.enable_threads:
317 config.available_features.add("thread_support")
319 # Check if we should allow outputs to console.
320 run_console_tests = int(lit_config.params.get("enable_console", "0"))
321 if run_console_tests != 0:
322 config.available_features.add("console")
324 lit.util.usePlatformSdkOnDarwin(config, lit_config)
325 macOSSDKVersion = lit.util.findPlatformSdkVersionOnMacOS(config, lit_config)
326 if macOSSDKVersion is not None:
327 config.available_features.add("macos-sdk-" + str(macOSSDKVersion))
329 if os.path.exists("/etc/gentoo-release"):
330 config.available_features.add("gentoo")
332 if config.enable_shared:
333 config.available_features.add("enable_shared")
335 # Add a vendor-specific feature.
336 if config.clang_vendor_uti:
337 config.available_features.add("clang-vendor=" + config.clang_vendor_uti)
339 if config.have_llvm_driver:
340 config.available_features.add("llvm-driver")
343 # Some tests perform deep recursion, which requires a larger pthread stack size
344 # than the relatively low default of 192 KiB for 64-bit processes on AIX. The
345 # `AIXTHREAD_STK` environment variable provides a non-intrusive way to request
346 # a larger pthread stack size for the tests. Various applications and runtime
347 # libraries on AIX use a default pthread stack size of 4 MiB, so we will use
348 # that as a default value here.
349 if "AIXTHREAD_STK" in os.environ:
350 config.environment["AIXTHREAD_STK"] = os.environ["AIXTHREAD_STK"]
351 elif platform.system() == "AIX":
352 config.environment["AIXTHREAD_STK"] = "4194304"
354 # Some tools support an environment variable "OBJECT_MODE" on AIX OS, which
355 # controls the kind of objects they will support. If there is no "OBJECT_MODE"
356 # environment variable specified, the default behaviour is to support 32-bit
357 # objects only. In order to not affect most test cases, which expect to support
358 # 32-bit and 64-bit objects by default, set the environment variable
359 # "OBJECT_MODE" to "any" by default on AIX OS.
361 if "system-aix" in config.available_features:
362 config.substitutions.append(("llvm-nm", "env OBJECT_MODE=any llvm-nm"))
363 config.substitutions.append(("llvm-ar", "env OBJECT_MODE=any llvm-ar"))
364 config.substitutions.append(("llvm-ranlib", "env OBJECT_MODE=any llvm-ranlib"))
366 # It is not realistically possible to account for all options that could
367 # possibly be present in system and user configuration files, so disable
368 # default configs for the test runs.
369 config.environment["CLANG_NO_DEFAULT_CONFIG"] = "1"