blob: e79f22209ded74a7b3038da58411784fb00337e0 [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,
32 cpp_flags, ld_flags, exec_env):
Daniel Dunbarbc9a8482010-09-15 04:11:29 +000033 self.cxx_under_test = cxx_under_test
Justin Bogner33a2a2e2014-09-03 04:32:08 +000034 self.use_verify_for_fail = use_verify_for_fail
Daniel Dunbar5f09d9e02010-09-15 04:31:58 +000035 self.cpp_flags = list(cpp_flags)
36 self.ld_flags = list(ld_flags)
Daniel Dunbar84958712013-02-05 18:03:49 +000037 self.exec_env = dict(exec_env)
Daniel Dunbar42ea4632010-09-15 03:57:04 +000038
Daniel Dunbar42ea4632010-09-15 03:57:04 +000039 def execute(self, test, lit_config):
Howard Hinnant3778f272013-01-14 17:12:54 +000040 while True:
41 try:
42 return self._execute(test, lit_config)
43 except OSError, oe:
44 if oe.errno != errno.ETXTBSY:
45 raise
46 time.sleep(0.1)
47
48 def _execute(self, test, lit_config):
Daniel Dunbarf51f0312013-02-05 21:03:25 +000049 # Extract test metadata from the test file.
Daniel Dunbarf51f0312013-02-05 21:03:25 +000050 requires = []
Eric Fiselier339bdc32014-08-18 06:43:06 +000051 unsupported = []
Justin Bogner2cfd1fe2014-09-03 06:01:52 +000052 use_verify = False
Daniel Dunbarf51f0312013-02-05 21:03:25 +000053 with open(test.getSourcePath()) as f:
54 for ln in f:
55 if 'XFAIL:' in ln:
56 items = ln[ln.index('XFAIL:') + 6:].split(',')
Daniel Dunbar019c5902013-08-21 23:06:32 +000057 test.xfails.extend([s.strip() for s in items])
Daniel Dunbarf51f0312013-02-05 21:03:25 +000058 elif 'REQUIRES:' in ln:
59 items = ln[ln.index('REQUIRES:') + 9:].split(',')
60 requires.extend([s.strip() for s in items])
Eric Fiselier339bdc32014-08-18 06:43:06 +000061 elif 'UNSUPPORTED:' in ln:
62 items = ln[ln.index('UNSUPPORTED:') + 12:].split(',')
63 unsupported.extend([s.strip() for s in items])
Justin Bogner2cfd1fe2014-09-03 06:01:52 +000064 elif 'USE_VERIFY' in ln and self.use_verify_for_fail:
65 use_verify = True
Eric Fiselier993dfb12014-07-31 22:56:52 +000066 elif not ln.strip().startswith("//") and ln.strip():
Daniel Dunbarf51f0312013-02-05 21:03:25 +000067 # Stop at the first non-empty line that is not a C++
68 # comment.
69 break
70
71 # Check that we have the required features.
72 #
73 # FIXME: For now, this is cribbed from lit.TestRunner, to avoid
74 # introducing a dependency there. What we more ideally would like to do
Daniel Dunbar019c5902013-08-21 23:06:32 +000075 # is lift the "requires" handling to be a core lit framework feature.
Daniel Dunbarf51f0312013-02-05 21:03:25 +000076 missing_required_features = [f for f in requires
77 if f not in test.config.available_features]
78 if missing_required_features:
79 return (lit.Test.UNSUPPORTED,
80 "Test requires the following features: %s" % (
81 ', '.join(missing_required_features),))
82
Eric Fiselier339bdc32014-08-18 06:43:06 +000083 unsupported_features = [f for f in unsupported
84 if f in test.config.available_features]
85 if unsupported_features:
86 return (lit.Test.UNSUPPORTED,
87 "Test is unsupported with the following features: %s" % (
88 ', '.join(unsupported_features),))
89
Daniel Dunbarf51f0312013-02-05 21:03:25 +000090 # Evaluate the test.
Justin Bogner2cfd1fe2014-09-03 06:01:52 +000091 return self._evaluate_test(test, use_verify, lit_config)
Daniel Dunbarf51f0312013-02-05 21:03:25 +000092
Dan Albert86b75a42014-11-24 22:24:06 +000093 def _build(self, exec_path, source_path, compile_only=False,
94 use_verify=False):
95 cmd = [self.cxx_under_test, '-o', exec_path,
96 source_path] + self.cpp_flags
97
98 if compile_only:
99 cmd += ['-c']
100 else:
101 cmd += self.ld_flags
102
103 if use_verify:
104 cmd += ['-Xclang', '-verify']
105
Eric Fiseliere620b5e2014-11-25 03:03:32 +0000106 out, err, rc = lit.util.executeCommand(cmd)
Dan Albert86b75a42014-11-24 22:24:06 +0000107 return cmd, out, err, rc
108
109 def _clean(self, exec_path):
110 os.remove(exec_path)
111
112 def _run(self, exec_path, lit_config, in_dir=None):
113 cmd = []
114 if self.exec_env:
115 cmd.append('env')
116 cmd.extend('%s=%s' % (name, value)
117 for name,value in self.exec_env.items())
118 cmd.append(exec_path)
119 if lit_config.useValgrind:
120 cmd = lit_config.valgrindArgs + cmd
Eric Fiseliere620b5e2014-11-25 03:03:32 +0000121 out, err, exitCode = lit.util.executeCommand(cmd, cwd=in_dir)
Dan Albert86b75a42014-11-24 22:24:06 +0000122 return cmd, out, err, exitCode
123
Justin Bogner2cfd1fe2014-09-03 06:01:52 +0000124 def _evaluate_test(self, test, use_verify, lit_config):
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000125 name = test.path_in_suite[-1]
126 source_path = test.getSourcePath()
Howard Hinnant3778f272013-01-14 17:12:54 +0000127 source_dir = os.path.dirname(source_path)
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000128
129 # Check what kind of test this is.
130 assert name.endswith('.pass.cpp') or name.endswith('.fail.cpp')
131 expected_compile_fail = name.endswith('.fail.cpp')
132
133 # If this is a compile (failure) test, build it and check for failure.
134 if expected_compile_fail:
Dan Albert86b75a42014-11-24 22:24:06 +0000135 cmd, out, err, rc = self._build('/dev/null', source_path,
136 compile_only=True,
137 use_verify=use_verify)
138 expected_rc = 0 if use_verify else 1
Justin Bogner33a2a2e2014-09-03 04:32:08 +0000139 if rc == expected_rc:
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000140 return lit.Test.PASS, ""
141 else:
142 report = """Command: %s\n""" % ' '.join(["'%s'" % a
143 for a in cmd])
Justin Bogner33a2a2e2014-09-03 04:32:08 +0000144 report += """Exit Code: %d\n""" % rc
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000145 if out:
146 report += """Standard Output:\n--\n%s--""" % out
147 if err:
148 report += """Standard Error:\n--\n%s--""" % err
149 report += "\n\nExpected compilation to fail!"
Daniel Dunbar5f09d9e02010-09-15 04:31:58 +0000150 return lit.Test.FAIL, report
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000151 else:
152 exec_file = tempfile.NamedTemporaryFile(suffix="exe", delete=False)
153 exec_path = exec_file.name
154 exec_file.close()
155
156 try:
Dan Albert86b75a42014-11-24 22:24:06 +0000157 cmd, out, err, rc = self._build(exec_path, source_path)
158 compile_cmd = cmd
159 if rc != 0:
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000160 report = """Command: %s\n""" % ' '.join(["'%s'" % a
161 for a in cmd])
Dan Albert86b75a42014-11-24 22:24:06 +0000162 report += """Exit Code: %d\n""" % rc
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000163 if out:
164 report += """Standard Output:\n--\n%s--""" % out
165 if err:
166 report += """Standard Error:\n--\n%s--""" % err
167 report += "\n\nCompilation failed unexpectedly!"
168 return lit.Test.FAIL, report
169
Dan Albert86b75a42014-11-24 22:24:06 +0000170 cmd, out, err, rc = self._run(exec_path, lit_config,
171 source_dir)
172 if rc != 0:
Daniel Dunbar62b94392013-02-12 19:28:51 +0000173 report = """Compiled With: %s\n""" % \
174 ' '.join(["'%s'" % a for a in compile_cmd])
175 report += """Command: %s\n""" % \
176 ' '.join(["'%s'" % a for a in cmd])
Dan Albert86b75a42014-11-24 22:24:06 +0000177 report += """Exit Code: %d\n""" % rc
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000178 if out:
179 report += """Standard Output:\n--\n%s--""" % out
180 if err:
181 report += """Standard Error:\n--\n%s--""" % err
182 report += "\n\nCompiled test failed unexpectedly!"
183 return lit.Test.FAIL, report
184 finally:
185 try:
Dan Albert86b75a42014-11-24 22:24:06 +0000186 # Note that cleanup of exec_file happens in `_clean()`. If
187 # you override this, cleanup is your reponsibility.
188 self._clean(exec_path)
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000189 except:
190 pass
191 return lit.Test.PASS, ""
192
Dan Albertae2526b2014-08-21 17:30:44 +0000193
194class Configuration(object):
195 def __init__(self, lit_config, config):
196 self.lit_config = lit_config
197 self.config = config
198 self.cxx = None
199 self.src_root = None
200 self.obj_root = None
201 self.env = {}
Eric Fiseliercf82c1e2014-11-24 23:46:42 +0000202 self.compile_flags = ['-nostdinc++']
203 self.link_flags = ['-nodefaultlibs']
Dan Albertae2526b2014-08-21 17:30:44 +0000204 self.use_system_lib = False
Justin Bogner33a2a2e2014-09-03 04:32:08 +0000205 self.use_clang_verify = False
Dan Albertae2526b2014-08-21 17:30:44 +0000206
207 if platform.system() not in ('Darwin', 'FreeBSD', 'Linux'):
208 self.lit_config.fatal("unrecognized system")
209
210 def get_lit_conf(self, name, default=None):
211 val = self.lit_config.params.get(name, None)
212 if val is None:
213 val = getattr(self.config, name, None)
214 if val is None:
215 val = default
216 return val
217
Justin Bogner33a2a2e2014-09-03 04:32:08 +0000218 def get_lit_bool(self, name):
219 conf = self.get_lit_conf(name)
220 if conf is None:
221 return None
222 if conf.lower() in ('1', 'true'):
223 return True
224 if conf.lower() in ('', '0', 'false'):
225 return False
226 self.lit_config.fatal(
227 "parameter '{}' should be true or false".format(name))
228
Dan Albertae2526b2014-08-21 17:30:44 +0000229 def configure(self):
230 self.configure_cxx()
Eric Fiselierb92da3f2014-12-06 21:13:15 +0000231 self.probe_cxx()
Dan Albertae2526b2014-08-21 17:30:44 +0000232 self.configure_triple()
233 self.configure_src_root()
234 self.configure_obj_root()
235 self.configure_use_system_lib()
Justin Bogner33a2a2e2014-09-03 04:32:08 +0000236 self.configure_use_clang_verify()
Dan Albertae2526b2014-08-21 17:30:44 +0000237 self.configure_env()
238 self.configure_std_flag()
239 self.configure_compile_flags()
240 self.configure_link_flags()
241 self.configure_sanitizer()
242 self.configure_features()
Eric Fiseliercf82c1e2014-11-24 23:46:42 +0000243 # Print the final compile and link flags.
244 self.lit_config.note('Using compile flags: %s' % self.compile_flags)
245 self.lit_config.note('Using link flags: %s' % self.link_flags)
246 # Print as list to prevent "set([...])" from being printed.
247 self.lit_config.note('Using available_features: %s' %
248 list(self.config.available_features))
Dan Albertae2526b2014-08-21 17:30:44 +0000249
250 def get_test_format(self):
251 return LibcxxTestFormat(
252 self.cxx,
Justin Bogner33a2a2e2014-09-03 04:32:08 +0000253 self.use_clang_verify,
Eric Fiseliercf82c1e2014-11-24 23:46:42 +0000254 cpp_flags=self.compile_flags,
255 ld_flags=self.link_flags,
Dan Albertae2526b2014-08-21 17:30:44 +0000256 exec_env=self.env)
257
258 def configure_cxx(self):
259 # Gather various compiler parameters.
260 self.cxx = self.get_lit_conf('cxx_under_test')
261
262 # If no specific cxx_under_test was given, attempt to infer it as
263 # clang++.
264 if self.cxx is None:
265 clangxx = lit.util.which('clang++',
266 self.config.environment['PATH'])
267 if clangxx:
268 self.cxx = clangxx
269 self.lit_config.note(
270 "inferred cxx_under_test as: %r" % self.cxx)
271 if not self.cxx:
272 self.lit_config.fatal('must specify user parameter cxx_under_test '
273 '(e.g., --param=cxx_under_test=clang++)')
274
Eric Fiselierb92da3f2014-12-06 21:13:15 +0000275 def probe_cxx(self):
276 # Dump all of the predefined macros
277 dump_macro_cmd = [self.cxx, '-dM', '-E', '-x', 'c++', '/dev/null']
278 out, err, rc = lit.util.executeCommand(dump_macro_cmd)
279 if rc != 0:
280 self.lit_config.warning('Failed to dump macros for compiler: %s' %
281 self.cxx)
282 return
283 # Create a dict containing all the predefined macros.
284 macros = {}
285 lines = [l.strip() for l in out.split('\n') if l.strip()]
286 for l in lines:
287 assert l.startswith('#define ')
288 l = l[len('#define '):]
289 macro, _, value = l.partition(' ')
290 macros[macro] = value
291 # Add compiler information to available features.
292 compiler_name = None
293 major_ver = minor_ver = None
294 if '__clang__' in macros.keys():
295 compiler_name = 'clang'
296 # Treat apple's llvm fork differently.
297 if '__apple_build_type__' in macros.keys():
298 compiler_name = 'apple-clang'
299 major_ver = macros['__clang_major__']
300 minor_ver = macros['__clang_minor__']
301 elif '__GNUC__' in macros.keys():
302 compiler_name = 'gcc'
303 major_ver = macros['__GNUC__']
304 minor_ver = macros['__GNUC_MINOR__']
305 else:
306 self.lit_config.warning('Failed to detect compiler for cxx: %s' %
307 self.cxx)
308 if compiler_name is not None:
309 self.config.available_features.add(compiler_name)
310 self.config.available_features.add('%s-%s.%s' % (
311 compiler_name, major_ver, minor_ver))
312
Dan Albertae2526b2014-08-21 17:30:44 +0000313 def configure_src_root(self):
314 self.src_root = self.get_lit_conf(
315 'libcxx_src_root', os.path.dirname(self.config.test_source_root))
316
317 def configure_obj_root(self):
318 self.obj_root = self.get_lit_conf('libcxx_obj_root', self.src_root)
319
320 def configure_use_system_lib(self):
321 # This test suite supports testing against either the system library or
322 # the locally built one; the former mode is useful for testing ABI
323 # compatibility between the current headers and a shipping dynamic
324 # library.
Justin Bogner33a2a2e2014-09-03 04:32:08 +0000325 self.use_system_lib = self.get_lit_bool('use_system_lib')
326 if self.use_system_lib is None:
Dan Albertae2526b2014-08-21 17:30:44 +0000327 # Default to testing against the locally built libc++ library.
328 self.use_system_lib = False
329 self.lit_config.note(
330 "inferred use_system_lib as: %r" % self.use_system_lib)
331
Justin Bogner33a2a2e2014-09-03 04:32:08 +0000332 def configure_use_clang_verify(self):
333 '''If set, run clang with -verify on failing tests.'''
334 self.use_clang_verify = self.get_lit_bool('use_clang_verify')
335 if self.use_clang_verify is None:
336 # TODO: Default this to True when using clang.
337 self.use_clang_verify = False
338 self.lit_config.note(
339 "inferred use_clang_verify as: %r" % self.use_clang_verify)
340
Dan Albertae2526b2014-08-21 17:30:44 +0000341 def configure_features(self):
Jonathan Roelofsb352db72014-09-05 19:03:46 +0000342 additional_features = self.get_lit_conf('additional_features')
343 if additional_features:
344 for f in additional_features.split(','):
345 self.config.available_features.add(f.strip())
Jonathan Roelofs3547c542014-09-05 17:21:57 +0000346
Dan Albertae2526b2014-08-21 17:30:44 +0000347 # Figure out which of the required locales we support
348 locales = {
349 'Darwin': {
350 'en_US.UTF-8': 'en_US.UTF-8',
351 'cs_CZ.ISO8859-2': 'cs_CZ.ISO8859-2',
352 'fr_FR.UTF-8': 'fr_FR.UTF-8',
353 'fr_CA.ISO8859-1': 'cs_CZ.ISO8859-1',
354 'ru_RU.UTF-8': 'ru_RU.UTF-8',
355 'zh_CN.UTF-8': 'zh_CN.UTF-8',
356 },
357 'FreeBSD': {
358 'en_US.UTF-8': 'en_US.UTF-8',
359 'cs_CZ.ISO8859-2': 'cs_CZ.ISO8859-2',
360 'fr_FR.UTF-8': 'fr_FR.UTF-8',
361 'fr_CA.ISO8859-1': 'fr_CA.ISO8859-1',
362 'ru_RU.UTF-8': 'ru_RU.UTF-8',
363 'zh_CN.UTF-8': 'zh_CN.UTF-8',
364 },
365 'Linux': {
366 'en_US.UTF-8': 'en_US.UTF-8',
367 'cs_CZ.ISO8859-2': 'cs_CZ.ISO-8859-2',
368 'fr_FR.UTF-8': 'fr_FR.UTF-8',
369 'fr_CA.ISO8859-1': 'fr_CA.ISO-8859-1',
370 'ru_RU.UTF-8': 'ru_RU.UTF-8',
371 'zh_CN.UTF-8': 'zh_CN.UTF-8',
372 },
373 'Windows': {
374 'en_US.UTF-8': 'English_United States.1252',
375 'cs_CZ.ISO8859-2': 'Czech_Czech Republic.1250',
376 'fr_FR.UTF-8': 'French_France.1252',
377 'fr_CA.ISO8859-1': 'French_Canada.1252',
378 'ru_RU.UTF-8': 'Russian_Russia.1251',
379 'zh_CN.UTF-8': 'Chinese_China.936',
380 },
381 }
382
383 default_locale = locale.setlocale(locale.LC_ALL)
384 for feature, loc in locales[platform.system()].items():
385 try:
386 locale.setlocale(locale.LC_ALL, loc)
Eric Fiselier561dfb52014-08-23 04:02:21 +0000387 self.config.available_features.add('locale.{0}'.format(feature))
Dan Albertae2526b2014-08-21 17:30:44 +0000388 except:
Eric Fiselier561dfb52014-08-23 04:02:21 +0000389 self.lit_config.warning('The locale {0} is not supported by '
Dan Albertae2526b2014-08-21 17:30:44 +0000390 'your platform. Some tests will be '
391 'unsupported.'.format(loc))
392 locale.setlocale(locale.LC_ALL, default_locale)
393
394 # Write an "available feature" that combines the triple when
395 # use_system_lib is enabled. This is so that we can easily write XFAIL
396 # markers for tests that are known to fail with versions of libc++ as
397 # were shipped with a particular triple.
398 if self.use_system_lib:
Dan Albertae2526b2014-08-21 17:30:44 +0000399 self.config.available_features.add(
Eric Fiselierbb191412014-10-27 22:14:25 +0000400 'with_system_lib=%s' % self.config.target_triple)
Dan Albertae2526b2014-08-21 17:30:44 +0000401
Eric Fiselierb9f99732014-12-06 21:02:58 +0000402 # TODO 6/12/2014: Remove these once the buildmaster restarts.
403 # Removing before will break the bot that tests libcpp-has-no-threads.
404 if 'libcpp-has-no-threads' in self.config.available_features \
405 and '-D_LIBCPP_HAS_NO_THREADS' not in self.compile_flags:
Jonathan Roelofs3547c542014-09-05 17:21:57 +0000406 self.compile_flags += ['-D_LIBCPP_HAS_NO_THREADS']
407
Eric Fiselierb9f99732014-12-06 21:02:58 +0000408 if 'libcpp-has-no-monotonic-clock' in self.config.available_features \
409 and '-D_LIBCPP_HAS_NO_MONOTONIC_CLOCK' not in self.compile_flags:
Jonathan Roelofs3547c542014-09-05 17:21:57 +0000410 self.compile_flags += ['-D_LIBCPP_HAS_NO_MONOTONIC_CLOCK']
411
Eric Fiselier548415172014-11-21 08:02:38 +0000412 # Some linux distributions have different locale data than others.
413 # Insert the distributions name and name-version into the available
414 # features to allow tests to XFAIL on them.
415 if sys.platform.startswith('linux'):
Eric Fiseliera77ccfe2014-11-21 08:54:35 +0000416 name, ver, _ = platform.linux_distribution()
417 name = name.lower().strip()
418 ver = ver.lower().strip()
419 self.config.available_features.add(name)
420 self.config.available_features.add('%s-%s' % (name, ver))
Eric Fiselier548415172014-11-21 08:02:38 +0000421
Dan Albertae2526b2014-08-21 17:30:44 +0000422 def configure_compile_flags(self):
423 # Configure extra compiler flags.
424 self.compile_flags += ['-I' + self.src_root + '/include',
425 '-I' + self.src_root + '/test/support']
Eric Fiselier460b2242014-10-23 22:57:56 +0000426 if sys.platform.startswith('linux'):
Eric Fiselier6f9da552014-10-18 01:15:17 +0000427 self.compile_flags += ['-D__STDC_FORMAT_MACROS',
428 '-D__STDC_LIMIT_MACROS',
429 '-D__STDC_CONSTANT_MACROS']
Eric Fiselierb9f99732014-12-06 21:02:58 +0000430 # Configure threading features.
431 enable_threads = self.get_lit_bool('enable_threads')
432 enable_monotonic_clock = self.get_lit_bool('enable_monotonic_clock')
433 assert enable_threads is not None and enable_monotonic_clock is not None
434 if not enable_threads:
435 self.compile_flags += ['-D_LIBCPP_HAS_NO_THREADS']
436 self.config.available_features.add('libcpp-has-no-threads')
437 if not enable_monotonic_clock:
438 self.compile_flags += ['-D_LIBCPP_HAS_NO_MONOTONIC_CLOCK']
439 self.config.available_features.add('libcpp-has-no-monotonic-clock')
440 elif not enable_monotonic_clock:
441 self.lit_config.fatal('enable_monotonic_clock cannot be false when'
442 ' enable_threads is true.')
Dan Albertae2526b2014-08-21 17:30:44 +0000443
444 def configure_link_flags(self):
Eric Fiselier6f9da552014-10-18 01:15:17 +0000445 # Configure library search paths
Eric Fiseliera63c1492014-10-19 00:42:41 +0000446 abi_library_path = self.get_lit_conf('abi_library_path', '')
Eric Fiselier6f9da552014-10-18 01:15:17 +0000447 self.link_flags += ['-L' + self.obj_root + '/lib']
Eric Fiseliera63c1492014-10-19 00:42:41 +0000448 if not self.use_system_lib:
449 self.link_flags += ['-Wl,-rpath', '-Wl,' + self.obj_root + '/lib']
450 if abi_library_path:
451 self.link_flags += ['-L' + abi_library_path,
452 '-Wl,-rpath', '-Wl,' + abi_library_path]
Eric Fiselier6f9da552014-10-18 01:15:17 +0000453 # Configure libraries
454 self.link_flags += ['-lc++']
Dan Albertae2526b2014-08-21 17:30:44 +0000455 link_flags_str = self.get_lit_conf('link_flags')
456 if link_flags_str is None:
457 cxx_abi = self.get_lit_conf('cxx_abi', 'libcxxabi')
458 if cxx_abi == 'libstdc++':
459 self.link_flags += ['-lstdc++']
460 elif cxx_abi == 'libsupc++':
461 self.link_flags += ['-lsupc++']
462 elif cxx_abi == 'libcxxabi':
463 self.link_flags += ['-lc++abi']
464 elif cxx_abi == 'libcxxrt':
465 self.link_flags += ['-lcxxrt']
466 elif cxx_abi == 'none':
467 pass
468 else:
469 self.lit_config.fatal(
470 'C++ ABI setting %s unsupported for tests' % cxx_abi)
471
472 if sys.platform == 'darwin':
473 self.link_flags += ['-lSystem']
Eric Fiselier460b2242014-10-23 22:57:56 +0000474 elif sys.platform.startswith('linux'):
Dan Albertae2526b2014-08-21 17:30:44 +0000475 self.link_flags += ['-lgcc_eh', '-lc', '-lm', '-lpthread',
476 '-lrt', '-lgcc_s']
477 elif sys.platform.startswith('freebsd'):
478 self.link_flags += ['-lc', '-lm', '-pthread', '-lgcc_s']
479 else:
Eric Fiselier6f9da552014-10-18 01:15:17 +0000480 self.lit_config.fatal("unrecognized system: %r" % sys.platform)
Dan Albertae2526b2014-08-21 17:30:44 +0000481
Dan Albertae2526b2014-08-21 17:30:44 +0000482 if link_flags_str:
483 self.link_flags += shlex.split(link_flags_str)
484
Dan Albertae2526b2014-08-21 17:30:44 +0000485
486 def configure_std_flag(self):
487 # Try and get the std version from the command line. Fall back to
488 # default given in lit.site.cfg is not present. If default is not
489 # present then force c++11.
490 std = self.get_lit_conf('std')
491 if std is None:
492 std = 'c++11'
493 self.lit_config.note('using default std: \'-std=c++11\'')
Eric Fiselier561dfb52014-08-23 04:02:21 +0000494 self.compile_flags += ['-std={0}'.format(std)]
Dan Albertae2526b2014-08-21 17:30:44 +0000495 self.config.available_features.add(std)
496
497 def configure_sanitizer(self):
498 san = self.get_lit_conf('llvm_use_sanitizer', '').strip()
499 if san:
Eric Fiselierb941b502014-11-14 02:47:08 +0000500 # Search for llvm-symbolizer along the compiler path first
501 # and then along the PATH env variable.
502 symbolizer_search_paths = os.environ.get('PATH', '')
503 cxx_path = lit.util.which(self.cxx)
504 if cxx_path is not None:
505 symbolizer_search_paths = os.path.dirname(cxx_path) + \
506 os.pathsep + symbolizer_search_paths
507 llvm_symbolizer = lit.util.which('llvm-symbolizer',
508 symbolizer_search_paths)
509 # Setup the sanitizer compile flags
Eric Fiselier0425c7c2014-11-14 22:18:03 +0000510 self.compile_flags += ['-g', '-fno-omit-frame-pointer']
Eric Fiselier460b2242014-10-23 22:57:56 +0000511 if sys.platform.startswith('linux'):
Eric Fiselier062e6ee2014-10-23 02:54:15 +0000512 self.link_flags += ['-ldl']
Dan Albertae2526b2014-08-21 17:30:44 +0000513 if san == 'Address':
514 self.compile_flags += ['-fsanitize=address']
Eric Fiselierb941b502014-11-14 02:47:08 +0000515 if llvm_symbolizer is not None:
516 self.env['ASAN_SYMBOLIZER_PATH'] = llvm_symbolizer
Dan Albertae2526b2014-08-21 17:30:44 +0000517 self.config.available_features.add('asan')
518 elif san == 'Memory' or san == 'MemoryWithOrigins':
519 self.compile_flags += ['-fsanitize=memory']
520 if san == 'MemoryWithOrigins':
521 self.compile_flags += ['-fsanitize-memory-track-origins']
Eric Fiselierb941b502014-11-14 02:47:08 +0000522 if llvm_symbolizer is not None:
523 self.env['MSAN_SYMBOLIZER_PATH'] = llvm_symbolizer
Dan Albertae2526b2014-08-21 17:30:44 +0000524 self.config.available_features.add('msan')
Eric Fiselier04c1b742014-10-16 23:21:59 +0000525 elif san == 'Undefined':
526 self.compile_flags += ['-fsanitize=undefined',
527 '-fno-sanitize=vptr,function',
Eric Fiselierbc2d6322014-11-14 02:07:52 +0000528 '-fno-sanitize-recover', '-O3']
Eric Fiselier04c1b742014-10-16 23:21:59 +0000529 self.config.available_features.add('ubsan')
Eric Fiselier9b681f62014-11-18 21:26:45 +0000530 elif san == 'Thread':
531 self.compile_flags += ['-fsanitize=thread']
532 self.config.available_features.add('tsan')
Dan Albertae2526b2014-08-21 17:30:44 +0000533 else:
534 self.lit_config.fatal('unsupported value for '
Eric Fiselier561dfb52014-08-23 04:02:21 +0000535 'libcxx_use_san: {0}'.format(san))
Dan Albertae2526b2014-08-21 17:30:44 +0000536
537 def configure_triple(self):
538 # Get or infer the target triple.
539 self.config.target_triple = self.get_lit_conf('target_triple')
540 # If no target triple was given, try to infer it from the compiler
541 # under test.
542 if not self.config.target_triple:
Eric Fiselierbb191412014-10-27 22:14:25 +0000543 target_triple = lit.util.capture(
Dan Albertae2526b2014-08-21 17:30:44 +0000544 [self.cxx, '-dumpmachine']).strip()
Eric Fiselierbb191412014-10-27 22:14:25 +0000545 # Drop sub-major version components from the triple, because the
546 # current XFAIL handling expects exact matches for feature checks.
Eric Fiselierd6b46b42014-10-28 18:03:38 +0000547 # Example: x86_64-apple-darwin14.0.0 -> x86_64-apple-darwin14
Eric Fiselierbb191412014-10-27 22:14:25 +0000548 # The 5th group handles triples greater than 3 parts
549 # (ex x86_64-pc-linux-gnu).
550 target_triple = re.sub(r'([^-]+)-([^-]+)-([^.]+)([^-]*)(.*)',
551 r'\1-\2-\3\5', target_triple)
552 # linux-gnu is needed in the triple to properly identify linuxes
553 # that use GLIBC. Handle redhat and opensuse triples as special
554 # cases and append the missing `-gnu` portion.
555 if target_triple.endswith('redhat-linux') or \
556 target_triple.endswith('suse-linux'):
557 target_triple += '-gnu'
558 self.config.target_triple = target_triple
Dan Albertae2526b2014-08-21 17:30:44 +0000559 self.lit_config.note(
560 "inferred target_triple as: %r" % self.config.target_triple)
561
562 def configure_env(self):
563 # Configure extra linker parameters.
564 if sys.platform == 'darwin':
565 if not self.use_system_lib:
566 self.env['DYLD_LIBRARY_PATH'] = os.path.join(self.obj_root,
567 'lib')
568
569
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000570# name: The name of this test suite.
571config.name = 'libc++'
572
573# suffixes: A list of file extensions to treat as test files.
574config.suffixes = ['.cpp']
575
576# test_source_root: The root path where tests are located.
577config.test_source_root = os.path.dirname(__file__)
578
Dan Albert86b75a42014-11-24 22:24:06 +0000579cfg_variant = getattr(config, 'configuration_variant', '')
580if cfg_variant:
581 print 'Using configuration variant: %s' % cfg_variant
582
583# Construct an object of the type named `<VARIANT>Configuration`.
584configuration = globals()['%sConfiguration' % cfg_variant](lit_config, config)
Dan Albertae2526b2014-08-21 17:30:44 +0000585configuration.configure()
586config.test_format = configuration.get_test_format()