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.
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.
50 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
51 # subdirectories contain auxiliary inputs for various tests in their parent
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
]
90 "clang-offload-packager",
97 "clang-linker-wrapper",
104 command
=FindTool("clang-extdef-mapping"),
109 if config
.clang_examples
:
110 config
.available_features
.add("examples")
113 def have_host_jit_feature_support(feature_name
):
114 clang_repl_exe
= lit
.util
.which("clang-repl", config
.clang_tools_dir
)
116 if not clang_repl_exe
:
120 clang_repl_cmd
= subprocess
.Popen(
121 [clang_repl_exe
, "--host-supports-" + feature_name
], stdout
=subprocess
.PIPE
124 print("could not exec clang-repl")
127 clang_repl_out
= clang_repl_cmd
.stdout
.read().decode("ascii")
128 clang_repl_cmd
.wait()
130 return "true" in clang_repl_out
132 def have_host_clang_repl_cuda():
133 clang_repl_exe
= lit
.util
.which('clang-repl', config
.clang_tools_dir
)
135 if not clang_repl_exe
:
138 testcode
= b
'\n'.join([
139 b
"__global__ void test_func() {}",
140 b
"test_func<<<1,1>>>();",
141 b
"extern \"C\" int puts(const char *s);",
142 b
"puts(cudaGetLastError() ? \"failure\" : \"success\");",
146 clang_repl_cmd
= subprocess
.run([clang_repl_exe
, '--cuda'],
147 stdout
=subprocess
.PIPE
,
148 stderr
=subprocess
.PIPE
,
153 if clang_repl_cmd
.returncode
== 0:
154 if clang_repl_cmd
.stdout
.find(b
"success") != -1:
159 if have_host_jit_feature_support('jit'):
160 config
.available_features
.add('host-supports-jit')
162 if have_host_clang_repl_cuda():
163 config
.available_features
.add('host-supports-cuda')
165 if config
.clang_staticanalyzer
:
166 config
.available_features
.add("staticanalyzer")
167 tools
.append("clang-check")
169 if config
.clang_staticanalyzer_z3
:
170 config
.available_features
.add("z3")
172 config
.available_features
.add("no-z3")
174 check_analyzer_fixit_path
= os
.path
.join(
175 config
.test_source_root
, "Analysis", "check-analyzer-fixit.py"
177 config
.substitutions
.append(
179 "%check_analyzer_fixit",
180 '"%s" %s' % (config
.python_executable
, check_analyzer_fixit_path
),
184 llvm_config
.add_tool_substitutions(tools
, tool_dirs
)
186 config
.substitutions
.append(
191 config
.python_executable
,
192 os
.path
.join(config
.clang_src_dir
, "utils", "hmaptool", "hmaptool"),
197 config
.substitutions
.append(
202 config
.python_executable
,
203 os
.path
.join(config
.clang_src_dir
, "utils", "module-deps-to-rsp.py"),
208 config
.substitutions
.append(("%host_cc", config
.host_cc
))
209 config
.substitutions
.append(("%host_cxx", config
.host_cxx
))
212 # Plugins (loadable modules)
213 if config
.has_plugins
and config
.llvm_plugin_ext
:
214 config
.available_features
.add("plugins")
216 if config
.clang_default_pie_on_linux
:
217 config
.available_features
.add("default-pie-on-linux")
219 # Set available features we allow tests to conditionalize on.
221 if config
.clang_default_cxx_stdlib
!= "":
222 config
.available_features
.add(
223 "default-cxx-stdlib={}".format(config
.clang_default_cxx_stdlib
)
226 # As of 2011.08, crash-recovery tests still do not pass on FreeBSD.
227 if platform
.system() not in ["FreeBSD"]:
228 config
.available_features
.add("crash-recovery")
230 # ANSI escape sequences in non-dumb terminal
231 if platform
.system() not in ["Windows"]:
232 config
.available_features
.add("ansi-escape-sequences")
234 # Capability to print utf8 to the terminal.
235 # Windows expects codepage, unless Wide API.
236 if platform
.system() not in ["Windows"]:
237 config
.available_features
.add("utf8-capable-terminal")
239 # Support for libgcc runtime. Used to rule out tests that require
240 # clang to run with -rtlib=libgcc.
241 if platform
.system() not in ["Darwin", "Fuchsia"]:
242 config
.available_features
.add("libgcc")
244 # Case-insensitive file system
247 def is_filesystem_case_insensitive():
248 handle
, path
= tempfile
.mkstemp(prefix
="case-test", dir=config
.test_exec_root
)
249 isInsensitive
= os
.path
.exists(
250 os
.path
.join(os
.path
.dirname(path
), os
.path
.basename(path
).upper())
257 if is_filesystem_case_insensitive():
258 config
.available_features
.add("case-insensitive-filesystem")
260 # Tests that require the /dev/fd filesystem.
261 if os
.path
.exists("/dev/fd/0") and sys
.platform
not in ["cygwin"]:
262 config
.available_features
.add("dev-fd-fs")
264 # Set on native MS environment.
265 if re
.match(r
".*-(windows-msvc)$", config
.target_triple
):
266 config
.available_features
.add("ms-sdk")
268 # [PR8833] LLP64-incompatible tests
270 r
"^(aarch64|x86_64).*-(windows-msvc|windows-gnu)$", config
.target_triple
272 config
.available_features
.add("LP64")
274 # Tests that are specific to the Apple Silicon macOS.
275 if re
.match(r
"^arm64(e)?-apple-(macos|darwin)", config
.target_triple
):
276 config
.available_features
.add("apple-silicon-mac")
278 # [PR18856] Depends to remove opened file. On win32, a file could be removed
279 # only if all handles were closed.
280 if platform
.system() not in ["Windows"]:
281 config
.available_features
.add("can-remove-opened-file")
284 known_arches
= ["x86_64", "mips64", "ppc64", "aarch64"]
285 if any(config
.target_triple
.startswith(x
) for x
in known_arches
):
286 config
.available_features
.add("clang-target-64-bits")
289 def calculate_arch_features(arch_string
):
291 for arch
in arch_string
.split():
292 features
.append(arch
.lower() + "-registered-target")
296 llvm_config
.feature_config(
298 ("--assertion-mode", {"ON": "asserts"}),
299 ("--cxxflags", {r
"-D_GLIBCXX_DEBUG\b": "libstdcxx-safe-mode"}),
300 ("--targets-built", calculate_arch_features
),
304 if lit
.util
.which("xmllint"):
305 config
.available_features
.add("xmllint")
307 if config
.enable_backtrace
:
308 config
.available_features
.add("backtrace")
310 if config
.enable_threads
:
311 config
.available_features
.add("thread_support")
313 # Check if we should allow outputs to console.
314 run_console_tests
= int(lit_config
.params
.get("enable_console", "0"))
315 if run_console_tests
!= 0:
316 config
.available_features
.add("console")
318 lit
.util
.usePlatformSdkOnDarwin(config
, lit_config
)
319 macOSSDKVersion
= lit
.util
.findPlatformSdkVersionOnMacOS(config
, lit_config
)
320 if macOSSDKVersion
is not None:
321 config
.available_features
.add("macos-sdk-" + str(macOSSDKVersion
))
323 if os
.path
.exists("/etc/gentoo-release"):
324 config
.available_features
.add("gentoo")
326 if config
.enable_shared
:
327 config
.available_features
.add("enable_shared")
329 # Add a vendor-specific feature.
330 if config
.clang_vendor_uti
:
331 config
.available_features
.add("clang-vendor=" + config
.clang_vendor_uti
)
333 if config
.have_llvm_driver
:
334 config
.available_features
.add("llvm-driver")
337 # Some tests perform deep recursion, which requires a larger pthread stack size
338 # than the relatively low default of 192 KiB for 64-bit processes on AIX. The
339 # `AIXTHREAD_STK` environment variable provides a non-intrusive way to request
340 # a larger pthread stack size for the tests. Various applications and runtime
341 # libraries on AIX use a default pthread stack size of 4 MiB, so we will use
342 # that as a default value here.
343 if "AIXTHREAD_STK" in os
.environ
:
344 config
.environment
["AIXTHREAD_STK"] = os
.environ
["AIXTHREAD_STK"]
345 elif platform
.system() == "AIX":
346 config
.environment
["AIXTHREAD_STK"] = "4194304"
348 # Some tools support an environment variable "OBJECT_MODE" on AIX OS, which
349 # controls the kind of objects they will support. If there is no "OBJECT_MODE"
350 # environment variable specified, the default behaviour is to support 32-bit
351 # objects only. In order to not affect most test cases, which expect to support
352 # 32-bit and 64-bit objects by default, set the environment variable
353 # "OBJECT_MODE" to "any" by default on AIX OS.
355 if "system-aix" in config
.available_features
:
356 config
.substitutions
.append(("llvm-nm", "env OBJECT_MODE=any llvm-nm"))
357 config
.substitutions
.append(("llvm-ar", "env OBJECT_MODE=any llvm-ar"))
358 config
.substitutions
.append(("llvm-ranlib", "env OBJECT_MODE=any llvm-ranlib"))
360 # It is not realistically possible to account for all options that could
361 # possibly be present in system and user configuration files, so disable
362 # default configs for the test runs.
363 config
.environment
["CLANG_NO_DEFAULT_CONFIG"] = "1"