3 # Configuration file for the 'lit' test runner.
8 # name: The name of this test suite.
11 # testFormat: The test format to use to interpret tests.
12 config.test_format = lit.formats.TclTest()
14 # suffixes: A list of file extensions to treat as test files, this is actually
18 # test_source_root: The root path where tests are located.
19 config.test_source_root = os.path.dirname(__file__)
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')
26 # Tweak the PATH to include the scripts dir, the tools dir, and the llvm-gcc bin
28 if llvm_obj_root is not None:
29 llvm_src_root = getattr(config, 'llvm_src_root', None)
31 lit.fatal('No LLVM source root set!')
32 path = os.path.pathsep.join((os.path.join(llvm_src_root, 'test',
34 config.environment['PATH']))
35 config.environment['PATH'] = path
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
43 llvmgcc_dir = getattr(config, 'llvmgcc_dir', None)
45 path = os.path.pathsep.join((os.path.join(llvmgcc_dir, 'bin'),
46 config.environment['PATH']))
47 config.environment['PATH'] = path
49 # Propagate 'HOME' through the environment.
50 if 'HOME' in os.environ:
51 config.environment['HOME'] = os.environ['HOME']
53 # Propagate 'INCLUDE' through the environment.
54 if 'INCLUDE' in os.environ:
55 config.environment['INCLUDE'] = os.environ['INCLUDE']
57 # Propagate 'LIB' through the environment.
58 if 'LIB' in os.environ:
59 config.environment['LIB'] = os.environ['LIB']
61 # Propagate the temp directory. Windows requires this because it uses \Windows\
62 # if none of these are present.
63 if 'TMP' in os.environ:
64 config.environment['TMP'] = os.environ['TMP']
65 if 'TEMP' in os.environ:
66 config.environment['TEMP'] = os.environ['TEMP']
68 # Propagate LLVM_SRC_ROOT into the environment.
69 config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '')
71 # Propagate PYTHON_EXECUTABLE into the environment
72 config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
79 # Check that the object root is known.
80 if 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).
86 # 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)
92 # Try to detect the situation where we are using an out-of-tree build by
93 # looking for 'llvm-config'.
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.
100 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
102 lit.fatal('No site specific configuration available!')
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()
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!')
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!')
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)
125 # Load site data from DejaGNU's site.exp.
128 # FIXME: Implement lit.site.cfg.
129 for line in open(os.path.join(config.llvm_obj_root, 'test', 'site.exp')):
130 m = re.match('set ([^ ]+) "(.*)"', line)
132 site_exp[m.group(1)] = m.group(2)
135 config.substitutions.append(('%llvmgcc_only', site_exp['llvmgcc']))
136 for sub in ['llvmgcc', 'llvmgxx', 'emitir', 'compile_cxx', 'compile_c',
137 'link', 'shlibext', 'ocamlopt', 'llvmdsymutil', 'llvmlibsdir',
140 if sub in ('llvmgcc', 'llvmgxx'):
141 config.substitutions.append(('%' + sub,
142 site_exp[sub] + ' %emitir -w'))
143 # 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', '')))
149 config.substitutions.append(('%' + sub, site_exp[sub]))
153 # Provide target_triple for use in XFAIL and XTARGET.
154 config.target_triple = site_exp['target_triplet']
156 # 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.
158 config.target_triple += lit.valgrindTriple
160 # Provide llvm_supports_target for use in local configs.
161 targets = set(site_exp["TARGETS_TO_BUILD"].split())
162 def llvm_supports_target(name):
163 return name in targets
165 def llvm_supports_darwin_and_target(name):
166 return 'darwin' in config.target_triple and llvm_supports_target(name)
168 langs = set([s.strip() for s in site_exp['llvmgcc_langs'].split(',')])
169 def llvm_gcc_supports(name):
170 return name.strip() in langs
172 bindings = set([s.strip() for s in site_exp['llvm_bindings'].split(',')])
173 def llvm_supports_binding(name):
174 return name.strip() in bindings
176 # Provide on_clone hook for reading 'dg.exp'.
178 simpleLibData = re.compile(r"""load_lib llvm.exp
180 RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]""",
182 conditionalLibData = re.compile(r"""load_lib llvm.exp
184 if.*\[ ?(llvm[^ ]*) ([^ ]*) ?\].*{
185 *RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]
187 def 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(',')]
192 cfg.suffixes = ['.' + match]
194 libPath = os.path.join(os.path.dirname(for_path),
196 if not os.path.exists(libPath):
197 cfg.unsupported = True
200 # Reset unsupported, in case we inherited it.
201 cfg.unsupported = False
202 lib = open(libPath).read().strip()
204 # Check for a simple library.
205 m = simpleLibData.match(lib)
207 addSuffixes(m.group(1))
210 # Check for a conditional test set.
211 m = conditionalLibData.match(lib)
213 funcname,arg,match = m.groups()
216 func = globals().get(funcname)
218 lit.error('unsupported predicate %r' % funcname)
220 cfg.unsupported = True
222 # Otherwise, give up.
223 lit.error('unable to understand %r:\n%s' % (libPath, lib))
225 config.on_clone = on_clone
230 if sys.platform not in ['win32']:
231 config.available_features.add('shell')
234 # FIXME: This should be supplied by Makefile or autoconf.
235 if sys.platform in ['win32', 'cygwin']:
236 loadable_module = (config.enable_shared == 1)
238 loadable_module = True
241 config.available_features.add('loadable_module')