blob: 638af28ed9ccd2b23eeed25f761fbb008e1c11b2 [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
22# test_exec_root: The root path where tests should be run.
23llvm_obj_root = getattr(config, 'llvm_obj_root', None)
24if llvm_obj_root is not None:
25 config.test_exec_root = os.path.join(llvm_obj_root, 'test')
26
Daniel Dunbar5ed7be12009-11-08 09:08:00 +000027# Tweak the PATH to include the scripts dir, the tools dir, and the llvm-gcc bin
28# dir (if available).
29if 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)
Daniel Dunbar5ed7be12009-11-08 09:08:00 +000045 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
Duncan Sands51a64552010-09-13 13:32:22 +000050# Propagate 'HOME' through the environment.
Daniel Dunbar1321fec2010-08-10 19:36:25 +000051if 'HOME' in os.environ:
52 config.environment['HOME'] = os.environ['HOME']
Daniel Dunbar55983f12010-02-25 22:09:09 +000053
Duncan Sands51a64552010-09-13 13:32:22 +000054# Propagate 'INCLUDE' through the environment.
Michael J. Spencer06b7f582010-08-30 14:49:00 +000055if 'INCLUDE' in os.environ:
56 config.environment['INCLUDE'] = os.environ['INCLUDE']
57
Duncan Sands51a64552010-09-13 13:32:22 +000058# Propagate 'LIB' through the environment.
Michael J. Spencer06b7f582010-08-30 14:49:00 +000059if 'LIB' in os.environ:
60 config.environment['LIB'] = os.environ['LIB']
61
Michael J. Spencer44d392a2010-12-07 01:23:49 +000062# Propagate the temp directory. Windows requires this because it uses \Windows\
63# if none of these are present.
64if 'TMP' in os.environ:
65 config.environment['TMP'] = os.environ['TMP']
66if 'TEMP' in os.environ:
67 config.environment['TEMP'] = os.environ['TEMP']
68
Duncan Sands51a64552010-09-13 13:32:22 +000069# Propagate LLVM_SRC_ROOT into the environment.
Daniel Dunbar238e73f2010-06-23 18:06:16 +000070config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '')
Daniel Dunbar9b2cb692010-06-12 16:21:19 +000071
Duncan Sands51a64552010-09-13 13:32:22 +000072# Propagate PYTHON_EXECUTABLE into the environment
Daniel Dunbar9b2cb692010-06-12 16:21:19 +000073config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
74 '')
75
Daniel Dunbar70a3b772009-09-08 05:31:44 +000076###
77
78import os
79
80# Check that the object root is known.
81if 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
Daniel Dunbaraefd63d2009-12-08 19:47:36 +000087 # 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
Daniel Dunbar70a3b772009-09-08 05:31:44 +000093 # 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.
127import re
128site_exp = {}
129# FIXME: Implement lit.site.cfg.
130for line in open(os.path.join(config.llvm_obj_root, 'test', 'site.exp')):
Bob Wilson8d854a42010-08-20 14:19:38 +0000131 m = re.match('set ([^ ]+) "(.*)"', line)
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000132 if m:
133 site_exp[m.group(1)] = m.group(2)
134
135# Add substitutions.
Daniel Dunbarb0c9a992009-10-30 21:13:59 +0000136config.substitutions.append(('%llvmgcc_only', site_exp['llvmgcc']))
Duncan Sands48f296d2010-11-25 21:19:52 +0000137for sub in ['llvmgcc', 'llvmgxx', 'emitir', 'compile_cxx', 'compile_c',
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000138 'link', 'shlibext', 'ocamlopt', 'llvmdsymutil', 'llvmlibsdir',
NAKAMURA Takumi38d439f2010-11-29 00:20:21 +0000139 'llvmshlibdir',
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000140 'bugpoint_topts']:
141 if sub in ('llvmgcc', 'llvmgxx'):
142 config.substitutions.append(('%' + sub,
Duncan Sands48f296d2010-11-25 21:19:52 +0000143 site_exp[sub] + ' %emitir -w'))
Benjamin Kramer66c439a2010-02-04 18:40:11 +0000144 # 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', '')))
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000149 else:
150 config.substitutions.append(('%' + sub, site_exp[sub]))
151
David Greene18d49872011-01-03 17:30:25 +0000152# 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).
David Greenefd1ed5f2011-01-03 21:55:08 +0000158 # Don't match 'bugpoint-' or 'clang-'.
159for pattern in [r"\bbugpoint\b(?!-)", r"\bclang\b(?!-)",
David Greene18d49872011-01-03 17:30:25 +0000160 r"\bedis\b", r"\bgold\b",
161 r"\bllc\b", r"\blli\b",
162 r"\bllvm-ar\b", r"\bllvm-as\b",
163 r"\bllvm-bcanalyzer\b", r"\bllvm-config\b",
164 r"\bllvm-diff\b", r"\bllvm-dis\b",
165 r"\bllvm-extract\b", r"\bllvm-ld\b",
166 r"\bllvm-link\b", r"\bllvm-mc\b",
167 r"\bllvm-nm\b", r"\bllvm-prof\b",
168 r"\bllvm-ranlib\b", r"\bllvm-shlib\b",
169 r"\bllvm-stub\b", r"\bllvm2cpp\b",
170 # Don't match '-llvmc'.
171 r"(?<!-)\bllvmc\b", r"\blto\b",
172 # Don't match '.opt', '-opt'
173 # or '^opt'.
174 r"\bmacho-dump\b", r"(?<!\.|-|\^)\bopt\b",
175 r"\btblgen\b", r"\bFileCheck\b",
176 r"\bFileUpdate\b", r"\bc-index-test\b",
177 r"\bfpcmp\b", r"\bllvm-PerfectShuffle\b",
178 # Handle these specially as they are strings searched
179 # for during testing.
180 r"\| \bcount\b", r"\| \bnot\b"]:
181 # Extract the tool name from the pattern. This relies on the tool
182 # name being surrounded by \b word match operators. If the
183 # pattern starts with "| ", include it in the string to be
184 # substituted.
185 substitution = re.sub(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
186 r"\2" + llvm_tools_dir + "/" + r"\4",
187 pattern)
188 config.substitutions.append((pattern, substitution))
189
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000190excludes = []
191
192# Provide target_triple for use in XFAIL and XTARGET.
193config.target_triple = site_exp['target_triplet']
194
Jeffrey Yasskin32989de2010-03-20 23:08:45 +0000195# When running under valgrind, we mangle '-vg' or '-vg_leak' onto the end of the
196# triple so we can check it with XFAIL and XTARGET.
197config.target_triple += lit.valgrindTriple
Daniel Dunbara56a8102010-03-20 21:12:48 +0000198
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000199# Provide llvm_supports_target for use in local configs.
200targets = set(site_exp["TARGETS_TO_BUILD"].split())
201def llvm_supports_target(name):
202 return name in targets
203
Daniel Dunbar197f1f02010-02-02 22:00:15 +0000204def llvm_supports_darwin_and_target(name):
205 return 'darwin' in config.target_triple and llvm_supports_target(name)
206
Daniel Dunbar2e5ec112010-08-19 16:47:54 +0000207langs = set([s.strip() for s in site_exp['llvmgcc_langs'].split(',')])
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000208def llvm_gcc_supports(name):
Daniel Dunbar62b4d712010-08-19 16:46:52 +0000209 return name.strip() in langs
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000210
Daniel Dunbar2e5ec112010-08-19 16:47:54 +0000211bindings = set([s.strip() for s in site_exp['llvm_bindings'].split(',')])
Daniel Dunbar840a7182009-09-13 01:41:18 +0000212def llvm_supports_binding(name):
Daniel Dunbar62b4d712010-08-19 16:46:52 +0000213 return name.strip() in bindings
Daniel Dunbar840a7182009-09-13 01:41:18 +0000214
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000215# Provide on_clone hook for reading 'dg.exp'.
216import os
217simpleLibData = re.compile(r"""load_lib llvm.exp
218
219RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]""",
220 re.MULTILINE)
221conditionalLibData = re.compile(r"""load_lib llvm.exp
222
223if.*\[ ?(llvm[^ ]*) ([^ ]*) ?\].*{
224 *RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]
225\}""", re.MULTILINE)
226def on_clone(parent, cfg, for_path):
227 def addSuffixes(match):
228 if match[0] == '{' and match[-1] == '}':
229 cfg.suffixes = ['.' + s for s in match[1:-1].split(',')]
230 else:
231 cfg.suffixes = ['.' + match]
232
233 libPath = os.path.join(os.path.dirname(for_path),
234 'dg.exp')
235 if not os.path.exists(libPath):
236 cfg.unsupported = True
237 return
238
239 # Reset unsupported, in case we inherited it.
240 cfg.unsupported = False
241 lib = open(libPath).read().strip()
242
243 # Check for a simple library.
244 m = simpleLibData.match(lib)
245 if m:
246 addSuffixes(m.group(1))
247 return
248
249 # Check for a conditional test set.
250 m = conditionalLibData.match(lib)
251 if m:
252 funcname,arg,match = m.groups()
253 addSuffixes(match)
254
255 func = globals().get(funcname)
256 if not func:
257 lit.error('unsupported predicate %r' % funcname)
258 elif not func(arg):
259 cfg.unsupported = True
260 return
261 # Otherwise, give up.
262 lit.error('unable to understand %r:\n%s' % (libPath, lib))
263
264config.on_clone = on_clone
NAKAMURA Takumib3ccc122010-11-29 00:20:09 +0000265
266### Features
267
NAKAMURA Takumie7331ee2010-12-07 02:43:51 +0000268# Shell execution
269if sys.platform not in ['win32']:
270 config.available_features.add('shell')
271
NAKAMURA Takumib3ccc122010-11-29 00:20:09 +0000272# Loadable module
273# FIXME: This should be supplied by Makefile or autoconf.
274if sys.platform in ['win32', 'cygwin']:
275 loadable_module = (config.enable_shared == 1)
276else:
277 loadable_module = True
278
279if loadable_module:
280 config.available_features.add('loadable_module')