Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 1 | # -*- Python -*- |
| 2 | |
| 3 | import os |
| 4 | import platform |
| 5 | import re |
| 6 | import subprocess |
Michael J. Spencer | a4f983e | 2014-03-26 00:53:48 | [diff] [blame] | 7 | import locale |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 8 | |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 | [diff] [blame] | 9 | import lit.formats |
| 10 | import lit.util |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 11 | |
Zachary Turner | d4401d3 | 2017-09-18 22:26:48 | [diff] [blame] | 12 | from lit.llvm import llvm_config |
| 13 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 14 | # Configuration file for the 'lit' test runner. |
| 15 | |
| 16 | # name: The name of this test suite. |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 17 | config.name = "lld" |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 18 | |
| 19 | # testFormat: The test format to use to interpret tests. |
| 20 | # |
Sam Clegg | ab58e4c | 2020-12-04 00:51:56 | [diff] [blame] | 21 | # For now we require '&&' between commands, until they get globally killed and the test runner updated. |
Zachary Turner | d4401d3 | 2017-09-18 22:26:48 | [diff] [blame] | 22 | config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 23 | |
| 24 | # suffixes: A list of file extensions to treat as test files. |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 25 | config.suffixes = [".ll", ".s", ".test", ".yaml", ".objtxt"] |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 26 | |
Rafael Espindola | c08ab8e | 2015-04-24 15:51:45 | [diff] [blame] | 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. |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 30 | config.excludes = ["Inputs"] |
Rafael Espindola | c08ab8e | 2015-04-24 15:51:45 | [diff] [blame] | 31 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 32 | # test_source_root: The root path where tests are located. |
| 33 | config.test_source_root = os.path.dirname(__file__) |
| 34 | |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 35 | config.test_exec_root = os.path.join(config.lld_obj_root, "test") |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 36 | |
Zachary Turner | 96b04b6 | 2017-10-06 17:54:46 | [diff] [blame] | 37 | llvm_config.use_default_substitutions() |
Zachary Turner | ad5997e | 2017-10-12 21:56:05 | [diff] [blame] | 38 | llvm_config.use_lld() |
Pete Cooper | 80c9b94 | 2015-12-10 19:17:35 | [diff] [blame] | 39 | |
Zachary Turner | 0aa02c0 | 2017-09-21 22:16:40 | [diff] [blame] | 40 | tool_patterns = [ |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 41 | "llc", |
| 42 | "llvm-as", |
| 43 | "llvm-mc", |
| 44 | "llvm-nm", |
| 45 | "llvm-objdump", |
| 46 | "llvm-otool", |
| 47 | "llvm-pdbutil", |
Ellis Hoag | 85af42d | 2023-05-31 21:17:35 | [diff] [blame] | 48 | "llvm-profdata", |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 49 | "llvm-dwarfdump", |
| 50 | "llvm-readelf", |
| 51 | "llvm-readobj", |
| 52 | "obj2yaml", |
| 53 | "yaml2obj", |
| 54 | "opt", |
| 55 | "llvm-dis", |
| 56 | ] |
Pete Cooper | 80c9b94 | 2015-12-10 19:17:35 | [diff] [blame] | 57 | |
Zachary Turner | ad5997e | 2017-10-12 21:56:05 | [diff] [blame] | 58 | llvm_config.add_tool_substitutions(tool_patterns) |
Pete Cooper | 80c9b94 | 2015-12-10 19:17:35 | [diff] [blame] | 59 | |
Kamil Rytarowski | ae1ab91 | 2018-12-23 21:20:09 | [diff] [blame] | 60 | # 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 Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 62 | if platform.system() in ["NetBSD"]: |
Kamil Rytarowski | ae1ab91 | 2018-12-23 21:20:09 | [diff] [blame] | 63 | config.test_retry_attempts = 2 |
| 64 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 65 | # When running under valgrind, we mangle '-vg' onto the end of the triple so we |
| 66 | # can check it with XFAIL and XTARGET. |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 | [diff] [blame] | 67 | if lit_config.useValgrind: |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 68 | config.target_triple += "-vg" |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 69 | |
Zachary Turner | d4401d3 | 2017-09-18 22:26:48 | [diff] [blame] | 70 | llvm_config.feature_config( |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 71 | [ |
| 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 Ueyama | f23b27a | 2013-11-04 05:17:54 | [diff] [blame] | 92 | |
Eric Christopher | 7baac21 | 2018-03-20 18:10:30 | [diff] [blame] | 93 | # Set a fake constant version so that we get consistent output. |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 94 | config.environment["LLD_VERSION"] = "LLD 1.0" |
Shoaib Meenai | 7a4b276 | 2021-10-31 23:55:12 | [diff] [blame] | 95 | |
| 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 Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 99 | run_lld_main_twice = lit_config.params.get("RUN_LLD_MAIN_TWICE", False) |
Shoaib Meenai | 7a4b276 | 2021-10-31 23:55:12 | [diff] [blame] | 100 | if not run_lld_main_twice: |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 101 | config.environment["LLD_IN_TEST"] = "1" |
Shoaib Meenai | 7a4b276 | 2021-10-31 23:55:12 | [diff] [blame] | 102 | else: |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 103 | config.environment["LLD_IN_TEST"] = "2" |
Shoaib Meenai | 7a4b276 | 2021-10-31 23:55:12 | [diff] [blame] | 104 | # Many ELF tests fail in this mode. |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 105 | config.excludes.append("ELF") |
Shoaib Meenai | 7a4b276 | 2021-10-31 23:55:12 | [diff] [blame] | 106 | # Some old Mach-O backend tests fail, and it's due for removal anyway. |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 107 | config.excludes.append("mach-o") |
Shoaib Meenai | 7a4b276 | 2021-10-31 23:55:12 | [diff] [blame] | 108 | # Some new Mach-O backend tests fail; give them a way to mark themselves |
| 109 | # unsupported in this mode. |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 110 | config.available_features.add("main-run-twice") |
Rui Ueyama | 3da3f06 | 2016-11-10 20:20:37 | [diff] [blame] | 111 | |
Eric Beckmann | c8dba24 | 2017-07-08 03:06:10 | [diff] [blame] | 112 | # Indirectly check if the mt.exe Microsoft utility exists by searching for |
Eric Beckmann | 87c6acf | 2017-08-22 03:15:28 | [diff] [blame] | 113 | # cvtres, which always accompanies it. Alternatively, check if we can use |
| 114 | # libxml2 to merge manifests. |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 115 | if lit.util.which("cvtres", config.environment["PATH"]) or config.have_libxml2: |
| 116 | config.available_features.add("manifest_tool") |
Eric Beckmann | 0aa4b7d | 2017-09-06 01:50:36 | [diff] [blame] | 117 | |
Ben Dunbobbin | dfb77f2 | 2022-07-01 15:45:09 | [diff] [blame] | 118 | if config.enable_backtrace: |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 119 | config.available_features.add("backtrace") |
Ben Dunbobbin | dfb77f2 | 2022-07-01 15:45:09 | [diff] [blame] | 120 | |
Petr Hosek | c4d7536 | 2020-07-24 22:47:38 | [diff] [blame] | 121 | if config.have_libxml2: |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 122 | config.available_features.add("libxml2") |
Peter Collingbourne | 75257bc | 2017-10-20 19:48:26 | [diff] [blame] | 123 | |
Zachary Turner | f228276 | 2018-03-23 19:57:25 | [diff] [blame] | 124 | if config.have_dia_sdk: |
| 125 | config.available_features.add("diasdk") |
| 126 | |
Peter Collingbourne | 16d9a0a | 2019-03-01 18:53:41 | [diff] [blame] | 127 | if config.sizeof_void_p == 8: |
| 128 | config.available_features.add("llvm-64-bits") |
| 129 | |
Jakob Koschel | 0c86198 | 2022-03-24 06:52:16 | [diff] [blame] | 130 | if config.has_plugins: |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 131 | config.available_features.add("plugins") |
Jakob Koschel | 0c86198 | 2022-03-24 06:52:16 | [diff] [blame] | 132 | |
| 133 | if config.build_examples: |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 134 | config.available_features.add("examples") |
Jakob Koschel | 0c86198 | 2022-03-24 06:52:16 | [diff] [blame] | 135 | |
| 136 | if config.linked_bye_extension: |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 137 | config.substitutions.append(("%loadbye", "")) |
| 138 | config.substitutions.append(("%loadnewpmbye", "")) |
Jakob Koschel | 0c86198 | 2022-03-24 06:52:16 | [diff] [blame] | 139 | else: |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 140 | 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 Koschel | 0c86198 | 2022-03-24 06:52:16 | [diff] [blame] | 154 | |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 155 | tar_executable = lit.util.which("tar", config.environment["PATH"]) |
Igor Kudrin | 85e68a6 | 2017-10-26 02:31:36 | [diff] [blame] | 156 | if tar_executable: |
Martin Storsjö | a885567 | 2021-03-24 21:58:54 | [diff] [blame] | 157 | env = os.environ |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 158 | env["LANG"] = "C" |
Igor Kudrin | 85e68a6 | 2017-10-26 02:31:36 | [diff] [blame] | 159 | tar_version = subprocess.Popen( |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 160 | [tar_executable, "--version"], |
Michal Gorny | fbed4e1 | 2018-12-14 22:38:01 | [diff] [blame] | 161 | stdout=subprocess.PIPE, |
| 162 | stderr=subprocess.PIPE, |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 163 | env=env, |
| 164 | ) |
Michal Gorny | fbed4e1 | 2018-12-14 22:38:01 | [diff] [blame] | 165 | sout, _ = tar_version.communicate() |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 166 | if "GNU tar" in sout.decode(): |
| 167 | config.available_features.add("gnutar") |
Mateusz Mikuła | 9b58b0c | 2020-10-08 06:34:18 | [diff] [blame] | 168 | |
| 169 | # ELF tests expect the default target for ld.lld to be ELF. |
| 170 | if config.ld_lld_default_mingw: |
Tobias Hieta | f98ee40 | 2023-05-17 14:59:41 | [diff] [blame] | 171 | config.excludes.append("ELF") |