Adding a basic ELF dynamic loader and MC-JIT for ELF. Functionality is currently...
[oota-llvm.git] / test / lit.cfg
1 # -*- Python -*-
2
3 # Configuration file for the 'lit' test runner.
4
5 import os
6 import sys
7 import re
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 # To ignore test output on stderr so it doesn't trigger failures uncomment this:
16 #config.test_format = lit.formats.TclTest(ignoreStdErr=True)
17
18 # suffixes: A list of file extensions to treat as test files, this is actually
19 # set by on_clone().
20 config.suffixes = []
21
22 # test_source_root: The root path where tests are located.
23 config.test_source_root = os.path.dirname(__file__)
24
25 # Tweak PATH for Win32
26 if sys.platform in ['win32']:
27     # Seek sane tools in directories and set to $PATH.
28     path = getattr(config, 'lit_tools_dir', None)
29     path = lit.getToolsPath(path,
30                             config.environment['PATH'],
31                             ['cmp.exe', 'grep.exe', 'sed.exe'])
32     if path is not None:
33         path = os.path.pathsep.join((path,
34                                      config.environment['PATH']))
35         config.environment['PATH'] = path
36
37 # test_exec_root: The root path where tests should be run.
38 llvm_obj_root = getattr(config, 'llvm_obj_root', None)
39 if llvm_obj_root is not None:
40     config.test_exec_root = os.path.join(llvm_obj_root, 'test')
41
42 # Tweak the PATH to include the scripts dir, the tools dir, and the llvm-gcc bin
43 # dir (if available).
44 if llvm_obj_root is not None:
45     llvm_src_root = getattr(config, 'llvm_src_root', None)
46     if not llvm_src_root:
47         lit.fatal('No LLVM source root set!')
48     path = os.path.pathsep.join((os.path.join(llvm_src_root, 'test',
49                                               'Scripts'),
50                                  config.environment['PATH']))
51     config.environment['PATH'] = path
52
53     llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
54     if not llvm_tools_dir:
55         lit.fatal('No LLVM tools dir set!')
56     path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
57     config.environment['PATH'] = path
58
59 # Propagate 'HOME' through the environment.
60 if 'HOME' in os.environ:
61     config.environment['HOME'] = os.environ['HOME']
62
63 # Propagate 'INCLUDE' through the environment.
64 if 'INCLUDE' in os.environ:
65     config.environment['INCLUDE'] = os.environ['INCLUDE']
66
67 # Propagate 'LIB' through the environment.
68 if 'LIB' in os.environ:
69     config.environment['LIB'] = os.environ['LIB']
70
71 # Propagate the temp directory. Windows requires this because it uses \Windows\
72 # if none of these are present.
73 if 'TMP' in os.environ:
74     config.environment['TMP'] = os.environ['TMP']
75 if 'TEMP' in os.environ:
76     config.environment['TEMP'] = os.environ['TEMP']
77
78 # Propagate LLVM_SRC_ROOT into the environment.
79 config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '')
80
81 # Propagate PYTHON_EXECUTABLE into the environment
82 config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
83                                                   '')
84
85 ###
86
87 import os
88
89 # Check that the object root is known.
90 if config.test_exec_root is None:
91     # Otherwise, we haven't loaded the site specific configuration (the user is
92     # probably trying to run on a test file directly, and either the site
93     # configuration hasn't been created by the build system, or we are in an
94     # out-of-tree build situation).
95
96     # Check for 'llvm_site_config' user parameter, and use that if available.
97     site_cfg = lit.params.get('llvm_site_config', None)
98     if site_cfg and os.path.exists(site_cfg):
99         lit.load_config(config, site_cfg)
100         raise SystemExit
101
102     # Try to detect the situation where we are using an out-of-tree build by
103     # looking for 'llvm-config'.
104     #
105     # FIXME: I debated (i.e., wrote and threw away) adding logic to
106     # automagically generate the lit.site.cfg if we are in some kind of fresh
107     # build situation. This means knowing how to invoke the build system
108     # though, and I decided it was too much magic.
109
110     llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
111     if not llvm_config:
112         lit.fatal('No site specific configuration available!')
113
114     # Get the source and object roots.
115     llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
116     llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
117
118     # Validate that we got a tree which points to here.
119     this_src_root = os.path.dirname(config.test_source_root)
120     if os.path.realpath(llvm_src_root) != os.path.realpath(this_src_root):
121         lit.fatal('No site specific configuration available!')
122
123     # Check that the site specific configuration exists.
124     site_cfg = os.path.join(llvm_obj_root, 'test', 'lit.site.cfg')
125     if not os.path.exists(site_cfg):
126         lit.fatal('No site specific configuration available!')
127
128     # Okay, that worked. Notify the user of the automagic, and reconfigure.
129     lit.note('using out-of-tree build at %r' % llvm_obj_root)
130     lit.load_config(config, site_cfg)
131     raise SystemExit
132
133 ###
134
135 # Load site data from DejaGNU's site.exp.
136 import re
137 site_exp = {}
138 # FIXME: Implement lit.site.cfg.
139 for line in open(os.path.join(config.llvm_obj_root, 'test', 'site.exp')):
140     m = re.match('set ([^ ]+) "(.*)"', line)
141     if m:
142         site_exp[m.group(1)] = m.group(2)
143
144 # Provide target_triple for use in XFAIL and XTARGET.
145 config.target_triple = site_exp['target_triplet']
146
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
150
151 # Process jit implementation option
152 jit_impl_cfg = lit.params.get('jit_impl', None)
153 if jit_impl_cfg == 'mcjit':
154   # When running with mcjit, mangle -mcjit into target triple
155   # and add -use-mcjit flag to lli invocation
156   if 'i686' in config.target_triple:
157     config.target_triple += jit_impl_cfg + '-ia32'
158   elif 'x86_64' in config.target_triple:
159     config.target_triple += jit_impl_cfg + '-ia64'
160   else:
161     config.target_triple += jit_impl_cfg
162
163   config.substitutions.append( ('%lli', 'lli -use-mcjit') )
164 else:
165   config.substitutions.append( ('%lli', 'lli') )
166
167 # Add substitutions.
168 for sub in ['link', 'shlibext', 'ocamlopt', 'llvmshlibdir']:
169     config.substitutions.append(('%' + sub, site_exp[sub]))
170
171 # For each occurrence of an llvm tool name as its own word, replace it
172 # with the full path to the build directory holding that tool.  This
173 # ensures that we are testing the tools just built and not some random
174 # tools that might happen to be in the user's PATH.  Thus this list
175 # includes every tool placed in $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
176 # (llvm_tools_dir in lit parlance).
177                 # Don't match 'bugpoint-' or 'clang-'.
178                 # Don't match '/clang' or '-clang'.
179 if os.pathsep == ';':
180     pathext = os.environ.get('PATHEXT', '').split(';')
181 else:
182     pathext = ['']
183 for pattern in [r"\bbugpoint\b(?!-)",   r"(?<!/|-)\bclang\b(?!-)",
184                 r"\bgold\b",
185                 r"\bllc\b",             r"\blli\b",
186                 r"\bllvm-ar\b",         r"\bllvm-as\b",
187                 r"\bllvm-bcanalyzer\b", r"\bllvm-config\b",
188                 r"\bllvm-cov\b",        r"\bllvm-diff\b",
189                 r"\bllvm-dis\b",        r"\bllvm-dwarfdump\b",
190                 r"\bllvm-extract\b",    r"\bllvm-ld\b",
191                 r"\bllvm-link\b",       r"\bllvm-mc\b",
192                 r"\bllvm-nm\b",         r"\bllvm-objdump\b",
193                 r"\bllvm-prof\b",       r"\bllvm-ranlib\b",
194                 r"\bllvm-rtdyld\b",     r"\bllvm-shlib\b",
195                 r"\bllvm-size\b",       r"\bllvm-stub\b",
196                 # Don't match '-llvmc'.
197                 r"(?<!-)\bllvmc\b",     r"\blto\b",
198                                         # Don't match '.opt', '-opt',
199                                         # '^opt' or '/opt'.
200                 r"\bmacho-dump\b",      r"(?<!\.|-|\^|/)\bopt\b",
201                 r"\bllvm-tblgen\b",     r"\bFileCheck\b",
202                 r"\bFileUpdate\b",      r"\bc-index-test\b",
203                 r"\bfpcmp\b",           r"\bllvm-PerfectShuffle\b",
204                 # Handle these specially as they are strings searched
205                 # for during testing.
206                 r"\| \bcount\b",         r"\| \bnot\b"]:
207     # Extract the tool name from the pattern.  This relies on the tool
208     # name being surrounded by \b word match operators.  If the
209     # pattern starts with "| ", include it in the string to be
210     # substituted.
211     substitution = re.sub(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
212                           r"\2" + llvm_tools_dir + "/" + r"\4",
213                           pattern)
214     for ext in pathext:
215         substitution_ext = substitution + ext
216         if os.path.exists(substitution_ext):
217              substitution = substitution_ext
218              break
219     config.substitutions.append((pattern, substitution))
220
221 excludes = []
222
223 # Provide llvm_supports_target for use in local configs.
224 targets = set(site_exp["TARGETS_TO_BUILD"].split())
225 def llvm_supports_target(name):
226     return name in targets
227
228 def llvm_supports_darwin_and_target(name):
229     return 'darwin' in config.target_triple and llvm_supports_target(name)
230
231 bindings = set([s.strip() for s in site_exp['llvm_bindings'].split(',')])
232 def llvm_supports_binding(name):
233     return name.strip() in bindings
234
235 # Provide on_clone hook for reading 'dg.exp'.
236 import os
237 simpleLibData = re.compile(r"""load_lib llvm.exp
238
239 RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]""",
240                            re.MULTILINE)
241 conditionalLibData = re.compile(r"""load_lib llvm.exp
242
243 if.*\[ ?(llvm[^ ]*) ([^ ]*) ?\].*{
244  *RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]
245 \}""", re.MULTILINE)
246 def on_clone(parent, cfg, for_path):
247     def addSuffixes(match):
248         if match[0] == '{' and match[-1] == '}':
249             cfg.suffixes = ['.' + s for s in match[1:-1].split(',')]
250         else:
251             cfg.suffixes = ['.' + match]
252
253     libPath = os.path.join(os.path.dirname(for_path),
254                            'dg.exp')
255     if not os.path.exists(libPath):
256         cfg.unsupported = True
257         return
258
259     # Reset unsupported, in case we inherited it.
260     cfg.unsupported = False
261     lib = open(libPath).read().strip()
262
263     # Check for a simple library.
264     m = simpleLibData.match(lib)
265     if m:
266         addSuffixes(m.group(1))
267         return
268
269     # Check for a conditional test set.
270     m = conditionalLibData.match(lib)
271     if m:
272         funcname,arg,match = m.groups()
273         addSuffixes(match)
274
275         func = globals().get(funcname)
276         if not func:
277             lit.error('unsupported predicate %r' % funcname)
278         elif not func(arg):
279             cfg.unsupported = True
280         return
281     # Otherwise, give up.
282     lit.error('unable to understand %r:\n%s' % (libPath, lib))
283
284 config.on_clone = on_clone
285
286 ### Features
287
288 # Shell execution
289 if sys.platform not in ['win32'] or lit.getBashPath() != '':
290     config.available_features.add('shell')
291
292 # Loadable module
293 # FIXME: This should be supplied by Makefile or autoconf.
294 if sys.platform in ['win32', 'cygwin']:
295     loadable_module = (config.enable_shared == 1)
296 else:
297     loadable_module = True
298
299 if loadable_module:
300     config.available_features.add('loadable_module')
301
302 # llc knows whether he is compiled with -DNDEBUG.
303 import subprocess
304 llc_cmd = subprocess.Popen([os.path.join(llvm_tools_dir, 'llc'), '-version'],
305                            stdout = subprocess.PIPE)
306 if re.search(r'with assertions', llc_cmd.stdout.read()):
307     config.available_features.add('asserts')
308 llc_cmd.wait()