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 # To ignore test output on stderr so it doesn't trigger failures uncomment this:
16 #config.test_format = lit.formats.TclTest(ignoreStdErr=True)
18 # suffixes: A list of file extensions to treat as test files, this is actually
22 # test_source_root: The root path where tests are located.
23 config.test_source_root = os.path.dirname(__file__)
25 # Tweak PATH for Win32
26 if sys.platform in ['win32']:
27 # Seek sane tools in directories and set to $PATH.
28 path = getattr(config, 'lit_tools_dir', None)
29 path = lit.getToolsPath(path,
30 config.environment['PATH'],
31 ['cmp.exe', 'grep.exe', 'sed.exe'])
33 path = os.path.pathsep.join((path,
34 config.environment['PATH']))
35 config.environment['PATH'] = path
37 # test_exec_root: The root path where tests should be run.
38 llvm_obj_root = getattr(config, 'llvm_obj_root', None)
39 if llvm_obj_root is not None:
40 config.test_exec_root = os.path.join(llvm_obj_root, 'test')
42 # Tweak the PATH to include the scripts dir, the tools dir, and the llvm-gcc bin
44 if llvm_obj_root is not None:
45 # Include llvm-gcc first, as the llvm-gcc binaryies will not appear
46 # neither in the tools nor in the scripts dir. However it might be
47 # possible, that some old llvm tools are in the llvm-gcc dir. Adding
48 # llvm-gcc dir first ensures, that those will always be overwritten
49 # by the new tools in llvm_tools_dir. So now outdated tools are used
51 llvmgcc_dir = getattr(config, 'llvmgcc_dir', None)
53 path = os.path.pathsep.join((os.path.join(llvmgcc_dir, 'bin'),
54 config.environment['PATH']))
55 config.environment['PATH'] = path
57 llvm_src_root = getattr(config, 'llvm_src_root', None)
59 lit.fatal('No LLVM source root set!')
60 path = os.path.pathsep.join((os.path.join(llvm_src_root, 'test',
62 config.environment['PATH']))
63 config.environment['PATH'] = path
65 llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
66 if not llvm_tools_dir:
67 lit.fatal('No LLVM tools dir set!')
68 path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
69 config.environment['PATH'] = path
71 # Propagate 'HOME' through the environment.
72 if 'HOME' in os.environ:
73 config.environment['HOME'] = os.environ['HOME']
75 # Propagate 'INCLUDE' through the environment.
76 if 'INCLUDE' in os.environ:
77 config.environment['INCLUDE'] = os.environ['INCLUDE']
79 # Propagate 'LIB' through the environment.
80 if 'LIB' in os.environ:
81 config.environment['LIB'] = os.environ['LIB']
83 # Propagate the temp directory. Windows requires this because it uses \Windows\
84 # if none of these are present.
85 if 'TMP' in os.environ:
86 config.environment['TMP'] = os.environ['TMP']
87 if 'TEMP' in os.environ:
88 config.environment['TEMP'] = os.environ['TEMP']
90 # Propagate LLVM_SRC_ROOT into the environment.
91 config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '')
93 # Propagate PYTHON_EXECUTABLE into the environment
94 config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
101 # Check that the object root is known.
102 if config.test_exec_root is None:
103 # Otherwise, we haven't loaded the site specific configuration (the user is
104 # probably trying to run on a test file directly, and either the site
105 # configuration hasn't been created by the build system, or we are in an
106 # out-of-tree build situation).
108 # Check for 'llvm_site_config' user parameter, and use that if available.
109 site_cfg = lit.params.get('llvm_site_config', None)
110 if site_cfg and os.path.exists(site_cfg):
111 lit.load_config(config, site_cfg)
114 # Try to detect the situation where we are using an out-of-tree build by
115 # looking for 'llvm-config'.
117 # FIXME: I debated (i.e., wrote and threw away) adding logic to
118 # automagically generate the lit.site.cfg if we are in some kind of fresh
119 # build situation. This means knowing how to invoke the build system
120 # though, and I decided it was too much magic.
122 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
124 lit.fatal('No site specific configuration available!')
126 # Get the source and object roots.
127 llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
128 llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
130 # Validate that we got a tree which points to here.
131 this_src_root = os.path.dirname(config.test_source_root)
132 if os.path.realpath(llvm_src_root) != os.path.realpath(this_src_root):
133 lit.fatal('No site specific configuration available!')
135 # Check that the site specific configuration exists.
136 site_cfg = os.path.join(llvm_obj_root, 'test', 'lit.site.cfg')
137 if not os.path.exists(site_cfg):
138 lit.fatal('No site specific configuration available!')
140 # Okay, that worked. Notify the user of the automagic, and reconfigure.
141 lit.note('using out-of-tree build at %r' % llvm_obj_root)
142 lit.load_config(config, site_cfg)
147 # Load site data from DejaGNU's site.exp.
150 # FIXME: Implement lit.site.cfg.
151 for line in open(os.path.join(config.llvm_obj_root, 'test', 'site.exp')):
152 m = re.match('set ([^ ]+) "(.*)"', line)
154 site_exp[m.group(1)] = m.group(2)
157 config.substitutions.append(('%llvmgcc_only', site_exp['llvmgcc']))
158 for sub in ['llvmgcc', 'llvmgxx', 'emitir', 'compile_cxx', 'compile_c',
159 'link', 'shlibext', 'ocamlopt', 'llvmdsymutil', 'llvmlibsdir',
162 if sub in ('llvmgcc', 'llvmgxx'):
163 config.substitutions.append(('%' + sub,
164 site_exp[sub] + ' %emitir -w'))
165 # FIXME: This is a hack to avoid LLVMC tests failing due to a clang driver
166 # warning when passing in "-fexceptions -fno-exceptions".
167 elif sub == 'compile_cxx':
168 config.substitutions.append(('%' + sub,
169 site_exp[sub].replace('-fno-exceptions', '')))
171 config.substitutions.append(('%' + sub, site_exp[sub]))
173 # For each occurrence of an llvm tool name as its own word, replace it
174 # with the full path to the build directory holding that tool. This
175 # ensures that we are testing the tools just built and not some random
176 # tools that might happen to be in the user's PATH. Thus this list
177 # includes every tool placed in $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
178 # (llvm_tools_dir in lit parlance).
179 # Don't match 'bugpoint-' or 'clang-'.
180 # Don't match '/clang' or '-clang'.
181 if os.pathsep == ';':
182 pathext = os.environ.get('PATHEXT', '').split(';')
185 for pattern in [r"\bbugpoint\b(?!-)", r"(?<!/|-)\bclang\b(?!-)",
187 r"\bllc\b", r"\blli\b",
188 r"\bllvm-ar\b", r"\bllvm-as\b",
189 r"\bllvm-bcanalyzer\b", r"\bllvm-config\b",
190 r"\bllvm-diff\b", r"\bllvm-dis\b",
191 r"\bllvm-extract\b", r"\bllvm-ld\b",
192 r"\bllvm-link\b", r"\bllvm-mc\b",
193 r"\bllvm-nm\b", r"\bllvm-prof\b",
194 r"\bllvm-ranlib\b", r"\bllvm-shlib\b",
195 r"\bllvm-stub\b", r"\bllvm2cpp\b",
196 # Don't match '-llvmc'.
197 r"(?<!-)\bllvmc\b", r"\blto\b",
198 # Don't match '.opt', '-opt',
200 r"\bmacho-dump\b", r"(?<!\.|-|\^|/)\bopt\b",
201 r"\btblgen\b", r"\bFileCheck\b",
202 r"\bFileUpdate\b", r"\bc-index-test\b",
203 r"\bfpcmp\b", r"\bllvm-PerfectShuffle\b",
204 # Handle these specially as they are strings searched
205 # for during testing.
206 r"\| \bcount\b", r"\| \bnot\b"]:
207 # Extract the tool name from the pattern. This relies on the tool
208 # name being surrounded by \b word match operators. If the
209 # pattern starts with "| ", include it in the string to be
211 substitution = re.sub(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
212 r"\2" + llvm_tools_dir + "/" + r"\4",
215 substitution_ext = substitution + ext
216 if os.path.exists(substitution_ext):
217 substitution = substitution_ext
219 config.substitutions.append((pattern, substitution))
223 # Provide target_triple for use in XFAIL and XTARGET.
224 config.target_triple = site_exp['target_triplet']
226 # When running under valgrind, we mangle '-vg' or '-vg_leak' onto the end of the
227 # triple so we can check it with XFAIL and XTARGET.
228 config.target_triple += lit.valgrindTriple
230 # Provide llvm_supports_target for use in local configs.
231 targets = set(site_exp["TARGETS_TO_BUILD"].split())
232 def llvm_supports_target(name):
233 return name in targets
235 def llvm_supports_darwin_and_target(name):
236 return 'darwin' in config.target_triple and llvm_supports_target(name)
238 bindings = set([s.strip() for s in site_exp['llvm_bindings'].split(',')])
239 def llvm_supports_binding(name):
240 return name.strip() in bindings
242 # Provide on_clone hook for reading 'dg.exp'.
244 simpleLibData = re.compile(r"""load_lib llvm.exp
246 RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]""",
248 conditionalLibData = re.compile(r"""load_lib llvm.exp
250 if.*\[ ?(llvm[^ ]*) ([^ ]*) ?\].*{
251 *RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]
253 def on_clone(parent, cfg, for_path):
254 def addSuffixes(match):
255 if match[0] == '{' and match[-1] == '}':
256 cfg.suffixes = ['.' + s for s in match[1:-1].split(',')]
258 cfg.suffixes = ['.' + match]
260 libPath = os.path.join(os.path.dirname(for_path),
262 if not os.path.exists(libPath):
263 cfg.unsupported = True
266 # Reset unsupported, in case we inherited it.
267 cfg.unsupported = False
268 lib = open(libPath).read().strip()
270 # Check for a simple library.
271 m = simpleLibData.match(lib)
273 addSuffixes(m.group(1))
276 # Check for a conditional test set.
277 m = conditionalLibData.match(lib)
279 funcname,arg,match = m.groups()
282 func = globals().get(funcname)
284 lit.error('unsupported predicate %r' % funcname)
286 cfg.unsupported = True
288 # Otherwise, give up.
289 lit.error('unable to understand %r:\n%s' % (libPath, lib))
291 config.on_clone = on_clone
296 if sys.platform not in ['win32'] or lit.getBashPath() != '':
297 config.available_features.add('shell')
300 # FIXME: This should be supplied by Makefile or autoconf.
301 if sys.platform in ['win32', 'cygwin']:
302 loadable_module = (config.enable_shared == 1)
304 loadable_module = True
307 config.available_features.add('loadable_module')
309 if config.enable_assertions:
310 config.available_features.add('asserts')