188 lines · python
1# -*- Python -*-2 3import os4import platform5import re6import subprocess7import locale8 9import lit.formats10import lit.util11 12from lit.llvm import llvm_config13 14# Configuration file for the 'lit' test runner.15 16# name: The name of this test suite.17config.name = "lld"18 19# TODO: Consolidate the logic for turning on the internal shell by default for all LLVM test suites.20# See https://github.com/llvm/llvm-project/issues/106636 for more details.21#22# We prefer the lit internal shell which provides a better user experience on failures23# and is faster unless the user explicitly disables it with LIT_USE_INTERNAL_SHELL=024# env var.25use_lit_shell = True26lit_shell_env = os.environ.get("LIT_USE_INTERNAL_SHELL")27if lit_shell_env:28 use_lit_shell = lit.util.pythonize_bool(lit_shell_env)29 30# testFormat: The test format to use to interpret tests.31#32# For now we require '&&' between commands, until they get globally killed and the test runner updated.33config.test_format = lit.formats.ShTest(execute_external=not use_lit_shell)34 35# suffixes: A list of file extensions to treat as test files.36config.suffixes = [".ll", ".s", ".test", ".yaml", ".objtxt"]37 38# excludes: A list of directories to exclude from the testsuite. The 'Inputs'39# subdirectories contain auxiliary inputs for various tests in their parent40# directories.41config.excludes = ["Inputs"]42 43# test_source_root: The root path where tests are located.44config.test_source_root = os.path.dirname(__file__)45 46config.test_exec_root = os.path.join(config.lld_obj_root, "test")47 48llvm_config.use_default_substitutions()49llvm_config.use_lld()50config.substitutions.append(("%llvm_src_root", config.llvm_src_root))51 52tool_patterns = [53 "llc",54 "llvm-as",55 "llvm-cgdata",56 "llvm-mc",57 "llvm-nm",58 "llvm-objdump",59 "llvm-otool",60 "llvm-pdbutil",61 "llvm-profdata",62 "llvm-dwarfdump",63 "llvm-readelf",64 "llvm-readobj",65 "obj2yaml",66 "yaml2obj",67 "opt",68 "llvm-dis",69]70 71llvm_config.add_tool_substitutions(tool_patterns)72 73# LLD tests tend to be flaky on NetBSD, so add some retries.74# We don't do this on other platforms because it's slower.75if platform.system() in ["NetBSD"]:76 config.test_retry_attempts = 277 78# When running under valgrind, we mangle '-vg' onto the end of the triple so we79# can check it with XFAIL and XTARGET.80if lit_config.useValgrind:81 config.target_triple += "-vg"82 83llvm_config.feature_config(84 [85 (86 "--targets-built",87 {88 "AArch64": "aarch64",89 "AMDGPU": "amdgpu",90 "ARM": "arm",91 "AVR": "avr",92 "Hexagon": "hexagon",93 "LoongArch": "loongarch",94 "Mips": "mips",95 "MSP430": "msp430",96 "PowerPC": "ppc",97 "RISCV": "riscv",98 "Sparc": "sparc",99 "SystemZ": "systemz",100 "WebAssembly": "wasm",101 "X86": "x86",102 },103 ),104 ("--assertion-mode", {"ON": "asserts"}),105 ]106)107 108# Set a fake constant version so that we get consistent output.109config.environment["LLD_VERSION"] = "LLD 1.0"110 111# LLD_IN_TEST determines how many times `main` is run inside each process, which112# lets us test that it's cleaning up after itself and resetting global state113# correctly (which is important for usage as a library).114run_lld_main_twice = lit_config.params.get("RUN_LLD_MAIN_TWICE", False)115if not run_lld_main_twice:116 config.environment["LLD_IN_TEST"] = "1"117else:118 config.environment["LLD_IN_TEST"] = "2"119 # Many wasm tests fail.120 config.excludes.append("wasm")121 # Some new Mach-O backend tests fail; give them a way to mark themselves122 # unsupported in this mode.123 config.available_features.add("main-run-twice")124 125# Indirectly check if the mt.exe Microsoft utility exists by searching for126# cvtres, which always accompanies it. Alternatively, check if we can use127# libxml2 to merge manifests.128if lit.util.which("cvtres", config.environment["PATH"]) or config.have_libxml2:129 config.available_features.add("manifest_tool")130 131if config.enable_backtrace:132 config.available_features.add("backtrace")133 134if config.have_libxml2:135 config.available_features.add("libxml2")136 137if config.have_dia_sdk:138 config.available_features.add("diasdk")139 140if config.sizeof_void_p == 8:141 config.available_features.add("llvm-64-bits")142 143if config.has_plugins:144 config.available_features.add("plugins")145 146if config.build_examples:147 config.available_features.add("examples")148 149if config.linked_bye_extension:150 config.substitutions.append(("%loadbye", ""))151 config.substitutions.append(("%loadnewpmbye", ""))152else:153 config.substitutions.append(154 (155 "%loadbye",156 "-load={}/Bye{}".format(config.llvm_shlib_dir, config.llvm_shlib_ext),157 )158 )159 config.substitutions.append(160 (161 "%loadnewpmbye",162 "-load-pass-plugin={}/Bye{}".format(163 config.llvm_shlib_dir, config.llvm_shlib_ext164 ),165 )166 )167 168tar_executable = lit.util.which("tar", config.environment["PATH"])169if tar_executable:170 env = os.environ171 env["LANG"] = "C"172 tar_version = subprocess.Popen(173 [tar_executable, "--version"],174 stdout=subprocess.PIPE,175 stderr=subprocess.PIPE,176 env=env,177 )178 sout, _ = tar_version.communicate()179 if "GNU tar" in sout.decode():180 config.available_features.add("gnutar")181 182# ELF tests expect the default target for ld.lld to be ELF.183if config.ld_lld_default_mingw:184 config.excludes.append("ELF")185 186if config.enable_threads:187 config.available_features.add("thread_support")188