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 llvm_src_root = getattr(config, 'llvm_src_root', None)
47 lit.fatal('No LLVM source root set!')
48 path = os.path.pathsep.join((os.path.join(llvm_src_root, 'test',
50 config.environment['PATH']))
51 config.environment['PATH'] = path
53 llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
54 if not llvm_tools_dir:
55 lit.fatal('No LLVM tools dir set!')
56 path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
57 config.environment['PATH'] = path
59 # Propagate 'HOME' through the environment.
60 if 'HOME' in os.environ:
61 config.environment['HOME'] = os.environ['HOME']
63 # Propagate 'INCLUDE' through the environment.
64 if 'INCLUDE' in os.environ:
65 config.environment['INCLUDE'] = os.environ['INCLUDE']
67 # Propagate 'LIB' through the environment.
68 if 'LIB' in os.environ:
69 config.environment['LIB'] = os.environ['LIB']
71 # Propagate the temp directory. Windows requires this because it uses \Windows\
72 # if none of these are present.
73 if 'TMP' in os.environ:
74 config.environment['TMP'] = os.environ['TMP']
75 if 'TEMP' in os.environ:
76 config.environment['TEMP'] = os.environ['TEMP']
78 # Propagate LLVM_SRC_ROOT into the environment.
79 config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '')
81 # Propagate PYTHON_EXECUTABLE into the environment
82 config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
89 # Check that the object root is known.
90 if config.test_exec_root is None:
91 # Otherwise, we haven't loaded the site specific configuration (the user is
92 # probably trying to run on a test file directly, and either the site
93 # configuration hasn't been created by the build system, or we are in an
94 # out-of-tree build situation).
96 # Check for 'llvm_site_config' user parameter, and use that if available.
97 site_cfg = lit.params.get('llvm_site_config', None)
98 if site_cfg and os.path.exists(site_cfg):
99 lit.load_config(config, site_cfg)
102 # Try to detect the situation where we are using an out-of-tree build by
103 # looking for 'llvm-config'.
105 # FIXME: I debated (i.e., wrote and threw away) adding logic to
106 # automagically generate the lit.site.cfg if we are in some kind of fresh
107 # build situation. This means knowing how to invoke the build system
108 # though, and I decided it was too much magic.
110 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
112 lit.fatal('No site specific configuration available!')
114 # Get the source and object roots.
115 llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
116 llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
118 # Validate that we got a tree which points to here.
119 this_src_root = os.path.dirname(config.test_source_root)
120 if os.path.realpath(llvm_src_root) != os.path.realpath(this_src_root):
121 lit.fatal('No site specific configuration available!')
123 # Check that the site specific configuration exists.
124 site_cfg = os.path.join(llvm_obj_root, 'test', 'lit.site.cfg')
125 if not os.path.exists(site_cfg):
126 lit.fatal('No site specific configuration available!')
128 # Okay, that worked. Notify the user of the automagic, and reconfigure.
129 lit.note('using out-of-tree build at %r' % llvm_obj_root)
130 lit.load_config(config, site_cfg)
135 # Load site data from DejaGNU's site.exp.
138 # FIXME: Implement lit.site.cfg.
139 for line in open(os.path.join(config.llvm_obj_root, 'test', 'site.exp')):
140 m = re.match('set ([^ ]+) "(.*)"', line)
142 site_exp[m.group(1)] = m.group(2)
145 for sub in ['link', 'shlibext', 'ocamlopt', 'llvmshlibdir']:
146 config.substitutions.append(('%' + sub, site_exp[sub]))
148 # For each occurrence of an llvm tool name as its own word, replace it
149 # with the full path to the build directory holding that tool. This
150 # ensures that we are testing the tools just built and not some random
151 # tools that might happen to be in the user's PATH. Thus this list
152 # includes every tool placed in $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
153 # (llvm_tools_dir in lit parlance).
154 # Don't match 'bugpoint-' or 'clang-'.
155 # Don't match '/clang' or '-clang'.
156 if os.pathsep == ';':
157 pathext = os.environ.get('PATHEXT', '').split(';')
160 for pattern in [r"\bbugpoint\b(?!-)", r"(?<!/|-)\bclang\b(?!-)",
162 r"\bllc\b", r"\blli\b",
163 r"\bllvm-ar\b", r"\bllvm-as\b",
164 r"\bllvm-bcanalyzer\b", r"\bllvm-config\b",
165 r"\bllvm-cov\b", r"\bllvm-diff\b",
166 r"\bllvm-dis\b", r"\bllvm-dwarfdump\b",
167 r"\bllvm-extract\b", r"\bllvm-ld\b",
168 r"\bllvm-link\b", r"\bllvm-mc\b",
169 r"\bllvm-nm\b", r"\bllvm-objdump\b",
170 r"\bllvm-prof\b", r"\bllvm-ranlib\b",
171 r"\bllvm-rtdyld\b", r"\bllvm-shlib\b",
172 r"\bllvm-size\b", r"\bllvm-stub\b",
173 # Don't match '-llvmc'.
174 r"(?<!-)\bllvmc\b", r"\blto\b",
175 # Don't match '.opt', '-opt',
177 r"\bmacho-dump\b", r"(?<!\.|-|\^|/)\bopt\b",
178 r"\bllvm-tblgen\b", r"\bFileCheck\b",
179 r"\bFileUpdate\b", r"\bc-index-test\b",
180 r"\bfpcmp\b", r"\bllvm-PerfectShuffle\b",
181 # Handle these specially as they are strings searched
182 # for during testing.
183 r"\| \bcount\b", r"\| \bnot\b"]:
184 # Extract the tool name from the pattern. This relies on the tool
185 # name being surrounded by \b word match operators. If the
186 # pattern starts with "| ", include it in the string to be
188 substitution = re.sub(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
189 r"\2" + llvm_tools_dir + "/" + r"\4",
192 substitution_ext = substitution + ext
193 if os.path.exists(substitution_ext):
194 substitution = substitution_ext
196 config.substitutions.append((pattern, substitution))
200 # Provide target_triple for use in XFAIL and XTARGET.
201 config.target_triple = site_exp['target_triplet']
203 # When running under valgrind, we mangle '-vg' or '-vg_leak' onto the end of the
204 # triple so we can check it with XFAIL and XTARGET.
205 config.target_triple += lit.valgrindTriple
207 # Provide llvm_supports_target for use in local configs.
208 targets = set(site_exp["TARGETS_TO_BUILD"].split())
209 def llvm_supports_target(name):
210 return name in targets
212 def llvm_supports_darwin_and_target(name):
213 return 'darwin' in config.target_triple and llvm_supports_target(name)
215 bindings = set([s.strip() for s in site_exp['llvm_bindings'].split(',')])
216 def llvm_supports_binding(name):
217 return name.strip() in bindings
219 # Provide on_clone hook for reading 'dg.exp'.
221 simpleLibData = re.compile(r"""load_lib llvm.exp
223 RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]""",
225 conditionalLibData = re.compile(r"""load_lib llvm.exp
227 if.*\[ ?(llvm[^ ]*) ([^ ]*) ?\].*{
228 *RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]
230 def on_clone(parent, cfg, for_path):
231 def addSuffixes(match):
232 if match[0] == '{' and match[-1] == '}':
233 cfg.suffixes = ['.' + s for s in match[1:-1].split(',')]
235 cfg.suffixes = ['.' + match]
237 libPath = os.path.join(os.path.dirname(for_path),
239 if not os.path.exists(libPath):
240 cfg.unsupported = True
243 # Reset unsupported, in case we inherited it.
244 cfg.unsupported = False
245 lib = open(libPath).read().strip()
247 # Check for a simple library.
248 m = simpleLibData.match(lib)
250 addSuffixes(m.group(1))
253 # Check for a conditional test set.
254 m = conditionalLibData.match(lib)
256 funcname,arg,match = m.groups()
259 func = globals().get(funcname)
261 lit.error('unsupported predicate %r' % funcname)
263 cfg.unsupported = True
265 # Otherwise, give up.
266 lit.error('unable to understand %r:\n%s' % (libPath, lib))
268 config.on_clone = on_clone
273 if sys.platform not in ['win32'] or lit.getBashPath() != '':
274 config.available_features.add('shell')
277 # FIXME: This should be supplied by Makefile or autoconf.
278 if sys.platform in ['win32', 'cygwin']:
279 loadable_module = (config.enable_shared == 1)
281 loadable_module = True
284 config.available_features.add('loadable_module')
286 if config.enable_assertions:
287 config.available_features.add('asserts')