3 # Configuration file for the 'lit' test runner.
9 # name: The name of this test suite.
12 # testFormat: The test format to use to interpret tests.
13 config.test_format = lit.formats.TclTest()
15 # suffixes: A list of file extensions to treat as test files, this is actually
19 # test_source_root: The root path where tests are located.
20 config.test_source_root = os.path.dirname(__file__)
22 # Tweak PATH for Win32
23 if sys.platform in ['win32']:
24 # Seek sane tools in directories and set to $PATH.
25 path = getattr(config, 'lit_tools_dir', None)
26 path = lit.getToolsPath(path,
27 config.environment['PATH'],
28 ['cmp.exe', 'grep.exe', 'sed.exe'])
30 path = os.path.pathsep.join((path,
31 config.environment['PATH']))
32 config.environment['PATH'] = path
34 # test_exec_root: The root path where tests should be run.
35 llvm_obj_root = getattr(config, 'llvm_obj_root', None)
36 if llvm_obj_root is not None:
37 config.test_exec_root = os.path.join(llvm_obj_root, 'test')
39 # Tweak the PATH to include the scripts dir, the tools dir, and the llvm-gcc bin
41 if llvm_obj_root is not None:
42 # Include llvm-gcc first, as the llvm-gcc binaryies will not appear
43 # neither in the tools nor in the scripts dir. However it might be
44 # possible, that some old llvm tools are in the llvm-gcc dir. Adding
45 # llvm-gcc dir first ensures, that those will always be overwritten
46 # by the new tools in llvm_tools_dir. So now outdated tools are used
48 llvmgcc_dir = getattr(config, 'llvmgcc_dir', None)
50 path = os.path.pathsep.join((os.path.join(llvmgcc_dir, 'bin'),
51 config.environment['PATH']))
52 config.environment['PATH'] = path
54 llvm_src_root = getattr(config, 'llvm_src_root', None)
56 lit.fatal('No LLVM source root set!')
57 path = os.path.pathsep.join((os.path.join(llvm_src_root, 'test',
59 config.environment['PATH']))
60 config.environment['PATH'] = path
62 llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
63 if not llvm_tools_dir:
64 lit.fatal('No LLVM tools dir set!')
65 path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
66 config.environment['PATH'] = path
68 # Propagate 'HOME' through the environment.
69 if 'HOME' in os.environ:
70 config.environment['HOME'] = os.environ['HOME']
72 # Propagate 'INCLUDE' through the environment.
73 if 'INCLUDE' in os.environ:
74 config.environment['INCLUDE'] = os.environ['INCLUDE']
76 # Propagate 'LIB' through the environment.
77 if 'LIB' in os.environ:
78 config.environment['LIB'] = os.environ['LIB']
80 # Propagate the temp directory. Windows requires this because it uses \Windows\
81 # if none of these are present.
82 if 'TMP' in os.environ:
83 config.environment['TMP'] = os.environ['TMP']
84 if 'TEMP' in os.environ:
85 config.environment['TEMP'] = os.environ['TEMP']
87 # Propagate LLVM_SRC_ROOT into the environment.
88 config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '')
90 # Propagate PYTHON_EXECUTABLE into the environment
91 config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
98 # Check that the object root is known.
99 if config.test_exec_root is None:
100 # Otherwise, we haven't loaded the site specific configuration (the user is
101 # probably trying to run on a test file directly, and either the site
102 # configuration hasn't been created by the build system, or we are in an
103 # out-of-tree build situation).
105 # Check for 'llvm_site_config' user parameter, and use that if available.
106 site_cfg = lit.params.get('llvm_site_config', None)
107 if site_cfg and os.path.exists(site_cfg):
108 lit.load_config(config, site_cfg)
111 # Try to detect the situation where we are using an out-of-tree build by
112 # looking for 'llvm-config'.
114 # FIXME: I debated (i.e., wrote and threw away) adding logic to
115 # automagically generate the lit.site.cfg if we are in some kind of fresh
116 # build situation. This means knowing how to invoke the build system
117 # though, and I decided it was too much magic.
119 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
121 lit.fatal('No site specific configuration available!')
123 # Get the source and object roots.
124 llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
125 llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
127 # Validate that we got a tree which points to here.
128 this_src_root = os.path.dirname(config.test_source_root)
129 if os.path.realpath(llvm_src_root) != os.path.realpath(this_src_root):
130 lit.fatal('No site specific configuration available!')
132 # Check that the site specific configuration exists.
133 site_cfg = os.path.join(llvm_obj_root, 'test', 'lit.site.cfg')
134 if not os.path.exists(site_cfg):
135 lit.fatal('No site specific configuration available!')
137 # Okay, that worked. Notify the user of the automagic, and reconfigure.
138 lit.note('using out-of-tree build at %r' % llvm_obj_root)
139 lit.load_config(config, site_cfg)
144 # Load site data from DejaGNU's site.exp.
147 # FIXME: Implement lit.site.cfg.
148 for line in open(os.path.join(config.llvm_obj_root, 'test', 'site.exp')):
149 m = re.match('set ([^ ]+) "(.*)"', line)
151 site_exp[m.group(1)] = m.group(2)
154 config.substitutions.append(('%llvmgcc_only', site_exp['llvmgcc']))
155 for sub in ['llvmgcc', 'llvmgxx', 'emitir', 'compile_cxx', 'compile_c',
156 'link', 'shlibext', 'ocamlopt', 'llvmdsymutil', 'llvmlibsdir',
159 if sub in ('llvmgcc', 'llvmgxx'):
160 config.substitutions.append(('%' + sub,
161 site_exp[sub] + ' %emitir -w'))
162 # FIXME: This is a hack to avoid LLVMC tests failing due to a clang driver
163 # warning when passing in "-fexceptions -fno-exceptions".
164 elif sub == 'compile_cxx':
165 config.substitutions.append(('%' + sub,
166 site_exp[sub].replace('-fno-exceptions', '')))
168 config.substitutions.append(('%' + sub, site_exp[sub]))
170 # For each occurrence of an llvm tool name as its own word, replace it
171 # with the full path to the build directory holding that tool. This
172 # ensures that we are testing the tools just built and not some random
173 # tools that might happen to be in the user's PATH. Thus this list
174 # includes every tool placed in $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
175 # (llvm_tools_dir in lit parlance).
176 # Don't match 'bugpoint-' or 'clang-'.
177 # Don't match '/clang'.
178 if os.pathsep == ';':
179 pathext = os.environ.get('PATHEXT', '').split(';')
182 for pattern in [r"\bbugpoint\b(?!-)", r"(?<!/)\bclang\b(?!-)",
184 r"\bllc\b", r"\blli\b",
185 r"\bllvm-ar\b", r"\bllvm-as\b",
186 r"\bllvm-bcanalyzer\b", r"\bllvm-config\b",
187 r"\bllvm-diff\b", r"\bllvm-dis\b",
188 r"\bllvm-extract\b", r"\bllvm-ld\b",
189 r"\bllvm-link\b", r"\bllvm-mc\b",
190 r"\bllvm-nm\b", r"\bllvm-prof\b",
191 r"\bllvm-ranlib\b", r"\bllvm-shlib\b",
192 r"\bllvm-stub\b", r"\bllvm2cpp\b",
193 # Don't match '-llvmc'.
194 r"(?<!-)\bllvmc\b", r"\blto\b",
195 # Don't match '.opt', '-opt',
197 r"\bmacho-dump\b", r"(?<!\.|-|\^|/)\bopt\b",
198 r"\btblgen\b", r"\bFileCheck\b",
199 r"\bFileUpdate\b", r"\bc-index-test\b",
200 r"\bfpcmp\b", r"\bllvm-PerfectShuffle\b",
201 # Handle these specially as they are strings searched
202 # for during testing.
203 r"\| \bcount\b", r"\| \bnot\b"]:
204 # Extract the tool name from the pattern. This relies on the tool
205 # name being surrounded by \b word match operators. If the
206 # pattern starts with "| ", include it in the string to be
208 substitution = re.sub(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
209 r"\2" + llvm_tools_dir + "/" + r"\4",
212 substitution_ext = substitution + ext
213 if os.path.exists(substitution_ext):
214 substitution = substitution_ext
216 config.substitutions.append((pattern, substitution))
220 # Provide target_triple for use in XFAIL and XTARGET.
221 config.target_triple = site_exp['target_triplet']
223 # When running under valgrind, we mangle '-vg' or '-vg_leak' onto the end of the
224 # triple so we can check it with XFAIL and XTARGET.
225 config.target_triple += lit.valgrindTriple
227 # Provide llvm_supports_target for use in local configs.
228 targets = set(site_exp["TARGETS_TO_BUILD"].split())
229 def llvm_supports_target(name):
230 return name in targets
232 def llvm_supports_darwin_and_target(name):
233 return 'darwin' in config.target_triple and llvm_supports_target(name)
235 langs = set([s.strip() for s in site_exp['llvmgcc_langs'].split(',')])
236 def llvm_gcc_supports(name):
237 return name.strip() in langs
239 bindings = set([s.strip() for s in site_exp['llvm_bindings'].split(',')])
240 def llvm_supports_binding(name):
241 return name.strip() in bindings
243 # Provide on_clone hook for reading 'dg.exp'.
245 simpleLibData = re.compile(r"""load_lib llvm.exp
247 RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]""",
249 conditionalLibData = re.compile(r"""load_lib llvm.exp
251 if.*\[ ?(llvm[^ ]*) ([^ ]*) ?\].*{
252 *RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]
254 def on_clone(parent, cfg, for_path):
255 def addSuffixes(match):
256 if match[0] == '{' and match[-1] == '}':
257 cfg.suffixes = ['.' + s for s in match[1:-1].split(',')]
259 cfg.suffixes = ['.' + match]
261 libPath = os.path.join(os.path.dirname(for_path),
263 if not os.path.exists(libPath):
264 cfg.unsupported = True
267 # Reset unsupported, in case we inherited it.
268 cfg.unsupported = False
269 lib = open(libPath).read().strip()
271 # Check for a simple library.
272 m = simpleLibData.match(lib)
274 addSuffixes(m.group(1))
277 # Check for a conditional test set.
278 m = conditionalLibData.match(lib)
280 funcname,arg,match = m.groups()
283 func = globals().get(funcname)
285 lit.error('unsupported predicate %r' % funcname)
287 cfg.unsupported = True
289 # Otherwise, give up.
290 lit.error('unable to understand %r:\n%s' % (libPath, lib))
292 config.on_clone = on_clone
297 if sys.platform not in ['win32'] or lit.getBashPath() != '':
298 config.available_features.add('shell')
301 # FIXME: This should be supplied by Makefile or autoconf.
302 if sys.platform in ['win32', 'cygwin']:
303 loadable_module = (config.enable_shared == 1)
305 loadable_module = True
308 config.available_features.add('loadable_module')