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