| Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 1 | # -*- Python -*- |
| 2 | |
| 3 | # Configuration file for the 'lit' test runner. |
| 4 | |
| 5 | import os |
| NAKAMURA Takumi | b3ccc12 | 2010-11-29 00:20:09 +0000 | [diff] [blame] | 6 | import sys |
| David Greene | 18d4987 | 2011-01-03 17:30:25 +0000 | [diff] [blame] | 7 | import re |
| Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 8 | |
| 9 | # name: The name of this test suite. |
| 10 | config.name = 'LLVM' |
| 11 | |
| 12 | # testFormat: The test format to use to interpret tests. |
| 13 | config.test_format = lit.formats.TclTest() |
| 14 | |
| 15 | # suffixes: A list of file extensions to treat as test files, this is actually |
| 16 | # set by on_clone(). |
| 17 | config.suffixes = [] |
| 18 | |
| 19 | # test_source_root: The root path where tests are located. |
| 20 | config.test_source_root = os.path.dirname(__file__) |
| 21 | |
| NAKAMURA Takumi | c37b429 | 2011-02-09 04:19:21 +0000 | [diff] [blame] | 22 | # Tweak PATH for Win32 |
| 23 | if sys.platform in ['win32']: |
| 24 | # Seek sane tools in directories and set to $PATH. |
| 25 | path = getattr(config, 'lit_tools_dir', None) |
| 26 | path = lit.getToolsPath(path, |
| 27 | config.environment['PATH'], |
| 28 | ['cmp.exe', 'grep.exe', 'sed.exe']) |
| 29 | if path is not None: |
| 30 | path = os.path.pathsep.join((path, |
| 31 | config.environment['PATH'])) |
| 32 | config.environment['PATH'] = path |
| 33 | |
| Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 34 | # test_exec_root: The root path where tests should be run. |
| 35 | llvm_obj_root = getattr(config, 'llvm_obj_root', None) |
| 36 | if llvm_obj_root is not None: |
| 37 | config.test_exec_root = os.path.join(llvm_obj_root, 'test') |
| 38 | |
| Daniel Dunbar | 5ed7be1 | 2009-11-08 09:08:00 +0000 | [diff] [blame] | 39 | # Tweak the PATH to include the scripts dir, the tools dir, and the llvm-gcc bin |
| 40 | # dir (if available). |
| 41 | if llvm_obj_root is not None: |
| Tobias Grosser | ee38f85 | 2011-01-04 16:01:17 +0000 | [diff] [blame] | 42 | # Include llvm-gcc first, as the llvm-gcc binaryies will not appear |
| 43 | # neither in the tools nor in the scripts dir. However it might be |
| 44 | # possible, that some old llvm tools are in the llvm-gcc dir. Adding |
| 45 | # llvm-gcc dir first ensures, that those will always be overwritten |
| 46 | # by the new tools in llvm_tools_dir. So now outdated tools are used |
| 47 | # for testing |
| 48 | llvmgcc_dir = getattr(config, 'llvmgcc_dir', None) |
| 49 | if llvmgcc_dir: |
| 50 | path = os.path.pathsep.join((os.path.join(llvmgcc_dir, 'bin'), |
| 51 | config.environment['PATH'])) |
| 52 | config.environment['PATH'] = path |
| 53 | |
| Daniel Dunbar | 5ed7be1 | 2009-11-08 09:08:00 +0000 | [diff] [blame] | 54 | llvm_src_root = getattr(config, 'llvm_src_root', None) |
| 55 | if not llvm_src_root: |
| 56 | lit.fatal('No LLVM source root set!') |
| 57 | path = os.path.pathsep.join((os.path.join(llvm_src_root, 'test', |
| 58 | 'Scripts'), |
| 59 | config.environment['PATH'])) |
| 60 | config.environment['PATH'] = path |
| 61 | |
| 62 | llvm_tools_dir = getattr(config, 'llvm_tools_dir', None) |
| 63 | if not llvm_tools_dir: |
| 64 | lit.fatal('No LLVM tools dir set!') |
| 65 | path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH'])) |
| 66 | config.environment['PATH'] = path |
| 67 | |
| Duncan Sands | 51a6455 | 2010-09-13 13:32:22 +0000 | [diff] [blame] | 68 | # Propagate 'HOME' through the environment. |
| Daniel Dunbar | 1321fec | 2010-08-10 19:36:25 +0000 | [diff] [blame] | 69 | if 'HOME' in os.environ: |
| 70 | config.environment['HOME'] = os.environ['HOME'] |
| Daniel Dunbar | 55983f1 | 2010-02-25 22:09:09 +0000 | [diff] [blame] | 71 | |
| Duncan Sands | 51a6455 | 2010-09-13 13:32:22 +0000 | [diff] [blame] | 72 | # Propagate 'INCLUDE' through the environment. |
| Michael J. Spencer | 06b7f58 | 2010-08-30 14:49:00 +0000 | [diff] [blame] | 73 | if 'INCLUDE' in os.environ: |
| 74 | config.environment['INCLUDE'] = os.environ['INCLUDE'] |
| 75 | |
| Duncan Sands | 51a6455 | 2010-09-13 13:32:22 +0000 | [diff] [blame] | 76 | # Propagate 'LIB' through the environment. |
| Michael J. Spencer | 06b7f58 | 2010-08-30 14:49:00 +0000 | [diff] [blame] | 77 | if 'LIB' in os.environ: |
| 78 | config.environment['LIB'] = os.environ['LIB'] |
| 79 | |
| Michael J. Spencer | 44d392a | 2010-12-07 01:23:49 +0000 | [diff] [blame] | 80 | # Propagate the temp directory. Windows requires this because it uses \Windows\ |
| 81 | # if none of these are present. |
| 82 | if 'TMP' in os.environ: |
| 83 | config.environment['TMP'] = os.environ['TMP'] |
| 84 | if 'TEMP' in os.environ: |
| 85 | config.environment['TEMP'] = os.environ['TEMP'] |
| 86 | |
| Duncan Sands | 51a6455 | 2010-09-13 13:32:22 +0000 | [diff] [blame] | 87 | # Propagate LLVM_SRC_ROOT into the environment. |
| Daniel Dunbar | 238e73f | 2010-06-23 18:06:16 +0000 | [diff] [blame] | 88 | config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '') |
| Daniel Dunbar | 9b2cb69 | 2010-06-12 16:21:19 +0000 | [diff] [blame] | 89 | |
| Duncan Sands | 51a6455 | 2010-09-13 13:32:22 +0000 | [diff] [blame] | 90 | # Propagate PYTHON_EXECUTABLE into the environment |
| Daniel Dunbar | 9b2cb69 | 2010-06-12 16:21:19 +0000 | [diff] [blame] | 91 | config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable', |
| 92 | '') |
| 93 | |
| Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 94 | ### |
| 95 | |
| 96 | import os |
| 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 | |
| Daniel Dunbar | aefd63d | 2009-12-08 19:47:36 +0000 | [diff] [blame] | 105 | # Check for 'llvm_site_config' user parameter, and use that if available. |
| 106 | site_cfg = lit.params.get('llvm_site_config', None) |
| 107 | if site_cfg and os.path.exists(site_cfg): |
| 108 | lit.load_config(config, site_cfg) |
| 109 | raise SystemExit |
| 110 | |
| Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 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 |
| 117 | # though, and I decided it was too much magic. |
| 118 | |
| 119 | llvm_config = lit.util.which('llvm-config', config.environment['PATH']) |
| 120 | if not llvm_config: |
| 121 | lit.fatal('No site specific configuration available!') |
| 122 | |
| 123 | # Get the source and object roots. |
| 124 | llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip() |
| 125 | llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip() |
| 126 | |
| 127 | # Validate that we got a tree which points to here. |
| 128 | this_src_root = os.path.dirname(config.test_source_root) |
| 129 | if os.path.realpath(llvm_src_root) != os.path.realpath(this_src_root): |
| 130 | lit.fatal('No site specific configuration available!') |
| 131 | |
| 132 | # Check that the site specific configuration exists. |
| 133 | site_cfg = os.path.join(llvm_obj_root, 'test', 'lit.site.cfg') |
| 134 | if not os.path.exists(site_cfg): |
| 135 | lit.fatal('No site specific configuration available!') |
| 136 | |
| 137 | # Okay, that worked. Notify the user of the automagic, and reconfigure. |
| 138 | lit.note('using out-of-tree build at %r' % llvm_obj_root) |
| 139 | lit.load_config(config, site_cfg) |
| 140 | raise SystemExit |
| 141 | |
| 142 | ### |
| 143 | |
| 144 | # Load site data from DejaGNU's site.exp. |
| 145 | import re |
| 146 | site_exp = {} |
| 147 | # FIXME: Implement lit.site.cfg. |
| 148 | for line in open(os.path.join(config.llvm_obj_root, 'test', 'site.exp')): |
| Bob Wilson | 8d854a4 | 2010-08-20 14:19:38 +0000 | [diff] [blame] | 149 | m = re.match('set ([^ ]+) "(.*)"', line) |
| Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 150 | if m: |
| 151 | site_exp[m.group(1)] = m.group(2) |
| 152 | |
| 153 | # Add substitutions. |
| Daniel Dunbar | b0c9a99 | 2009-10-30 21:13:59 +0000 | [diff] [blame] | 154 | config.substitutions.append(('%llvmgcc_only', site_exp['llvmgcc'])) |
| Duncan Sands | 48f296d | 2010-11-25 21:19:52 +0000 | [diff] [blame] | 155 | for sub in ['llvmgcc', 'llvmgxx', 'emitir', 'compile_cxx', 'compile_c', |
| Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 156 | 'link', 'shlibext', 'ocamlopt', 'llvmdsymutil', 'llvmlibsdir', |
| NAKAMURA Takumi | 38d439f | 2010-11-29 00:20:21 +0000 | [diff] [blame] | 157 | 'llvmshlibdir', |
| Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 158 | 'bugpoint_topts']: |
| 159 | if sub in ('llvmgcc', 'llvmgxx'): |
| 160 | config.substitutions.append(('%' + sub, |
| Duncan Sands | 48f296d | 2010-11-25 21:19:52 +0000 | [diff] [blame] | 161 | site_exp[sub] + ' %emitir -w')) |
| Benjamin Kramer | 66c439a | 2010-02-04 18:40:11 +0000 | [diff] [blame] | 162 | # FIXME: This is a hack to avoid LLVMC tests failing due to a clang driver |
| 163 | # warning when passing in "-fexceptions -fno-exceptions". |
| 164 | elif sub == 'compile_cxx': |
| 165 | config.substitutions.append(('%' + sub, |
| 166 | site_exp[sub].replace('-fno-exceptions', ''))) |
| Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 167 | else: |
| 168 | config.substitutions.append(('%' + sub, site_exp[sub])) |
| 169 | |
| David Greene | 18d4987 | 2011-01-03 17:30:25 +0000 | [diff] [blame] | 170 | # For each occurrence of an llvm tool name as its own word, replace it |
| 171 | # with the full path to the build directory holding that tool. This |
| 172 | # ensures that we are testing the tools just built and not some random |
| 173 | # tools that might happen to be in the user's PATH. Thus this list |
| 174 | # includes every tool placed in $(LLVM_OBJ_ROOT)/$(BuildMode)/bin |
| 175 | # (llvm_tools_dir in lit parlance). |
| David Greene | fd1ed5f | 2011-01-03 21:55:08 +0000 | [diff] [blame] | 176 | # Don't match 'bugpoint-' or 'clang-'. |
| David Greene | 70ecc97 | 2011-01-04 01:05:30 +0000 | [diff] [blame] | 177 | # Don't match '/clang'. |
| NAKAMURA Takumi | 027f98c | 2011-02-24 12:34:34 +0000 | [diff] [blame] | 178 | if os.pathsep == ';': |
| 179 | pathext = os.environ.get('PATHEXT', '').split(';') |
| 180 | else: |
| 181 | pathext = [''] |
| David Greene | 70ecc97 | 2011-01-04 01:05:30 +0000 | [diff] [blame] | 182 | for pattern in [r"\bbugpoint\b(?!-)", r"(?<!/)\bclang\b(?!-)", |
| Sean Callanan | 41dfd2b | 2011-02-22 02:05:53 +0000 | [diff] [blame] | 183 | r"\bgold\b", |
| David Greene | 18d4987 | 2011-01-03 17:30:25 +0000 | [diff] [blame] | 184 | r"\bllc\b", r"\blli\b", |
| 185 | r"\bllvm-ar\b", r"\bllvm-as\b", |
| 186 | r"\bllvm-bcanalyzer\b", r"\bllvm-config\b", |
| 187 | r"\bllvm-diff\b", r"\bllvm-dis\b", |
| 188 | r"\bllvm-extract\b", r"\bllvm-ld\b", |
| 189 | r"\bllvm-link\b", r"\bllvm-mc\b", |
| 190 | r"\bllvm-nm\b", r"\bllvm-prof\b", |
| 191 | r"\bllvm-ranlib\b", r"\bllvm-shlib\b", |
| 192 | r"\bllvm-stub\b", r"\bllvm2cpp\b", |
| 193 | # Don't match '-llvmc'. |
| 194 | r"(?<!-)\bllvmc\b", r"\blto\b", |
| Frits van Bommel | c95ff3c | 2011-01-05 15:10:24 +0000 | [diff] [blame] | 195 | # Don't match '.opt', '-opt', |
| 196 | # '^opt' or '/opt'. |
| 197 | r"\bmacho-dump\b", r"(?<!\.|-|\^|/)\bopt\b", |
| David Greene | 18d4987 | 2011-01-03 17:30:25 +0000 | [diff] [blame] | 198 | r"\btblgen\b", r"\bFileCheck\b", |
| 199 | r"\bFileUpdate\b", r"\bc-index-test\b", |
| 200 | r"\bfpcmp\b", r"\bllvm-PerfectShuffle\b", |
| 201 | # Handle these specially as they are strings searched |
| 202 | # for during testing. |
| 203 | r"\| \bcount\b", r"\| \bnot\b"]: |
| 204 | # Extract the tool name from the pattern. This relies on the tool |
| 205 | # name being surrounded by \b word match operators. If the |
| 206 | # pattern starts with "| ", include it in the string to be |
| 207 | # substituted. |
| 208 | substitution = re.sub(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$", |
| 209 | r"\2" + llvm_tools_dir + "/" + r"\4", |
| 210 | pattern) |
| NAKAMURA Takumi | 027f98c | 2011-02-24 12:34:34 +0000 | [diff] [blame] | 211 | for ext in pathext: |
| 212 | substitution_ext = substitution + ext |
| 213 | if os.path.exists(substitution_ext): |
| 214 | substitution = substitution_ext |
| 215 | break |
| David Greene | 18d4987 | 2011-01-03 17:30:25 +0000 | [diff] [blame] | 216 | config.substitutions.append((pattern, substitution)) |
| 217 | |
| Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 218 | excludes = [] |
| 219 | |
| 220 | # Provide target_triple for use in XFAIL and XTARGET. |
| 221 | config.target_triple = site_exp['target_triplet'] |
| 222 | |
| Jeffrey Yasskin | 32989de | 2010-03-20 23:08:45 +0000 | [diff] [blame] | 223 | # When running under valgrind, we mangle '-vg' or '-vg_leak' onto the end of the |
| 224 | # triple so we can check it with XFAIL and XTARGET. |
| 225 | config.target_triple += lit.valgrindTriple |
| Daniel Dunbar | a56a810 | 2010-03-20 21:12:48 +0000 | [diff] [blame] | 226 | |
| Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 227 | # Provide llvm_supports_target for use in local configs. |
| 228 | targets = set(site_exp["TARGETS_TO_BUILD"].split()) |
| 229 | def llvm_supports_target(name): |
| 230 | return name in targets |
| 231 | |
| Daniel Dunbar | 197f1f0 | 2010-02-02 22:00:15 +0000 | [diff] [blame] | 232 | def llvm_supports_darwin_and_target(name): |
| 233 | return 'darwin' in config.target_triple and llvm_supports_target(name) |
| 234 | |
| Daniel Dunbar | 2e5ec11 | 2010-08-19 16:47:54 +0000 | [diff] [blame] | 235 | langs = set([s.strip() for s in site_exp['llvmgcc_langs'].split(',')]) |
| Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 236 | def llvm_gcc_supports(name): |
| Daniel Dunbar | 62b4d71 | 2010-08-19 16:46:52 +0000 | [diff] [blame] | 237 | return name.strip() in langs |
| Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 238 | |
| Daniel Dunbar | 2e5ec11 | 2010-08-19 16:47:54 +0000 | [diff] [blame] | 239 | bindings = set([s.strip() for s in site_exp['llvm_bindings'].split(',')]) |
| Daniel Dunbar | 840a718 | 2009-09-13 01:41:18 +0000 | [diff] [blame] | 240 | def llvm_supports_binding(name): |
| Daniel Dunbar | 62b4d71 | 2010-08-19 16:46:52 +0000 | [diff] [blame] | 241 | return name.strip() in bindings |
| Daniel Dunbar | 840a718 | 2009-09-13 01:41:18 +0000 | [diff] [blame] | 242 | |
| Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 243 | # Provide on_clone hook for reading 'dg.exp'. |
| 244 | import os |
| 245 | simpleLibData = re.compile(r"""load_lib llvm.exp |
| 246 | |
| 247 | RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]""", |
| 248 | re.MULTILINE) |
| 249 | conditionalLibData = re.compile(r"""load_lib llvm.exp |
| 250 | |
| 251 | if.*\[ ?(llvm[^ ]*) ([^ ]*) ?\].*{ |
| 252 | *RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\] |
| 253 | \}""", re.MULTILINE) |
| 254 | def on_clone(parent, cfg, for_path): |
| 255 | def addSuffixes(match): |
| 256 | if match[0] == '{' and match[-1] == '}': |
| 257 | cfg.suffixes = ['.' + s for s in match[1:-1].split(',')] |
| 258 | else: |
| 259 | cfg.suffixes = ['.' + match] |
| 260 | |
| 261 | libPath = os.path.join(os.path.dirname(for_path), |
| 262 | 'dg.exp') |
| 263 | if not os.path.exists(libPath): |
| 264 | cfg.unsupported = True |
| 265 | return |
| 266 | |
| 267 | # Reset unsupported, in case we inherited it. |
| 268 | cfg.unsupported = False |
| 269 | lib = open(libPath).read().strip() |
| 270 | |
| 271 | # Check for a simple library. |
| 272 | m = simpleLibData.match(lib) |
| 273 | if m: |
| 274 | addSuffixes(m.group(1)) |
| 275 | return |
| 276 | |
| 277 | # Check for a conditional test set. |
| 278 | m = conditionalLibData.match(lib) |
| 279 | if m: |
| 280 | funcname,arg,match = m.groups() |
| 281 | addSuffixes(match) |
| 282 | |
| 283 | func = globals().get(funcname) |
| 284 | if not func: |
| 285 | lit.error('unsupported predicate %r' % funcname) |
| 286 | elif not func(arg): |
| 287 | cfg.unsupported = True |
| 288 | return |
| 289 | # Otherwise, give up. |
| 290 | lit.error('unable to understand %r:\n%s' % (libPath, lib)) |
| 291 | |
| 292 | config.on_clone = on_clone |
| NAKAMURA Takumi | b3ccc12 | 2010-11-29 00:20:09 +0000 | [diff] [blame] | 293 | |
| 294 | ### Features |
| 295 | |
| NAKAMURA Takumi | e7331ee | 2010-12-07 02:43:51 +0000 | [diff] [blame] | 296 | # Shell execution |
| NAKAMURA Takumi | c37b429 | 2011-02-09 04:19:21 +0000 | [diff] [blame] | 297 | if sys.platform not in ['win32'] or lit.getBashPath() != '': |
| NAKAMURA Takumi | e7331ee | 2010-12-07 02:43:51 +0000 | [diff] [blame] | 298 | config.available_features.add('shell') |
| 299 | |
| NAKAMURA Takumi | b3ccc12 | 2010-11-29 00:20:09 +0000 | [diff] [blame] | 300 | # Loadable module |
| 301 | # FIXME: This should be supplied by Makefile or autoconf. |
| 302 | if sys.platform in ['win32', 'cygwin']: |
| 303 | loadable_module = (config.enable_shared == 1) |
| 304 | else: |
| 305 | loadable_module = True |
| 306 | |
| 307 | if loadable_module: |
| 308 | config.available_features.add('loadable_module') |