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 # test_exec_root: The root path where tests should be run.
23 llvm_obj_root = getattr(config, 'llvm_obj_root', None)
24 if llvm_obj_root is not None:
25 config.test_exec_root = os.path.join(llvm_obj_root, 'test')
27 # Tweak the PATH to include the scripts dir, the tools dir, and the llvm-gcc bin
29 if llvm_obj_root is not None:
30 # Include llvm-gcc first, as the llvm-gcc binaryies will not appear
31 # neither in the tools nor in the scripts dir. However it might be
32 # possible, that some old llvm tools are in the llvm-gcc dir. Adding
33 # llvm-gcc dir first ensures, that those will always be overwritten
34 # by the new tools in llvm_tools_dir. So now outdated tools are used
36 llvmgcc_dir = getattr(config, 'llvmgcc_dir', None)
38 path = os.path.pathsep.join((os.path.join(llvmgcc_dir, 'bin'),
39 config.environment['PATH']))
40 config.environment['PATH'] = path
42 llvm_src_root = getattr(config, 'llvm_src_root', None)
44 lit.fatal('No LLVM source root set!')
45 path = os.path.pathsep.join((os.path.join(llvm_src_root, 'test',
47 config.environment['PATH']))
48 config.environment['PATH'] = path
50 llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
51 if not llvm_tools_dir:
52 lit.fatal('No LLVM tools dir set!')
53 path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
54 config.environment['PATH'] = path
56 # Propagate 'HOME' through the environment.
57 if 'HOME' in os.environ:
58 config.environment['HOME'] = os.environ['HOME']
60 # Propagate 'INCLUDE' through the environment.
61 if 'INCLUDE' in os.environ:
62 config.environment['INCLUDE'] = os.environ['INCLUDE']
64 # Propagate 'LIB' through the environment.
65 if 'LIB' in os.environ:
66 config.environment['LIB'] = os.environ['LIB']
68 # Propagate the temp directory. Windows requires this because it uses \Windows\
69 # if none of these are present.
70 if 'TMP' in os.environ:
71 config.environment['TMP'] = os.environ['TMP']
72 if 'TEMP' in os.environ:
73 config.environment['TEMP'] = os.environ['TEMP']
75 # Propagate LLVM_SRC_ROOT into the environment.
76 config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '')
78 # Propagate PYTHON_EXECUTABLE into the environment
79 config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
86 # Check that the object root is known.
87 if config.test_exec_root is None:
88 # Otherwise, we haven't loaded the site specific configuration (the user is
89 # probably trying to run on a test file directly, and either the site
90 # configuration hasn't been created by the build system, or we are in an
91 # out-of-tree build situation).
93 # Check for 'llvm_site_config' user parameter, and use that if available.
94 site_cfg = lit.params.get('llvm_site_config', None)
95 if site_cfg and os.path.exists(site_cfg):
96 lit.load_config(config, site_cfg)
99 # Try to detect the situation where we are using an out-of-tree build by
100 # looking for 'llvm-config'.
102 # FIXME: I debated (i.e., wrote and threw away) adding logic to
103 # automagically generate the lit.site.cfg if we are in some kind of fresh
104 # build situation. This means knowing how to invoke the build system
105 # though, and I decided it was too much magic.
107 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
109 lit.fatal('No site specific configuration available!')
111 # Get the source and object roots.
112 llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
113 llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
115 # Validate that we got a tree which points to here.
116 this_src_root = os.path.dirname(config.test_source_root)
117 if os.path.realpath(llvm_src_root) != os.path.realpath(this_src_root):
118 lit.fatal('No site specific configuration available!')
120 # Check that the site specific configuration exists.
121 site_cfg = os.path.join(llvm_obj_root, 'test', 'lit.site.cfg')
122 if not os.path.exists(site_cfg):
123 lit.fatal('No site specific configuration available!')
125 # Okay, that worked. Notify the user of the automagic, and reconfigure.
126 lit.note('using out-of-tree build at %r' % llvm_obj_root)
127 lit.load_config(config, site_cfg)
132 # Load site data from DejaGNU's site.exp.
135 # FIXME: Implement lit.site.cfg.
136 for line in open(os.path.join(config.llvm_obj_root, 'test', 'site.exp')):
137 m = re.match('set ([^ ]+) "(.*)"', line)
139 site_exp[m.group(1)] = m.group(2)
142 config.substitutions.append(('%llvmgcc_only', site_exp['llvmgcc']))
143 for sub in ['llvmgcc', 'llvmgxx', 'emitir', 'compile_cxx', 'compile_c',
144 'link', 'shlibext', 'ocamlopt', 'llvmdsymutil', 'llvmlibsdir',
147 if sub in ('llvmgcc', 'llvmgxx'):
148 config.substitutions.append(('%' + sub,
149 site_exp[sub] + ' %emitir -w'))
150 # FIXME: This is a hack to avoid LLVMC tests failing due to a clang driver
151 # warning when passing in "-fexceptions -fno-exceptions".
152 elif sub == 'compile_cxx':
153 config.substitutions.append(('%' + sub,
154 site_exp[sub].replace('-fno-exceptions', '')))
156 config.substitutions.append(('%' + sub, site_exp[sub]))
158 # For each occurrence of an llvm tool name as its own word, replace it
159 # with the full path to the build directory holding that tool. This
160 # ensures that we are testing the tools just built and not some random
161 # tools that might happen to be in the user's PATH. Thus this list
162 # includes every tool placed in $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
163 # (llvm_tools_dir in lit parlance).
164 # Don't match 'bugpoint-' or 'clang-'.
165 # Don't match '/clang'.
166 for pattern in [r"\bbugpoint\b(?!-)", r"(?<!/)\bclang\b(?!-)",
167 r"\bedis\b", r"\bgold\b",
168 r"\bllc\b", r"\blli\b",
169 r"\bllvm-ar\b", r"\bllvm-as\b",
170 r"\bllvm-bcanalyzer\b", r"\bllvm-config\b",
171 r"\bllvm-diff\b", r"\bllvm-dis\b",
172 r"\bllvm-extract\b", r"\bllvm-ld\b",
173 r"\bllvm-link\b", r"\bllvm-mc\b",
174 r"\bllvm-nm\b", r"\bllvm-prof\b",
175 r"\bllvm-ranlib\b", r"\bllvm-shlib\b",
176 r"\bllvm-stub\b", r"\bllvm2cpp\b",
177 # Don't match '-llvmc'.
178 r"(?<!-)\bllvmc\b", r"\blto\b",
179 # Don't match '.opt', '-opt',
181 r"\bmacho-dump\b", r"(?<!\.|-|\^|/)\bopt\b",
182 r"\btblgen\b", r"\bFileCheck\b",
183 r"\bFileUpdate\b", r"\bc-index-test\b",
184 r"\bfpcmp\b", r"\bllvm-PerfectShuffle\b",
185 # Handle these specially as they are strings searched
186 # for during testing.
187 r"\| \bcount\b", r"\| \bnot\b"]:
188 # Extract the tool name from the pattern. This relies on the tool
189 # name being surrounded by \b word match operators. If the
190 # pattern starts with "| ", include it in the string to be
192 substitution = re.sub(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
193 r"\2" + llvm_tools_dir + "/" + r"\4",
195 config.substitutions.append((pattern, substitution))
199 # Provide target_triple for use in XFAIL and XTARGET.
200 config.target_triple = site_exp['target_triplet']
202 # When running under valgrind, we mangle '-vg' or '-vg_leak' onto the end of the
203 # triple so we can check it with XFAIL and XTARGET.
204 config.target_triple += lit.valgrindTriple
206 # Provide llvm_supports_target for use in local configs.
207 targets = set(site_exp["TARGETS_TO_BUILD"].split())
208 def llvm_supports_target(name):
209 return name in targets
211 def llvm_supports_darwin_and_target(name):
212 return 'darwin' in config.target_triple and llvm_supports_target(name)
214 langs = set([s.strip() for s in site_exp['llvmgcc_langs'].split(',')])
215 def llvm_gcc_supports(name):
216 return name.strip() in langs
218 bindings = set([s.strip() for s in site_exp['llvm_bindings'].split(',')])
219 def llvm_supports_binding(name):
220 return name.strip() in bindings
222 # Provide on_clone hook for reading 'dg.exp'.
224 simpleLibData = re.compile(r"""load_lib llvm.exp
226 RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]""",
228 conditionalLibData = re.compile(r"""load_lib llvm.exp
230 if.*\[ ?(llvm[^ ]*) ([^ ]*) ?\].*{
231 *RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]
233 def on_clone(parent, cfg, for_path):
234 def addSuffixes(match):
235 if match[0] == '{' and match[-1] == '}':
236 cfg.suffixes = ['.' + s for s in match[1:-1].split(',')]
238 cfg.suffixes = ['.' + match]
240 libPath = os.path.join(os.path.dirname(for_path),
242 if not os.path.exists(libPath):
243 cfg.unsupported = True
246 # Reset unsupported, in case we inherited it.
247 cfg.unsupported = False
248 lib = open(libPath).read().strip()
250 # Check for a simple library.
251 m = simpleLibData.match(lib)
253 addSuffixes(m.group(1))
256 # Check for a conditional test set.
257 m = conditionalLibData.match(lib)
259 funcname,arg,match = m.groups()
262 func = globals().get(funcname)
264 lit.error('unsupported predicate %r' % funcname)
266 cfg.unsupported = True
268 # Otherwise, give up.
269 lit.error('unable to understand %r:\n%s' % (libPath, lib))
271 config.on_clone = on_clone
276 if sys.platform not in ['win32']:
277 config.available_features.add('shell')
280 # FIXME: This should be supplied by Makefile or autoconf.
281 if sys.platform in ['win32', 'cygwin']:
282 loadable_module = (config.enable_shared == 1)
284 loadable_module = True
287 config.available_features.add('loadable_module')