| 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 |
# testFormat: The test format to use to interpret tests. |
| 22 |
# |
| 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) |
| 26 |
|
| 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", |
| 48 |
] |
| 49 |
|
| 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", |
| 59 |
] |
| 60 |
|
| 61 |
# test_source_root: The root path where tests are located. |
| 62 |
config.test_source_root = os.path.dirname(__file__) |
| 63 |
|
| 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") |
| 66 |
|
| 67 |
llvm_config.use_default_substitutions() |
| 68 |
|
| 69 |
llvm_config.use_clang() |
| 70 |
|
| 71 |
config.substitutions.append(("%src_include_dir", config.clang_src_dir + "/include")) |
| 72 |
|
| 73 |
config.substitutions.append(("%target_triple", config.target_triple)) |
| 74 |
|
| 75 |
config.substitutions.append(("%PATH%", config.environment["PATH"])) |
| 76 |
|
| 77 |
|
| 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] |
| 83 |
|
| 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 |
"llvm-lto", |
| 100 |
"llvm-lto2", |
| 101 |
"llvm-profdata", |
| 102 |
"llvm-readtapi", |
| 103 |
ToolSubst( |
| 104 |
"%clang_extdef_map", |
| 105 |
command=FindTool("clang-extdef-mapping"), |
| 106 |
unresolved="ignore", |
| 107 |
), |
| 108 |
] |
| 109 |
|
| 110 |
if config.clang_examples: |
| 111 |
config.available_features.add("examples") |
| 112 |
|
| 113 |
|
| 114 |
def have_host_jit_feature_support(feature_name): |
| 115 |
clang_repl_exe = lit.util.which("clang-repl", config.clang_tools_dir) |
| 116 |
|
| 117 |
if not clang_repl_exe: |
| 118 |
return False |
| 119 |
|
| 120 |
try: |
| 121 |
clang_repl_cmd = subprocess.Popen( |
| 122 |
[clang_repl_exe, "--host-supports-" + feature_name], stdout=subprocess.PIPE |
| 123 |
) |
| 124 |
except OSError: |
| 125 |
print("could not exec clang-repl") |
| 126 |
return False |
| 127 |
|
| 128 |
clang_repl_out = clang_repl_cmd.stdout.read().decode("ascii") |
| 129 |
clang_repl_cmd.wait() |
| 130 |
|
| 131 |
return "true" in clang_repl_out |
| 132 |
|
| 133 |
def have_host_clang_repl_cuda(): |
| 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([ |
| 140 |
b"__global__ void test_func() {}", |
| 141 |
b"test_func<<<1,1>>>();", |
| 142 |
b"extern \"C\" int puts(const char *s);", |
| 143 |
b"puts(cudaGetLastError() ? \"failure\" : \"success\");", |
| 144 |
b"%quit" |
| 145 |
]) |
| 146 |
try: |
| 147 |
clang_repl_cmd = subprocess.run([clang_repl_exe, '--cuda'], |
| 148 |
stdout=subprocess.PIPE, |
| 149 |
stderr=subprocess.PIPE, |
| 150 |
input=testcode) |
| 151 |
except OSError: |
| 152 |
return False |
| 153 |
|
| 154 |
if clang_repl_cmd.returncode == 0: |
| 155 |
if clang_repl_cmd.stdout.find(b"success") != -1: |
| 156 |
return True |
| 157 |
|
| 158 |
return False |
| 159 |
|
| 160 |
if have_host_jit_feature_support('jit'): |
| 161 |
config.available_features.add('host-supports-jit') |
| 162 |
|
| 163 |
if have_host_clang_repl_cuda(): |
| 164 |
config.available_features.add('host-supports-cuda') |
| 165 |
|
| 166 |
if config.clang_staticanalyzer: |
| 167 |
config.available_features.add("staticanalyzer") |
| 168 |
tools.append("clang-check") |
| 169 |
|
| 170 |
if config.clang_staticanalyzer_z3: |
| 171 |
config.available_features.add("z3") |
| 172 |
else: |
| 173 |
config.available_features.add("no-z3") |
| 174 |
|
| 175 |
check_analyzer_fixit_path = os.path.join( |
| 176 |
config.test_source_root, "Analysis", "check-analyzer-fixit.py" |
| 177 |
) |
| 178 |
config.substitutions.append( |
| 179 |
( |
| 180 |
"%check_analyzer_fixit", |
| 181 |
'"%s" %s' % (config.python_executable, check_analyzer_fixit_path), |
| 182 |
) |
| 183 |
) |
| 184 |
|
| 185 |
llvm_config.add_tool_substitutions(tools, tool_dirs) |
| 186 |
|
| 187 |
config.substitutions.append( |
| 188 |
( |
| 189 |
"%hmaptool", |
| 190 |
"'%s' %s" |
| 191 |
% ( |
| 192 |
config.python_executable, |
| 193 |
os.path.join(config.clang_src_dir, "utils", "hmaptool", "hmaptool"), |
| 194 |
), |
| 195 |
) |
| 196 |
) |
| 197 |
|
| 198 |
config.substitutions.append( |
| 199 |
( |
| 200 |
"%deps-to-rsp", |
| 201 |
'"%s" %s' |
| 202 |
% ( |
| 203 |
config.python_executable, |
| 204 |
os.path.join(config.clang_src_dir, "utils", "module-deps-to-rsp.py"), |
| 205 |
), |
| 206 |
) |
| 207 |
) |
| 208 |
|
| 209 |
config.substitutions.append(("%host_cc", config.host_cc)) |
| 210 |
config.substitutions.append(("%host_cxx", config.host_cxx)) |
| 211 |
|
| 212 |
|
| 213 |
# Plugins (loadable modules) |
| 214 |
if config.has_plugins and config.llvm_plugin_ext: |
| 215 |
config.available_features.add("plugins") |
| 216 |
|
| 217 |
if config.clang_default_pie_on_linux: |
| 218 |
config.available_features.add("default-pie-on-linux") |
| 219 |
|
| 220 |
# Set available features we allow tests to conditionalize on. |
| 221 |
# |
| 222 |
if config.clang_default_cxx_stdlib != "": |
| 223 |
config.available_features.add( |
| 224 |
"default-cxx-stdlib={}".format(config.clang_default_cxx_stdlib) |
| 225 |
) |
| 226 |
|
| 227 |
# As of 2011.08, crash-recovery tests still do not pass on FreeBSD. |
| 228 |
if platform.system() not in ["FreeBSD"]: |
| 229 |
config.available_features.add("crash-recovery") |
| 230 |
|
| 231 |
# ANSI escape sequences in non-dumb terminal |
| 232 |
if platform.system() not in ["Windows"]: |
| 233 |
config.available_features.add("ansi-escape-sequences") |
| 234 |
|
| 235 |
# Capability to print utf8 to the terminal. |
| 236 |
# Windows expects codepage, unless Wide API. |
| 237 |
if platform.system() not in ["Windows"]: |
| 238 |
config.available_features.add("utf8-capable-terminal") |
| 239 |
|
| 240 |
# Support for libgcc runtime. Used to rule out tests that require |
| 241 |
# clang to run with -rtlib=libgcc. |
| 242 |
if platform.system() not in ["Darwin", "Fuchsia"]: |
| 243 |
config.available_features.add("libgcc") |
| 244 |
|
| 245 |
# Case-insensitive file system |
| 246 |
|
| 247 |
|
| 248 |
def is_filesystem_case_insensitive(): |
| 249 |
handle, path = tempfile.mkstemp(prefix="case-test", dir=config.test_exec_root) |
| 250 |
isInsensitive = os.path.exists( |
| 251 |
os.path.join(os.path.dirname(path), os.path.basename(path).upper()) |
| 252 |
) |
| 253 |
os.close(handle) |
| 254 |
os.remove(path) |
| 255 |
return isInsensitive |
| 256 |
|
| 257 |
|
| 258 |
if is_filesystem_case_insensitive(): |
| 259 |
config.available_features.add("case-insensitive-filesystem") |
| 260 |
|
| 261 |
# Tests that require the /dev/fd filesystem. |
| 262 |
if os.path.exists("/dev/fd/0") and sys.platform not in ["cygwin"]: |
| 263 |
config.available_features.add("dev-fd-fs") |
| 264 |
|
| 265 |
# Set on native MS environment. |
| 266 |
if re.match(r".*-(windows-msvc)$", config.target_triple): |
| 267 |
config.available_features.add("ms-sdk") |
| 268 |
|
| 269 |
# [PR8833] LLP64-incompatible tests |
| 270 |
if not re.match( |
| 271 |
r"^(aarch64|x86_64).*-(windows-msvc|windows-gnu)$", config.target_triple |
| 272 |
): |
| 273 |
config.available_features.add("LP64") |
| 274 |
|
| 275 |
# Tests that are specific to the Apple Silicon macOS. |
| 276 |
if re.match(r"^arm64(e)?-apple-(macos|darwin)", config.target_triple): |
| 277 |
config.available_features.add("apple-silicon-mac") |
| 278 |
|
| 279 |
# [PR18856] Depends to remove opened file. On win32, a file could be removed |
| 280 |
# only if all handles were closed. |
| 281 |
if platform.system() not in ["Windows"]: |
| 282 |
config.available_features.add("can-remove-opened-file") |
| 283 |
|
| 284 |
# Features |
| 285 |
known_arches = ["x86_64", "mips64", "ppc64", "aarch64"] |
| 286 |
if any(config.target_triple.startswith(x) for x in known_arches): |
| 287 |
config.available_features.add("clang-target-64-bits") |
| 288 |
|
| 289 |
|
| 290 |
def calculate_arch_features(arch_string): |
| 291 |
features = [] |
| 292 |
for arch in arch_string.split(): |
| 293 |
features.append(arch.lower() + "-registered-target") |
| 294 |
return features |
| 295 |
|
| 296 |
|
| 297 |
llvm_config.feature_config( |
| 298 |
[ |
| 299 |
("--assertion-mode", {"ON": "asserts"}), |
| 300 |
("--cxxflags", {r"-D_GLIBCXX_DEBUG\b": "libstdcxx-safe-mode"}), |
| 301 |
("--targets-built", calculate_arch_features), |
| 302 |
] |
| 303 |
) |
| 304 |
|
| 305 |
if lit.util.which("xmllint"): |
| 306 |
config.available_features.add("xmllint") |
| 307 |
|
| 308 |
if config.enable_backtrace: |
| 309 |
config.available_features.add("backtrace") |
| 310 |
|
| 311 |
if config.enable_threads: |
| 312 |
config.available_features.add("thread_support") |
| 313 |
|
| 314 |
# Check if we should allow outputs to console. |
| 315 |
run_console_tests = int(lit_config.params.get("enable_console", "0")) |
| 316 |
if run_console_tests != 0: |
| 317 |
config.available_features.add("console") |
| 318 |
|
| 319 |
lit.util.usePlatformSdkOnDarwin(config, lit_config) |
| 320 |
macOSSDKVersion = lit.util.findPlatformSdkVersionOnMacOS(config, lit_config) |
| 321 |
if macOSSDKVersion is not None: |
| 322 |
config.available_features.add("macos-sdk-" + str(macOSSDKVersion)) |
| 323 |
|
| 324 |
if os.path.exists("/etc/gentoo-release"): |
| 325 |
config.available_features.add("gentoo") |
| 326 |
|
| 327 |
if config.enable_shared: |
| 328 |
config.available_features.add("enable_shared") |
| 329 |
|
| 330 |
# Add a vendor-specific feature. |
| 331 |
if config.clang_vendor_uti: |
| 332 |
config.available_features.add("clang-vendor=" + config.clang_vendor_uti) |
| 333 |
|
| 334 |
if config.have_llvm_driver: |
| 335 |
config.available_features.add("llvm-driver") |
| 336 |
|
| 337 |
|
| 338 |
# Some tests perform deep recursion, which requires a larger pthread stack size |
| 339 |
# than the relatively low default of 192 KiB for 64-bit processes on AIX. The |
| 340 |
# `AIXTHREAD_STK` environment variable provides a non-intrusive way to request |
| 341 |
# a larger pthread stack size for the tests. Various applications and runtime |
| 342 |
# libraries on AIX use a default pthread stack size of 4 MiB, so we will use |
| 343 |
# that as a default value here. |
| 344 |
if "AIXTHREAD_STK" in os.environ: |
| 345 |
config.environment["AIXTHREAD_STK"] = os.environ["AIXTHREAD_STK"] |
| 346 |
elif platform.system() == "AIX": |
| 347 |
config.environment["AIXTHREAD_STK"] = "4194304" |
| 348 |
|
| 349 |
# Some tools support an environment variable "OBJECT_MODE" on AIX OS, which |
| 350 |
# controls the kind of objects they will support. If there is no "OBJECT_MODE" |
| 351 |
# environment variable specified, the default behaviour is to support 32-bit |
| 352 |
# objects only. In order to not affect most test cases, which expect to support |
| 353 |
# 32-bit and 64-bit objects by default, set the environment variable |
| 354 |
# "OBJECT_MODE" to "any" by default on AIX OS. |
| 355 |
|
| 356 |
if "system-aix" in config.available_features: |
| 357 |
config.substitutions.append(("llvm-nm", "env OBJECT_MODE=any llvm-nm")) |
| 358 |
config.substitutions.append(("llvm-ar", "env OBJECT_MODE=any llvm-ar")) |
| 359 |
config.substitutions.append(("llvm-ranlib", "env OBJECT_MODE=any llvm-ranlib")) |
| 360 |
|
| 361 |
# It is not realistically possible to account for all options that could |
| 362 |
# possibly be present in system and user configuration files, so disable |
| 363 |
# default configs for the test runs. |
| 364 |
config.environment["CLANG_NO_DEFAULT_CONFIG"] = "1" |