[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / lit.cfg.py
blob7e7934d5fe0f5f959222e20157a38c2f7db695eb
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 "clang-installapi",
94 "opt",
95 "llvm-ifs",
96 "yaml2obj",
97 "clang-linker-wrapper",
98 "clang-nvlink-wrapper",
99 "clang-sycl-linker",
100 "llvm-lto",
101 "llvm-lto2",
102 "llvm-profdata",
103 "llvm-readtapi",
104 ToolSubst(
105 "%clang_extdef_map",
106 command=FindTool("clang-extdef-mapping"),
107 unresolved="ignore",
111 if config.clang_examples:
112 config.available_features.add("examples")
115 def have_host_jit_feature_support(feature_name):
116 clang_repl_exe = lit.util.which("clang-repl", config.clang_tools_dir)
118 if not clang_repl_exe:
119 return False
121 try:
122 clang_repl_cmd = subprocess.Popen(
123 [clang_repl_exe, "--host-supports-" + feature_name], stdout=subprocess.PIPE
125 except OSError:
126 print("could not exec clang-repl")
127 return False
129 clang_repl_out = clang_repl_cmd.stdout.read().decode("ascii")
130 clang_repl_cmd.wait()
132 return "true" in clang_repl_out
134 def have_host_clang_repl_cuda():
135 clang_repl_exe = lit.util.which('clang-repl', config.clang_tools_dir)
137 if not clang_repl_exe:
138 return False
140 testcode = b'\n'.join([
141 b"__global__ void test_func() {}",
142 b"test_func<<<1,1>>>();",
143 b"extern \"C\" int puts(const char *s);",
144 b"puts(cudaGetLastError() ? \"failure\" : \"success\");",
145 b"%quit"
147 try:
148 clang_repl_cmd = subprocess.run([clang_repl_exe, '--cuda'],
149 stdout=subprocess.PIPE,
150 stderr=subprocess.PIPE,
151 input=testcode)
152 except OSError:
153 return False
155 if clang_repl_cmd.returncode == 0:
156 if clang_repl_cmd.stdout.find(b"success") != -1:
157 return True
159 return False
161 if have_host_jit_feature_support('jit'):
162 config.available_features.add('host-supports-jit')
164 if have_host_clang_repl_cuda():
165 config.available_features.add('host-supports-cuda')
167 if config.clang_staticanalyzer:
168 config.available_features.add("staticanalyzer")
169 tools.append("clang-check")
171 if config.clang_staticanalyzer_z3:
172 config.available_features.add("z3")
173 else:
174 config.available_features.add("no-z3")
176 check_analyzer_fixit_path = os.path.join(
177 config.test_source_root, "Analysis", "check-analyzer-fixit.py"
179 config.substitutions.append(
181 "%check_analyzer_fixit",
182 '"%s" %s' % (config.python_executable, check_analyzer_fixit_path),
186 llvm_config.add_tool_substitutions(tools, tool_dirs)
188 config.substitutions.append(
190 "%hmaptool",
191 "'%s' %s"
193 config.python_executable,
194 os.path.join(config.clang_src_dir, "utils", "hmaptool", "hmaptool"),
199 config.substitutions.append(
201 "%deps-to-rsp",
202 '"%s" %s'
204 config.python_executable,
205 os.path.join(config.clang_src_dir, "utils", "module-deps-to-rsp.py"),
210 config.substitutions.append(("%host_cc", config.host_cc))
211 config.substitutions.append(("%host_cxx", config.host_cxx))
213 # Determine whether the test target is compatible with execution on the host.
214 if "aarch64" in config.host_arch:
215 config.available_features.add("aarch64-host")
217 # Plugins (loadable modules)
218 if config.has_plugins and config.llvm_plugin_ext:
219 config.available_features.add("plugins")
221 if config.clang_default_pie_on_linux:
222 config.available_features.add("default-pie-on-linux")
224 # Set available features we allow tests to conditionalize on.
226 if config.clang_default_cxx_stdlib != "":
227 config.available_features.add(
228 "default-cxx-stdlib={}".format(config.clang_default_cxx_stdlib)
231 # As of 2011.08, crash-recovery tests still do not pass on FreeBSD.
232 if platform.system() not in ["FreeBSD"]:
233 config.available_features.add("crash-recovery")
235 # ANSI escape sequences in non-dumb terminal
236 if platform.system() not in ["Windows"]:
237 config.available_features.add("ansi-escape-sequences")
239 # Capability to print utf8 to the terminal.
240 # Windows expects codepage, unless Wide API.
241 if platform.system() not in ["Windows"]:
242 config.available_features.add("utf8-capable-terminal")
244 # Support for libgcc runtime. Used to rule out tests that require
245 # clang to run with -rtlib=libgcc.
246 if platform.system() not in ["Darwin", "Fuchsia"]:
247 config.available_features.add("libgcc")
249 # Case-insensitive file system
252 def is_filesystem_case_insensitive():
253 handle, path = tempfile.mkstemp(prefix="case-test", dir=config.test_exec_root)
254 isInsensitive = os.path.exists(
255 os.path.join(os.path.dirname(path), os.path.basename(path).upper())
257 os.close(handle)
258 os.remove(path)
259 return isInsensitive
262 if is_filesystem_case_insensitive():
263 config.available_features.add("case-insensitive-filesystem")
265 # Tests that require the /dev/fd filesystem.
266 if os.path.exists("/dev/fd/0") and sys.platform not in ["cygwin"]:
267 config.available_features.add("dev-fd-fs")
269 # Set on native MS environment.
270 if re.match(r".*-(windows-msvc)$", config.target_triple):
271 config.available_features.add("ms-sdk")
273 # [PR8833] LLP64-incompatible tests
274 if not re.match(
275 r"^(aarch64|x86_64).*-(windows-msvc|windows-gnu)$", config.target_triple
277 config.available_features.add("LP64")
279 # Tests that are specific to the Apple Silicon macOS.
280 if re.match(r"^arm64(e)?-apple-(macos|darwin)", config.target_triple):
281 config.available_features.add("apple-silicon-mac")
283 # [PR18856] Depends to remove opened file. On win32, a file could be removed
284 # only if all handles were closed.
285 if platform.system() not in ["Windows"]:
286 config.available_features.add("can-remove-opened-file")
288 # Features
289 known_arches = ["x86_64", "mips64", "ppc64", "aarch64"]
290 if any(config.target_triple.startswith(x) for x in known_arches):
291 config.available_features.add("clang-target-64-bits")
294 def calculate_arch_features(arch_string):
295 features = []
296 for arch in arch_string.split():
297 features.append(arch.lower() + "-registered-target")
298 return features
301 llvm_config.feature_config(
303 ("--assertion-mode", {"ON": "asserts"}),
304 ("--cxxflags", {r"-D_GLIBCXX_DEBUG\b": "libstdcxx-safe-mode"}),
305 ("--targets-built", calculate_arch_features),
309 if lit.util.which("xmllint"):
310 config.available_features.add("xmllint")
312 if config.enable_backtrace:
313 config.available_features.add("backtrace")
315 if config.enable_threads:
316 config.available_features.add("thread_support")
318 # Check if we should allow outputs to console.
319 run_console_tests = int(lit_config.params.get("enable_console", "0"))
320 if run_console_tests != 0:
321 config.available_features.add("console")
323 lit.util.usePlatformSdkOnDarwin(config, lit_config)
324 macOSSDKVersion = lit.util.findPlatformSdkVersionOnMacOS(config, lit_config)
325 if macOSSDKVersion is not None:
326 config.available_features.add("macos-sdk-" + str(macOSSDKVersion))
328 if os.path.exists("/etc/gentoo-release"):
329 config.available_features.add("gentoo")
331 if config.enable_shared:
332 config.available_features.add("enable_shared")
334 # Add a vendor-specific feature.
335 if config.clang_vendor_uti:
336 config.available_features.add("clang-vendor=" + config.clang_vendor_uti)
338 if config.have_llvm_driver:
339 config.available_features.add("llvm-driver")
342 # Some tests perform deep recursion, which requires a larger pthread stack size
343 # than the relatively low default of 192 KiB for 64-bit processes on AIX. The
344 # `AIXTHREAD_STK` environment variable provides a non-intrusive way to request
345 # a larger pthread stack size for the tests. Various applications and runtime
346 # libraries on AIX use a default pthread stack size of 4 MiB, so we will use
347 # that as a default value here.
348 if "AIXTHREAD_STK" in os.environ:
349 config.environment["AIXTHREAD_STK"] = os.environ["AIXTHREAD_STK"]
350 elif platform.system() == "AIX":
351 config.environment["AIXTHREAD_STK"] = "4194304"
353 # Some tools support an environment variable "OBJECT_MODE" on AIX OS, which
354 # controls the kind of objects they will support. If there is no "OBJECT_MODE"
355 # environment variable specified, the default behaviour is to support 32-bit
356 # objects only. In order to not affect most test cases, which expect to support
357 # 32-bit and 64-bit objects by default, set the environment variable
358 # "OBJECT_MODE" to "any" by default on AIX OS.
360 if "system-aix" in config.available_features:
361 config.substitutions.append(("llvm-nm", "env OBJECT_MODE=any llvm-nm"))
362 config.substitutions.append(("llvm-ar", "env OBJECT_MODE=any llvm-ar"))
363 config.substitutions.append(("llvm-ranlib", "env OBJECT_MODE=any llvm-ranlib"))
365 # It is not realistically possible to account for all options that could
366 # possibly be present in system and user configuration files, so disable
367 # default configs for the test runs.
368 config.environment["CLANG_NO_DEFAULT_CONFIG"] = "1"