b5c5706ad6a5aa2f4e5bfbb5e5086b66123c9d14
[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 # test_exec_root: The root path where tests should be run.
23 llvm_obj_root = getattr(config, 'llvm_obj_root', None)
24 if llvm_obj_root is not None:
25     config.test_exec_root = os.path.join(llvm_obj_root, 'test')
26
27 # Tweak the PATH to include the scripts dir, the tools dir, and the llvm-gcc bin
28 # dir (if available).
29 if llvm_obj_root is not None:
30     llvm_src_root = getattr(config, 'llvm_src_root', None)
31     if not llvm_src_root:
32         lit.fatal('No LLVM source root set!')
33     path = os.path.pathsep.join((os.path.join(llvm_src_root, 'test',
34                                               'Scripts'),
35                                  config.environment['PATH']))
36     config.environment['PATH'] = path
37
38     llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
39     if not llvm_tools_dir:
40         lit.fatal('No LLVM tools dir set!')
41     path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
42     config.environment['PATH'] = path
43
44     llvmgcc_dir = getattr(config, 'llvmgcc_dir', None)
45     if llvmgcc_dir:
46         path = os.path.pathsep.join((os.path.join(llvmgcc_dir, 'bin'),
47                                      config.environment['PATH']))
48         config.environment['PATH'] = path
49
50 # Propagate 'HOME' through the environment.
51 if 'HOME' in os.environ:
52     config.environment['HOME'] = os.environ['HOME']
53
54 # Propagate 'INCLUDE' through the environment.
55 if 'INCLUDE' in os.environ:
56     config.environment['INCLUDE'] = os.environ['INCLUDE']
57
58 # Propagate 'LIB' through the environment.
59 if 'LIB' in os.environ:
60     config.environment['LIB'] = os.environ['LIB']
61
62 # Propagate the temp directory. Windows requires this because it uses \Windows\
63 # if none of these are present.
64 if 'TMP' in os.environ:
65     config.environment['TMP'] = os.environ['TMP']
66 if 'TEMP' in os.environ:
67     config.environment['TEMP'] = os.environ['TEMP']
68
69 # Propagate LLVM_SRC_ROOT into the environment.
70 config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '')
71
72 # Propagate PYTHON_EXECUTABLE into the environment
73 config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
74                                                   '')
75
76 ###
77
78 import os
79
80 # Check that the object root is known.
81 if config.test_exec_root is None:
82     # Otherwise, we haven't loaded the site specific configuration (the user is
83     # probably trying to run on a test file directly, and either the site
84     # configuration hasn't been created by the build system, or we are in an
85     # out-of-tree build situation).
86
87     # Check for 'llvm_site_config' user parameter, and use that if available.
88     site_cfg = lit.params.get('llvm_site_config', None)
89     if site_cfg and os.path.exists(site_cfg):
90         lit.load_config(config, site_cfg)
91         raise SystemExit
92
93     # Try to detect the situation where we are using an out-of-tree build by
94     # looking for 'llvm-config'.
95     #
96     # FIXME: I debated (i.e., wrote and threw away) adding logic to
97     # automagically generate the lit.site.cfg if we are in some kind of fresh
98     # build situation. This means knowing how to invoke the build system
99     # though, and I decided it was too much magic.
100
101     llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
102     if not llvm_config:
103         lit.fatal('No site specific configuration available!')
104
105     # Get the source and object roots.
106     llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
107     llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
108
109     # Validate that we got a tree which points to here.
110     this_src_root = os.path.dirname(config.test_source_root)
111     if os.path.realpath(llvm_src_root) != os.path.realpath(this_src_root):
112         lit.fatal('No site specific configuration available!')
113
114     # Check that the site specific configuration exists.
115     site_cfg = os.path.join(llvm_obj_root, 'test', 'lit.site.cfg')
116     if not os.path.exists(site_cfg):
117         lit.fatal('No site specific configuration available!')
118
119     # Okay, that worked. Notify the user of the automagic, and reconfigure.
120     lit.note('using out-of-tree build at %r' % llvm_obj_root)
121     lit.load_config(config, site_cfg)
122     raise SystemExit
123
124 ###
125
126 # Load site data from DejaGNU's site.exp.
127 import re
128 site_exp = {}
129 # FIXME: Implement lit.site.cfg.
130 for line in open(os.path.join(config.llvm_obj_root, 'test', 'site.exp')):
131     m = re.match('set ([^ ]+) "(.*)"', line)
132     if m:
133         site_exp[m.group(1)] = m.group(2)
134
135 # Add substitutions.
136 config.substitutions.append(('%llvmgcc_only', site_exp['llvmgcc']))
137 for sub in ['llvmgcc', 'llvmgxx', 'emitir', 'compile_cxx', 'compile_c',
138             'link', 'shlibext', 'ocamlopt', 'llvmdsymutil', 'llvmlibsdir',
139             'llvmshlibdir',
140             'bugpoint_topts']:
141     if sub in ('llvmgcc', 'llvmgxx'):
142         config.substitutions.append(('%' + sub,
143                                      site_exp[sub] + ' %emitir -w'))
144     # FIXME: This is a hack to avoid LLVMC tests failing due to a clang driver
145     #        warning when passing in "-fexceptions -fno-exceptions".
146     elif sub == 'compile_cxx':
147         config.substitutions.append(('%' + sub,
148                                   site_exp[sub].replace('-fno-exceptions', '')))
149     else:
150         config.substitutions.append(('%' + sub, site_exp[sub]))
151
152 # For each occurrence of an llvm tool name as its own word, replace it
153 # with the full path to the build directory holding that tool.  This
154 # ensures that we are testing the tools just built and not some random
155 # tools that might happen to be in the user's PATH.  Thus this list
156 # includes every tool placed in $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
157 # (llvm_tools_dir in lit parlance).
158                 # Don't match 'bugpoint-' or 'clang-'.
159                                         # Don't match '/clang'.
160 for pattern in [r"\bbugpoint\b(?!-)",   r"(?<!/)\bclang\b(?!-)",
161                 r"\bedis\b",            r"\bgold\b",
162                 r"\bllc\b",             r"\blli\b",
163                 r"\bllvm-ar\b",         r"\bllvm-as\b",
164                 r"\bllvm-bcanalyzer\b", r"\bllvm-config\b",
165                 r"\bllvm-diff\b",       r"\bllvm-dis\b",
166                 r"\bllvm-extract\b",    r"\bllvm-ld\b",
167                 r"\bllvm-link\b",       r"\bllvm-mc\b",
168                 r"\bllvm-nm\b",         r"\bllvm-prof\b",
169                 r"\bllvm-ranlib\b",     r"\bllvm-shlib\b",
170                 r"\bllvm-stub\b",       r"\bllvm2cpp\b",
171                 # Don't match '-llvmc'.
172                 r"(?<!-)\bllvmc\b",     r"\blto\b",
173                                         # Don't match '.opt', '-opt'
174                                         # or '^opt'.
175                 r"\bmacho-dump\b",      r"(?<!\.|-|\^)\bopt\b",
176                 r"\btblgen\b",          r"\bFileCheck\b",
177                 r"\bFileUpdate\b",      r"\bc-index-test\b",
178                 r"\bfpcmp\b",           r"\bllvm-PerfectShuffle\b",
179                 # Handle these specially as they are strings searched
180                 # for during testing.
181                 r"\| \bcount\b",         r"\| \bnot\b"]:
182     # Extract the tool name from the pattern.  This relies on the tool
183     # name being surrounded by \b word match operators.  If the
184     # pattern starts with "| ", include it in the string to be
185     # substituted.
186     substitution = re.sub(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
187                           r"\2" + llvm_tools_dir + "/" + r"\4",
188                           pattern)
189     config.substitutions.append((pattern, substitution))
190
191 excludes = []
192
193 # Provide target_triple for use in XFAIL and XTARGET.
194 config.target_triple = site_exp['target_triplet']
195
196 # When running under valgrind, we mangle '-vg' or '-vg_leak' onto the end of the
197 # triple so we can check it with XFAIL and XTARGET.
198 config.target_triple += lit.valgrindTriple
199
200 # Provide llvm_supports_target for use in local configs.
201 targets = set(site_exp["TARGETS_TO_BUILD"].split())
202 def llvm_supports_target(name):
203     return name in targets
204
205 def llvm_supports_darwin_and_target(name):
206     return 'darwin' in config.target_triple and llvm_supports_target(name)
207
208 langs = set([s.strip() for s in site_exp['llvmgcc_langs'].split(',')])
209 def llvm_gcc_supports(name):
210     return name.strip() in langs
211
212 bindings = set([s.strip() for s in site_exp['llvm_bindings'].split(',')])
213 def llvm_supports_binding(name):
214     return name.strip() in bindings
215
216 # Provide on_clone hook for reading 'dg.exp'.
217 import os
218 simpleLibData = re.compile(r"""load_lib llvm.exp
219
220 RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]""",
221                            re.MULTILINE)
222 conditionalLibData = re.compile(r"""load_lib llvm.exp
223
224 if.*\[ ?(llvm[^ ]*) ([^ ]*) ?\].*{
225  *RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]
226 \}""", re.MULTILINE)
227 def on_clone(parent, cfg, for_path):
228     def addSuffixes(match):
229         if match[0] == '{' and match[-1] == '}':
230             cfg.suffixes = ['.' + s for s in match[1:-1].split(',')]
231         else:
232             cfg.suffixes = ['.' + match]
233
234     libPath = os.path.join(os.path.dirname(for_path),
235                            'dg.exp')
236     if not os.path.exists(libPath):
237         cfg.unsupported = True
238         return
239
240     # Reset unsupported, in case we inherited it.
241     cfg.unsupported = False
242     lib = open(libPath).read().strip()
243
244     # Check for a simple library.
245     m = simpleLibData.match(lib)
246     if m:
247         addSuffixes(m.group(1))
248         return
249
250     # Check for a conditional test set.
251     m = conditionalLibData.match(lib)
252     if m:
253         funcname,arg,match = m.groups()
254         addSuffixes(match)
255
256         func = globals().get(funcname)
257         if not func:
258             lit.error('unsupported predicate %r' % funcname)
259         elif not func(arg):
260             cfg.unsupported = True
261         return
262     # Otherwise, give up.
263     lit.error('unable to understand %r:\n%s' % (libPath, lib))
264
265 config.on_clone = on_clone
266
267 ### Features
268
269 # Shell execution
270 if sys.platform not in ['win32']:
271     config.available_features.add('shell')
272
273 # Loadable module
274 # FIXME: This should be supplied by Makefile or autoconf.
275 if sys.platform in ['win32', 'cygwin']:
276     loadable_module = (config.enable_shared == 1)
277 else:
278     loadable_module = True
279
280 if loadable_module:
281     config.available_features.add('loadable_module')