| 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 |
| 6 | |
| 7 | # name: The name of this test suite. |
| 8 | config.name = 'LLVM' |
| 9 | |
| 10 | # testFormat: The test format to use to interpret tests. |
| 11 | config.test_format = lit.formats.TclTest() |
| 12 | |
| 13 | # suffixes: A list of file extensions to treat as test files, this is actually |
| 14 | # set by on_clone(). |
| 15 | config.suffixes = [] |
| 16 | |
| 17 | # test_source_root: The root path where tests are located. |
| 18 | config.test_source_root = os.path.dirname(__file__) |
| 19 | |
| 20 | # test_exec_root: The root path where tests should be run. |
| 21 | llvm_obj_root = getattr(config, 'llvm_obj_root', None) |
| 22 | if llvm_obj_root is not None: |
| 23 | config.test_exec_root = os.path.join(llvm_obj_root, 'test') |
| 24 | |
| Daniel Dunbar | 5ed7be1 | 2009-11-08 09:08:00 +0000 | [diff] [blame] | 25 | # Tweak the PATH to include the scripts dir, the tools dir, and the llvm-gcc bin |
| 26 | # dir (if available). |
| 27 | if llvm_obj_root is not None: |
| 28 | llvm_src_root = getattr(config, 'llvm_src_root', None) |
| 29 | if not llvm_src_root: |
| 30 | lit.fatal('No LLVM source root set!') |
| 31 | path = os.path.pathsep.join((os.path.join(llvm_src_root, 'test', |
| 32 | 'Scripts'), |
| 33 | config.environment['PATH'])) |
| 34 | config.environment['PATH'] = path |
| 35 | |
| 36 | llvm_tools_dir = getattr(config, 'llvm_tools_dir', None) |
| 37 | if not llvm_tools_dir: |
| 38 | lit.fatal('No LLVM tools dir set!') |
| 39 | path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH'])) |
| 40 | config.environment['PATH'] = path |
| 41 | |
| 42 | llvmgcc_dir = getattr(config, 'llvmgcc_dir', None) |
| Daniel Dunbar | 5ed7be1 | 2009-11-08 09:08:00 +0000 | [diff] [blame] | 43 | if llvmgcc_dir: |
| 44 | path = os.path.pathsep.join((os.path.join(llvmgcc_dir, 'bin'), |
| 45 | config.environment['PATH'])) |
| 46 | config.environment['PATH'] = path |
| 47 | |
| Daniel Dunbar | 55983f1 | 2010-02-25 22:09:09 +0000 | [diff] [blame] | 48 | # Propogate 'HOME' through the environment. |
| Daniel Dunbar | 1321fec | 2010-08-10 19:36:25 +0000 | [diff] [blame] | 49 | if 'HOME' in os.environ: |
| 50 | config.environment['HOME'] = os.environ['HOME'] |
| Daniel Dunbar | 55983f1 | 2010-02-25 22:09:09 +0000 | [diff] [blame] | 51 | |
| Michael J. Spencer | 06b7f58 | 2010-08-30 14:49:00 +0000 | [diff] [blame^] | 52 | # Propogate 'INCLUDE' through the environment. |
| 53 | if 'INCLUDE' in os.environ: |
| 54 | config.environment['INCLUDE'] = os.environ['INCLUDE'] |
| 55 | |
| 56 | # Propogate 'LIB' through the environment. |
| 57 | if 'LIB' in os.environ: |
| 58 | config.environment['LIB'] = os.environ['LIB'] |
| 59 | |
| Daniel Dunbar | 9b2cb69 | 2010-06-12 16:21:19 +0000 | [diff] [blame] | 60 | # Propogate LLVM_SRC_ROOT into the environment. |
| Daniel Dunbar | 238e73f | 2010-06-23 18:06:16 +0000 | [diff] [blame] | 61 | config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '') |
| Daniel Dunbar | 9b2cb69 | 2010-06-12 16:21:19 +0000 | [diff] [blame] | 62 | |
| 63 | # Propogate PYTHON_EXEUTABLE into the environment |
| 64 | config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable', |
| 65 | '') |
| 66 | |
| Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 67 | ### |
| 68 | |
| 69 | import os |
| 70 | |
| 71 | # Check that the object root is known. |
| 72 | if config.test_exec_root is None: |
| 73 | # Otherwise, we haven't loaded the site specific configuration (the user is |
| 74 | # probably trying to run on a test file directly, and either the site |
| 75 | # configuration hasn't been created by the build system, or we are in an |
| 76 | # out-of-tree build situation). |
| 77 | |
| Daniel Dunbar | aefd63d | 2009-12-08 19:47:36 +0000 | [diff] [blame] | 78 | # Check for 'llvm_site_config' user parameter, and use that if available. |
| 79 | site_cfg = lit.params.get('llvm_site_config', None) |
| 80 | if site_cfg and os.path.exists(site_cfg): |
| 81 | lit.load_config(config, site_cfg) |
| 82 | raise SystemExit |
| 83 | |
| Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 84 | # Try to detect the situation where we are using an out-of-tree build by |
| 85 | # looking for 'llvm-config'. |
| 86 | # |
| 87 | # FIXME: I debated (i.e., wrote and threw away) adding logic to |
| 88 | # automagically generate the lit.site.cfg if we are in some kind of fresh |
| 89 | # build situation. This means knowing how to invoke the build system |
| 90 | # though, and I decided it was too much magic. |
| 91 | |
| 92 | llvm_config = lit.util.which('llvm-config', config.environment['PATH']) |
| 93 | if not llvm_config: |
| 94 | lit.fatal('No site specific configuration available!') |
| 95 | |
| 96 | # Get the source and object roots. |
| 97 | llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip() |
| 98 | llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip() |
| 99 | |
| 100 | # Validate that we got a tree which points to here. |
| 101 | this_src_root = os.path.dirname(config.test_source_root) |
| 102 | if os.path.realpath(llvm_src_root) != os.path.realpath(this_src_root): |
| 103 | lit.fatal('No site specific configuration available!') |
| 104 | |
| 105 | # Check that the site specific configuration exists. |
| 106 | site_cfg = os.path.join(llvm_obj_root, 'test', 'lit.site.cfg') |
| 107 | if not os.path.exists(site_cfg): |
| 108 | lit.fatal('No site specific configuration available!') |
| 109 | |
| 110 | # Okay, that worked. Notify the user of the automagic, and reconfigure. |
| 111 | lit.note('using out-of-tree build at %r' % llvm_obj_root) |
| 112 | lit.load_config(config, site_cfg) |
| 113 | raise SystemExit |
| 114 | |
| 115 | ### |
| 116 | |
| 117 | # Load site data from DejaGNU's site.exp. |
| 118 | import re |
| 119 | site_exp = {} |
| 120 | # FIXME: Implement lit.site.cfg. |
| 121 | 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] | 122 | m = re.match('set ([^ ]+) "(.*)"', line) |
| Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 123 | if m: |
| 124 | site_exp[m.group(1)] = m.group(2) |
| 125 | |
| 126 | # Add substitutions. |
| Daniel Dunbar | b0c9a99 | 2009-10-30 21:13:59 +0000 | [diff] [blame] | 127 | config.substitutions.append(('%llvmgcc_only', site_exp['llvmgcc'])) |
| Daniel Dunbar | f3e2d80 | 2009-09-10 04:56:59 +0000 | [diff] [blame] | 128 | for sub in ['llvmgcc', 'llvmgxx', 'compile_cxx', 'compile_c', |
| Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 129 | 'link', 'shlibext', 'ocamlopt', 'llvmdsymutil', 'llvmlibsdir', |
| 130 | 'bugpoint_topts']: |
| 131 | if sub in ('llvmgcc', 'llvmgxx'): |
| 132 | config.substitutions.append(('%' + sub, |
| 133 | site_exp[sub] + ' -emit-llvm -w')) |
| Benjamin Kramer | 66c439a | 2010-02-04 18:40:11 +0000 | [diff] [blame] | 134 | # FIXME: This is a hack to avoid LLVMC tests failing due to a clang driver |
| 135 | # warning when passing in "-fexceptions -fno-exceptions". |
| 136 | elif sub == 'compile_cxx': |
| 137 | config.substitutions.append(('%' + sub, |
| 138 | site_exp[sub].replace('-fno-exceptions', ''))) |
| Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 139 | else: |
| 140 | config.substitutions.append(('%' + sub, site_exp[sub])) |
| 141 | |
| 142 | excludes = [] |
| 143 | |
| 144 | # Provide target_triple for use in XFAIL and XTARGET. |
| 145 | config.target_triple = site_exp['target_triplet'] |
| 146 | |
| Jeffrey Yasskin | 32989de | 2010-03-20 23:08:45 +0000 | [diff] [blame] | 147 | # When running under valgrind, we mangle '-vg' or '-vg_leak' onto the end of the |
| 148 | # triple so we can check it with XFAIL and XTARGET. |
| 149 | config.target_triple += lit.valgrindTriple |
| Daniel Dunbar | a56a810 | 2010-03-20 21:12:48 +0000 | [diff] [blame] | 150 | |
| Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 151 | # Provide llvm_supports_target for use in local configs. |
| 152 | targets = set(site_exp["TARGETS_TO_BUILD"].split()) |
| 153 | def llvm_supports_target(name): |
| 154 | return name in targets |
| 155 | |
| Daniel Dunbar | 197f1f0 | 2010-02-02 22:00:15 +0000 | [diff] [blame] | 156 | def llvm_supports_darwin_and_target(name): |
| 157 | return 'darwin' in config.target_triple and llvm_supports_target(name) |
| 158 | |
| Daniel Dunbar | 2e5ec11 | 2010-08-19 16:47:54 +0000 | [diff] [blame] | 159 | langs = set([s.strip() for s in site_exp['llvmgcc_langs'].split(',')]) |
| Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 160 | def llvm_gcc_supports(name): |
| Daniel Dunbar | 62b4d71 | 2010-08-19 16:46:52 +0000 | [diff] [blame] | 161 | return name.strip() in langs |
| Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 162 | |
| Daniel Dunbar | 2e5ec11 | 2010-08-19 16:47:54 +0000 | [diff] [blame] | 163 | bindings = set([s.strip() for s in site_exp['llvm_bindings'].split(',')]) |
| Daniel Dunbar | 840a718 | 2009-09-13 01:41:18 +0000 | [diff] [blame] | 164 | def llvm_supports_binding(name): |
| Daniel Dunbar | 62b4d71 | 2010-08-19 16:46:52 +0000 | [diff] [blame] | 165 | return name.strip() in bindings |
| Daniel Dunbar | 840a718 | 2009-09-13 01:41:18 +0000 | [diff] [blame] | 166 | |
| Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 167 | # Provide on_clone hook for reading 'dg.exp'. |
| 168 | import os |
| 169 | simpleLibData = re.compile(r"""load_lib llvm.exp |
| 170 | |
| 171 | RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]""", |
| 172 | re.MULTILINE) |
| 173 | conditionalLibData = re.compile(r"""load_lib llvm.exp |
| 174 | |
| 175 | if.*\[ ?(llvm[^ ]*) ([^ ]*) ?\].*{ |
| 176 | *RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\] |
| 177 | \}""", re.MULTILINE) |
| 178 | def on_clone(parent, cfg, for_path): |
| 179 | def addSuffixes(match): |
| 180 | if match[0] == '{' and match[-1] == '}': |
| 181 | cfg.suffixes = ['.' + s for s in match[1:-1].split(',')] |
| 182 | else: |
| 183 | cfg.suffixes = ['.' + match] |
| 184 | |
| 185 | libPath = os.path.join(os.path.dirname(for_path), |
| 186 | 'dg.exp') |
| 187 | if not os.path.exists(libPath): |
| 188 | cfg.unsupported = True |
| 189 | return |
| 190 | |
| 191 | # Reset unsupported, in case we inherited it. |
| 192 | cfg.unsupported = False |
| 193 | lib = open(libPath).read().strip() |
| 194 | |
| 195 | # Check for a simple library. |
| 196 | m = simpleLibData.match(lib) |
| 197 | if m: |
| 198 | addSuffixes(m.group(1)) |
| 199 | return |
| 200 | |
| 201 | # Check for a conditional test set. |
| 202 | m = conditionalLibData.match(lib) |
| 203 | if m: |
| 204 | funcname,arg,match = m.groups() |
| 205 | addSuffixes(match) |
| 206 | |
| 207 | func = globals().get(funcname) |
| 208 | if not func: |
| 209 | lit.error('unsupported predicate %r' % funcname) |
| 210 | elif not func(arg): |
| 211 | cfg.unsupported = True |
| 212 | return |
| 213 | # Otherwise, give up. |
| 214 | lit.error('unable to understand %r:\n%s' % (libPath, lib)) |
| 215 | |
| 216 | config.on_clone = on_clone |