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 | |
| 25 | ### |
| 26 | |
| 27 | import os |
| 28 | |
| 29 | # Check that the object root is known. |
| 30 | if config.test_exec_root is None: |
| 31 | # Otherwise, we haven't loaded the site specific configuration (the user is |
| 32 | # probably trying to run on a test file directly, and either the site |
| 33 | # configuration hasn't been created by the build system, or we are in an |
| 34 | # out-of-tree build situation). |
| 35 | |
| 36 | # Try to detect the situation where we are using an out-of-tree build by |
| 37 | # looking for 'llvm-config'. |
| 38 | # |
| 39 | # FIXME: I debated (i.e., wrote and threw away) adding logic to |
| 40 | # automagically generate the lit.site.cfg if we are in some kind of fresh |
| 41 | # build situation. This means knowing how to invoke the build system |
| 42 | # though, and I decided it was too much magic. |
| 43 | |
| 44 | llvm_config = lit.util.which('llvm-config', config.environment['PATH']) |
| 45 | if not llvm_config: |
| 46 | lit.fatal('No site specific configuration available!') |
| 47 | |
| 48 | # Get the source and object roots. |
| 49 | llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip() |
| 50 | llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip() |
| 51 | |
| 52 | # Validate that we got a tree which points to here. |
| 53 | this_src_root = os.path.dirname(config.test_source_root) |
| 54 | if os.path.realpath(llvm_src_root) != os.path.realpath(this_src_root): |
| 55 | lit.fatal('No site specific configuration available!') |
| 56 | |
| 57 | # Check that the site specific configuration exists. |
| 58 | site_cfg = os.path.join(llvm_obj_root, 'test', 'lit.site.cfg') |
| 59 | if not os.path.exists(site_cfg): |
| 60 | lit.fatal('No site specific configuration available!') |
| 61 | |
| 62 | # Okay, that worked. Notify the user of the automagic, and reconfigure. |
| 63 | lit.note('using out-of-tree build at %r' % llvm_obj_root) |
| 64 | lit.load_config(config, site_cfg) |
| 65 | raise SystemExit |
| 66 | |
| 67 | ### |
| 68 | |
| 69 | # Load site data from DejaGNU's site.exp. |
| 70 | import re |
| 71 | site_exp = {} |
| 72 | # FIXME: Implement lit.site.cfg. |
| 73 | for line in open(os.path.join(config.llvm_obj_root, 'test', 'site.exp')): |
| 74 | m = re.match('set ([^ ]+) "([^"]*)"', line) |
| 75 | if m: |
| 76 | site_exp[m.group(1)] = m.group(2) |
| 77 | |
| 78 | # Add substitutions. |
Daniel Dunbar | f3e2d80 | 2009-09-10 04:56:59 +0000 | [diff] [blame] | 79 | for sub in ['llvmgcc', 'llvmgxx', 'compile_cxx', 'compile_c', |
Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 80 | 'link', 'shlibext', 'ocamlopt', 'llvmdsymutil', 'llvmlibsdir', |
| 81 | 'bugpoint_topts']: |
| 82 | if sub in ('llvmgcc', 'llvmgxx'): |
| 83 | config.substitutions.append(('%' + sub, |
| 84 | site_exp[sub] + ' -emit-llvm -w')) |
| 85 | else: |
| 86 | config.substitutions.append(('%' + sub, site_exp[sub])) |
| 87 | |
| 88 | excludes = [] |
| 89 | |
| 90 | # Provide target_triple for use in XFAIL and XTARGET. |
| 91 | config.target_triple = site_exp['target_triplet'] |
| 92 | |
| 93 | # Provide llvm_supports_target for use in local configs. |
| 94 | targets = set(site_exp["TARGETS_TO_BUILD"].split()) |
| 95 | def llvm_supports_target(name): |
| 96 | return name in targets |
| 97 | |
| 98 | langs = set(site_exp['llvmgcc_langs'].split(',')) |
| 99 | def llvm_gcc_supports(name): |
| 100 | return name in langs |
| 101 | |
Daniel Dunbar | 840a718 | 2009-09-13 01:41:18 +0000 | [diff] [blame^] | 102 | bindings = set(site_exp['llvm_bindings'].split(',')) |
| 103 | def llvm_supports_binding(name): |
| 104 | return name in langs |
| 105 | |
Daniel Dunbar | 70a3b77 | 2009-09-08 05:31:44 +0000 | [diff] [blame] | 106 | # Provide on_clone hook for reading 'dg.exp'. |
| 107 | import os |
| 108 | simpleLibData = re.compile(r"""load_lib llvm.exp |
| 109 | |
| 110 | RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]""", |
| 111 | re.MULTILINE) |
| 112 | conditionalLibData = re.compile(r"""load_lib llvm.exp |
| 113 | |
| 114 | if.*\[ ?(llvm[^ ]*) ([^ ]*) ?\].*{ |
| 115 | *RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\] |
| 116 | \}""", re.MULTILINE) |
| 117 | def on_clone(parent, cfg, for_path): |
| 118 | def addSuffixes(match): |
| 119 | if match[0] == '{' and match[-1] == '}': |
| 120 | cfg.suffixes = ['.' + s for s in match[1:-1].split(',')] |
| 121 | else: |
| 122 | cfg.suffixes = ['.' + match] |
| 123 | |
| 124 | libPath = os.path.join(os.path.dirname(for_path), |
| 125 | 'dg.exp') |
| 126 | if not os.path.exists(libPath): |
| 127 | cfg.unsupported = True |
| 128 | return |
| 129 | |
| 130 | # Reset unsupported, in case we inherited it. |
| 131 | cfg.unsupported = False |
| 132 | lib = open(libPath).read().strip() |
| 133 | |
| 134 | # Check for a simple library. |
| 135 | m = simpleLibData.match(lib) |
| 136 | if m: |
| 137 | addSuffixes(m.group(1)) |
| 138 | return |
| 139 | |
| 140 | # Check for a conditional test set. |
| 141 | m = conditionalLibData.match(lib) |
| 142 | if m: |
| 143 | funcname,arg,match = m.groups() |
| 144 | addSuffixes(match) |
| 145 | |
| 146 | func = globals().get(funcname) |
| 147 | if not func: |
| 148 | lit.error('unsupported predicate %r' % funcname) |
| 149 | elif not func(arg): |
| 150 | cfg.unsupported = True |
| 151 | return |
| 152 | # Otherwise, give up. |
| 153 | lit.error('unable to understand %r:\n%s' % (libPath, lib)) |
| 154 | |
| 155 | config.on_clone = on_clone |