Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [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 +0000 | [diff] [blame] | 7 | import locale |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 8 | |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 9 | import lit.formats |
| 10 | import lit.util |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 11 | |
| 12 | # Configuration file for the 'lit' test runner. |
| 13 | |
| 14 | # name: The name of this test suite. |
| 15 | config.name = 'lld' |
| 16 | |
Rafael Espindola | ccd3adc | 2015-08-05 19:55:17 +0000 | [diff] [blame] | 17 | # Tweak PATH for Win32 |
| 18 | if sys.platform in ['win32']: |
| 19 | # Seek sane tools in directories and set to $PATH. |
| 20 | path = getattr(config, 'lit_tools_dir', None) |
| 21 | path = lit_config.getToolsPath(path, |
| 22 | config.environment['PATH'], |
| 23 | ['cmp.exe', 'grep.exe', 'sed.exe']) |
| 24 | if path is not None: |
| 25 | path = os.path.pathsep.join((path, |
| 26 | config.environment['PATH'])) |
| 27 | config.environment['PATH'] = path |
| 28 | |
Reid Kleckner | 5959176 | 2015-05-20 20:41:45 +0000 | [diff] [blame] | 29 | # Choose between lit's internal shell pipeline runner and a real shell. If |
| 30 | # LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override. |
| 31 | use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL") |
| 32 | if use_lit_shell: |
| 33 | # 0 is external, "" is default, and everything else is internal. |
| 34 | execute_external = (use_lit_shell == "0") |
| 35 | else: |
| 36 | # Otherwise we default to internal on Windows and external elsewhere, as |
| 37 | # bash on Windows is usually very slow. |
| 38 | execute_external = (not sys.platform in ['win32']) |
| 39 | |
| 40 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 41 | # testFormat: The test format to use to interpret tests. |
| 42 | # |
| 43 | # For now we require '&&' between commands, until they get globally killed and |
| 44 | # the test runner updated. |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 45 | config.test_format = lit.formats.ShTest(execute_external) |
| 46 | |
| 47 | # suffixes: A list of file extensions to treat as test files. |
Reid Kleckner | 41ff570 | 2017-06-13 15:39:49 +0000 | [diff] [blame] | 48 | config.suffixes = ['.ll', '.s', '.objtxt', '.test'] |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 49 | |
Rafael Espindola | c08ab8e | 2015-04-24 15:51:45 +0000 | [diff] [blame] | 50 | # excludes: A list of directories to exclude from the testsuite. The 'Inputs' |
| 51 | # subdirectories contain auxiliary inputs for various tests in their parent |
| 52 | # directories. |
| 53 | config.excludes = ['Inputs'] |
| 54 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 55 | # test_source_root: The root path where tests are located. |
| 56 | config.test_source_root = os.path.dirname(__file__) |
| 57 | |
| 58 | # test_exec_root: The root path where tests should be run. |
| 59 | lld_obj_root = getattr(config, 'lld_obj_root', None) |
| 60 | if lld_obj_root is not None: |
| 61 | config.test_exec_root = os.path.join(lld_obj_root, 'test') |
| 62 | |
| 63 | # Set llvm_{src,obj}_root for use by others. |
| 64 | config.llvm_src_root = getattr(config, 'llvm_src_root', None) |
| 65 | config.llvm_obj_root = getattr(config, 'llvm_obj_root', None) |
| 66 | |
| 67 | # Tweak the PATH to include the tools dir and the scripts dir. |
| 68 | if lld_obj_root is not None: |
Michal Gorny | 7d0f0e3 | 2017-02-08 20:08:25 +0000 | [diff] [blame] | 69 | lld_tools_dir = getattr(config, 'lld_tools_dir', None) |
| 70 | if not lld_tools_dir: |
| 71 | lit_config.fatal('No LLD tools dir set!') |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 72 | llvm_tools_dir = getattr(config, 'llvm_tools_dir', None) |
| 73 | if not llvm_tools_dir: |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 74 | lit_config.fatal('No LLVM tools dir set!') |
Michal Gorny | 7d0f0e3 | 2017-02-08 20:08:25 +0000 | [diff] [blame] | 75 | path = os.path.pathsep.join((lld_tools_dir, llvm_tools_dir, config.environment['PATH'])) |
Sid Manning | 37e3120 | 2012-09-14 20:04:36 +0000 | [diff] [blame] | 76 | path = os.path.pathsep.join((os.path.join(getattr(config, 'llvm_src_root', None),'test','Scripts'),path)) |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 77 | |
Sid Manning | 37e3120 | 2012-09-14 20:04:36 +0000 | [diff] [blame] | 78 | config.environment['PATH'] = path |
Hemant Kulkarni | 927bbc2 | 2012-09-14 16:11:34 +0000 | [diff] [blame] | 79 | |
Michal Gorny | 7d0f0e3 | 2017-02-08 20:08:25 +0000 | [diff] [blame] | 80 | lld_libs_dir = getattr(config, 'lld_libs_dir', None) |
| 81 | if not lld_libs_dir: |
| 82 | lit_config.fatal('No LLD libs dir set!') |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 83 | llvm_libs_dir = getattr(config, 'llvm_libs_dir', None) |
| 84 | if not llvm_libs_dir: |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 85 | lit_config.fatal('No LLVM libs dir set!') |
Michal Gorny | 7d0f0e3 | 2017-02-08 20:08:25 +0000 | [diff] [blame] | 86 | path = os.path.pathsep.join((lld_libs_dir, llvm_libs_dir, |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 87 | config.environment.get('LD_LIBRARY_PATH',''))) |
| 88 | config.environment['LD_LIBRARY_PATH'] = path |
| 89 | |
Michael J. Spencer | ca20ffb | 2013-01-13 01:09:51 +0000 | [diff] [blame] | 90 | # Propagate LLVM_SRC_ROOT into the environment. |
| 91 | config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '') |
| 92 | |
| 93 | # Propagate PYTHON_EXECUTABLE into the environment |
| 94 | config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable', |
| 95 | '') |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 96 | ### |
| 97 | |
| 98 | # Check that the object root is known. |
| 99 | if config.test_exec_root is None: |
| 100 | # Otherwise, we haven't loaded the site specific configuration (the user is |
| 101 | # probably trying to run on a test file directly, and either the site |
| 102 | # configuration hasn't been created by the build system, or we are in an |
| 103 | # out-of-tree build situation). |
| 104 | |
| 105 | # Check for 'lld_site_config' user parameter, and use that if available. |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 106 | site_cfg = lit_config.params.get('lld_site_config', None) |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 107 | if site_cfg and os.path.exists(site_cfg): |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 108 | lit_config.load_config(config, site_cfg) |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 109 | raise SystemExit |
| 110 | |
| 111 | # Try to detect the situation where we are using an out-of-tree build by |
| 112 | # looking for 'llvm-config'. |
| 113 | # |
| 114 | # FIXME: I debated (i.e., wrote and threw away) adding logic to |
| 115 | # automagically generate the lit.site.cfg if we are in some kind of fresh |
| 116 | # build situation. This means knowing how to invoke the build system though, |
| 117 | # and I decided it was too much magic. We should solve this by just having |
| 118 | # the .cfg files generated during the configuration step. |
| 119 | |
| 120 | llvm_config = lit.util.which('llvm-config', config.environment['PATH']) |
| 121 | if not llvm_config: |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 122 | lit_config.fatal('No site specific configuration available!') |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 123 | |
| 124 | # Get the source and object roots. |
| 125 | llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip() |
| 126 | llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip() |
| 127 | lld_src_root = os.path.join(llvm_src_root, "tools", "lld") |
| 128 | lld_obj_root = os.path.join(llvm_obj_root, "tools", "lld") |
| 129 | |
| 130 | # Validate that we got a tree which points to here, using the standard |
| 131 | # tools/lld layout. |
| 132 | this_src_root = os.path.dirname(config.test_source_root) |
| 133 | if os.path.realpath(lld_src_root) != os.path.realpath(this_src_root): |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 134 | lit_config.fatal('No site specific configuration available!') |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 135 | |
| 136 | # Check that the site specific configuration exists. |
| 137 | site_cfg = os.path.join(lld_obj_root, 'test', 'lit.site.cfg') |
| 138 | if not os.path.exists(site_cfg): |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 139 | lit_config.fatal( |
| 140 | 'No site specific configuration available! You may need to ' |
| 141 | 'run "make test" in your lld build directory.') |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 142 | |
| 143 | # Okay, that worked. Notify the user of the automagic, and reconfigure. |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 144 | lit_config.note('using out-of-tree build at %r' % lld_obj_root) |
| 145 | lit_config.load_config(config, site_cfg) |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 146 | raise SystemExit |
| 147 | |
Pete Cooper | 80c9b94 | 2015-12-10 19:17:35 +0000 | [diff] [blame] | 148 | # For each occurrence of a lld tool name as its own word, replace it |
| 149 | # with the full path to the build directory holding that tool. This |
| 150 | # ensures that we are testing the tools just built and not some random |
| 151 | # tools that might happen to be in the user's PATH. |
| 152 | |
| 153 | # Regex assertions to reject neighbor hyphens/dots (seen in some tests). |
| 154 | # For example, we want to prefix 'lld' and 'ld.lld' but not the 'lld' inside |
| 155 | # of 'ld.lld'. |
Lang Hames | fc3438c | 2015-12-11 22:09:03 +0000 | [diff] [blame] | 156 | NoPreJunk = r"(?<!(-|\.|/))" |
| 157 | NoPostJunk = r"(?!(-|\.))" |
Pete Cooper | 80c9b94 | 2015-12-10 19:17:35 +0000 | [diff] [blame] | 158 | |
Rafael Espindola | cb09daa | 2016-10-26 18:59:00 +0000 | [diff] [blame] | 159 | config.substitutions.append( (r"\bld.lld\b", 'ld.lld --full-shutdown') ) |
| 160 | |
Pete Cooper | 80c9b94 | 2015-12-10 19:17:35 +0000 | [diff] [blame] | 161 | tool_patterns = [r"\bFileCheck\b", |
| 162 | r"\bnot\b", |
Lang Hames | fc3438c | 2015-12-11 22:09:03 +0000 | [diff] [blame] | 163 | NoPreJunk + r"\blld\b" + NoPostJunk, |
Pete Cooper | 80c9b94 | 2015-12-10 19:17:35 +0000 | [diff] [blame] | 164 | r"\bld.lld\b", |
| 165 | r"\blld-link\b", |
Rafael Espindola | 069b1c1 | 2016-07-21 18:08:36 +0000 | [diff] [blame] | 166 | r"\bllvm-as\b", |
Pete Cooper | 80c9b94 | 2015-12-10 19:17:35 +0000 | [diff] [blame] | 167 | r"\bllvm-mc\b", |
| 168 | r"\bllvm-nm\b", |
| 169 | r"\bllvm-objdump\b", |
Sam Clegg | be37367 | 2017-06-13 15:53:53 +0000 | [diff] [blame^] | 170 | r"\bllvm-pdbutil\b", |
Pete Cooper | 80c9b94 | 2015-12-10 19:17:35 +0000 | [diff] [blame] | 171 | r"\bllvm-readobj\b", |
Pete Cooper | cb7d83c | 2016-08-11 21:03:56 +0000 | [diff] [blame] | 172 | r"\bobj2yaml\b", |
Pete Cooper | 80c9b94 | 2015-12-10 19:17:35 +0000 | [diff] [blame] | 173 | r"\byaml2obj\b"] |
| 174 | |
| 175 | for pattern in tool_patterns: |
| 176 | # Extract the tool name from the pattern. This relies on the tool |
| 177 | # name being surrounded by \b word match operators. If the |
| 178 | # pattern starts with "| ", include it in the string to be |
| 179 | # substituted. |
| 180 | tool_match = re.match(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_\.]+)\\b\W*$", |
| 181 | pattern) |
| 182 | tool_pipe = tool_match.group(2) |
| 183 | tool_name = tool_match.group(4) |
Michal Gorny | 7d0f0e3 | 2017-02-08 20:08:25 +0000 | [diff] [blame] | 184 | tool_path = lit.util.which(tool_name, config.environment['PATH']) |
Pete Cooper | 80c9b94 | 2015-12-10 19:17:35 +0000 | [diff] [blame] | 185 | if not tool_path: |
| 186 | # Warn, but still provide a substitution. |
Michal Gorny | 7d0f0e3 | 2017-02-08 20:08:25 +0000 | [diff] [blame] | 187 | lit_config.note('Did not find ' + tool_name + ' in ' + path) |
Pete Cooper | 80c9b94 | 2015-12-10 19:17:35 +0000 | [diff] [blame] | 188 | tool_path = llvm_tools_dir + '/' + tool_name |
| 189 | config.substitutions.append((pattern, tool_pipe + tool_path)) |
| 190 | |
NAKAMURA Takumi | 1272954 | 2016-02-09 07:30:18 +0000 | [diff] [blame] | 191 | # Add site-specific substitutions. |
| 192 | config.substitutions.append( ('%python', config.python_executable) ) |
| 193 | |
Pete Cooper | 80c9b94 | 2015-12-10 19:17:35 +0000 | [diff] [blame] | 194 | ### |
| 195 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 196 | # When running under valgrind, we mangle '-vg' onto the end of the triple so we |
| 197 | # can check it with XFAIL and XTARGET. |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 198 | if lit_config.useValgrind: |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 199 | config.target_triple += '-vg' |
| 200 | |
| 201 | # Shell execution |
Reid Kleckner | 750e76d | 2016-03-30 20:15:50 +0000 | [diff] [blame] | 202 | if execute_external: |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 203 | config.available_features.add('shell') |
Rui Ueyama | 9249222 | 2013-07-03 09:09:13 +0000 | [diff] [blame] | 204 | |
Rui Ueyama | 287956f | 2016-07-07 03:55:57 +0000 | [diff] [blame] | 205 | # zlib compression library |
Michal Gorny | a028b33 | 2017-02-08 20:08:29 +0000 | [diff] [blame] | 206 | if config.have_zlib: |
Rui Ueyama | 287956f | 2016-07-07 03:55:57 +0000 | [diff] [blame] | 207 | config.available_features.add("zlib") |
| 208 | |
Nick Kledzik | 50bda29 | 2014-09-11 00:52:05 +0000 | [diff] [blame] | 209 | # Running on Darwin OS |
| 210 | if platform.system() in ['Darwin']: |
| 211 | config.available_features.add('system-linker-mach-o') |
| 212 | |
| 213 | # Running on ELF based *nix |
Ed Maste | 933daef | 2014-09-12 13:16:30 +0000 | [diff] [blame] | 214 | if platform.system() in ['FreeBSD', 'Linux']: |
Nick Kledzik | 50bda29 | 2014-09-11 00:52:05 +0000 | [diff] [blame] | 215 | config.available_features.add('system-linker-elf') |
| 216 | |
George Rimar | e893689 | 2016-11-11 13:23:13 +0000 | [diff] [blame] | 217 | # Running on Windows |
| 218 | if platform.system() in ['Windows']: |
| 219 | config.available_features.add('system-windows') |
| 220 | |
NAKAMURA Takumi | c96ae0c | 2016-02-09 07:30:11 +0000 | [diff] [blame] | 221 | # Set if host-cxxabi's demangler can handle target's symbols. |
| 222 | if platform.system() not in ['Windows']: |
| 223 | config.available_features.add('demangler') |
| 224 | |
Shankar Easwaran | 7a0818d | 2014-02-25 02:29:17 +0000 | [diff] [blame] | 225 | # llvm-config knows whether it is compiled with asserts (and) |
| 226 | # whether we are operating in release/debug mode. |
Rui Ueyama | 9249222 | 2013-07-03 09:09:13 +0000 | [diff] [blame] | 227 | import subprocess |
| 228 | try: |
Shankar Easwaran | 7a0818d | 2014-02-25 02:29:17 +0000 | [diff] [blame] | 229 | llvm_config_cmd = \ |
| 230 | subprocess.Popen([os.path.join(llvm_tools_dir, 'llvm-config'), |
Filipe Cabecinhas | cd8c610 | 2014-04-23 05:35:26 +0000 | [diff] [blame] | 231 | '--build-mode', '--assertion-mode', '--targets-built'], |
Shankar Easwaran | 7a0818d | 2014-02-25 02:29:17 +0000 | [diff] [blame] | 232 | stdout = subprocess.PIPE) |
Michael J. Spencer | a4f983e | 2014-03-26 00:53:48 +0000 | [diff] [blame] | 233 | except OSError as why: |
| 234 | print("Could not find llvm-config in " + llvm_tools_dir) |
Rui Ueyama | 9249222 | 2013-07-03 09:09:13 +0000 | [diff] [blame] | 235 | exit(42) |
| 236 | |
Michael J. Spencer | 876bee8 | 2014-03-26 01:19:07 +0000 | [diff] [blame] | 237 | llvm_config_output = llvm_config_cmd.stdout.read().decode('utf_8') |
Shankar Easwaran | 7a0818d | 2014-02-25 02:29:17 +0000 | [diff] [blame] | 238 | llvm_config_output_list = llvm_config_output.split("\n") |
| 239 | |
| 240 | if re.search(r'DEBUG', llvm_config_output_list[0]): |
Rui Ueyama | 130a6eb | 2013-07-04 09:29:47 +0000 | [diff] [blame] | 241 | config.available_features.add('debug') |
Shankar Easwaran | 7a0818d | 2014-02-25 02:29:17 +0000 | [diff] [blame] | 242 | if re.search(r'ON', llvm_config_output_list[1]): |
Rui Ueyama | 9249222 | 2013-07-03 09:09:13 +0000 | [diff] [blame] | 243 | config.available_features.add('asserts') |
Rafael Espindola | 83af95d | 2015-09-28 12:22:25 +0000 | [diff] [blame] | 244 | |
| 245 | archs = llvm_config_output_list[2] |
| 246 | if re.search(r'AArch64', archs): |
| 247 | config.available_features.add('aarch64') |
| 248 | if re.search(r'ARM', archs): |
Simon Atanasyan | d7bc5d0 | 2014-07-31 19:02:10 +0000 | [diff] [blame] | 249 | config.available_features.add('arm') |
Rafael Espindola | 83af95d | 2015-09-28 12:22:25 +0000 | [diff] [blame] | 250 | if re.search(r'Mips', archs): |
Filipe Cabecinhas | cd8c610 | 2014-04-23 05:35:26 +0000 | [diff] [blame] | 251 | config.available_features.add('mips') |
Rafael Espindola | 83af95d | 2015-09-28 12:22:25 +0000 | [diff] [blame] | 252 | if re.search(r'X86', archs): |
Filipe Cabecinhas | d1787ad | 2015-01-24 03:55:22 +0000 | [diff] [blame] | 253 | config.available_features.add('x86') |
Rafael Espindola | 83af95d | 2015-09-28 12:22:25 +0000 | [diff] [blame] | 254 | if re.search(r'PowerPC', archs): |
Rafael Espindola | 1c2f64d | 2015-08-05 23:40:20 +0000 | [diff] [blame] | 255 | config.available_features.add('ppc') |
Tom Stellard | 68a55e6 | 2016-01-07 05:02:38 +0000 | [diff] [blame] | 256 | if re.search(r'AMDGPU', archs): |
| 257 | config.available_features.add('amdgpu') |
Shankar Easwaran | 7a0818d | 2014-02-25 02:29:17 +0000 | [diff] [blame] | 258 | llvm_config_cmd.wait() |
Rui Ueyama | f23b27a | 2013-11-04 05:17:54 +0000 | [diff] [blame] | 259 | |
Rui Ueyama | 3da3f06 | 2016-11-10 20:20:37 +0000 | [diff] [blame] | 260 | # Set a fake constant version so that we get consitent output. |
| 261 | config.environment['LLD_VERSION'] = 'LLD 1.0' |
| 262 | |
Rui Ueyama | f23b27a | 2013-11-04 05:17:54 +0000 | [diff] [blame] | 263 | # Check if Windows resource file compiler exists. |
| 264 | cvtres = lit.util.which('cvtres', config.environment['PATH']) |
| 265 | rc = lit.util.which('rc', config.environment['PATH']) |
| 266 | if cvtres and rc: |
| 267 | config.available_features.add('winres') |