blob: e7cd818690373f9862483136329a5c9d853eaeb0 [file] [log] [blame]
Daniel Dunbar62b94392013-02-12 19:28:51 +00001# -*- Python -*- vim: set syntax=python tabstop=4 expandtab cc=80:
Daniel Dunbar42ea4632010-09-15 03:57:04 +00002
3# Configuration file for the 'lit' test runner.
4
Daniel Dunbarb6b3e502013-08-30 19:52:12 +00005import errno
Dan Alberta85b27f2014-08-04 18:44:48 +00006import locale
Daniel Dunbar42ea4632010-09-15 03:57:04 +00007import os
8import platform
Daniel Dunbarb6b3e502013-08-30 19:52:12 +00009import re
10import shlex
Daniel Dunbar42ea4632010-09-15 03:57:04 +000011import signal
12import subprocess
Daniel Dunbarb6b3e502013-08-30 19:52:12 +000013import sys
14import tempfile
Howard Hinnant3778f272013-01-14 17:12:54 +000015import time
Daniel Dunbar42ea4632010-09-15 03:57:04 +000016
Daniel Dunbar4a381292013-08-09 14:44:11 +000017import lit.Test
18import lit.formats
19import lit.util
20
Daniel Dunbar42ea4632010-09-15 03:57:04 +000021class LibcxxTestFormat(lit.formats.FileBasedTest):
22 """
23 Custom test format handler for use with the test format use by libc++.
24
25 Tests fall into two categories:
26 FOO.pass.cpp - Executable test which should compile, run, and exit with
27 code 0.
28 FOO.fail.cpp - Negative test case which is expected to fail compilation.
29 """
30
Justin Bogner33a2a2e2014-09-03 04:32:08 +000031 def __init__(self, cxx_under_test, use_verify_for_fail,
Eric Fiselier469a4f92014-12-19 19:27:32 +000032 cpp_flags, ld_flags, exec_env,
33 use_ccache=False):
Daniel Dunbarbc9a8482010-09-15 04:11:29 +000034 self.cxx_under_test = cxx_under_test
Justin Bogner33a2a2e2014-09-03 04:32:08 +000035 self.use_verify_for_fail = use_verify_for_fail
Daniel Dunbar5f09d9e02010-09-15 04:31:58 +000036 self.cpp_flags = list(cpp_flags)
37 self.ld_flags = list(ld_flags)
Daniel Dunbar84958712013-02-05 18:03:49 +000038 self.exec_env = dict(exec_env)
Eric Fiselier469a4f92014-12-19 19:27:32 +000039 self.use_ccache = use_ccache
Daniel Dunbar42ea4632010-09-15 03:57:04 +000040
Daniel Dunbar42ea4632010-09-15 03:57:04 +000041 def execute(self, test, lit_config):
Howard Hinnant3778f272013-01-14 17:12:54 +000042 while True:
43 try:
44 return self._execute(test, lit_config)
45 except OSError, oe:
46 if oe.errno != errno.ETXTBSY:
47 raise
48 time.sleep(0.1)
49
50 def _execute(self, test, lit_config):
Daniel Dunbarf51f0312013-02-05 21:03:25 +000051 # Extract test metadata from the test file.
Daniel Dunbarf51f0312013-02-05 21:03:25 +000052 requires = []
Eric Fiselier339bdc32014-08-18 06:43:06 +000053 unsupported = []
Justin Bogner2cfd1fe2014-09-03 06:01:52 +000054 use_verify = False
Daniel Dunbarf51f0312013-02-05 21:03:25 +000055 with open(test.getSourcePath()) as f:
56 for ln in f:
57 if 'XFAIL:' in ln:
58 items = ln[ln.index('XFAIL:') + 6:].split(',')
Daniel Dunbar019c5902013-08-21 23:06:32 +000059 test.xfails.extend([s.strip() for s in items])
Daniel Dunbarf51f0312013-02-05 21:03:25 +000060 elif 'REQUIRES:' in ln:
61 items = ln[ln.index('REQUIRES:') + 9:].split(',')
62 requires.extend([s.strip() for s in items])
Eric Fiselier339bdc32014-08-18 06:43:06 +000063 elif 'UNSUPPORTED:' in ln:
64 items = ln[ln.index('UNSUPPORTED:') + 12:].split(',')
65 unsupported.extend([s.strip() for s in items])
Justin Bogner2cfd1fe2014-09-03 06:01:52 +000066 elif 'USE_VERIFY' in ln and self.use_verify_for_fail:
67 use_verify = True
Eric Fiselier993dfb12014-07-31 22:56:52 +000068 elif not ln.strip().startswith("//") and ln.strip():
Daniel Dunbarf51f0312013-02-05 21:03:25 +000069 # Stop at the first non-empty line that is not a C++
70 # comment.
71 break
72
73 # Check that we have the required features.
74 #
75 # FIXME: For now, this is cribbed from lit.TestRunner, to avoid
76 # introducing a dependency there. What we more ideally would like to do
Daniel Dunbar019c5902013-08-21 23:06:32 +000077 # is lift the "requires" handling to be a core lit framework feature.
Daniel Dunbarf51f0312013-02-05 21:03:25 +000078 missing_required_features = [f for f in requires
79 if f not in test.config.available_features]
80 if missing_required_features:
81 return (lit.Test.UNSUPPORTED,
82 "Test requires the following features: %s" % (
83 ', '.join(missing_required_features),))
84
Eric Fiselier339bdc32014-08-18 06:43:06 +000085 unsupported_features = [f for f in unsupported
86 if f in test.config.available_features]
87 if unsupported_features:
88 return (lit.Test.UNSUPPORTED,
89 "Test is unsupported with the following features: %s" % (
90 ', '.join(unsupported_features),))
91
Daniel Dunbarf51f0312013-02-05 21:03:25 +000092 # Evaluate the test.
Justin Bogner2cfd1fe2014-09-03 06:01:52 +000093 return self._evaluate_test(test, use_verify, lit_config)
Daniel Dunbarf51f0312013-02-05 21:03:25 +000094
Eric Fiselier67945b62014-12-07 04:28:50 +000095 def _make_report(self, cmd, out, err, rc):
96 report = "Command: %s\n" % cmd
97 report += "Exit Code: %d\n" % rc
98 if out:
99 report += "Standard Output:\n--\n%s--\n" % out
100 if err:
101 report += "Standard Error:\n--\n%s--\n" % err
102 report += '\n'
103 return cmd, report, rc
104
Eric Fiselier469a4f92014-12-19 19:27:32 +0000105 def _compile(self, output_path, source_path, use_verify=False):
106 cmd = [self.cxx_under_test, '-c', '-o', output_path, source_path]
107 cmd += self.cpp_flags
Dan Albert86b75a42014-11-24 22:24:06 +0000108 if use_verify:
109 cmd += ['-Xclang', '-verify']
Eric Fiselier469a4f92014-12-19 19:27:32 +0000110 if self.use_ccache:
111 cmd = ['ccache'] + cmd
Eric Fiseliere620b5e2014-11-25 03:03:32 +0000112 out, err, rc = lit.util.executeCommand(cmd)
Eric Fiselier469a4f92014-12-19 19:27:32 +0000113 return cmd, out, err, rc
114
115 def _link(self, exec_path, object_path):
116 cmd = [self.cxx_under_test, '-o', exec_path, object_path]
117 cmd += self.cpp_flags + self.ld_flags
118 out, err, rc = lit.util.executeCommand(cmd)
119 return cmd, out, err, rc
120
121 def _compile_and_link(self, exec_path, source_path):
122 object_file = tempfile.NamedTemporaryFile(suffix=".o", delete=False)
123 object_path = object_file.name
124 object_file.close()
125 try:
126 cmd, out, err, rc = self._compile(object_path, source_path)
127 if rc != 0:
128 return cmd, out, err, rc
129 return self._link(exec_path, object_path)
130 finally:
131 try:
132 os.remove(object_path)
133 except:
134 pass
135
136 def _build(self, exec_path, source_path, compile_only=False,
137 use_verify=False):
138 if compile_only:
139 cmd, out, err, rc = self._compile(exec_path, source_path, use_verify)
140 else:
141 assert not use_verify
142 cmd, out, err, rc = self._compile_and_link(exec_path, source_path)
Eric Fiselier67945b62014-12-07 04:28:50 +0000143 return self._make_report(cmd, out, err, rc)
Dan Albert86b75a42014-11-24 22:24:06 +0000144
145 def _clean(self, exec_path):
146 os.remove(exec_path)
147
148 def _run(self, exec_path, lit_config, in_dir=None):
149 cmd = []
150 if self.exec_env:
151 cmd.append('env')
152 cmd.extend('%s=%s' % (name, value)
153 for name,value in self.exec_env.items())
154 cmd.append(exec_path)
155 if lit_config.useValgrind:
156 cmd = lit_config.valgrindArgs + cmd
Eric Fiselier67945b62014-12-07 04:28:50 +0000157 out, err, rc = lit.util.executeCommand(cmd, cwd=in_dir)
158 return self._make_report(cmd, out, err, rc)
Dan Albert86b75a42014-11-24 22:24:06 +0000159
Justin Bogner2cfd1fe2014-09-03 06:01:52 +0000160 def _evaluate_test(self, test, use_verify, lit_config):
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000161 name = test.path_in_suite[-1]
162 source_path = test.getSourcePath()
Howard Hinnant3778f272013-01-14 17:12:54 +0000163 source_dir = os.path.dirname(source_path)
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000164
165 # Check what kind of test this is.
166 assert name.endswith('.pass.cpp') or name.endswith('.fail.cpp')
167 expected_compile_fail = name.endswith('.fail.cpp')
168
169 # If this is a compile (failure) test, build it and check for failure.
170 if expected_compile_fail:
Eric Fiselier67945b62014-12-07 04:28:50 +0000171 cmd, report, rc = self._build('/dev/null', source_path,
172 compile_only=True,
173 use_verify=use_verify)
Dan Albert86b75a42014-11-24 22:24:06 +0000174 expected_rc = 0 if use_verify else 1
Justin Bogner33a2a2e2014-09-03 04:32:08 +0000175 if rc == expected_rc:
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000176 return lit.Test.PASS, ""
177 else:
Eric Fiselier67945b62014-12-07 04:28:50 +0000178 return lit.Test.FAIL, report + 'Expected compilation to fail!\n'
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000179 else:
180 exec_file = tempfile.NamedTemporaryFile(suffix="exe", delete=False)
181 exec_path = exec_file.name
182 exec_file.close()
183
184 try:
Eric Fiselier67945b62014-12-07 04:28:50 +0000185 cmd, report, rc = self._build(exec_path, source_path)
Dan Albert86b75a42014-11-24 22:24:06 +0000186 compile_cmd = cmd
187 if rc != 0:
Eric Fiselier67945b62014-12-07 04:28:50 +0000188 report += "Compilation failed unexpectedly!"
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000189 return lit.Test.FAIL, report
190
Eric Fiselier67945b62014-12-07 04:28:50 +0000191 cmd, report, rc = self._run(exec_path, lit_config,
192 source_dir)
Dan Albert86b75a42014-11-24 22:24:06 +0000193 if rc != 0:
Eric Fiselier67945b62014-12-07 04:28:50 +0000194 report = "Compiled With: %s\n%s" % (compile_cmd, report)
195 report += "Compiled test failed unexpectedly!"
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000196 return lit.Test.FAIL, report
197 finally:
198 try:
Dan Albert86b75a42014-11-24 22:24:06 +0000199 # Note that cleanup of exec_file happens in `_clean()`. If
200 # you override this, cleanup is your reponsibility.
201 self._clean(exec_path)
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000202 except:
203 pass
204 return lit.Test.PASS, ""
205
Dan Albertae2526b2014-08-21 17:30:44 +0000206
207class Configuration(object):
208 def __init__(self, lit_config, config):
209 self.lit_config = lit_config
210 self.config = config
211 self.cxx = None
212 self.src_root = None
213 self.obj_root = None
214 self.env = {}
Eric Fiseliercf82c1e2014-11-24 23:46:42 +0000215 self.compile_flags = ['-nostdinc++']
216 self.link_flags = ['-nodefaultlibs']
Dan Albertae2526b2014-08-21 17:30:44 +0000217 self.use_system_lib = False
Justin Bogner33a2a2e2014-09-03 04:32:08 +0000218 self.use_clang_verify = False
Eric Fiselier469a4f92014-12-19 19:27:32 +0000219 self.use_ccache = False
Dan Albertae2526b2014-08-21 17:30:44 +0000220
221 if platform.system() not in ('Darwin', 'FreeBSD', 'Linux'):
222 self.lit_config.fatal("unrecognized system")
223
224 def get_lit_conf(self, name, default=None):
225 val = self.lit_config.params.get(name, None)
226 if val is None:
227 val = getattr(self.config, name, None)
228 if val is None:
229 val = default
230 return val
231
Eric Fiselier9cfa8b72014-12-07 08:52:19 +0000232 def get_lit_bool(self, name, default=None):
Justin Bogner33a2a2e2014-09-03 04:32:08 +0000233 conf = self.get_lit_conf(name)
234 if conf is None:
Eric Fiselier9cfa8b72014-12-07 08:52:19 +0000235 return default
Justin Bogner33a2a2e2014-09-03 04:32:08 +0000236 if conf.lower() in ('1', 'true'):
237 return True
238 if conf.lower() in ('', '0', 'false'):
239 return False
240 self.lit_config.fatal(
241 "parameter '{}' should be true or false".format(name))
242
Dan Albertae2526b2014-08-21 17:30:44 +0000243 def configure(self):
244 self.configure_cxx()
Eric Fiselierb92da3f2014-12-06 21:13:15 +0000245 self.probe_cxx()
Dan Albertae2526b2014-08-21 17:30:44 +0000246 self.configure_triple()
247 self.configure_src_root()
248 self.configure_obj_root()
249 self.configure_use_system_lib()
Justin Bogner33a2a2e2014-09-03 04:32:08 +0000250 self.configure_use_clang_verify()
Eric Fiselier469a4f92014-12-19 19:27:32 +0000251 self.configure_ccache()
Eric Fiselierb967e322014-12-07 00:34:23 +0000252 self.configure_env()
Dan Albertae2526b2014-08-21 17:30:44 +0000253 self.configure_std_flag()
254 self.configure_compile_flags()
255 self.configure_link_flags()
256 self.configure_sanitizer()
257 self.configure_features()
Eric Fiseliercf82c1e2014-11-24 23:46:42 +0000258 # Print the final compile and link flags.
259 self.lit_config.note('Using compile flags: %s' % self.compile_flags)
260 self.lit_config.note('Using link flags: %s' % self.link_flags)
261 # Print as list to prevent "set([...])" from being printed.
262 self.lit_config.note('Using available_features: %s' %
263 list(self.config.available_features))
Dan Albertae2526b2014-08-21 17:30:44 +0000264
265 def get_test_format(self):
266 return LibcxxTestFormat(
267 self.cxx,
Justin Bogner33a2a2e2014-09-03 04:32:08 +0000268 self.use_clang_verify,
Eric Fiseliercf82c1e2014-11-24 23:46:42 +0000269 cpp_flags=self.compile_flags,
270 ld_flags=self.link_flags,
Eric Fiselier469a4f92014-12-19 19:27:32 +0000271 exec_env=self.env,
272 use_ccache=self.use_ccache)
Dan Albertae2526b2014-08-21 17:30:44 +0000273
274 def configure_cxx(self):
275 # Gather various compiler parameters.
276 self.cxx = self.get_lit_conf('cxx_under_test')
277
278 # If no specific cxx_under_test was given, attempt to infer it as
279 # clang++.
280 if self.cxx is None:
281 clangxx = lit.util.which('clang++',
282 self.config.environment['PATH'])
283 if clangxx:
284 self.cxx = clangxx
285 self.lit_config.note(
286 "inferred cxx_under_test as: %r" % self.cxx)
287 if not self.cxx:
288 self.lit_config.fatal('must specify user parameter cxx_under_test '
289 '(e.g., --param=cxx_under_test=clang++)')
290
Eric Fiselierb92da3f2014-12-06 21:13:15 +0000291 def probe_cxx(self):
292 # Dump all of the predefined macros
293 dump_macro_cmd = [self.cxx, '-dM', '-E', '-x', 'c++', '/dev/null']
294 out, err, rc = lit.util.executeCommand(dump_macro_cmd)
295 if rc != 0:
296 self.lit_config.warning('Failed to dump macros for compiler: %s' %
297 self.cxx)
298 return
299 # Create a dict containing all the predefined macros.
300 macros = {}
301 lines = [l.strip() for l in out.split('\n') if l.strip()]
302 for l in lines:
303 assert l.startswith('#define ')
304 l = l[len('#define '):]
305 macro, _, value = l.partition(' ')
306 macros[macro] = value
307 # Add compiler information to available features.
308 compiler_name = None
309 major_ver = minor_ver = None
310 if '__clang__' in macros.keys():
311 compiler_name = 'clang'
312 # Treat apple's llvm fork differently.
Eric Fiselier9db46352014-12-06 22:49:38 +0000313 if '__apple_build_version__' in macros.keys():
Eric Fiselierb92da3f2014-12-06 21:13:15 +0000314 compiler_name = 'apple-clang'
315 major_ver = macros['__clang_major__']
316 minor_ver = macros['__clang_minor__']
317 elif '__GNUC__' in macros.keys():
318 compiler_name = 'gcc'
319 major_ver = macros['__GNUC__']
320 minor_ver = macros['__GNUC_MINOR__']
321 else:
322 self.lit_config.warning('Failed to detect compiler for cxx: %s' %
323 self.cxx)
324 if compiler_name is not None:
325 self.config.available_features.add(compiler_name)
326 self.config.available_features.add('%s-%s.%s' % (
327 compiler_name, major_ver, minor_ver))
328
Dan Albertae2526b2014-08-21 17:30:44 +0000329 def configure_src_root(self):
330 self.src_root = self.get_lit_conf(
331 'libcxx_src_root', os.path.dirname(self.config.test_source_root))
332
333 def configure_obj_root(self):
334 self.obj_root = self.get_lit_conf('libcxx_obj_root', self.src_root)
335
336 def configure_use_system_lib(self):
337 # This test suite supports testing against either the system library or
338 # the locally built one; the former mode is useful for testing ABI
339 # compatibility between the current headers and a shipping dynamic
340 # library.
Justin Bogner33a2a2e2014-09-03 04:32:08 +0000341 self.use_system_lib = self.get_lit_bool('use_system_lib')
342 if self.use_system_lib is None:
Dan Albertae2526b2014-08-21 17:30:44 +0000343 # Default to testing against the locally built libc++ library.
344 self.use_system_lib = False
345 self.lit_config.note(
346 "inferred use_system_lib as: %r" % self.use_system_lib)
347
Justin Bogner33a2a2e2014-09-03 04:32:08 +0000348 def configure_use_clang_verify(self):
349 '''If set, run clang with -verify on failing tests.'''
350 self.use_clang_verify = self.get_lit_bool('use_clang_verify')
351 if self.use_clang_verify is None:
352 # TODO: Default this to True when using clang.
353 self.use_clang_verify = False
354 self.lit_config.note(
355 "inferred use_clang_verify as: %r" % self.use_clang_verify)
356
Eric Fiselier469a4f92014-12-19 19:27:32 +0000357 def configure_ccache(self):
358 self.use_ccache = self.get_lit_bool('use_ccache', False)
359 if self.use_ccache:
360 self.lit_config.note('enabling ccache')
361
Dan Albertae2526b2014-08-21 17:30:44 +0000362 def configure_features(self):
Jonathan Roelofsb352db72014-09-05 19:03:46 +0000363 additional_features = self.get_lit_conf('additional_features')
364 if additional_features:
365 for f in additional_features.split(','):
366 self.config.available_features.add(f.strip())
Jonathan Roelofs3547c542014-09-05 17:21:57 +0000367
Dan Albertae2526b2014-08-21 17:30:44 +0000368 # Figure out which of the required locales we support
369 locales = {
370 'Darwin': {
371 'en_US.UTF-8': 'en_US.UTF-8',
372 'cs_CZ.ISO8859-2': 'cs_CZ.ISO8859-2',
373 'fr_FR.UTF-8': 'fr_FR.UTF-8',
374 'fr_CA.ISO8859-1': 'cs_CZ.ISO8859-1',
375 'ru_RU.UTF-8': 'ru_RU.UTF-8',
376 'zh_CN.UTF-8': 'zh_CN.UTF-8',
377 },
378 'FreeBSD': {
379 'en_US.UTF-8': 'en_US.UTF-8',
380 'cs_CZ.ISO8859-2': 'cs_CZ.ISO8859-2',
381 'fr_FR.UTF-8': 'fr_FR.UTF-8',
382 'fr_CA.ISO8859-1': 'fr_CA.ISO8859-1',
383 'ru_RU.UTF-8': 'ru_RU.UTF-8',
384 'zh_CN.UTF-8': 'zh_CN.UTF-8',
385 },
386 'Linux': {
387 'en_US.UTF-8': 'en_US.UTF-8',
388 'cs_CZ.ISO8859-2': 'cs_CZ.ISO-8859-2',
389 'fr_FR.UTF-8': 'fr_FR.UTF-8',
390 'fr_CA.ISO8859-1': 'fr_CA.ISO-8859-1',
391 'ru_RU.UTF-8': 'ru_RU.UTF-8',
392 'zh_CN.UTF-8': 'zh_CN.UTF-8',
393 },
394 'Windows': {
395 'en_US.UTF-8': 'English_United States.1252',
396 'cs_CZ.ISO8859-2': 'Czech_Czech Republic.1250',
397 'fr_FR.UTF-8': 'French_France.1252',
398 'fr_CA.ISO8859-1': 'French_Canada.1252',
399 'ru_RU.UTF-8': 'Russian_Russia.1251',
400 'zh_CN.UTF-8': 'Chinese_China.936',
401 },
402 }
403
404 default_locale = locale.setlocale(locale.LC_ALL)
405 for feature, loc in locales[platform.system()].items():
406 try:
407 locale.setlocale(locale.LC_ALL, loc)
Eric Fiselier561dfb52014-08-23 04:02:21 +0000408 self.config.available_features.add('locale.{0}'.format(feature))
Dan Albertae2526b2014-08-21 17:30:44 +0000409 except:
Eric Fiselier561dfb52014-08-23 04:02:21 +0000410 self.lit_config.warning('The locale {0} is not supported by '
Dan Albertae2526b2014-08-21 17:30:44 +0000411 'your platform. Some tests will be '
412 'unsupported.'.format(loc))
413 locale.setlocale(locale.LC_ALL, default_locale)
414
415 # Write an "available feature" that combines the triple when
416 # use_system_lib is enabled. This is so that we can easily write XFAIL
417 # markers for tests that are known to fail with versions of libc++ as
418 # were shipped with a particular triple.
419 if self.use_system_lib:
Dan Albertae2526b2014-08-21 17:30:44 +0000420 self.config.available_features.add(
Eric Fiselierbb191412014-10-27 22:14:25 +0000421 'with_system_lib=%s' % self.config.target_triple)
Dan Albertae2526b2014-08-21 17:30:44 +0000422
Eric Fiselierb9f99732014-12-06 21:02:58 +0000423 # TODO 6/12/2014: Remove these once the buildmaster restarts.
424 # Removing before will break the bot that tests libcpp-has-no-threads.
425 if 'libcpp-has-no-threads' in self.config.available_features \
426 and '-D_LIBCPP_HAS_NO_THREADS' not in self.compile_flags:
Jonathan Roelofs3547c542014-09-05 17:21:57 +0000427 self.compile_flags += ['-D_LIBCPP_HAS_NO_THREADS']
428
Eric Fiselierb9f99732014-12-06 21:02:58 +0000429 if 'libcpp-has-no-monotonic-clock' in self.config.available_features \
430 and '-D_LIBCPP_HAS_NO_MONOTONIC_CLOCK' not in self.compile_flags:
Jonathan Roelofs3547c542014-09-05 17:21:57 +0000431 self.compile_flags += ['-D_LIBCPP_HAS_NO_MONOTONIC_CLOCK']
432
Eric Fiselier548415172014-11-21 08:02:38 +0000433 # Some linux distributions have different locale data than others.
434 # Insert the distributions name and name-version into the available
435 # features to allow tests to XFAIL on them.
436 if sys.platform.startswith('linux'):
Eric Fiseliera77ccfe2014-11-21 08:54:35 +0000437 name, ver, _ = platform.linux_distribution()
438 name = name.lower().strip()
439 ver = ver.lower().strip()
440 self.config.available_features.add(name)
441 self.config.available_features.add('%s-%s' % (name, ver))
Eric Fiselier548415172014-11-21 08:02:38 +0000442
Jonathan Roelofs256ecc32014-12-11 18:35:36 +0000443 # Simulator testing can take a really long time for some of these tests
444 # so add a feature check so we can REQUIRES: long_tests in them
445 self.long_tests = self.get_lit_bool('long_tests')
446 if self.long_tests is None:
447 # Default to running long tests.
448 self.long_tests = True
449 self.lit_config.note(
450 "inferred long_tests as: %r" % self.long_tests)
451
452 if self.long_tests:
453 self.config.available_features.add('long_tests')
454
Dan Albertae2526b2014-08-21 17:30:44 +0000455 def configure_compile_flags(self):
456 # Configure extra compiler flags.
457 self.compile_flags += ['-I' + self.src_root + '/include',
458 '-I' + self.src_root + '/test/support']
Eric Fiselier460b2242014-10-23 22:57:56 +0000459 if sys.platform.startswith('linux'):
Eric Fiselier6f9da552014-10-18 01:15:17 +0000460 self.compile_flags += ['-D__STDC_FORMAT_MACROS',
461 '-D__STDC_LIMIT_MACROS',
462 '-D__STDC_CONSTANT_MACROS']
Eric Fiselier7a687492014-12-12 02:36:23 +0000463 enable_exceptions = self.get_lit_bool('enable_exceptions', True)
464 if enable_exceptions:
465 self.config.available_features.add('exceptions')
466 else:
467 self.compile_flags += ['-fno-exceptions']
468 enable_rtti = self.get_lit_bool('enable_rtti', True)
469 if enable_rtti:
470 self.config.available_features.add('rtti')
471 else:
472 self.compile_flags += ['-fno-rtti', '-D_LIBCPP_NO_RTTI']
Eric Fiselier0e8f0d92014-12-12 03:12:18 +0000473 enable_32bit = self.get_lit_bool('enable_32bit', False)
474 if enable_32bit:
475 self.compile_flags += ['-m32']
Eric Fiselierb9f99732014-12-06 21:02:58 +0000476 # Configure threading features.
Eric Fiselier9cfa8b72014-12-07 08:52:19 +0000477 enable_threads = self.get_lit_bool('enable_threads', True)
478 enable_monotonic_clock = self.get_lit_bool('enable_monotonic_clock', True)
Eric Fiselierb9f99732014-12-06 21:02:58 +0000479 if not enable_threads:
480 self.compile_flags += ['-D_LIBCPP_HAS_NO_THREADS']
481 self.config.available_features.add('libcpp-has-no-threads')
482 if not enable_monotonic_clock:
483 self.compile_flags += ['-D_LIBCPP_HAS_NO_MONOTONIC_CLOCK']
484 self.config.available_features.add('libcpp-has-no-monotonic-clock')
485 elif not enable_monotonic_clock:
486 self.lit_config.fatal('enable_monotonic_clock cannot be false when'
487 ' enable_threads is true.')
Dan Albertae2526b2014-08-21 17:30:44 +0000488
Eric Fiselier7a687492014-12-12 02:36:23 +0000489
Dan Albertae2526b2014-08-21 17:30:44 +0000490 def configure_link_flags(self):
Eric Fiselier6f9da552014-10-18 01:15:17 +0000491 # Configure library search paths
Eric Fiseliera63c1492014-10-19 00:42:41 +0000492 abi_library_path = self.get_lit_conf('abi_library_path', '')
Eric Fiseliera63c1492014-10-19 00:42:41 +0000493 if not self.use_system_lib:
Eric Fiseliera1c73a62014-12-06 22:08:51 +0000494 self.link_flags += ['-L' + self.obj_root + '/lib']
495 self.link_flags += ['-Wl,-rpath,' + self.obj_root + '/lib']
Eric Fiseliera63c1492014-10-19 00:42:41 +0000496 if abi_library_path:
497 self.link_flags += ['-L' + abi_library_path,
Eric Fiseliera1c73a62014-12-06 22:08:51 +0000498 '-Wl,-rpath,' + abi_library_path]
Eric Fiselier6f9da552014-10-18 01:15:17 +0000499 # Configure libraries
500 self.link_flags += ['-lc++']
Dan Albertae2526b2014-08-21 17:30:44 +0000501 link_flags_str = self.get_lit_conf('link_flags')
502 if link_flags_str is None:
503 cxx_abi = self.get_lit_conf('cxx_abi', 'libcxxabi')
504 if cxx_abi == 'libstdc++':
505 self.link_flags += ['-lstdc++']
506 elif cxx_abi == 'libsupc++':
507 self.link_flags += ['-lsupc++']
508 elif cxx_abi == 'libcxxabi':
509 self.link_flags += ['-lc++abi']
510 elif cxx_abi == 'libcxxrt':
511 self.link_flags += ['-lcxxrt']
512 elif cxx_abi == 'none':
513 pass
514 else:
515 self.lit_config.fatal(
516 'C++ ABI setting %s unsupported for tests' % cxx_abi)
517
518 if sys.platform == 'darwin':
519 self.link_flags += ['-lSystem']
Eric Fiselier460b2242014-10-23 22:57:56 +0000520 elif sys.platform.startswith('linux'):
Dan Albertae2526b2014-08-21 17:30:44 +0000521 self.link_flags += ['-lgcc_eh', '-lc', '-lm', '-lpthread',
522 '-lrt', '-lgcc_s']
523 elif sys.platform.startswith('freebsd'):
524 self.link_flags += ['-lc', '-lm', '-pthread', '-lgcc_s']
525 else:
Eric Fiselier6f9da552014-10-18 01:15:17 +0000526 self.lit_config.fatal("unrecognized system: %r" % sys.platform)
Dan Albertae2526b2014-08-21 17:30:44 +0000527
Dan Albertae2526b2014-08-21 17:30:44 +0000528 if link_flags_str:
529 self.link_flags += shlex.split(link_flags_str)
530
Dan Albertae2526b2014-08-21 17:30:44 +0000531
532 def configure_std_flag(self):
533 # Try and get the std version from the command line. Fall back to
534 # default given in lit.site.cfg is not present. If default is not
535 # present then force c++11.
536 std = self.get_lit_conf('std')
537 if std is None:
538 std = 'c++11'
539 self.lit_config.note('using default std: \'-std=c++11\'')
Eric Fiselier561dfb52014-08-23 04:02:21 +0000540 self.compile_flags += ['-std={0}'.format(std)]
Dan Albertae2526b2014-08-21 17:30:44 +0000541 self.config.available_features.add(std)
542
543 def configure_sanitizer(self):
544 san = self.get_lit_conf('llvm_use_sanitizer', '').strip()
545 if san:
Eric Fiselierb941b502014-11-14 02:47:08 +0000546 # Search for llvm-symbolizer along the compiler path first
547 # and then along the PATH env variable.
548 symbolizer_search_paths = os.environ.get('PATH', '')
549 cxx_path = lit.util.which(self.cxx)
550 if cxx_path is not None:
551 symbolizer_search_paths = os.path.dirname(cxx_path) + \
552 os.pathsep + symbolizer_search_paths
553 llvm_symbolizer = lit.util.which('llvm-symbolizer',
554 symbolizer_search_paths)
555 # Setup the sanitizer compile flags
Eric Fiselier0425c7c2014-11-14 22:18:03 +0000556 self.compile_flags += ['-g', '-fno-omit-frame-pointer']
Eric Fiselier460b2242014-10-23 22:57:56 +0000557 if sys.platform.startswith('linux'):
Eric Fiselier062e6ee2014-10-23 02:54:15 +0000558 self.link_flags += ['-ldl']
Dan Albertae2526b2014-08-21 17:30:44 +0000559 if san == 'Address':
560 self.compile_flags += ['-fsanitize=address']
Eric Fiselierb941b502014-11-14 02:47:08 +0000561 if llvm_symbolizer is not None:
562 self.env['ASAN_SYMBOLIZER_PATH'] = llvm_symbolizer
Dan Albertae2526b2014-08-21 17:30:44 +0000563 self.config.available_features.add('asan')
564 elif san == 'Memory' or san == 'MemoryWithOrigins':
565 self.compile_flags += ['-fsanitize=memory']
566 if san == 'MemoryWithOrigins':
567 self.compile_flags += ['-fsanitize-memory-track-origins']
Eric Fiselierb941b502014-11-14 02:47:08 +0000568 if llvm_symbolizer is not None:
569 self.env['MSAN_SYMBOLIZER_PATH'] = llvm_symbolizer
Dan Albertae2526b2014-08-21 17:30:44 +0000570 self.config.available_features.add('msan')
Eric Fiselier04c1b742014-10-16 23:21:59 +0000571 elif san == 'Undefined':
572 self.compile_flags += ['-fsanitize=undefined',
573 '-fno-sanitize=vptr,function',
Eric Fiselierbc2d6322014-11-14 02:07:52 +0000574 '-fno-sanitize-recover', '-O3']
Eric Fiselier04c1b742014-10-16 23:21:59 +0000575 self.config.available_features.add('ubsan')
Eric Fiselier9b681f62014-11-18 21:26:45 +0000576 elif san == 'Thread':
577 self.compile_flags += ['-fsanitize=thread']
578 self.config.available_features.add('tsan')
Dan Albertae2526b2014-08-21 17:30:44 +0000579 else:
580 self.lit_config.fatal('unsupported value for '
Eric Fiselier561dfb52014-08-23 04:02:21 +0000581 'libcxx_use_san: {0}'.format(san))
Dan Albertae2526b2014-08-21 17:30:44 +0000582
583 def configure_triple(self):
584 # Get or infer the target triple.
585 self.config.target_triple = self.get_lit_conf('target_triple')
586 # If no target triple was given, try to infer it from the compiler
587 # under test.
588 if not self.config.target_triple:
Eric Fiselierbb191412014-10-27 22:14:25 +0000589 target_triple = lit.util.capture(
Dan Albertae2526b2014-08-21 17:30:44 +0000590 [self.cxx, '-dumpmachine']).strip()
Eric Fiselierbb191412014-10-27 22:14:25 +0000591 # Drop sub-major version components from the triple, because the
592 # current XFAIL handling expects exact matches for feature checks.
Eric Fiselierd6b46b42014-10-28 18:03:38 +0000593 # Example: x86_64-apple-darwin14.0.0 -> x86_64-apple-darwin14
Eric Fiselierbb191412014-10-27 22:14:25 +0000594 # The 5th group handles triples greater than 3 parts
595 # (ex x86_64-pc-linux-gnu).
596 target_triple = re.sub(r'([^-]+)-([^-]+)-([^.]+)([^-]*)(.*)',
597 r'\1-\2-\3\5', target_triple)
598 # linux-gnu is needed in the triple to properly identify linuxes
599 # that use GLIBC. Handle redhat and opensuse triples as special
600 # cases and append the missing `-gnu` portion.
601 if target_triple.endswith('redhat-linux') or \
602 target_triple.endswith('suse-linux'):
603 target_triple += '-gnu'
604 self.config.target_triple = target_triple
Dan Albertae2526b2014-08-21 17:30:44 +0000605 self.lit_config.note(
606 "inferred target_triple as: %r" % self.config.target_triple)
607
Eric Fiselierb967e322014-12-07 00:34:23 +0000608 def configure_env(self):
609 if sys.platform == 'darwin' and not self.use_system_lib:
610 self.env['DYLD_LIBRARY_PATH'] = os.path.join(self.obj_root, 'lib')
Dan Albertae2526b2014-08-21 17:30:44 +0000611
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000612# name: The name of this test suite.
613config.name = 'libc++'
614
615# suffixes: A list of file extensions to treat as test files.
616config.suffixes = ['.cpp']
617
618# test_source_root: The root path where tests are located.
619config.test_source_root = os.path.dirname(__file__)
620
Dan Albert86b75a42014-11-24 22:24:06 +0000621cfg_variant = getattr(config, 'configuration_variant', '')
622if cfg_variant:
623 print 'Using configuration variant: %s' % cfg_variant
624
625# Construct an object of the type named `<VARIANT>Configuration`.
626configuration = globals()['%sConfiguration' % cfg_variant](lit_config, config)
Dan Albertae2526b2014-08-21 17:30:44 +0000627configuration.configure()
628config.test_format = configuration.get_test_format()