blob: 9a2f74c21c93f368feffef976de0427ef8b97045 [file] [log] [blame]
Daniel Dunbar70a3b772009-09-08 05:31:44 +00001# -*- Python -*-
2
3# Configuration file for the 'lit' test runner.
4
5import os
NAKAMURA Takumib3ccc122010-11-29 00:20:09 +00006import sys
David Greene18d49872011-01-03 17:30:25 +00007import re
Daniel Dunbar70a3b772009-09-08 05:31:44 +00008
9# name: The name of this test suite.
10config.name = 'LLVM'
11
12# testFormat: The test format to use to interpret tests.
13config.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().
17config.suffixes = []
18
19# test_source_root: The root path where tests are located.
20config.test_source_root = os.path.dirname(__file__)
21
NAKAMURA Takumic37b4292011-02-09 04:19:21 +000022# Tweak PATH for Win32
23if 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
Daniel Dunbar70a3b772009-09-08 05:31:44 +000034# test_exec_root: The root path where tests should be run.
35llvm_obj_root = getattr(config, 'llvm_obj_root', None)
36if llvm_obj_root is not None:
37 config.test_exec_root = os.path.join(llvm_obj_root, 'test')
38
Daniel Dunbar5ed7be12009-11-08 09:08:00 +000039# Tweak the PATH to include the scripts dir, the tools dir, and the llvm-gcc bin
40# dir (if available).
41if llvm_obj_root is not None:
Tobias Grosseree38f852011-01-04 16:01:17 +000042 # 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
Daniel Dunbar5ed7be12009-11-08 09:08:00 +000054 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
Duncan Sands51a64552010-09-13 13:32:22 +000068# Propagate 'HOME' through the environment.
Daniel Dunbar1321fec2010-08-10 19:36:25 +000069if 'HOME' in os.environ:
70 config.environment['HOME'] = os.environ['HOME']
Daniel Dunbar55983f12010-02-25 22:09:09 +000071
Duncan Sands51a64552010-09-13 13:32:22 +000072# Propagate 'INCLUDE' through the environment.
Michael J. Spencer06b7f582010-08-30 14:49:00 +000073if 'INCLUDE' in os.environ:
74 config.environment['INCLUDE'] = os.environ['INCLUDE']
75
Duncan Sands51a64552010-09-13 13:32:22 +000076# Propagate 'LIB' through the environment.
Michael J. Spencer06b7f582010-08-30 14:49:00 +000077if 'LIB' in os.environ:
78 config.environment['LIB'] = os.environ['LIB']
79
Michael J. Spencer44d392a2010-12-07 01:23:49 +000080# Propagate the temp directory. Windows requires this because it uses \Windows\
81# if none of these are present.
82if 'TMP' in os.environ:
83 config.environment['TMP'] = os.environ['TMP']
84if 'TEMP' in os.environ:
85 config.environment['TEMP'] = os.environ['TEMP']
86
Duncan Sands51a64552010-09-13 13:32:22 +000087# Propagate LLVM_SRC_ROOT into the environment.
Daniel Dunbar238e73f2010-06-23 18:06:16 +000088config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '')
Daniel Dunbar9b2cb692010-06-12 16:21:19 +000089
Duncan Sands51a64552010-09-13 13:32:22 +000090# Propagate PYTHON_EXECUTABLE into the environment
Daniel Dunbar9b2cb692010-06-12 16:21:19 +000091config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
92 '')
93
Daniel Dunbar70a3b772009-09-08 05:31:44 +000094###
95
96import os
97
98# Check that the object root is known.
99if 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
Daniel Dunbaraefd63d2009-12-08 19:47:36 +0000105 # 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
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000111 # 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.
145import re
146site_exp = {}
147# FIXME: Implement lit.site.cfg.
148for line in open(os.path.join(config.llvm_obj_root, 'test', 'site.exp')):
Bob Wilson8d854a42010-08-20 14:19:38 +0000149 m = re.match('set ([^ ]+) "(.*)"', line)
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000150 if m:
151 site_exp[m.group(1)] = m.group(2)
152
153# Add substitutions.
Daniel Dunbarb0c9a992009-10-30 21:13:59 +0000154config.substitutions.append(('%llvmgcc_only', site_exp['llvmgcc']))
Duncan Sands48f296d2010-11-25 21:19:52 +0000155for sub in ['llvmgcc', 'llvmgxx', 'emitir', 'compile_cxx', 'compile_c',
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000156 'link', 'shlibext', 'ocamlopt', 'llvmdsymutil', 'llvmlibsdir',
NAKAMURA Takumi38d439f2010-11-29 00:20:21 +0000157 'llvmshlibdir',
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000158 'bugpoint_topts']:
159 if sub in ('llvmgcc', 'llvmgxx'):
160 config.substitutions.append(('%' + sub,
Duncan Sands48f296d2010-11-25 21:19:52 +0000161 site_exp[sub] + ' %emitir -w'))
Benjamin Kramer66c439a2010-02-04 18:40:11 +0000162 # 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', '')))
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000167 else:
168 config.substitutions.append(('%' + sub, site_exp[sub]))
169
David Greene18d49872011-01-03 17:30:25 +0000170# 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).
David Greenefd1ed5f2011-01-03 21:55:08 +0000176 # Don't match 'bugpoint-' or 'clang-'.
David Greene70ecc972011-01-04 01:05:30 +0000177 # Don't match '/clang'.
NAKAMURA Takumi027f98c2011-02-24 12:34:34 +0000178if os.pathsep == ';':
179 pathext = os.environ.get('PATHEXT', '').split(';')
180else:
181 pathext = ['']
David Greene70ecc972011-01-04 01:05:30 +0000182for pattern in [r"\bbugpoint\b(?!-)", r"(?<!/)\bclang\b(?!-)",
Sean Callanan41dfd2b2011-02-22 02:05:53 +0000183 r"\bgold\b",
David Greene18d49872011-01-03 17:30:25 +0000184 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",
Frits van Bommelc95ff3c2011-01-05 15:10:24 +0000195 # Don't match '.opt', '-opt',
196 # '^opt' or '/opt'.
197 r"\bmacho-dump\b", r"(?<!\.|-|\^|/)\bopt\b",
David Greene18d49872011-01-03 17:30:25 +0000198 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)
NAKAMURA Takumi027f98c2011-02-24 12:34:34 +0000211 for ext in pathext:
212 substitution_ext = substitution + ext
213 if os.path.exists(substitution_ext):
214 substitution = substitution_ext
215 break
David Greene18d49872011-01-03 17:30:25 +0000216 config.substitutions.append((pattern, substitution))
217
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000218excludes = []
219
220# Provide target_triple for use in XFAIL and XTARGET.
221config.target_triple = site_exp['target_triplet']
222
Jeffrey Yasskin32989de2010-03-20 23:08:45 +0000223# 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.
225config.target_triple += lit.valgrindTriple
Daniel Dunbara56a8102010-03-20 21:12:48 +0000226
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000227# Provide llvm_supports_target for use in local configs.
228targets = set(site_exp["TARGETS_TO_BUILD"].split())
229def llvm_supports_target(name):
230 return name in targets
231
Daniel Dunbar197f1f02010-02-02 22:00:15 +0000232def llvm_supports_darwin_and_target(name):
233 return 'darwin' in config.target_triple and llvm_supports_target(name)
234
Daniel Dunbar2e5ec112010-08-19 16:47:54 +0000235langs = set([s.strip() for s in site_exp['llvmgcc_langs'].split(',')])
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000236def llvm_gcc_supports(name):
Daniel Dunbar62b4d712010-08-19 16:46:52 +0000237 return name.strip() in langs
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000238
Daniel Dunbar2e5ec112010-08-19 16:47:54 +0000239bindings = set([s.strip() for s in site_exp['llvm_bindings'].split(',')])
Daniel Dunbar840a7182009-09-13 01:41:18 +0000240def llvm_supports_binding(name):
Daniel Dunbar62b4d712010-08-19 16:46:52 +0000241 return name.strip() in bindings
Daniel Dunbar840a7182009-09-13 01:41:18 +0000242
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000243# Provide on_clone hook for reading 'dg.exp'.
244import os
245simpleLibData = re.compile(r"""load_lib llvm.exp
246
247RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]""",
248 re.MULTILINE)
249conditionalLibData = re.compile(r"""load_lib llvm.exp
250
251if.*\[ ?(llvm[^ ]*) ([^ ]*) ?\].*{
252 *RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]
253\}""", re.MULTILINE)
254def 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
292config.on_clone = on_clone
NAKAMURA Takumib3ccc122010-11-29 00:20:09 +0000293
294### Features
295
NAKAMURA Takumie7331ee2010-12-07 02:43:51 +0000296# Shell execution
NAKAMURA Takumic37b4292011-02-09 04:19:21 +0000297if sys.platform not in ['win32'] or lit.getBashPath() != '':
NAKAMURA Takumie7331ee2010-12-07 02:43:51 +0000298 config.available_features.add('shell')
299
NAKAMURA Takumib3ccc122010-11-29 00:20:09 +0000300# Loadable module
301# FIXME: This should be supplied by Makefile or autoconf.
302if sys.platform in ['win32', 'cygwin']:
303 loadable_module = (config.enable_shared == 1)
304else:
305 loadable_module = True
306
307if loadable_module:
308 config.available_features.add('loadable_module')