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