test: Use $SharedLibDir for loadable modules. On Cygming, loadable modules are not...
[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
8 # name: The name of this test suite.
9 config.name = 'LLVM'
10
11 # testFormat: The test format to use to interpret tests.
12 config.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().
16 config.suffixes = []
17
18 # test_source_root: The root path where tests are located.
19 config.test_source_root = os.path.dirname(__file__)
20
21 # test_exec_root: The root path where tests should be run.
22 llvm_obj_root = getattr(config, 'llvm_obj_root', None)
23 if llvm_obj_root is not None:
24     config.test_exec_root = os.path.join(llvm_obj_root, 'test')
25
26 # Tweak the PATH to include the scripts dir, the tools dir, and the llvm-gcc bin
27 # dir (if available).
28 if 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)
44     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
49 # Propagate 'HOME' through the environment.
50 if 'HOME' in os.environ:
51     config.environment['HOME'] = os.environ['HOME']
52
53 # Propagate 'INCLUDE' through the environment.
54 if 'INCLUDE' in os.environ:
55     config.environment['INCLUDE'] = os.environ['INCLUDE']
56
57 # Propagate 'LIB' through the environment.
58 if 'LIB' in os.environ:
59     config.environment['LIB'] = os.environ['LIB']
60
61 # Propagate LLVM_SRC_ROOT into the environment.
62 config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '')
63
64 # Propagate PYTHON_EXECUTABLE into the environment
65 config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
66                                                   '')
67
68 ###
69
70 import os
71
72 # Check that the object root is known.
73 if config.test_exec_root is None:
74     # Otherwise, we haven't loaded the site specific configuration (the user is
75     # probably trying to run on a test file directly, and either the site
76     # configuration hasn't been created by the build system, or we are in an
77     # out-of-tree build situation).
78
79     # Check for 'llvm_site_config' user parameter, and use that if available.
80     site_cfg = lit.params.get('llvm_site_config', None)
81     if site_cfg and os.path.exists(site_cfg):
82         lit.load_config(config, site_cfg)
83         raise SystemExit
84
85     # Try to detect the situation where we are using an out-of-tree build by
86     # looking for 'llvm-config'.
87     #
88     # FIXME: I debated (i.e., wrote and threw away) adding logic to
89     # automagically generate the lit.site.cfg if we are in some kind of fresh
90     # build situation. This means knowing how to invoke the build system
91     # though, and I decided it was too much magic.
92
93     llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
94     if not llvm_config:
95         lit.fatal('No site specific configuration available!')
96
97     # Get the source and object roots.
98     llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
99     llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
100
101     # Validate that we got a tree which points to here.
102     this_src_root = os.path.dirname(config.test_source_root)
103     if os.path.realpath(llvm_src_root) != os.path.realpath(this_src_root):
104         lit.fatal('No site specific configuration available!')
105
106     # Check that the site specific configuration exists.
107     site_cfg = os.path.join(llvm_obj_root, 'test', 'lit.site.cfg')
108     if not os.path.exists(site_cfg):
109         lit.fatal('No site specific configuration available!')
110
111     # Okay, that worked. Notify the user of the automagic, and reconfigure.
112     lit.note('using out-of-tree build at %r' % llvm_obj_root)
113     lit.load_config(config, site_cfg)
114     raise SystemExit
115
116 ###
117
118 # Load site data from DejaGNU's site.exp.
119 import re
120 site_exp = {}
121 # FIXME: Implement lit.site.cfg.
122 for line in open(os.path.join(config.llvm_obj_root, 'test', 'site.exp')):
123     m = re.match('set ([^ ]+) "(.*)"', line)
124     if m:
125         site_exp[m.group(1)] = m.group(2)
126
127 # Add substitutions.
128 config.substitutions.append(('%llvmgcc_only', site_exp['llvmgcc']))
129 for sub in ['llvmgcc', 'llvmgxx', 'emitir', 'compile_cxx', 'compile_c',
130             'link', 'shlibext', 'ocamlopt', 'llvmdsymutil', 'llvmlibsdir',
131             'llvmshlibdir',
132             'bugpoint_topts']:
133     if sub in ('llvmgcc', 'llvmgxx'):
134         config.substitutions.append(('%' + sub,
135                                      site_exp[sub] + ' %emitir -w'))
136     # FIXME: This is a hack to avoid LLVMC tests failing due to a clang driver
137     #        warning when passing in "-fexceptions -fno-exceptions".
138     elif sub == 'compile_cxx':
139         config.substitutions.append(('%' + sub,
140                                   site_exp[sub].replace('-fno-exceptions', '')))
141     else:
142         config.substitutions.append(('%' + sub, site_exp[sub]))
143
144 excludes = []
145
146 # Provide target_triple for use in XFAIL and XTARGET.
147 config.target_triple = site_exp['target_triplet']
148
149 # When running under valgrind, we mangle '-vg' or '-vg_leak' onto the end of the
150 # triple so we can check it with XFAIL and XTARGET.
151 config.target_triple += lit.valgrindTriple
152
153 # Provide llvm_supports_target for use in local configs.
154 targets = set(site_exp["TARGETS_TO_BUILD"].split())
155 def llvm_supports_target(name):
156     return name in targets
157
158 def llvm_supports_darwin_and_target(name):
159     return 'darwin' in config.target_triple and llvm_supports_target(name)
160
161 langs = set([s.strip() for s in site_exp['llvmgcc_langs'].split(',')])
162 def llvm_gcc_supports(name):
163     return name.strip() in langs
164
165 bindings = set([s.strip() for s in site_exp['llvm_bindings'].split(',')])
166 def llvm_supports_binding(name):
167     return name.strip() in bindings
168
169 # Provide on_clone hook for reading 'dg.exp'.
170 import os
171 simpleLibData = re.compile(r"""load_lib llvm.exp
172
173 RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]""",
174                            re.MULTILINE)
175 conditionalLibData = re.compile(r"""load_lib llvm.exp
176
177 if.*\[ ?(llvm[^ ]*) ([^ ]*) ?\].*{
178  *RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]
179 \}""", re.MULTILINE)
180 def on_clone(parent, cfg, for_path):
181     def addSuffixes(match):
182         if match[0] == '{' and match[-1] == '}':
183             cfg.suffixes = ['.' + s for s in match[1:-1].split(',')]
184         else:
185             cfg.suffixes = ['.' + match]
186
187     libPath = os.path.join(os.path.dirname(for_path),
188                            'dg.exp')
189     if not os.path.exists(libPath):
190         cfg.unsupported = True
191         return
192
193     # Reset unsupported, in case we inherited it.
194     cfg.unsupported = False
195     lib = open(libPath).read().strip()
196
197     # Check for a simple library.
198     m = simpleLibData.match(lib)
199     if m:
200         addSuffixes(m.group(1))
201         return
202
203     # Check for a conditional test set.
204     m = conditionalLibData.match(lib)
205     if m:
206         funcname,arg,match = m.groups()
207         addSuffixes(match)
208
209         func = globals().get(funcname)
210         if not func:
211             lit.error('unsupported predicate %r' % funcname)
212         elif not func(arg):
213             cfg.unsupported = True
214         return
215     # Otherwise, give up.
216     lit.error('unable to understand %r:\n%s' % (libPath, lib))
217
218 config.on_clone = on_clone
219
220 ### Features
221
222 # Loadable module
223 # FIXME: This should be supplied by Makefile or autoconf.
224 if sys.platform in ['win32', 'cygwin']:
225     loadable_module = (config.enable_shared == 1)
226 else:
227     loadable_module = True
228
229 if loadable_module:
230     config.available_features.add('loadable_module')