1bbe23ae6SZachary Turner# -*- Python -*- 2bbe23ae6SZachary Turner 3bbe23ae6SZachary Turnerimport os 4bbe23ae6SZachary Turnerimport platform 5bbe23ae6SZachary Turnerimport re 6bbe23ae6SZachary Turnerimport subprocess 7bbe23ae6SZachary Turnerimport locale 8bbe23ae6SZachary Turner 9bbe23ae6SZachary Turnerimport lit.formats 10bbe23ae6SZachary Turnerimport lit.util 11bbe23ae6SZachary Turner 12bbe23ae6SZachary Turnerfrom lit.llvm import llvm_config 13bbe23ae6SZachary Turner 14bbe23ae6SZachary Turner# Configuration file for the 'lit' test runner. 15bbe23ae6SZachary Turner 16bbe23ae6SZachary Turner# name: The name of this test suite. 17f98ee40fSTobias Hietaconfig.name = "lld" 18bbe23ae6SZachary Turner 19bbe23ae6SZachary Turner# testFormat: The test format to use to interpret tests. 20bbe23ae6SZachary Turner# 21ab58e4cbSSam Clegg# For now we require '&&' between commands, until they get globally killed and the test runner updated. 22bbe23ae6SZachary Turnerconfig.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) 23bbe23ae6SZachary Turner 24bbe23ae6SZachary Turner# suffixes: A list of file extensions to treat as test files. 25f98ee40fSTobias Hietaconfig.suffixes = [".ll", ".s", ".test", ".yaml", ".objtxt"] 26bbe23ae6SZachary Turner 27bbe23ae6SZachary Turner# excludes: A list of directories to exclude from the testsuite. The 'Inputs' 28bbe23ae6SZachary Turner# subdirectories contain auxiliary inputs for various tests in their parent 29bbe23ae6SZachary Turner# directories. 30f98ee40fSTobias Hietaconfig.excludes = ["Inputs"] 31bbe23ae6SZachary Turner 32bbe23ae6SZachary Turner# test_source_root: The root path where tests are located. 33bbe23ae6SZachary Turnerconfig.test_source_root = os.path.dirname(__file__) 34bbe23ae6SZachary Turner 35f98ee40fSTobias Hietaconfig.test_exec_root = os.path.join(config.lld_obj_root, "test") 36bbe23ae6SZachary Turner 3796b04b68SZachary Turnerllvm_config.use_default_substitutions() 38ad5997e8SZachary Turnerllvm_config.use_lld() 39bbe23ae6SZachary Turner 400aa02c08SZachary Turnertool_patterns = [ 41f98ee40fSTobias Hieta "llc", 42f98ee40fSTobias Hieta "llvm-as", 43f4763b3dSKyungwoo Lee "llvm-cgdata", 44f98ee40fSTobias Hieta "llvm-mc", 45f98ee40fSTobias Hieta "llvm-nm", 46f98ee40fSTobias Hieta "llvm-objdump", 47f98ee40fSTobias Hieta "llvm-otool", 48f98ee40fSTobias Hieta "llvm-pdbutil", 4985af42dfSEllis Hoag "llvm-profdata", 50f98ee40fSTobias Hieta "llvm-dwarfdump", 51f98ee40fSTobias Hieta "llvm-readelf", 52f98ee40fSTobias Hieta "llvm-readobj", 53f98ee40fSTobias Hieta "obj2yaml", 54f98ee40fSTobias Hieta "yaml2obj", 55f98ee40fSTobias Hieta "opt", 56f98ee40fSTobias Hieta "llvm-dis", 57f98ee40fSTobias Hieta] 58bbe23ae6SZachary Turner 59ad5997e8SZachary Turnerllvm_config.add_tool_substitutions(tool_patterns) 60bbe23ae6SZachary Turner 61ae1ab910SKamil Rytarowski# LLD tests tend to be flaky on NetBSD, so add some retries. 62ae1ab910SKamil Rytarowski# We don't do this on other platforms because it's slower. 63f98ee40fSTobias Hietaif platform.system() in ["NetBSD"]: 64ae1ab910SKamil Rytarowski config.test_retry_attempts = 2 65ae1ab910SKamil Rytarowski 66bbe23ae6SZachary Turner# When running under valgrind, we mangle '-vg' onto the end of the triple so we 67bbe23ae6SZachary Turner# can check it with XFAIL and XTARGET. 68bbe23ae6SZachary Turnerif lit_config.useValgrind: 69f98ee40fSTobias Hieta config.target_triple += "-vg" 70bbe23ae6SZachary Turner 71bbe23ae6SZachary Turnerllvm_config.feature_config( 72f98ee40fSTobias Hieta [ 73f98ee40fSTobias Hieta ( 74f98ee40fSTobias Hieta "--targets-built", 75f98ee40fSTobias Hieta { 76f98ee40fSTobias Hieta "AArch64": "aarch64", 77f98ee40fSTobias Hieta "AMDGPU": "amdgpu", 78f98ee40fSTobias Hieta "ARM": "arm", 79f98ee40fSTobias Hieta "AVR": "avr", 80f98ee40fSTobias Hieta "Hexagon": "hexagon", 816084ee74SWANG Xuerui "LoongArch": "loongarch", 82f98ee40fSTobias Hieta "Mips": "mips", 83f98ee40fSTobias Hieta "MSP430": "msp430", 84f98ee40fSTobias Hieta "PowerPC": "ppc", 85f98ee40fSTobias Hieta "RISCV": "riscv", 86f98ee40fSTobias Hieta "Sparc": "sparc", 87fe3406e3SUlrich Weigand "SystemZ": "systemz", 88f98ee40fSTobias Hieta "WebAssembly": "wasm", 89f98ee40fSTobias Hieta "X86": "x86", 90f98ee40fSTobias Hieta }, 91f98ee40fSTobias Hieta ), 92f98ee40fSTobias Hieta ("--assertion-mode", {"ON": "asserts"}), 93f98ee40fSTobias Hieta ] 94f98ee40fSTobias Hieta) 95bbe23ae6SZachary Turner 967baac21bSEric Christopher# Set a fake constant version so that we get consistent output. 97f98ee40fSTobias Hietaconfig.environment["LLD_VERSION"] = "LLD 1.0" 987a4b2760SShoaib Meenai 997a4b2760SShoaib Meenai# LLD_IN_TEST determines how many times `main` is run inside each process, which 1007a4b2760SShoaib Meenai# lets us test that it's cleaning up after itself and resetting global state 1017a4b2760SShoaib Meenai# correctly (which is important for usage as a library). 102f98ee40fSTobias Hietarun_lld_main_twice = lit_config.params.get("RUN_LLD_MAIN_TWICE", False) 1037a4b2760SShoaib Meenaiif not run_lld_main_twice: 104f98ee40fSTobias Hieta config.environment["LLD_IN_TEST"] = "1" 1057a4b2760SShoaib Meenaielse: 106f98ee40fSTobias Hieta config.environment["LLD_IN_TEST"] = "2" 107*754b9463SFangrui Song # Many wasm tests fail. 108*754b9463SFangrui Song config.excludes.append("wasm") 1097a4b2760SShoaib Meenai # Some new Mach-O backend tests fail; give them a way to mark themselves 1107a4b2760SShoaib Meenai # unsupported in this mode. 111f98ee40fSTobias Hieta config.available_features.add("main-run-twice") 112bbe23ae6SZachary Turner 113bbe23ae6SZachary Turner# Indirectly check if the mt.exe Microsoft utility exists by searching for 114bbe23ae6SZachary Turner# cvtres, which always accompanies it. Alternatively, check if we can use 115bbe23ae6SZachary Turner# libxml2 to merge manifests. 116f98ee40fSTobias Hietaif lit.util.which("cvtres", config.environment["PATH"]) or config.have_libxml2: 117f98ee40fSTobias Hieta config.available_features.add("manifest_tool") 118bbe23ae6SZachary Turner 119dfb77f2eSBen Dunbobbinif config.enable_backtrace: 120f98ee40fSTobias Hieta config.available_features.add("backtrace") 121dfb77f2eSBen Dunbobbin 122c4d75361SPetr Hosekif config.have_libxml2: 123f98ee40fSTobias Hieta config.available_features.add("libxml2") 12475257bc2SPeter Collingbourne 125f2282762SZachary Turnerif config.have_dia_sdk: 126f2282762SZachary Turner config.available_features.add("diasdk") 127f2282762SZachary Turner 12816d9a0acSPeter Collingbourneif config.sizeof_void_p == 8: 12916d9a0acSPeter Collingbourne config.available_features.add("llvm-64-bits") 13016d9a0acSPeter Collingbourne 1310c86198bSJakob Koschelif config.has_plugins: 132f98ee40fSTobias Hieta config.available_features.add("plugins") 1330c86198bSJakob Koschel 1340c86198bSJakob Koschelif config.build_examples: 135f98ee40fSTobias Hieta config.available_features.add("examples") 1360c86198bSJakob Koschel 1370c86198bSJakob Koschelif config.linked_bye_extension: 138f98ee40fSTobias Hieta config.substitutions.append(("%loadbye", "")) 139f98ee40fSTobias Hieta config.substitutions.append(("%loadnewpmbye", "")) 1400c86198bSJakob Koschelelse: 141f98ee40fSTobias Hieta config.substitutions.append( 142f98ee40fSTobias Hieta ( 143f98ee40fSTobias Hieta "%loadbye", 144f98ee40fSTobias Hieta "-load={}/Bye{}".format(config.llvm_shlib_dir, config.llvm_shlib_ext), 145f98ee40fSTobias Hieta ) 146f98ee40fSTobias Hieta ) 147f98ee40fSTobias Hieta config.substitutions.append( 148f98ee40fSTobias Hieta ( 149f98ee40fSTobias Hieta "%loadnewpmbye", 150f98ee40fSTobias Hieta "-load-pass-plugin={}/Bye{}".format( 151f98ee40fSTobias Hieta config.llvm_shlib_dir, config.llvm_shlib_ext 152f98ee40fSTobias Hieta ), 153f98ee40fSTobias Hieta ) 154f98ee40fSTobias Hieta ) 1550c86198bSJakob Koschel 156f98ee40fSTobias Hietatar_executable = lit.util.which("tar", config.environment["PATH"]) 15785e68a66SIgor Kudrinif tar_executable: 158a8855673SMartin Storsjö env = os.environ 159f98ee40fSTobias Hieta env["LANG"] = "C" 16075257bc2SPeter Collingbourne tar_version = subprocess.Popen( 161f98ee40fSTobias Hieta [tar_executable, "--version"], 162fbed4e1dSMichal Gorny stdout=subprocess.PIPE, 163fbed4e1dSMichal Gorny stderr=subprocess.PIPE, 164f98ee40fSTobias Hieta env=env, 165f98ee40fSTobias Hieta ) 166fbed4e1dSMichal Gorny sout, _ = tar_version.communicate() 167f98ee40fSTobias Hieta if "GNU tar" in sout.decode(): 168f98ee40fSTobias Hieta config.available_features.add("gnutar") 1699b58b0c0SMateusz Mikuła 1709b58b0c0SMateusz Mikuła# ELF tests expect the default target for ld.lld to be ELF. 1719b58b0c0SMateusz Mikułaif config.ld_lld_default_mingw: 172f98ee40fSTobias Hieta config.excludes.append("ELF") 173