| 1 |
# -*- Python -*- |
| 2 |
|
| 3 |
import os |
| 4 |
import platform |
| 5 |
import re |
| 6 |
import subprocess |
| 7 |
import tempfile |
| 8 |
|
| 9 |
import lit.formats |
| 10 |
import lit.util |
| 11 |
|
| 12 |
from lit.llvm import llvm_config |
| 13 |
from lit.llvm.subst import ToolSubst |
| 14 |
from lit.llvm.subst import FindTool |
| 15 |
|
| 16 |
# Configuration file for the 'lit' test runner. |
| 17 |
|
| 18 |
# name: The name of this test suite. |
| 19 |
config.name = "Clang" |
| 20 |
|
| 21 |
# TODO: Consolidate the logic for turning on the internal shell by default for all LLVM test suites. |
| 22 |
# See https://github.com/llvm/llvm-project/issues/106636 for more details. |
| 23 |
# |
| 24 |
# We prefer the lit internal shell which provides a better user experience on failures |
| 25 |
# and is faster unless the user explicitly disables it with LIT_USE_INTERNAL_SHELL=0 |
| 26 |
# env var. |
| 27 |
use_lit_shell = True |
| 28 |
lit_shell_env = os.environ.get("LIT_USE_INTERNAL_SHELL") |
| 29 |
if lit_shell_env: |
| 30 |
use_lit_shell = lit.util.pythonize_bool(lit_shell_env) |
| 31 |
|
| 32 |
# testFormat: The test format to use to interpret tests. |
| 33 |
# |
| 34 |
# For now we require '&&' between commands, until they get globally killed and |
| 35 |
# the test runner updated. |
| 36 |
config.test_format = lit.formats.ShTest(execute_external=not use_lit_shell) |
| 37 |
|
| 38 |
# suffixes: A list of file extensions to treat as test files. |
| 39 |
config.suffixes = [ |
| 40 |
".c", |
| 41 |
".cpp", |
| 42 |
".i", |
| 43 |
".cir", |
| 44 |
".cppm", |
| 45 |
".m", |
| 46 |
".mm", |
| 47 |
".cu", |
| 48 |
".cuh", |
| 49 |
".hip", |
| 50 |
".hlsl", |
| 51 |
".ll", |
| 52 |
".cl", |
| 53 |
".clcpp", |
| 54 |
".s", |
| 55 |
".S", |
| 56 |
".modulemap", |
| 57 |
".test", |
| 58 |
".rs", |
| 59 |
".ifs", |
| 60 |
".rc", |
| 61 |
] |
| 62 |
|
| 63 |
# excludes: A list of directories to exclude from the testsuite. The 'Inputs' |
| 64 |
# subdirectories contain auxiliary inputs for various tests in their parent |
| 65 |
# directories. |
| 66 |
config.excludes = [ |
| 67 |
"Inputs", |
| 68 |
"CMakeLists.txt", |
| 69 |
"README.txt", |
| 70 |
"LICENSE.txt", |
| 71 |
"debuginfo-tests", |
| 72 |
] |
| 73 |
|
| 74 |
# test_source_root: The root path where tests are located. |
| 75 |
config.test_source_root = os.path.dirname(__file__) |
| 76 |
|
| 77 |
# test_exec_root: The root path where tests should be run. |
| 78 |
config.test_exec_root = os.path.join(config.clang_obj_root, "test") |
| 79 |
|
| 80 |
llvm_config.use_default_substitutions() |
| 81 |
|
| 82 |
llvm_config.use_clang() |
| 83 |
|
| 84 |
config.substitutions.append(("%src_dir", config.clang_src_dir)) |
| 85 |
|
| 86 |
config.substitutions.append(("%src_include_dir", config.clang_src_dir + "/include")) |
| 87 |
|
| 88 |
config.substitutions.append(("%target_triple", config.target_triple)) |
| 89 |
|
| 90 |
config.substitutions.append(("%PATH%", config.environment["PATH"])) |
| 91 |
|
| 92 |
|
| 93 |
# For each occurrence of a clang tool name, replace it with the full path to |
| 94 |
# the build directory holding that tool. We explicitly specify the directories |
| 95 |
# to search to ensure that we get the tools just built and not some random |
| 96 |
# tools that might happen to be in the user's PATH. |
| 97 |
tool_dirs = [config.clang_tools_dir, config.llvm_tools_dir] |
| 98 |
|
| 99 |
tools = [ |
| 100 |
"apinotes-test", |
| 101 |
"c-index-test", |
| 102 |
"cir-opt", |
| 103 |
"clang-diff", |
| 104 |
"clang-format", |
| 105 |
"clang-repl", |
| 106 |
"llvm-offload-binary", |
| 107 |
"clang-tblgen", |
| 108 |
"clang-scan-deps", |
| 109 |
"clang-installapi", |
| 110 |
"opt", |
| 111 |
"llvm-ifs", |
| 112 |
"yaml2obj", |
| 113 |
"clang-linker-wrapper", |
| 114 |
"clang-nvlink-wrapper", |
| 115 |
"clang-sycl-linker", |
| 116 |
"llvm-lto", |
| 117 |
"llvm-lto2", |
| 118 |
"llvm-profdata", |
| 119 |
"llvm-readtapi", |
| 120 |
ToolSubst( |
| 121 |
"%clang_extdef_map", |
| 122 |
command=FindTool("clang-extdef-mapping"), |
| 123 |
unresolved="ignore", |
| 124 |
), |
| 125 |
] |
| 126 |
|
| 127 |
if config.clang_examples: |
| 128 |
config.available_features.add("examples") |
| 129 |
if config.llvm_examples: |
| 130 |
config.available_features.add("llvm-examples") |
| 131 |
|
| 132 |
|
| 133 |
def have_host_out_of_process_jit_feature_support(): |
| 134 |
clang_repl_exe = lit.util.which("clang-repl", config.clang_tools_dir) |
| 135 |
|
| 136 |
if not clang_repl_exe: |
| 137 |
return False |
| 138 |
|
| 139 |
testcode = b"\n".join([b"int i = 0;", b"%quit"]) |
| 140 |
|
| 141 |
try: |
| 142 |
clang_repl_cmd = subprocess.run( |
| 143 |
[clang_repl_exe, "-orc-runtime", "-oop-executor"], |
| 144 |
stdout=subprocess.PIPE, |
| 145 |
stderr=subprocess.PIPE, |
| 146 |
input=testcode, |
| 147 |
) |
| 148 |
except OSError: |
| 149 |
return False |
| 150 |
|
| 151 |
if clang_repl_cmd.returncode == 0: |
| 152 |
return True |
| 153 |
|
| 154 |
return False |
| 155 |
|
| 156 |
|
| 157 |
def run_clang_repl(args): |
| 158 |
clang_repl_exe = lit.util.which("clang-repl", config.clang_tools_dir) |
| 159 |
|
| 160 |
if not clang_repl_exe: |
| 161 |
return "" |
| 162 |
|
| 163 |
try: |
| 164 |
clang_repl_cmd = subprocess.Popen( |
| 165 |
[clang_repl_exe, args], stdout=subprocess.PIPE |
| 166 |
) |
| 167 |
except OSError: |
| 168 |
print("could not exec clang-repl") |
| 169 |
return "" |
| 170 |
|
| 171 |
clang_repl_out = clang_repl_cmd.stdout.read().decode("ascii") |
| 172 |
clang_repl_cmd.wait() |
| 173 |
|
| 174 |
return clang_repl_out |
| 175 |
|
| 176 |
|
| 177 |
def have_host_jit_feature_support(feature_name): |
| 178 |
return "true" in run_clang_repl("--host-supports-" + feature_name) |
| 179 |
|
| 180 |
def have_host_clang_repl_cuda(): |
| 181 |
clang_repl_exe = lit.util.which('clang-repl', config.clang_tools_dir) |
| 182 |
|
| 183 |
if not clang_repl_exe: |
| 184 |
return False |
| 185 |
|
| 186 |
testcode = b'\n'.join([ |
| 187 |
b"__global__ void test_func() {}", |
| 188 |
b"test_func<<<1,1>>>();", |
| 189 |
b"extern \"C\" int puts(const char *s);", |
| 190 |
b"puts(cudaGetLastError() ? \"failure\" : \"success\");", |
| 191 |
b"%quit" |
| 192 |
]) |
| 193 |
try: |
| 194 |
clang_repl_cmd = subprocess.run([clang_repl_exe, '--cuda'], |
| 195 |
stdout=subprocess.PIPE, |
| 196 |
stderr=subprocess.PIPE, |
| 197 |
input=testcode) |
| 198 |
except OSError: |
| 199 |
return False |
| 200 |
|
| 201 |
if clang_repl_cmd.returncode == 0: |
| 202 |
if clang_repl_cmd.stdout.find(b"success") != -1: |
| 203 |
return True |
| 204 |
|
| 205 |
return False |
| 206 |
|
| 207 |
if have_host_jit_feature_support('jit'): |
| 208 |
config.available_features.add('host-supports-jit') |
| 209 |
|
| 210 |
if have_host_clang_repl_cuda(): |
| 211 |
config.available_features.add('host-supports-cuda') |
| 212 |
hosttriple = run_clang_repl("--host-jit-triple") |
| 213 |
config.substitutions.append(("%host-jit-triple", hosttriple.strip())) |
| 214 |
|
| 215 |
if have_host_out_of_process_jit_feature_support(): |
| 216 |
config.available_features.add("host-supports-out-of-process-jit") |
| 217 |
|
| 218 |
if config.clang_staticanalyzer: |
| 219 |
config.available_features.add("staticanalyzer") |
| 220 |
tools.append("clang-check") |
| 221 |
|
| 222 |
if config.clang_staticanalyzer_z3: |
| 223 |
config.available_features.add("z3") |
| 224 |
if config.clang_staticanalyzer_z3_mock: |
| 225 |
config.available_features.add("z3-mock") |
| 226 |
else: |
| 227 |
config.available_features.add("no-z3") |
| 228 |
|
| 229 |
check_analyzer_fixit_path = os.path.join( |
| 230 |
config.test_source_root, "Analysis", "check-analyzer-fixit.py" |
| 231 |
) |
| 232 |
config.substitutions.append( |
| 233 |
( |
| 234 |
"%check_analyzer_fixit", |
| 235 |
'"%s" %s' % (config.python_executable, check_analyzer_fixit_path), |
| 236 |
) |
| 237 |
) |
| 238 |
|
| 239 |
csv2json_path = os.path.join(config.test_source_root, "Analysis", "csv2json.py") |
| 240 |
config.substitutions.append( |
| 241 |
( |
| 242 |
"%csv2json", |
| 243 |
'"%s" %s' % (config.python_executable, csv2json_path), |
| 244 |
) |
| 245 |
) |
| 246 |
|
| 247 |
# ClangIR support |
| 248 |
if config.clang_enable_cir: |
| 249 |
config.available_features.add("cir-support") |
| 250 |
|
| 251 |
llvm_config.add_tool_substitutions(tools, tool_dirs) |
| 252 |
|
| 253 |
config.substitutions.append( |
| 254 |
( |
| 255 |
"%hmaptool", |
| 256 |
"'%s' %s" |
| 257 |
% ( |
| 258 |
config.python_executable, |
| 259 |
os.path.join(config.clang_src_dir, "utils", "hmaptool", "hmaptool"), |
| 260 |
), |
| 261 |
) |
| 262 |
) |
| 263 |
|
| 264 |
config.substitutions.append( |
| 265 |
( |
| 266 |
"%deps-to-rsp", |
| 267 |
'"%s" %s' |
| 268 |
% ( |
| 269 |
config.python_executable, |
| 270 |
os.path.join(config.clang_src_dir, "utils", "module-deps-to-rsp.py"), |
| 271 |
), |
| 272 |
) |
| 273 |
) |
| 274 |
|
| 275 |
# Determine whether the test target is compatible with execution on the host. |
| 276 |
if "aarch64" in config.host_arch: |
| 277 |
config.available_features.add("aarch64-host") |
| 278 |
|
| 279 |
# Some tests are sensitive to whether clang is statically or dynamically linked |
| 280 |
# to other libraries. |
| 281 |
if not (config.build_shared_libs or config.link_llvm_dylib or config.link_clang_dylib): |
| 282 |
config.available_features.add("static-libs") |
| 283 |
|
| 284 |
# Plugins (loadable modules) |
| 285 |
if config.has_plugins and config.llvm_plugin_ext: |
| 286 |
config.available_features.add("plugins") |
| 287 |
|
| 288 |
if config.clang_default_pie_on_linux: |
| 289 |
config.available_features.add("default-pie-on-linux") |
| 290 |
|
| 291 |
# Set available features we allow tests to conditionalize on. |
| 292 |
# |
| 293 |
if config.clang_default_cxx_stdlib != "": |
| 294 |
config.available_features.add( |
| 295 |
"default-cxx-stdlib={}".format(config.clang_default_cxx_stdlib) |
| 296 |
) |
| 297 |
|
| 298 |
# As of 2011.08, crash-recovery tests still do not pass on FreeBSD. |
| 299 |
if platform.system() not in ["FreeBSD"]: |
| 300 |
config.available_features.add("crash-recovery") |
| 301 |
|
| 302 |
# ANSI escape sequences in non-dumb terminal |
| 303 |
if platform.system() not in ["Windows"]: |
| 304 |
config.available_features.add("ansi-escape-sequences") |
| 305 |
|
| 306 |
# Capability to print utf8 to the terminal. |
| 307 |
# Windows expects codepage, unless Wide API. |
| 308 |
if platform.system() not in ["Windows"]: |
| 309 |
config.available_features.add("utf8-capable-terminal") |
| 310 |
|
| 311 |
# Support for libgcc runtime. Used to rule out tests that require |
| 312 |
# clang to run with -rtlib=libgcc. |
| 313 |
if platform.system() not in ["Darwin", "Fuchsia"]: |
| 314 |
config.available_features.add("libgcc") |
| 315 |
|
| 316 |
# Case-insensitive file system |
| 317 |
|
| 318 |
|
| 319 |
def is_filesystem_case_insensitive(): |
| 320 |
os.makedirs(config.test_exec_root, exist_ok=True) |
| 321 |
handle, path = tempfile.mkstemp(prefix="case-test", dir=config.test_exec_root) |
| 322 |
isInsensitive = os.path.exists( |
| 323 |
os.path.join(os.path.dirname(path), os.path.basename(path).upper()) |
| 324 |
) |
| 325 |
os.close(handle) |
| 326 |
os.remove(path) |
| 327 |
return isInsensitive |
| 328 |
|
| 329 |
|
| 330 |
if is_filesystem_case_insensitive(): |
| 331 |
config.available_features.add("case-insensitive-filesystem") |
| 332 |
|
| 333 |
# Tests that require the /dev/fd filesystem. |
| 334 |
if os.path.exists("/dev/fd/0") and sys.platform not in ["cygwin"]: |
| 335 |
config.available_features.add("dev-fd-fs") |
| 336 |
|
| 337 |
# Set on native MS environment. |
| 338 |
if re.match(r".*-(windows-msvc)$", config.target_triple): |
| 339 |
config.available_features.add("ms-sdk") |
| 340 |
|
| 341 |
# [PR8833] LLP64-incompatible tests |
| 342 |
if not re.match( |
| 343 |
r"^(aarch64|arm64ec|x86_64).*-(windows-msvc|windows-gnu)$", config.target_triple |
| 344 |
): |
| 345 |
config.available_features.add("LP64") |
| 346 |
|
| 347 |
# Tests that are specific to the Apple Silicon macOS. |
| 348 |
if re.match(r"^arm64(e)?-apple-(macos|darwin)", config.target_triple): |
| 349 |
config.available_features.add("apple-silicon-mac") |
| 350 |
|
| 351 |
# [PR18856] Depends to remove opened file. On win32, a file could be removed |
| 352 |
# only if all handles were closed. |
| 353 |
if platform.system() not in ["Windows"]: |
| 354 |
config.available_features.add("can-remove-opened-file") |
| 355 |
|
| 356 |
# Features |
| 357 |
known_arches = ["x86_64", "mips64", "ppc64", "aarch64"] |
| 358 |
if any(config.target_triple.startswith(x) for x in known_arches): |
| 359 |
config.available_features.add("clang-target-64-bits") |
| 360 |
|
| 361 |
|
| 362 |
def calculate_arch_features(arch_string): |
| 363 |
features = [] |
| 364 |
for arch in arch_string.split(): |
| 365 |
features.append(arch.lower() + "-registered-target") |
| 366 |
return features |
| 367 |
|
| 368 |
|
| 369 |
llvm_config.feature_config( |
| 370 |
[ |
| 371 |
("--assertion-mode", {"ON": "asserts"}), |
| 372 |
("--cxxflags", {r"-D_GLIBCXX_DEBUG\b": "libstdcxx-safe-mode"}), |
| 373 |
("--targets-built", calculate_arch_features), |
| 374 |
] |
| 375 |
) |
| 376 |
|
| 377 |
if lit.util.which("xmllint"): |
| 378 |
config.available_features.add("xmllint") |
| 379 |
|
| 380 |
if config.enable_backtrace: |
| 381 |
config.available_features.add("backtrace") |
| 382 |
|
| 383 |
if config.enable_threads: |
| 384 |
config.available_features.add("thread_support") |
| 385 |
|
| 386 |
# Check if we should allow outputs to console. |
| 387 |
run_console_tests = int(lit_config.params.get("enable_console", "0")) |
| 388 |
if run_console_tests != 0: |
| 389 |
config.available_features.add("console") |
| 390 |
|
| 391 |
lit.util.usePlatformSdkOnDarwin(config, lit_config) |
| 392 |
macOSSDKVersion = lit.util.findPlatformSdkVersionOnMacOS(config, lit_config) |
| 393 |
if macOSSDKVersion is not None: |
| 394 |
config.available_features.add("macos-sdk-" + str(macOSSDKVersion)) |
| 395 |
|
| 396 |
if os.path.exists("/etc/gentoo-release"): |
| 397 |
config.available_features.add("gentoo") |
| 398 |
|
| 399 |
if config.enable_shared: |
| 400 |
config.available_features.add("enable_shared") |
| 401 |
|
| 402 |
# Add a vendor-specific feature. |
| 403 |
if config.clang_vendor_uti: |
| 404 |
config.available_features.add("clang-vendor=" + config.clang_vendor_uti) |
| 405 |
|
| 406 |
if config.have_llvm_driver: |
| 407 |
config.available_features.add("llvm-driver") |
| 408 |
|
| 409 |
|
| 410 |
# Some tests perform deep recursion, which requires a larger pthread stack size |
| 411 |
# than the relatively low default of 192 KiB for 64-bit processes on AIX. The |
| 412 |
# `AIXTHREAD_STK` environment variable provides a non-intrusive way to request |
| 413 |
# a larger pthread stack size for the tests. Various applications and runtime |
| 414 |
# libraries on AIX use a default pthread stack size of 4 MiB, so we will use |
| 415 |
# that as a default value here. |
| 416 |
if "AIXTHREAD_STK" in os.environ: |
| 417 |
config.environment["AIXTHREAD_STK"] = os.environ["AIXTHREAD_STK"] |
| 418 |
elif platform.system() == "AIX": |
| 419 |
config.environment["AIXTHREAD_STK"] = "4194304" |
| 420 |
|
| 421 |
# Some tools support an environment variable "OBJECT_MODE" on AIX OS, which |
| 422 |
# controls the kind of objects they will support. If there is no "OBJECT_MODE" |
| 423 |
# environment variable specified, the default behaviour is to support 32-bit |
| 424 |
# objects only. In order to not affect most test cases, which expect to support |
| 425 |
# 32-bit and 64-bit objects by default, set the environment variable |
| 426 |
# "OBJECT_MODE" to "any" by default on AIX OS. |
| 427 |
|
| 428 |
if "system-aix" in config.available_features: |
| 429 |
config.substitutions.append(("llvm-nm", "env OBJECT_MODE=any llvm-nm")) |
| 430 |
config.substitutions.append(("llvm-ar", "env OBJECT_MODE=any llvm-ar")) |
| 431 |
config.substitutions.append(("llvm-ranlib", "env OBJECT_MODE=any llvm-ranlib")) |
| 432 |
|
| 433 |
# It is not realistically possible to account for all options that could |
| 434 |
# possibly be present in system and user configuration files, so disable |
| 435 |
# default configs for the test runs. |
| 436 |
config.environment["CLANG_NO_DEFAULT_CONFIG"] = "1" |
| 437 |
|
| 438 |
if lit_config.update_tests: |
| 439 |
import sys |
| 440 |
import os |
| 441 |
|
| 442 |
utilspath = os.path.join(config.llvm_src_root, "utils") |
| 443 |
sys.path.append(utilspath) |
| 444 |
from update_any_test_checks import utc_lit_plugin |
| 445 |
|
| 446 |
lit_config.test_updaters.append(utc_lit_plugin) |