blob: ad73e98bfe78ade27589fcd965df70afba9c1222 [file] [log] [blame]
Daniel Dunbar70a3b772009-09-08 05:31:44 +00001# -*- Python -*-
2
3# Configuration file for the 'lit' test runner.
4
5import os
6
7# name: The name of this test suite.
8config.name = 'LLVM'
9
10# testFormat: The test format to use to interpret tests.
11config.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().
15config.suffixes = []
16
17# test_source_root: The root path where tests are located.
18config.test_source_root = os.path.dirname(__file__)
19
20# test_exec_root: The root path where tests should be run.
21llvm_obj_root = getattr(config, 'llvm_obj_root', None)
22if llvm_obj_root is not None:
23 config.test_exec_root = os.path.join(llvm_obj_root, 'test')
24
Daniel Dunbar5ed7be12009-11-08 09:08:00 +000025# Tweak the PATH to include the scripts dir, the tools dir, and the llvm-gcc bin
26# dir (if available).
27if 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)
Daniel Dunbar5ed7be12009-11-08 09:08:00 +000043 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
Daniel Dunbar70a3b772009-09-08 05:31:44 +000048###
49
50import os
51
52# Check that the object root is known.
53if config.test_exec_root is None:
54 # Otherwise, we haven't loaded the site specific configuration (the user is
55 # probably trying to run on a test file directly, and either the site
56 # configuration hasn't been created by the build system, or we are in an
57 # out-of-tree build situation).
58
Daniel Dunbaraefd63d2009-12-08 19:47:36 +000059 # Check for 'llvm_site_config' user parameter, and use that if available.
60 site_cfg = lit.params.get('llvm_site_config', None)
61 if site_cfg and os.path.exists(site_cfg):
62 lit.load_config(config, site_cfg)
63 raise SystemExit
64
Daniel Dunbar70a3b772009-09-08 05:31:44 +000065 # Try to detect the situation where we are using an out-of-tree build by
66 # looking for 'llvm-config'.
67 #
68 # FIXME: I debated (i.e., wrote and threw away) adding logic to
69 # automagically generate the lit.site.cfg if we are in some kind of fresh
70 # build situation. This means knowing how to invoke the build system
71 # though, and I decided it was too much magic.
72
73 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
74 if not llvm_config:
75 lit.fatal('No site specific configuration available!')
76
77 # Get the source and object roots.
78 llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
79 llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
80
81 # Validate that we got a tree which points to here.
82 this_src_root = os.path.dirname(config.test_source_root)
83 if os.path.realpath(llvm_src_root) != os.path.realpath(this_src_root):
84 lit.fatal('No site specific configuration available!')
85
86 # Check that the site specific configuration exists.
87 site_cfg = os.path.join(llvm_obj_root, 'test', 'lit.site.cfg')
88 if not os.path.exists(site_cfg):
89 lit.fatal('No site specific configuration available!')
90
91 # Okay, that worked. Notify the user of the automagic, and reconfigure.
92 lit.note('using out-of-tree build at %r' % llvm_obj_root)
93 lit.load_config(config, site_cfg)
94 raise SystemExit
95
96###
97
98# Load site data from DejaGNU's site.exp.
99import re
100site_exp = {}
101# FIXME: Implement lit.site.cfg.
102for line in open(os.path.join(config.llvm_obj_root, 'test', 'site.exp')):
103 m = re.match('set ([^ ]+) "([^"]*)"', line)
104 if m:
105 site_exp[m.group(1)] = m.group(2)
106
107# Add substitutions.
Daniel Dunbarb0c9a992009-10-30 21:13:59 +0000108config.substitutions.append(('%llvmgcc_only', site_exp['llvmgcc']))
Daniel Dunbarf3e2d802009-09-10 04:56:59 +0000109for sub in ['llvmgcc', 'llvmgxx', 'compile_cxx', 'compile_c',
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000110 'link', 'shlibext', 'ocamlopt', 'llvmdsymutil', 'llvmlibsdir',
111 'bugpoint_topts']:
112 if sub in ('llvmgcc', 'llvmgxx'):
113 config.substitutions.append(('%' + sub,
114 site_exp[sub] + ' -emit-llvm -w'))
Benjamin Kramer66c439a2010-02-04 18:40:11 +0000115 # FIXME: This is a hack to avoid LLVMC tests failing due to a clang driver
116 # warning when passing in "-fexceptions -fno-exceptions".
117 elif sub == 'compile_cxx':
118 config.substitutions.append(('%' + sub,
119 site_exp[sub].replace('-fno-exceptions', '')))
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000120 else:
121 config.substitutions.append(('%' + sub, site_exp[sub]))
122
123excludes = []
124
125# Provide target_triple for use in XFAIL and XTARGET.
126config.target_triple = site_exp['target_triplet']
127
128# Provide llvm_supports_target for use in local configs.
129targets = set(site_exp["TARGETS_TO_BUILD"].split())
130def llvm_supports_target(name):
131 return name in targets
132
Daniel Dunbar197f1f02010-02-02 22:00:15 +0000133def llvm_supports_darwin_and_target(name):
134 return 'darwin' in config.target_triple and llvm_supports_target(name)
135
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000136langs = set(site_exp['llvmgcc_langs'].split(','))
137def llvm_gcc_supports(name):
138 return name in langs
139
Daniel Dunbar840a7182009-09-13 01:41:18 +0000140bindings = set(site_exp['llvm_bindings'].split(','))
141def llvm_supports_binding(name):
Daniel Dunbar89a9c912010-01-16 00:00:20 +0000142 return name in bindings
Daniel Dunbar840a7182009-09-13 01:41:18 +0000143
Daniel Dunbar70a3b772009-09-08 05:31:44 +0000144# Provide on_clone hook for reading 'dg.exp'.
145import os
146simpleLibData = re.compile(r"""load_lib llvm.exp
147
148RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]""",
149 re.MULTILINE)
150conditionalLibData = re.compile(r"""load_lib llvm.exp
151
152if.*\[ ?(llvm[^ ]*) ([^ ]*) ?\].*{
153 *RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]
154\}""", re.MULTILINE)
155def on_clone(parent, cfg, for_path):
156 def addSuffixes(match):
157 if match[0] == '{' and match[-1] == '}':
158 cfg.suffixes = ['.' + s for s in match[1:-1].split(',')]
159 else:
160 cfg.suffixes = ['.' + match]
161
162 libPath = os.path.join(os.path.dirname(for_path),
163 'dg.exp')
164 if not os.path.exists(libPath):
165 cfg.unsupported = True
166 return
167
168 # Reset unsupported, in case we inherited it.
169 cfg.unsupported = False
170 lib = open(libPath).read().strip()
171
172 # Check for a simple library.
173 m = simpleLibData.match(lib)
174 if m:
175 addSuffixes(m.group(1))
176 return
177
178 # Check for a conditional test set.
179 m = conditionalLibData.match(lib)
180 if m:
181 funcname,arg,match = m.groups()
182 addSuffixes(match)
183
184 func = globals().get(funcname)
185 if not func:
186 lit.error('unsupported predicate %r' % funcname)
187 elif not func(arg):
188 cfg.unsupported = True
189 return
190 # Otherwise, give up.
191 lit.error('unable to understand %r:\n%s' % (libPath, lib))
192
193config.on_clone = on_clone