blob: 8c869f0787bd78a9843cd8a8051a4d37d600343a [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
Daniel Dunbar70a3b772009-09-08 05:31:44 +00007
8# name: The name of this test suite.
9config.name = 'LLVM'
10
11# testFormat: The test format to use to interpret tests.
12config.test_format = lit.formats.TclTest()
13
14# suffixes: A list of file extensions to treat as test files, this is actually
15# set by on_clone().
16config.suffixes = []
17
18# test_source_root: The root path where tests are located.
19config.test_source_root = os.path.dirname(__file__)
20
21# test_exec_root: The root path where tests should be run.
22llvm_obj_root = getattr(config, 'llvm_obj_root', None)
23if llvm_obj_root is not None:
24 config.test_exec_root = os.path.join(llvm_obj_root, 'test')
25
Daniel Dunbar5ed7be12009-11-08 09:08:00 +000026# Tweak the PATH to include the scripts dir, the tools dir, and the llvm-gcc bin
27# dir (if available).
28if llvm_obj_root is not None:
29 llvm_src_root = getattr(config, 'llvm_src_root', None)
30 if not llvm_src_root:
31 lit.fatal('No LLVM source root set!')
32 path = os.path.pathsep.join((os.path.join(llvm_src_root, 'test',
33 'Scripts'),
34 config.environment['PATH']))
35 config.environment['PATH'] = path
36
37 llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
38 if not llvm_tools_dir:
39 lit.fatal('No LLVM tools dir set!')
40 path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
41 config.environment['PATH'] = path
42
43 llvmgcc_dir = getattr(config, 'llvmgcc_dir', None)
Daniel Dunbar5ed7be12009-11-08 09:08:00 +000044 if llvmgcc_dir:
45 path = os.path.pathsep.join((os.path.join(llvmgcc_dir, 'bin'),
46 config.environment['PATH']))
47 config.environment['PATH'] = path
48
Duncan Sands51a64552010-09-13 13:32:22 +000049# Propagate 'HOME' through the environment.
Daniel Dunbar1321fec2010-08-10 19:36:25 +000050if 'HOME' in os.environ:
51 config.environment['HOME'] = os.environ['HOME']
Daniel Dunbar55983f12010-02-25 22:09:09 +000052
Duncan Sands51a64552010-09-13 13:32:22 +000053# Propagate 'INCLUDE' through the environment.
Michael J. Spencer06b7f582010-08-30 14:49:00 +000054if 'INCLUDE' in os.environ:
55 config.environment['INCLUDE'] = os.environ['INCLUDE']
56
Duncan Sands51a64552010-09-13 13:32:22 +000057# Propagate 'LIB' through the environment.
Michael J. Spencer06b7f582010-08-30 14:49:00 +000058if 'LIB' in os.environ:
59 config.environment['LIB'] = os.environ['LIB']
60
Michael J. Spencer44d392a2010-12-07 01:23:49 +000061# Propagate the temp directory. Windows requires this because it uses \Windows\
62# if none of these are present.
63if 'TMP' in os.environ:
64 config.environment['TMP'] = os.environ['TMP']
65if 'TEMP' in os.environ:
66 config.environment['TEMP'] = os.environ['TEMP']
67
Duncan Sands51a64552010-09-13 13:32:22 +000068# Propagate LLVM_SRC_ROOT into the environment.
Daniel Dunbar238e73f2010-06-23 18:06:16 +000069config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '')
Daniel Dunbar9b2cb692010-06-12 16:21:19 +000070
Duncan Sands51a64552010-09-13 13:32:22 +000071# Propagate PYTHON_EXECUTABLE into the environment
Daniel Dunbar9b2cb692010-06-12 16:21:19 +000072config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
73 '')
74
Daniel Dunbar70a3b772009-09-08 05:31:44 +000075###
76
77import os
78
79# Check that the object root is known.
80if config.test_exec_root is None:
81 # Otherwise, we haven't loaded the site specific configuration (the user is
82 # probably trying to run on a test file directly, and either the site
83 # configuration hasn't been created by the build system, or we are in an
84 # out-of-tree build situation).
85
Daniel Dunbaraefd63d2009-12-08 19:47:36 +000086 # Check for 'llvm_site_config' user parameter, and use that if available.
87 site_cfg = lit.params.get('llvm_site_config', None)
88 if site_cfg and os.path.exists(site_cfg):
89 lit.load_config(config, site_cfg)
90 raise SystemExit
91
Daniel Dunbar70a3b772009-09-08 05:31:44 +000092 # Try to detect the situation where we are using an out-of-tree build by
93 # looking for 'llvm-config'.
94 #
95 # FIXME: I debated (i.e., wrote and threw away) adding logic to
96 # automagically generate the lit.site.cfg if we are in some kind of fresh
97 # build situation. This means knowing how to invoke the build system
98 # though, and I decided it was too much magic.
99
100 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
101 if not llvm_config:
102 lit.fatal('No site specific configuration available!')
103
104 # Get the source and object roots.
105 llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
106 llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
107
108 # Validate that we got a tree which points to here.
109 this_src_root = os.path.dirname(config.test_source_root)
110 if os.path.realpath(llvm_src_root) != os.path.realpath(this_src_root):
111 lit.fatal('No site specific configuration available!')
112
113 # Check that the site specific configuration exists.
114 site_cfg = os.path.join(llvm_obj_root, 'test', 'lit.site.cfg')
115 if not os.path.exists(site_cfg):
116 lit.fatal('No site specific configuration available!')
117
118 # Okay, that worked. Notify the user of the automagic, and reconfigure.
119 lit.note('using out-of-tree build at %r' % llvm_obj_root)
120 lit.load_config(config, site_cfg)
121 raise SystemExit
122
123###
124
125# Load site data from DejaGNU's site.exp.
126import re
127site_exp = {}
128# FIXME: Implement lit.site.cfg.
129for line in open(os.path.join(config.llvm_obj_root, 'test', 'site.exp')):
Bob Wilson8d854a42010-08-20 14:19:38 +0000130 m = re.match('set ([^ ]+) "(.*)"', line)
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000131 if m:
132 site_exp[m.group(1)] = m.group(2)
133
134# Add substitutions.
Daniel Dunbarb0c9a992009-10-30 21:13:59 +0000135config.substitutions.append(('%llvmgcc_only', site_exp['llvmgcc']))
Duncan Sands48f296d2010-11-25 21:19:52 +0000136for sub in ['llvmgcc', 'llvmgxx', 'emitir', 'compile_cxx', 'compile_c',
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000137 'link', 'shlibext', 'ocamlopt', 'llvmdsymutil', 'llvmlibsdir',
NAKAMURA Takumi38d439f2010-11-29 00:20:21 +0000138 'llvmshlibdir',
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000139 'bugpoint_topts']:
140 if sub in ('llvmgcc', 'llvmgxx'):
141 config.substitutions.append(('%' + sub,
Duncan Sands48f296d2010-11-25 21:19:52 +0000142 site_exp[sub] + ' %emitir -w'))
Benjamin Kramer66c439a2010-02-04 18:40:11 +0000143 # FIXME: This is a hack to avoid LLVMC tests failing due to a clang driver
144 # warning when passing in "-fexceptions -fno-exceptions".
145 elif sub == 'compile_cxx':
146 config.substitutions.append(('%' + sub,
147 site_exp[sub].replace('-fno-exceptions', '')))
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000148 else:
149 config.substitutions.append(('%' + sub, site_exp[sub]))
150
151excludes = []
152
153# Provide target_triple for use in XFAIL and XTARGET.
154config.target_triple = site_exp['target_triplet']
155
Jeffrey Yasskin32989de2010-03-20 23:08:45 +0000156# When running under valgrind, we mangle '-vg' or '-vg_leak' onto the end of the
157# triple so we can check it with XFAIL and XTARGET.
158config.target_triple += lit.valgrindTriple
Daniel Dunbara56a8102010-03-20 21:12:48 +0000159
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000160# Provide llvm_supports_target for use in local configs.
161targets = set(site_exp["TARGETS_TO_BUILD"].split())
162def llvm_supports_target(name):
163 return name in targets
164
Daniel Dunbar197f1f02010-02-02 22:00:15 +0000165def llvm_supports_darwin_and_target(name):
166 return 'darwin' in config.target_triple and llvm_supports_target(name)
167
Daniel Dunbar2e5ec112010-08-19 16:47:54 +0000168langs = set([s.strip() for s in site_exp['llvmgcc_langs'].split(',')])
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000169def llvm_gcc_supports(name):
Daniel Dunbar62b4d712010-08-19 16:46:52 +0000170 return name.strip() in langs
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000171
Daniel Dunbar2e5ec112010-08-19 16:47:54 +0000172bindings = set([s.strip() for s in site_exp['llvm_bindings'].split(',')])
Daniel Dunbar840a7182009-09-13 01:41:18 +0000173def llvm_supports_binding(name):
Daniel Dunbar62b4d712010-08-19 16:46:52 +0000174 return name.strip() in bindings
Daniel Dunbar840a7182009-09-13 01:41:18 +0000175
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000176# Provide on_clone hook for reading 'dg.exp'.
177import os
178simpleLibData = re.compile(r"""load_lib llvm.exp
179
180RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]""",
181 re.MULTILINE)
182conditionalLibData = re.compile(r"""load_lib llvm.exp
183
184if.*\[ ?(llvm[^ ]*) ([^ ]*) ?\].*{
185 *RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]
186\}""", re.MULTILINE)
187def on_clone(parent, cfg, for_path):
188 def addSuffixes(match):
189 if match[0] == '{' and match[-1] == '}':
190 cfg.suffixes = ['.' + s for s in match[1:-1].split(',')]
191 else:
192 cfg.suffixes = ['.' + match]
193
194 libPath = os.path.join(os.path.dirname(for_path),
195 'dg.exp')
196 if not os.path.exists(libPath):
197 cfg.unsupported = True
198 return
199
200 # Reset unsupported, in case we inherited it.
201 cfg.unsupported = False
202 lib = open(libPath).read().strip()
203
204 # Check for a simple library.
205 m = simpleLibData.match(lib)
206 if m:
207 addSuffixes(m.group(1))
208 return
209
210 # Check for a conditional test set.
211 m = conditionalLibData.match(lib)
212 if m:
213 funcname,arg,match = m.groups()
214 addSuffixes(match)
215
216 func = globals().get(funcname)
217 if not func:
218 lit.error('unsupported predicate %r' % funcname)
219 elif not func(arg):
220 cfg.unsupported = True
221 return
222 # Otherwise, give up.
223 lit.error('unable to understand %r:\n%s' % (libPath, lib))
224
225config.on_clone = on_clone
NAKAMURA Takumib3ccc122010-11-29 00:20:09 +0000226
227### Features
228
229# Loadable module
230# FIXME: This should be supplied by Makefile or autoconf.
231if sys.platform in ['win32', 'cygwin']:
232 loadable_module = (config.enable_shared == 1)
233else:
234 loadable_module = True
235
236if loadable_module:
237 config.available_features.add('loadable_module')