blob: 348c8289c6573c9756f44c799a4d76981e61212a [file] [log] [blame]
Michael J. Spencer773a8fb2011-12-18 08:27:591# -*- Python -*-
2
3import os
4import platform
5import re
6import subprocess
Michael J. Spencera4f983e2014-03-26 00:53:487import locale
Michael J. Spencer773a8fb2011-12-18 08:27:598
Daniel Dunbarbc7bfb12013-08-09 18:51:179import lit.formats
10import lit.util
Michael J. Spencer773a8fb2011-12-18 08:27:5911
Zachary Turnerd4401d32017-09-18 22:26:4812from lit.llvm import llvm_config
13
Michael J. Spencer773a8fb2011-12-18 08:27:5914# Configuration file for the 'lit' test runner.
15
16# name: The name of this test suite.
Tobias Hietaf98ee402023-05-17 14:59:4117config.name = "lld"
Michael J. Spencer773a8fb2011-12-18 08:27:5918
19# testFormat: The test format to use to interpret tests.
20#
Sam Cleggab58e4c2020-12-04 00:51:5621# For now we require '&&' between commands, until they get globally killed and the test runner updated.
Zachary Turnerd4401d32017-09-18 22:26:4822config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
Michael J. Spencer773a8fb2011-12-18 08:27:5923
24# suffixes: A list of file extensions to treat as test files.
Tobias Hietaf98ee402023-05-17 14:59:4125config.suffixes = [".ll", ".s", ".test", ".yaml", ".objtxt"]
Michael J. Spencer773a8fb2011-12-18 08:27:5926
Rafael Espindolac08ab8e2015-04-24 15:51:4527# 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.
Tobias Hietaf98ee402023-05-17 14:59:4130config.excludes = ["Inputs"]
Rafael Espindolac08ab8e2015-04-24 15:51:4531
Michael J. Spencer773a8fb2011-12-18 08:27:5932# test_source_root: The root path where tests are located.
33config.test_source_root = os.path.dirname(__file__)
34
Tobias Hietaf98ee402023-05-17 14:59:4135config.test_exec_root = os.path.join(config.lld_obj_root, "test")
Michael J. Spencer773a8fb2011-12-18 08:27:5936
Zachary Turner96b04b62017-10-06 17:54:4637llvm_config.use_default_substitutions()
Zachary Turnerad5997e2017-10-12 21:56:0538llvm_config.use_lld()
Pete Cooper80c9b942015-12-10 19:17:3539
Zachary Turner0aa02c02017-09-21 22:16:4040tool_patterns = [
Tobias Hietaf98ee402023-05-17 14:59:4141 "llc",
42 "llvm-as",
43 "llvm-mc",
44 "llvm-nm",
45 "llvm-objdump",
46 "llvm-otool",
47 "llvm-pdbutil",
Ellis Hoag85af42d2023-05-31 21:17:3548 "llvm-profdata",
Tobias Hietaf98ee402023-05-17 14:59:4149 "llvm-dwarfdump",
50 "llvm-readelf",
51 "llvm-readobj",
52 "obj2yaml",
53 "yaml2obj",
54 "opt",
55 "llvm-dis",
56]
Pete Cooper80c9b942015-12-10 19:17:3557
Zachary Turnerad5997e2017-10-12 21:56:0558llvm_config.add_tool_substitutions(tool_patterns)
Pete Cooper80c9b942015-12-10 19:17:3559
Kamil Rytarowskiae1ab912018-12-23 21:20:0960# LLD tests tend to be flaky on NetBSD, so add some retries.
61# We don't do this on other platforms because it's slower.
Tobias Hietaf98ee402023-05-17 14:59:4162if platform.system() in ["NetBSD"]:
Kamil Rytarowskiae1ab912018-12-23 21:20:0963 config.test_retry_attempts = 2
64
Michael J. Spencer773a8fb2011-12-18 08:27:5965# When running under valgrind, we mangle '-vg' onto the end of the triple so we
66# can check it with XFAIL and XTARGET.
Daniel Dunbarbc7bfb12013-08-09 18:51:1767if lit_config.useValgrind:
Tobias Hietaf98ee402023-05-17 14:59:4168 config.target_triple += "-vg"
Michael J. Spencer773a8fb2011-12-18 08:27:5969
Zachary Turnerd4401d32017-09-18 22:26:4870llvm_config.feature_config(
Tobias Hietaf98ee402023-05-17 14:59:4171 [
72 (
73 "--targets-built",
74 {
75 "AArch64": "aarch64",
76 "AMDGPU": "amdgpu",
77 "ARM": "arm",
78 "AVR": "avr",
79 "Hexagon": "hexagon",
80 "Mips": "mips",
81 "MSP430": "msp430",
82 "PowerPC": "ppc",
83 "RISCV": "riscv",
84 "Sparc": "sparc",
85 "WebAssembly": "wasm",
86 "X86": "x86",
87 },
88 ),
89 ("--assertion-mode", {"ON": "asserts"}),
90 ]
91)
Rui Ueyamaf23b27a2013-11-04 05:17:5492
Eric Christopher7baac212018-03-20 18:10:3093# Set a fake constant version so that we get consistent output.
Tobias Hietaf98ee402023-05-17 14:59:4194config.environment["LLD_VERSION"] = "LLD 1.0"
Shoaib Meenai7a4b2762021-10-31 23:55:1295
96# LLD_IN_TEST determines how many times `main` is run inside each process, which
97# lets us test that it's cleaning up after itself and resetting global state
98# correctly (which is important for usage as a library).
Tobias Hietaf98ee402023-05-17 14:59:4199run_lld_main_twice = lit_config.params.get("RUN_LLD_MAIN_TWICE", False)
Shoaib Meenai7a4b2762021-10-31 23:55:12100if not run_lld_main_twice:
Tobias Hietaf98ee402023-05-17 14:59:41101 config.environment["LLD_IN_TEST"] = "1"
Shoaib Meenai7a4b2762021-10-31 23:55:12102else:
Tobias Hietaf98ee402023-05-17 14:59:41103 config.environment["LLD_IN_TEST"] = "2"
Shoaib Meenai7a4b2762021-10-31 23:55:12104 # Many ELF tests fail in this mode.
Tobias Hietaf98ee402023-05-17 14:59:41105 config.excludes.append("ELF")
Shoaib Meenai7a4b2762021-10-31 23:55:12106 # Some old Mach-O backend tests fail, and it's due for removal anyway.
Tobias Hietaf98ee402023-05-17 14:59:41107 config.excludes.append("mach-o")
Shoaib Meenai7a4b2762021-10-31 23:55:12108 # Some new Mach-O backend tests fail; give them a way to mark themselves
109 # unsupported in this mode.
Tobias Hietaf98ee402023-05-17 14:59:41110 config.available_features.add("main-run-twice")
Rui Ueyama3da3f062016-11-10 20:20:37111
Eric Beckmannc8dba242017-07-08 03:06:10112# Indirectly check if the mt.exe Microsoft utility exists by searching for
Eric Beckmann87c6acf2017-08-22 03:15:28113# cvtres, which always accompanies it. Alternatively, check if we can use
114# libxml2 to merge manifests.
Tobias Hietaf98ee402023-05-17 14:59:41115if lit.util.which("cvtres", config.environment["PATH"]) or config.have_libxml2:
116 config.available_features.add("manifest_tool")
Eric Beckmann0aa4b7d2017-09-06 01:50:36117
Ben Dunbobbindfb77f22022-07-01 15:45:09118if config.enable_backtrace:
Tobias Hietaf98ee402023-05-17 14:59:41119 config.available_features.add("backtrace")
Ben Dunbobbindfb77f22022-07-01 15:45:09120
Petr Hosekc4d75362020-07-24 22:47:38121if config.have_libxml2:
Tobias Hietaf98ee402023-05-17 14:59:41122 config.available_features.add("libxml2")
Peter Collingbourne75257bc2017-10-20 19:48:26123
Zachary Turnerf2282762018-03-23 19:57:25124if config.have_dia_sdk:
125 config.available_features.add("diasdk")
126
Peter Collingbourne16d9a0a2019-03-01 18:53:41127if config.sizeof_void_p == 8:
128 config.available_features.add("llvm-64-bits")
129
Jakob Koschel0c861982022-03-24 06:52:16130if config.has_plugins:
Tobias Hietaf98ee402023-05-17 14:59:41131 config.available_features.add("plugins")
Jakob Koschel0c861982022-03-24 06:52:16132
133if config.build_examples:
Tobias Hietaf98ee402023-05-17 14:59:41134 config.available_features.add("examples")
Jakob Koschel0c861982022-03-24 06:52:16135
136if config.linked_bye_extension:
Tobias Hietaf98ee402023-05-17 14:59:41137 config.substitutions.append(("%loadbye", ""))
138 config.substitutions.append(("%loadnewpmbye", ""))
Jakob Koschel0c861982022-03-24 06:52:16139else:
Tobias Hietaf98ee402023-05-17 14:59:41140 config.substitutions.append(
141 (
142 "%loadbye",
143 "-load={}/Bye{}".format(config.llvm_shlib_dir, config.llvm_shlib_ext),
144 )
145 )
146 config.substitutions.append(
147 (
148 "%loadnewpmbye",
149 "-load-pass-plugin={}/Bye{}".format(
150 config.llvm_shlib_dir, config.llvm_shlib_ext
151 ),
152 )
153 )
Jakob Koschel0c861982022-03-24 06:52:16154
Tobias Hietaf98ee402023-05-17 14:59:41155tar_executable = lit.util.which("tar", config.environment["PATH"])
Igor Kudrin85e68a62017-10-26 02:31:36156if tar_executable:
Martin Storsjöa8855672021-03-24 21:58:54157 env = os.environ
Tobias Hietaf98ee402023-05-17 14:59:41158 env["LANG"] = "C"
Igor Kudrin85e68a62017-10-26 02:31:36159 tar_version = subprocess.Popen(
Tobias Hietaf98ee402023-05-17 14:59:41160 [tar_executable, "--version"],
Michal Gornyfbed4e12018-12-14 22:38:01161 stdout=subprocess.PIPE,
162 stderr=subprocess.PIPE,
Tobias Hietaf98ee402023-05-17 14:59:41163 env=env,
164 )
Michal Gornyfbed4e12018-12-14 22:38:01165 sout, _ = tar_version.communicate()
Tobias Hietaf98ee402023-05-17 14:59:41166 if "GNU tar" in sout.decode():
167 config.available_features.add("gnutar")
Mateusz Mikuła9b58b0c2020-10-08 06:34:18168
169# ELF tests expect the default target for ld.lld to be ELF.
170if config.ld_lld_default_mingw:
Tobias Hietaf98ee402023-05-17 14:59:41171 config.excludes.append("ELF")