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