Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 1 | import os |
| 2 | import platform |
| 3 | import re |
| 4 | import subprocess |
Jeremy Morse | 984fad2 | 2019-10-31 16:51:53 +0000 | [diff] [blame] | 5 | import sys |
Thomas Lively | 7062094 | 2022-03-17 15:22:17 -0700 | [diff] [blame] | 6 | |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 7 | import lit.formats |
| 8 | import lit.util |
| 9 | |
| 10 | from lit.llvm import llvm_config |
| 11 | from lit.llvm.subst import ToolSubst |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 12 | |
| 13 | # Configuration file for the 'lit' test runner. |
| 14 | |
| 15 | # name: The name of this test suite. |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 16 | config.name = "cross-project-tests" |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 17 | |
| 18 | # testFormat: The test format to use to interpret tests. |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 19 | config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) |
| 20 | |
| 21 | # suffixes: A list of file extensions to treat as test files. |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 22 | config.suffixes = [".c", ".cl", ".cpp", ".m"] |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 23 | |
| 24 | # excludes: A list of directories to exclude from the testsuite. The 'Inputs' |
| 25 | # subdirectories contain auxiliary inputs for various tests in their parent |
| 26 | # directories. |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 27 | config.excludes = ["Inputs"] |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 28 | |
| 29 | # test_source_root: The root path where tests are located. |
James Henderson | 24af099 | 2021-02-11 15:41:32 +0000 | [diff] [blame] | 30 | config.test_source_root = config.cross_project_tests_src_root |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 31 | |
| 32 | # test_exec_root: The root path where tests should be run. |
James Henderson | 24af099 | 2021-02-11 15:41:32 +0000 | [diff] [blame] | 33 | config.test_exec_root = config.cross_project_tests_obj_root |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 34 | |
Jeremy Morse | 984fad2 | 2019-10-31 16:51:53 +0000 | [diff] [blame] | 35 | llvm_config.use_default_substitutions() |
| 36 | |
Augusto Noronha | 7cabcdb | 2025-03-19 12:42:47 -0700 | [diff] [blame] | 37 | lldb_python_path = os.path.join( |
| 38 | config.llvm_libs_dir, |
| 39 | f"python{sys.version_info.major}.{sys.version_info.minor}", |
| 40 | "site-packages", |
| 41 | ) |
| 42 | python_exec_path = sys.executable |
Reid Kleckner | 75d38f1 | 2019-05-28 23:03:33 +0000 | [diff] [blame] | 43 | tools = [ |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 44 | ToolSubst( |
| 45 | "%test_debuginfo", |
Augusto Noronha | 7cabcdb | 2025-03-19 12:42:47 -0700 | [diff] [blame] | 46 | command="PYTHON_EXEC_PATH=" |
| 47 | + python_exec_path |
| 48 | + " LLDB_PYTHON_PATH=" |
| 49 | + lldb_python_path |
| 50 | + " " |
| 51 | + os.path.join( |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 52 | config.cross_project_tests_src_root, |
| 53 | "debuginfo-tests", |
| 54 | "llgdb-tests", |
| 55 | "test_debuginfo.pl", |
| 56 | ), |
| 57 | ), |
Christian Sigg | 60346bd | 2020-01-11 08:47:41 +0100 | [diff] [blame] | 58 | ToolSubst("%llvm_src_root", config.llvm_src_root), |
| 59 | ToolSubst("%llvm_tools_dir", config.llvm_tools_dir), |
Reid Kleckner | 75d38f1 | 2019-05-28 23:03:33 +0000 | [diff] [blame] | 60 | ] |
| 61 | |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 62 | |
Reid Kleckner | 75d38f1 | 2019-05-28 23:03:33 +0000 | [diff] [blame] | 63 | def get_required_attr(config, attr_name): |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 64 | attr_value = getattr(config, attr_name, None) |
Eisuke Kawashima | ca92bdf | 2025-01-13 21:03:04 +0900 | [diff] [blame] | 65 | if attr_value is None: |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 66 | lit_config.fatal( |
| 67 | "No attribute %r in test configuration! You may need to run " |
| 68 | "tests from your build directory or add this attribute " |
| 69 | "to lit.site.cfg " % attr_name |
| 70 | ) |
| 71 | return attr_value |
| 72 | |
Reid Kleckner | 75d38f1 | 2019-05-28 23:03:33 +0000 | [diff] [blame] | 73 | |
| 74 | # If this is an MSVC environment, the tests at the root of the tree are |
| 75 | # unsupported. The local win_cdb test suite, however, is supported. |
| 76 | is_msvc = get_required_attr(config, "is_msvc") |
| 77 | if is_msvc: |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 78 | config.available_features.add("msvc") |
Reid Kleckner | 75d38f1 | 2019-05-28 23:03:33 +0000 | [diff] [blame] | 79 | # FIXME: We should add some llvm lit utility code to find the Windows SDK |
| 80 | # and set up the environment appopriately. |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 81 | win_sdk = "C:/Program Files (x86)/Windows Kits/10/" |
| 82 | arch = "x64" |
| 83 | llvm_config.with_system_environment(["LIB", "LIBPATH", "INCLUDE"]) |
Reid Kleckner | 75d38f1 | 2019-05-28 23:03:33 +0000 | [diff] [blame] | 84 | # Clear _NT_SYMBOL_PATH to prevent cdb from attempting to load symbols from |
| 85 | # the network. |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 86 | llvm_config.with_environment("_NT_SYMBOL_PATH", "") |
| 87 | tools.append( |
| 88 | ToolSubst("%cdb", '"%s"' % os.path.join(win_sdk, "Debuggers", arch, "cdb.exe")) |
| 89 | ) |
Reid Kleckner | 75d38f1 | 2019-05-28 23:03:33 +0000 | [diff] [blame] | 90 | |
James Henderson | 4446a72 | 2021-02-09 14:57:03 +0000 | [diff] [blame] | 91 | # clang_src_dir and lld_src_dir are not used by these tests, but are required by |
| 92 | # use_clang() and use_lld() respectively, so set them to "", if needed. |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 93 | if not hasattr(config, "clang_src_dir"): |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 94 | config.clang_src_dir = "" |
Amir Ayupov | 9fec33a | 2024-01-18 19:59:09 -0800 | [diff] [blame] | 95 | llvm_config.use_clang(required=("clang" in config.llvm_enabled_projects)) |
James Henderson | 3827600 | 2021-02-09 15:19:27 +0000 | [diff] [blame] | 96 | |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 97 | if not hasattr(config, "lld_src_dir"): |
James Henderson | 4446a72 | 2021-02-09 14:57:03 +0000 | [diff] [blame] | 98 | config.lld_src_dir = "" |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 99 | llvm_config.use_lld(required=("lld" in config.llvm_enabled_projects)) |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 100 | |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 101 | if "compiler-rt" in config.llvm_enabled_projects: |
| 102 | config.available_features.add("compiler-rt") |
OCHyams | ac0f329 | 2022-02-09 17:08:43 +0000 | [diff] [blame] | 103 | |
OCHyams | 18ee898 | 2021-12-16 13:41:29 +0000 | [diff] [blame] | 104 | # Check which debuggers are available: |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 105 | lldb_path = llvm_config.use_llvm_tool("lldb", search_env="LLDB") |
OCHyams | 18ee898 | 2021-12-16 13:41:29 +0000 | [diff] [blame] | 106 | |
| 107 | if lldb_path is not None: |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 108 | config.available_features.add("lldb") |
| 109 | |
OCHyams | 18ee898 | 2021-12-16 13:41:29 +0000 | [diff] [blame] | 110 | |
| 111 | def configure_dexter_substitutions(): |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 112 | """Configure substitutions for host platform and return list of dependencies""" |
| 113 | # Produce dexter path, lldb path, and combine into the %dexter substitution |
| 114 | # for running a test. |
| 115 | dexter_path = os.path.join( |
| 116 | config.cross_project_tests_src_root, "debuginfo-tests", "dexter", "dexter.py" |
| 117 | ) |
| 118 | dexter_test_cmd = '"{}" "{}" test'.format(sys.executable, dexter_path) |
| 119 | if lldb_path is not None: |
| 120 | dexter_test_cmd += ' --lldb-executable "{}"'.format(lldb_path) |
| 121 | tools.append(ToolSubst("%dexter", dexter_test_cmd)) |
OCHyams | 18ee898 | 2021-12-16 13:41:29 +0000 | [diff] [blame] | 122 | |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 123 | # For testing other bits of dexter that aren't under the "test" subcommand, |
| 124 | # have a %dexter_base substitution. |
| 125 | dexter_base_cmd = '"{}" "{}"'.format(sys.executable, dexter_path) |
| 126 | tools.append(ToolSubst("%dexter_base", dexter_base_cmd)) |
OCHyams | 18ee898 | 2021-12-16 13:41:29 +0000 | [diff] [blame] | 127 | |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 128 | # Set up commands for DexTer regression tests. |
| 129 | # Builder, debugger, optimisation level and several other flags differ |
| 130 | # depending on whether we're running a unix like or windows os. |
| 131 | if platform.system() == "Windows": |
| 132 | # The Windows builder script uses lld. |
| 133 | dependencies = ["clang", "lld-link"] |
Stephen Tozer | b8fc288 | 2025-04-03 15:37:43 +0100 | [diff] [blame] | 134 | dexter_regression_test_c_builder = "clang-cl" |
| 135 | dexter_regression_test_cxx_builder = "clang-cl" |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 136 | dexter_regression_test_debugger = "dbgeng" |
Stephen Tozer | b8fc288 | 2025-04-03 15:37:43 +0100 | [diff] [blame] | 137 | dexter_regression_test_c_flags = "/Zi /Od" |
| 138 | dexter_regression_test_cxx_flags = "/Zi /Od" |
| 139 | dexter_regression_test_additional_flags = "" |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 140 | else: |
| 141 | # Use lldb as the debugger on non-Windows platforms. |
| 142 | dependencies = ["clang", "lldb"] |
Stephen Tozer | b8fc288 | 2025-04-03 15:37:43 +0100 | [diff] [blame] | 143 | dexter_regression_test_c_builder = "clang" |
| 144 | dexter_regression_test_cxx_builder = "clang++" |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 145 | dexter_regression_test_debugger = "lldb" |
Stephen Tozer | b8fc288 | 2025-04-03 15:37:43 +0100 | [diff] [blame] | 146 | dexter_regression_test_c_flags = "-O0 -glldb -std=gnu11" |
| 147 | dexter_regression_test_cxx_flags = "-O0 -glldb -std=gnu++11" |
| 148 | dexter_regression_test_additional_flags = '--lldb-executable "{}"'.format( |
| 149 | lldb_path |
| 150 | ) |
OCHyams | 18ee898 | 2021-12-16 13:41:29 +0000 | [diff] [blame] | 151 | |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 152 | tools.append( |
Stephen Tozer | b8fc288 | 2025-04-03 15:37:43 +0100 | [diff] [blame] | 153 | ToolSubst("%dexter_regression_test_c_builder", dexter_regression_test_c_builder) |
| 154 | ) |
| 155 | tools.append( |
| 156 | ToolSubst( |
| 157 | "%dexter_regression_test_cxx_builder", dexter_regression_test_cxx_builder |
| 158 | ) |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 159 | ) |
| 160 | tools.append( |
| 161 | ToolSubst("%dexter_regression_test_debugger", dexter_regression_test_debugger) |
| 162 | ) |
Stephen Tozer | 45a40c1 | 2023-09-05 16:04:53 +0100 | [diff] [blame] | 163 | # We don't need to distinguish cflags and ldflags because for Dexter |
| 164 | # regression tests we use clang to drive the linker, and so all flags will be |
| 165 | # passed in a single command. |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 166 | tools.append( |
Stephen Tozer | b8fc288 | 2025-04-03 15:37:43 +0100 | [diff] [blame] | 167 | ToolSubst("%dexter_regression_test_c_flags", dexter_regression_test_c_flags) |
| 168 | ) |
| 169 | tools.append( |
| 170 | ToolSubst("%dexter_regression_test_cxx_flags", dexter_regression_test_cxx_flags) |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 171 | ) |
OCHyams | de3f815 | 2022-01-26 11:09:21 +0000 | [diff] [blame] | 172 | |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 173 | # Typical command would take the form: |
Stephen Tozer | 45a40c1 | 2023-09-05 16:04:53 +0100 | [diff] [blame] | 174 | # ./path_to_py/python.exe ./path_to_dex/dexter.py test --fail-lt 1.0 -w --binary %t --debugger lldb --cflags '-O0 -g' |
| 175 | dexter_regression_test_run = " ".join( |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 176 | # "python", "dexter.py", test, fail_mode, builder, debugger, cflags, ldflags |
| 177 | [ |
| 178 | '"{}"'.format(sys.executable), |
| 179 | '"{}"'.format(dexter_path), |
| 180 | "test", |
| 181 | "--fail-lt 1.0 -w", |
| 182 | "--debugger", |
| 183 | dexter_regression_test_debugger, |
Stephen Tozer | b8fc288 | 2025-04-03 15:37:43 +0100 | [diff] [blame] | 184 | dexter_regression_test_additional_flags, |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 185 | ] |
| 186 | ) |
Stephen Tozer | 45a40c1 | 2023-09-05 16:04:53 +0100 | [diff] [blame] | 187 | tools.append(ToolSubst("%dexter_regression_test_run", dexter_regression_test_run)) |
OCHyams | 18ee898 | 2021-12-16 13:41:29 +0000 | [diff] [blame] | 188 | |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 189 | # Include build flags for %dexter_regression_test. |
Stephen Tozer | b8fc288 | 2025-04-03 15:37:43 +0100 | [diff] [blame] | 190 | dexter_regression_test_c_build = " ".join( |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 191 | [ |
Stephen Tozer | b8fc288 | 2025-04-03 15:37:43 +0100 | [diff] [blame] | 192 | dexter_regression_test_c_builder, |
| 193 | dexter_regression_test_c_flags, |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 194 | ] |
| 195 | ) |
Stephen Tozer | b8fc288 | 2025-04-03 15:37:43 +0100 | [diff] [blame] | 196 | dexter_regression_test_cxx_build = " ".join( |
| 197 | [ |
| 198 | dexter_regression_test_cxx_builder, |
| 199 | dexter_regression_test_cxx_flags, |
| 200 | ] |
| 201 | ) |
| 202 | tools.append( |
| 203 | ToolSubst("%dexter_regression_test_c_build", dexter_regression_test_c_build) |
| 204 | ) |
| 205 | tools.append( |
| 206 | ToolSubst("%dexter_regression_test_cxx_build", dexter_regression_test_cxx_build) |
| 207 | ) |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 208 | return dependencies |
| 209 | |
OCHyams | 18ee898 | 2021-12-16 13:41:29 +0000 | [diff] [blame] | 210 | |
OCHyams | 52bc1c1 | 2021-02-24 11:09:18 +0000 | [diff] [blame] | 211 | def add_host_triple(clang): |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 212 | return "{} --target={}".format(clang, config.host_triple) |
| 213 | |
OCHyams | 52bc1c1 | 2021-02-24 11:09:18 +0000 | [diff] [blame] | 214 | |
| 215 | # The set of arches we can build. |
| 216 | targets = set(config.targets_to_build) |
| 217 | # Add aliases to the target set. |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 218 | if "AArch64" in targets: |
| 219 | targets.add("arm64") |
| 220 | if "ARM" in config.targets_to_build: |
| 221 | targets.add("thumbv7") |
| 222 | |
OCHyams | 52bc1c1 | 2021-02-24 11:09:18 +0000 | [diff] [blame] | 223 | |
| 224 | def can_target_host(): |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 225 | # Check if the targets set contains anything that looks like our host arch. |
| 226 | # The arch name in the triple and targets set may be spelled differently |
| 227 | # (e.g. x86 vs X86). |
| 228 | return any(config.host_triple.lower().startswith(x.lower()) for x in targets) |
| 229 | |
OCHyams | 52bc1c1 | 2021-02-24 11:09:18 +0000 | [diff] [blame] | 230 | |
| 231 | # Dexter tests run on the host machine. If the host arch is supported add |
| 232 | # 'dexter' as an available feature and force the dexter tests to use the host |
| 233 | # triple. |
| 234 | if can_target_host(): |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 235 | if config.host_triple != config.target_triple: |
| 236 | print("Forcing dexter tests to use host triple {}.".format(config.host_triple)) |
| 237 | dependencies = configure_dexter_substitutions() |
| 238 | if all(d in config.available_features for d in dependencies): |
| 239 | config.available_features.add("dexter") |
| 240 | llvm_config.with_environment( |
| 241 | "PATHTOCLANG", add_host_triple(llvm_config.config.clang) |
| 242 | ) |
| 243 | llvm_config.with_environment( |
| 244 | "PATHTOCLANGPP", add_host_triple(llvm_config.use_llvm_tool("clang++")) |
| 245 | ) |
| 246 | llvm_config.with_environment( |
| 247 | "PATHTOCLANGCL", add_host_triple(llvm_config.use_llvm_tool("clang-cl")) |
| 248 | ) |
OCHyams | 52bc1c1 | 2021-02-24 11:09:18 +0000 | [diff] [blame] | 249 | else: |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 250 | print( |
| 251 | "Host triple {} not supported. Skipping dexter tests in the " |
| 252 | "debuginfo-tests project.".format(config.host_triple) |
| 253 | ) |
Jeremy Morse | 984fad2 | 2019-10-31 16:51:53 +0000 | [diff] [blame] | 254 | |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 255 | tool_dirs = [config.llvm_tools_dir] |
| 256 | |
Don Hinton | 3a58f67 | 2017-12-12 16:54:20 +0000 | [diff] [blame] | 257 | llvm_config.add_tool_substitutions(tools, tool_dirs) |
| 258 | |
| 259 | lit.util.usePlatformSdkOnDarwin(config, lit_config) |
Vedant Kumar | efab30c | 2018-08-04 00:02:48 +0000 | [diff] [blame] | 260 | |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 261 | if platform.system() == "Darwin": |
| 262 | xcode_lldb_vers = subprocess.check_output(["xcrun", "lldb", "--version"]).decode( |
| 263 | "utf-8" |
| 264 | ) |
Eisuke Kawashima | a1a3e01 | 2025-01-13 21:15:22 +0900 | [diff] [blame] | 265 | match = re.search(r"lldb-(\d+)", xcode_lldb_vers) |
Vedant Kumar | efab30c | 2018-08-04 00:02:48 +0000 | [diff] [blame] | 266 | if match: |
| 267 | apple_lldb_vers = int(match.group(1)) |
| 268 | if apple_lldb_vers < 1000: |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 269 | config.available_features.add("apple-lldb-pre-1000") |
| 270 | |
Jeremy Morse | 984fad2 | 2019-10-31 16:51:53 +0000 | [diff] [blame] | 271 | |
OCHyams | 5257efd | 2022-02-09 10:47:07 +0000 | [diff] [blame] | 272 | def get_gdb_version_string(): |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 273 | """Return gdb's version string, or None if gdb cannot be found or the |
| 274 | --version output is formatted unexpectedly. |
| 275 | """ |
| 276 | # See if we can get a gdb version, e.g. |
| 277 | # $ gdb --version |
| 278 | # GNU gdb (GDB) 10.2 |
| 279 | # ...More stuff... |
| 280 | try: |
| 281 | gdb_vers_lines = ( |
| 282 | subprocess.check_output(["gdb", "--version"]).decode().splitlines() |
| 283 | ) |
| 284 | except: |
| 285 | return None # We coudln't find gdb or something went wrong running it. |
| 286 | if len(gdb_vers_lines) < 1: |
| 287 | print("Unkown GDB version format (too few lines)", file=sys.stderr) |
| 288 | return None |
Eisuke Kawashima | a1a3e01 | 2025-01-13 21:15:22 +0900 | [diff] [blame] | 289 | match = re.search(r"GNU gdb \(.*?\) ((\d|\.)+)", gdb_vers_lines[0].strip()) |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 290 | if match is None: |
| 291 | print(f"Unkown GDB version format: {gdb_vers_lines[0]}", file=sys.stderr) |
| 292 | return None |
| 293 | return match.group(1) |
| 294 | |
OCHyams | 5257efd | 2022-02-09 10:47:07 +0000 | [diff] [blame] | 295 | |
| 296 | def get_clang_default_dwarf_version_string(triple): |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 297 | """Return the default dwarf version string for clang on this (host) platform |
| 298 | or None if we can't work it out. |
| 299 | """ |
| 300 | # Get the flags passed by the driver and look for -dwarf-version. |
| 301 | cmd = f'{llvm_config.use_llvm_tool("clang")} -g -xc -c - -v -### --target={triple}' |
| 302 | stderr = subprocess.run(cmd.split(), stderr=subprocess.PIPE).stderr.decode() |
Eisuke Kawashima | a1a3e01 | 2025-01-13 21:15:22 +0900 | [diff] [blame] | 303 | match = re.search(r"-dwarf-version=(\d+)", stderr) |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 304 | if match is None: |
| 305 | print("Cannot determine default dwarf version", file=sys.stderr) |
| 306 | return None |
| 307 | return match.group(1) |
| 308 | |
OCHyams | 5257efd | 2022-02-09 10:47:07 +0000 | [diff] [blame] | 309 | |
| 310 | # Some cross-project-tests use gdb, but not all versions of gdb are compatible |
| 311 | # with clang's dwarf. Add feature `gdb-clang-incompatibility` to signal that |
| 312 | # there's an incompatibility between clang's default dwarf version for this |
| 313 | # platform and the installed gdb version. |
| 314 | dwarf_version_string = get_clang_default_dwarf_version_string(config.host_triple) |
| 315 | gdb_version_string = get_gdb_version_string() |
| 316 | if dwarf_version_string and gdb_version_string: |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 317 | if int(dwarf_version_string) >= 5: |
dyung | 9374216 | 2024-07-22 11:28:11 -0700 | [diff] [blame] | 318 | try: |
| 319 | from packaging import version |
| 320 | except: |
| 321 | lit_config.fatal("Running gdb tests requires the packaging package") |
| 322 | if version.parse(gdb_version_string) < version.parse("10.1"): |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 323 | # Example for llgdb-tests, which use lldb on darwin but gdb elsewhere: |
| 324 | # XFAIL: !system-darwin && gdb-clang-incompatibility |
| 325 | config.available_features.add("gdb-clang-incompatibility") |
| 326 | print( |
| 327 | "XFAIL some tests: use gdb version >= 10.1 to restore test coverage", |
| 328 | file=sys.stderr, |
| 329 | ) |
OCHyams | 5257efd | 2022-02-09 10:47:07 +0000 | [diff] [blame] | 330 | |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 331 | llvm_config.feature_config([("--build-mode", {"Debug|RelWithDebInfo": "debug-info"})]) |
Thomas Lively | 7062094 | 2022-03-17 15:22:17 -0700 | [diff] [blame] | 332 | |
| 333 | # Allow 'REQUIRES: XXX-registered-target' in tests. |
| 334 | for arch in config.targets_to_build: |
Tobias Hieta | f98ee40 | 2023-05-17 16:59:41 +0200 | [diff] [blame] | 335 | config.available_features.add(arch.lower() + "-registered-target") |