lit support for REQUIRES: asserts.
[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 # 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
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
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
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:
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
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
68 # Propagate 'HOME' through the environment.
69 if 'HOME' in os.environ:
70     config.environment['HOME'] = os.environ['HOME']
71
72 # Propagate 'INCLUDE' through the environment.
73 if 'INCLUDE' in os.environ:
74     config.environment['INCLUDE'] = os.environ['INCLUDE']
75
76 # Propagate 'LIB' through the environment.
77 if 'LIB' in os.environ:
78     config.environment['LIB'] = os.environ['LIB']
79
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
87 # Propagate LLVM_SRC_ROOT into the environment.
88 config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '')
89
90 # Propagate PYTHON_EXECUTABLE into the environment
91 config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
92                                                   '')
93
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
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
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')):
149     m = re.match('set ([^ ]+) "(.*)"', line)
150     if m:
151         site_exp[m.group(1)] = m.group(2)
152
153 # Add substitutions.
154 config.substitutions.append(('%llvmgcc_only', site_exp['llvmgcc']))
155 for sub in ['llvmgcc', 'llvmgxx', 'emitir', 'compile_cxx', 'compile_c',
156             'link', 'shlibext', 'ocamlopt', 'llvmdsymutil', 'llvmlibsdir',
157             'llvmshlibdir',
158             'bugpoint_topts']:
159     if sub in ('llvmgcc', 'llvmgxx'):
160         config.substitutions.append(('%' + sub,
161                                      site_exp[sub] + ' %emitir -w'))
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', '')))
167     else:
168         config.substitutions.append(('%' + sub, site_exp[sub]))
169
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).
176                 # Don't match 'bugpoint-' or 'clang-'.
177                                         # Don't match '/clang'.
178 if os.pathsep == ';':
179     pathext = os.environ.get('PATHEXT', '').split(';')
180 else:
181     pathext = ['']
182 for pattern in [r"\bbugpoint\b(?!-)",   r"(?<!/)\bclang\b(?!-)",
183                 r"\bgold\b",
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",
195                                         # Don't match '.opt', '-opt',
196                                         # '^opt' or '/opt'.
197                 r"\bmacho-dump\b",      r"(?<!\.|-|\^|/)\bopt\b",
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)
211     for ext in pathext:
212         substitution_ext = substitution + ext
213         if os.path.exists(substitution_ext):
214              substitution = substitution_ext
215              break
216     config.substitutions.append((pattern, substitution))
217
218 excludes = []
219
220 # Provide target_triple for use in XFAIL and XTARGET.
221 config.target_triple = site_exp['target_triplet']
222
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
226
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
232 def llvm_supports_darwin_and_target(name):
233     return 'darwin' in config.target_triple and llvm_supports_target(name)
234
235 langs = set([s.strip() for s in site_exp['llvmgcc_langs'].split(',')])
236 def llvm_gcc_supports(name):
237     return name.strip() in langs
238
239 bindings = set([s.strip() for s in site_exp['llvm_bindings'].split(',')])
240 def llvm_supports_binding(name):
241     return name.strip() in bindings
242
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
293
294 ### Features
295
296 # Shell execution
297 if sys.platform not in ['win32'] or lit.getBashPath() != '':
298     config.available_features.add('shell')
299
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')
309
310 if config.enable_assertions:
311     config.available_features.add('asserts')