blob: 56b1b36e954bbd70df07729e0f19dac72e395e3d [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
Eric Fiselier67945b62014-12-07 04:28:50 +000093 def _make_report(self, cmd, out, err, rc):
94 report = "Command: %s\n" % cmd
95 report += "Exit Code: %d\n" % rc
96 if out:
97 report += "Standard Output:\n--\n%s--\n" % out
98 if err:
99 report += "Standard Error:\n--\n%s--\n" % err
100 report += '\n'
101 return cmd, report, rc
102
Dan Albert86b75a42014-11-24 22:24:06 +0000103 def _build(self, exec_path, source_path, compile_only=False,
104 use_verify=False):
105 cmd = [self.cxx_under_test, '-o', exec_path,
106 source_path] + self.cpp_flags
107
108 if compile_only:
109 cmd += ['-c']
110 else:
111 cmd += self.ld_flags
112
113 if use_verify:
114 cmd += ['-Xclang', '-verify']
115
Eric Fiseliere620b5e2014-11-25 03:03:32 +0000116 out, err, rc = lit.util.executeCommand(cmd)
Eric Fiselier67945b62014-12-07 04:28:50 +0000117 return self._make_report(cmd, out, err, rc)
Dan Albert86b75a42014-11-24 22:24:06 +0000118
119 def _clean(self, exec_path):
120 os.remove(exec_path)
121
122 def _run(self, exec_path, lit_config, in_dir=None):
123 cmd = []
124 if self.exec_env:
125 cmd.append('env')
126 cmd.extend('%s=%s' % (name, value)
127 for name,value in self.exec_env.items())
128 cmd.append(exec_path)
129 if lit_config.useValgrind:
130 cmd = lit_config.valgrindArgs + cmd
Eric Fiselier67945b62014-12-07 04:28:50 +0000131 out, err, rc = lit.util.executeCommand(cmd, cwd=in_dir)
132 return self._make_report(cmd, out, err, rc)
Dan Albert86b75a42014-11-24 22:24:06 +0000133
Justin Bogner2cfd1fe2014-09-03 06:01:52 +0000134 def _evaluate_test(self, test, use_verify, lit_config):
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000135 name = test.path_in_suite[-1]
136 source_path = test.getSourcePath()
Howard Hinnant3778f272013-01-14 17:12:54 +0000137 source_dir = os.path.dirname(source_path)
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000138
139 # Check what kind of test this is.
140 assert name.endswith('.pass.cpp') or name.endswith('.fail.cpp')
141 expected_compile_fail = name.endswith('.fail.cpp')
142
143 # If this is a compile (failure) test, build it and check for failure.
144 if expected_compile_fail:
Eric Fiselier67945b62014-12-07 04:28:50 +0000145 cmd, report, rc = self._build('/dev/null', source_path,
146 compile_only=True,
147 use_verify=use_verify)
Dan Albert86b75a42014-11-24 22:24:06 +0000148 expected_rc = 0 if use_verify else 1
Justin Bogner33a2a2e2014-09-03 04:32:08 +0000149 if rc == expected_rc:
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000150 return lit.Test.PASS, ""
151 else:
Eric Fiselier67945b62014-12-07 04:28:50 +0000152 return lit.Test.FAIL, report + 'Expected compilation to fail!\n'
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000153 else:
154 exec_file = tempfile.NamedTemporaryFile(suffix="exe", delete=False)
155 exec_path = exec_file.name
156 exec_file.close()
157
158 try:
Eric Fiselier67945b62014-12-07 04:28:50 +0000159 cmd, report, rc = self._build(exec_path, source_path)
Dan Albert86b75a42014-11-24 22:24:06 +0000160 compile_cmd = cmd
161 if rc != 0:
Eric Fiselier67945b62014-12-07 04:28:50 +0000162 report += "Compilation failed unexpectedly!"
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000163 return lit.Test.FAIL, report
164
Eric Fiselier67945b62014-12-07 04:28:50 +0000165 cmd, report, rc = self._run(exec_path, lit_config,
166 source_dir)
Dan Albert86b75a42014-11-24 22:24:06 +0000167 if rc != 0:
Eric Fiselier67945b62014-12-07 04:28:50 +0000168 report = "Compiled With: %s\n%s" % (compile_cmd, report)
169 report += "Compiled test failed unexpectedly!"
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000170 return lit.Test.FAIL, report
171 finally:
172 try:
Dan Albert86b75a42014-11-24 22:24:06 +0000173 # Note that cleanup of exec_file happens in `_clean()`. If
174 # you override this, cleanup is your reponsibility.
175 self._clean(exec_path)
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000176 except:
177 pass
178 return lit.Test.PASS, ""
179
Dan Albertae2526b2014-08-21 17:30:44 +0000180
181class Configuration(object):
182 def __init__(self, lit_config, config):
183 self.lit_config = lit_config
184 self.config = config
185 self.cxx = None
186 self.src_root = None
187 self.obj_root = None
188 self.env = {}
Eric Fiseliercf82c1e2014-11-24 23:46:42 +0000189 self.compile_flags = ['-nostdinc++']
190 self.link_flags = ['-nodefaultlibs']
Dan Albertae2526b2014-08-21 17:30:44 +0000191 self.use_system_lib = False
Justin Bogner33a2a2e2014-09-03 04:32:08 +0000192 self.use_clang_verify = False
Dan Albertae2526b2014-08-21 17:30:44 +0000193
194 if platform.system() not in ('Darwin', 'FreeBSD', 'Linux'):
195 self.lit_config.fatal("unrecognized system")
196
197 def get_lit_conf(self, name, default=None):
198 val = self.lit_config.params.get(name, None)
199 if val is None:
200 val = getattr(self.config, name, None)
201 if val is None:
202 val = default
203 return val
204
Justin Bogner33a2a2e2014-09-03 04:32:08 +0000205 def get_lit_bool(self, name):
206 conf = self.get_lit_conf(name)
207 if conf is None:
208 return None
209 if conf.lower() in ('1', 'true'):
210 return True
211 if conf.lower() in ('', '0', 'false'):
212 return False
213 self.lit_config.fatal(
214 "parameter '{}' should be true or false".format(name))
215
Dan Albertae2526b2014-08-21 17:30:44 +0000216 def configure(self):
217 self.configure_cxx()
Eric Fiselierb92da3f2014-12-06 21:13:15 +0000218 self.probe_cxx()
Dan Albertae2526b2014-08-21 17:30:44 +0000219 self.configure_triple()
220 self.configure_src_root()
221 self.configure_obj_root()
222 self.configure_use_system_lib()
Justin Bogner33a2a2e2014-09-03 04:32:08 +0000223 self.configure_use_clang_verify()
Eric Fiselierb967e322014-12-07 00:34:23 +0000224 self.configure_env()
Dan Albertae2526b2014-08-21 17:30:44 +0000225 self.configure_std_flag()
226 self.configure_compile_flags()
227 self.configure_link_flags()
228 self.configure_sanitizer()
229 self.configure_features()
Eric Fiseliercf82c1e2014-11-24 23:46:42 +0000230 # Print the final compile and link flags.
231 self.lit_config.note('Using compile flags: %s' % self.compile_flags)
232 self.lit_config.note('Using link flags: %s' % self.link_flags)
233 # Print as list to prevent "set([...])" from being printed.
234 self.lit_config.note('Using available_features: %s' %
235 list(self.config.available_features))
Dan Albertae2526b2014-08-21 17:30:44 +0000236
237 def get_test_format(self):
238 return LibcxxTestFormat(
239 self.cxx,
Justin Bogner33a2a2e2014-09-03 04:32:08 +0000240 self.use_clang_verify,
Eric Fiseliercf82c1e2014-11-24 23:46:42 +0000241 cpp_flags=self.compile_flags,
242 ld_flags=self.link_flags,
Dan Albertae2526b2014-08-21 17:30:44 +0000243 exec_env=self.env)
244
245 def configure_cxx(self):
246 # Gather various compiler parameters.
247 self.cxx = self.get_lit_conf('cxx_under_test')
248
249 # If no specific cxx_under_test was given, attempt to infer it as
250 # clang++.
251 if self.cxx is None:
252 clangxx = lit.util.which('clang++',
253 self.config.environment['PATH'])
254 if clangxx:
255 self.cxx = clangxx
256 self.lit_config.note(
257 "inferred cxx_under_test as: %r" % self.cxx)
258 if not self.cxx:
259 self.lit_config.fatal('must specify user parameter cxx_under_test '
260 '(e.g., --param=cxx_under_test=clang++)')
261
Eric Fiselierb92da3f2014-12-06 21:13:15 +0000262 def probe_cxx(self):
263 # Dump all of the predefined macros
264 dump_macro_cmd = [self.cxx, '-dM', '-E', '-x', 'c++', '/dev/null']
265 out, err, rc = lit.util.executeCommand(dump_macro_cmd)
266 if rc != 0:
267 self.lit_config.warning('Failed to dump macros for compiler: %s' %
268 self.cxx)
269 return
270 # Create a dict containing all the predefined macros.
271 macros = {}
272 lines = [l.strip() for l in out.split('\n') if l.strip()]
273 for l in lines:
274 assert l.startswith('#define ')
275 l = l[len('#define '):]
276 macro, _, value = l.partition(' ')
277 macros[macro] = value
278 # Add compiler information to available features.
279 compiler_name = None
280 major_ver = minor_ver = None
281 if '__clang__' in macros.keys():
282 compiler_name = 'clang'
283 # Treat apple's llvm fork differently.
Eric Fiselier9db46352014-12-06 22:49:38 +0000284 if '__apple_build_version__' in macros.keys():
Eric Fiselierb92da3f2014-12-06 21:13:15 +0000285 compiler_name = 'apple-clang'
286 major_ver = macros['__clang_major__']
287 minor_ver = macros['__clang_minor__']
288 elif '__GNUC__' in macros.keys():
289 compiler_name = 'gcc'
290 major_ver = macros['__GNUC__']
291 minor_ver = macros['__GNUC_MINOR__']
292 else:
293 self.lit_config.warning('Failed to detect compiler for cxx: %s' %
294 self.cxx)
295 if compiler_name is not None:
296 self.config.available_features.add(compiler_name)
297 self.config.available_features.add('%s-%s.%s' % (
298 compiler_name, major_ver, minor_ver))
299
Dan Albertae2526b2014-08-21 17:30:44 +0000300 def configure_src_root(self):
301 self.src_root = self.get_lit_conf(
302 'libcxx_src_root', os.path.dirname(self.config.test_source_root))
303
304 def configure_obj_root(self):
305 self.obj_root = self.get_lit_conf('libcxx_obj_root', self.src_root)
306
307 def configure_use_system_lib(self):
308 # This test suite supports testing against either the system library or
309 # the locally built one; the former mode is useful for testing ABI
310 # compatibility between the current headers and a shipping dynamic
311 # library.
Justin Bogner33a2a2e2014-09-03 04:32:08 +0000312 self.use_system_lib = self.get_lit_bool('use_system_lib')
313 if self.use_system_lib is None:
Dan Albertae2526b2014-08-21 17:30:44 +0000314 # Default to testing against the locally built libc++ library.
315 self.use_system_lib = False
316 self.lit_config.note(
317 "inferred use_system_lib as: %r" % self.use_system_lib)
318
Justin Bogner33a2a2e2014-09-03 04:32:08 +0000319 def configure_use_clang_verify(self):
320 '''If set, run clang with -verify on failing tests.'''
321 self.use_clang_verify = self.get_lit_bool('use_clang_verify')
322 if self.use_clang_verify is None:
323 # TODO: Default this to True when using clang.
324 self.use_clang_verify = False
325 self.lit_config.note(
326 "inferred use_clang_verify as: %r" % self.use_clang_verify)
327
Dan Albertae2526b2014-08-21 17:30:44 +0000328 def configure_features(self):
Jonathan Roelofsb352db72014-09-05 19:03:46 +0000329 additional_features = self.get_lit_conf('additional_features')
330 if additional_features:
331 for f in additional_features.split(','):
332 self.config.available_features.add(f.strip())
Jonathan Roelofs3547c542014-09-05 17:21:57 +0000333
Dan Albertae2526b2014-08-21 17:30:44 +0000334 # Figure out which of the required locales we support
335 locales = {
336 'Darwin': {
337 'en_US.UTF-8': 'en_US.UTF-8',
338 'cs_CZ.ISO8859-2': 'cs_CZ.ISO8859-2',
339 'fr_FR.UTF-8': 'fr_FR.UTF-8',
340 'fr_CA.ISO8859-1': 'cs_CZ.ISO8859-1',
341 'ru_RU.UTF-8': 'ru_RU.UTF-8',
342 'zh_CN.UTF-8': 'zh_CN.UTF-8',
343 },
344 'FreeBSD': {
345 'en_US.UTF-8': 'en_US.UTF-8',
346 'cs_CZ.ISO8859-2': 'cs_CZ.ISO8859-2',
347 'fr_FR.UTF-8': 'fr_FR.UTF-8',
348 'fr_CA.ISO8859-1': 'fr_CA.ISO8859-1',
349 'ru_RU.UTF-8': 'ru_RU.UTF-8',
350 'zh_CN.UTF-8': 'zh_CN.UTF-8',
351 },
352 'Linux': {
353 'en_US.UTF-8': 'en_US.UTF-8',
354 'cs_CZ.ISO8859-2': 'cs_CZ.ISO-8859-2',
355 'fr_FR.UTF-8': 'fr_FR.UTF-8',
356 'fr_CA.ISO8859-1': 'fr_CA.ISO-8859-1',
357 'ru_RU.UTF-8': 'ru_RU.UTF-8',
358 'zh_CN.UTF-8': 'zh_CN.UTF-8',
359 },
360 'Windows': {
361 'en_US.UTF-8': 'English_United States.1252',
362 'cs_CZ.ISO8859-2': 'Czech_Czech Republic.1250',
363 'fr_FR.UTF-8': 'French_France.1252',
364 'fr_CA.ISO8859-1': 'French_Canada.1252',
365 'ru_RU.UTF-8': 'Russian_Russia.1251',
366 'zh_CN.UTF-8': 'Chinese_China.936',
367 },
368 }
369
370 default_locale = locale.setlocale(locale.LC_ALL)
371 for feature, loc in locales[platform.system()].items():
372 try:
373 locale.setlocale(locale.LC_ALL, loc)
Eric Fiselier561dfb52014-08-23 04:02:21 +0000374 self.config.available_features.add('locale.{0}'.format(feature))
Dan Albertae2526b2014-08-21 17:30:44 +0000375 except:
Eric Fiselier561dfb52014-08-23 04:02:21 +0000376 self.lit_config.warning('The locale {0} is not supported by '
Dan Albertae2526b2014-08-21 17:30:44 +0000377 'your platform. Some tests will be '
378 'unsupported.'.format(loc))
379 locale.setlocale(locale.LC_ALL, default_locale)
380
381 # Write an "available feature" that combines the triple when
382 # use_system_lib is enabled. This is so that we can easily write XFAIL
383 # markers for tests that are known to fail with versions of libc++ as
384 # were shipped with a particular triple.
385 if self.use_system_lib:
Dan Albertae2526b2014-08-21 17:30:44 +0000386 self.config.available_features.add(
Eric Fiselierbb191412014-10-27 22:14:25 +0000387 'with_system_lib=%s' % self.config.target_triple)
Dan Albertae2526b2014-08-21 17:30:44 +0000388
Eric Fiselierb9f99732014-12-06 21:02:58 +0000389 # TODO 6/12/2014: Remove these once the buildmaster restarts.
390 # Removing before will break the bot that tests libcpp-has-no-threads.
391 if 'libcpp-has-no-threads' in self.config.available_features \
392 and '-D_LIBCPP_HAS_NO_THREADS' not in self.compile_flags:
Jonathan Roelofs3547c542014-09-05 17:21:57 +0000393 self.compile_flags += ['-D_LIBCPP_HAS_NO_THREADS']
394
Eric Fiselierb9f99732014-12-06 21:02:58 +0000395 if 'libcpp-has-no-monotonic-clock' in self.config.available_features \
396 and '-D_LIBCPP_HAS_NO_MONOTONIC_CLOCK' not in self.compile_flags:
Jonathan Roelofs3547c542014-09-05 17:21:57 +0000397 self.compile_flags += ['-D_LIBCPP_HAS_NO_MONOTONIC_CLOCK']
398
Eric Fiselier548415172014-11-21 08:02:38 +0000399 # Some linux distributions have different locale data than others.
400 # Insert the distributions name and name-version into the available
401 # features to allow tests to XFAIL on them.
402 if sys.platform.startswith('linux'):
Eric Fiseliera77ccfe2014-11-21 08:54:35 +0000403 name, ver, _ = platform.linux_distribution()
404 name = name.lower().strip()
405 ver = ver.lower().strip()
406 self.config.available_features.add(name)
407 self.config.available_features.add('%s-%s' % (name, ver))
Eric Fiselier548415172014-11-21 08:02:38 +0000408
Dan Albertae2526b2014-08-21 17:30:44 +0000409 def configure_compile_flags(self):
410 # Configure extra compiler flags.
411 self.compile_flags += ['-I' + self.src_root + '/include',
412 '-I' + self.src_root + '/test/support']
Eric Fiselier460b2242014-10-23 22:57:56 +0000413 if sys.platform.startswith('linux'):
Eric Fiselier6f9da552014-10-18 01:15:17 +0000414 self.compile_flags += ['-D__STDC_FORMAT_MACROS',
415 '-D__STDC_LIMIT_MACROS',
416 '-D__STDC_CONSTANT_MACROS']
Eric Fiselierb9f99732014-12-06 21:02:58 +0000417 # Configure threading features.
418 enable_threads = self.get_lit_bool('enable_threads')
419 enable_monotonic_clock = self.get_lit_bool('enable_monotonic_clock')
420 assert enable_threads is not None and enable_monotonic_clock is not None
421 if not enable_threads:
422 self.compile_flags += ['-D_LIBCPP_HAS_NO_THREADS']
423 self.config.available_features.add('libcpp-has-no-threads')
424 if not enable_monotonic_clock:
425 self.compile_flags += ['-D_LIBCPP_HAS_NO_MONOTONIC_CLOCK']
426 self.config.available_features.add('libcpp-has-no-monotonic-clock')
427 elif not enable_monotonic_clock:
428 self.lit_config.fatal('enable_monotonic_clock cannot be false when'
429 ' enable_threads is true.')
Dan Albertae2526b2014-08-21 17:30:44 +0000430
431 def configure_link_flags(self):
Eric Fiselier6f9da552014-10-18 01:15:17 +0000432 # Configure library search paths
Eric Fiseliera63c1492014-10-19 00:42:41 +0000433 abi_library_path = self.get_lit_conf('abi_library_path', '')
Eric Fiseliera63c1492014-10-19 00:42:41 +0000434 if not self.use_system_lib:
Eric Fiseliera1c73a62014-12-06 22:08:51 +0000435 self.link_flags += ['-L' + self.obj_root + '/lib']
436 self.link_flags += ['-Wl,-rpath,' + self.obj_root + '/lib']
Eric Fiseliera63c1492014-10-19 00:42:41 +0000437 if abi_library_path:
438 self.link_flags += ['-L' + abi_library_path,
Eric Fiseliera1c73a62014-12-06 22:08:51 +0000439 '-Wl,-rpath,' + abi_library_path]
Eric Fiselier6f9da552014-10-18 01:15:17 +0000440 # Configure libraries
441 self.link_flags += ['-lc++']
Dan Albertae2526b2014-08-21 17:30:44 +0000442 link_flags_str = self.get_lit_conf('link_flags')
443 if link_flags_str is None:
444 cxx_abi = self.get_lit_conf('cxx_abi', 'libcxxabi')
445 if cxx_abi == 'libstdc++':
446 self.link_flags += ['-lstdc++']
447 elif cxx_abi == 'libsupc++':
448 self.link_flags += ['-lsupc++']
449 elif cxx_abi == 'libcxxabi':
450 self.link_flags += ['-lc++abi']
451 elif cxx_abi == 'libcxxrt':
452 self.link_flags += ['-lcxxrt']
453 elif cxx_abi == 'none':
454 pass
455 else:
456 self.lit_config.fatal(
457 'C++ ABI setting %s unsupported for tests' % cxx_abi)
458
459 if sys.platform == 'darwin':
460 self.link_flags += ['-lSystem']
Eric Fiselier460b2242014-10-23 22:57:56 +0000461 elif sys.platform.startswith('linux'):
Dan Albertae2526b2014-08-21 17:30:44 +0000462 self.link_flags += ['-lgcc_eh', '-lc', '-lm', '-lpthread',
463 '-lrt', '-lgcc_s']
464 elif sys.platform.startswith('freebsd'):
465 self.link_flags += ['-lc', '-lm', '-pthread', '-lgcc_s']
466 else:
Eric Fiselier6f9da552014-10-18 01:15:17 +0000467 self.lit_config.fatal("unrecognized system: %r" % sys.platform)
Dan Albertae2526b2014-08-21 17:30:44 +0000468
Dan Albertae2526b2014-08-21 17:30:44 +0000469 if link_flags_str:
470 self.link_flags += shlex.split(link_flags_str)
471
Dan Albertae2526b2014-08-21 17:30:44 +0000472
473 def configure_std_flag(self):
474 # Try and get the std version from the command line. Fall back to
475 # default given in lit.site.cfg is not present. If default is not
476 # present then force c++11.
477 std = self.get_lit_conf('std')
478 if std is None:
479 std = 'c++11'
480 self.lit_config.note('using default std: \'-std=c++11\'')
Eric Fiselier561dfb52014-08-23 04:02:21 +0000481 self.compile_flags += ['-std={0}'.format(std)]
Dan Albertae2526b2014-08-21 17:30:44 +0000482 self.config.available_features.add(std)
483
484 def configure_sanitizer(self):
485 san = self.get_lit_conf('llvm_use_sanitizer', '').strip()
486 if san:
Eric Fiselierb941b502014-11-14 02:47:08 +0000487 # Search for llvm-symbolizer along the compiler path first
488 # and then along the PATH env variable.
489 symbolizer_search_paths = os.environ.get('PATH', '')
490 cxx_path = lit.util.which(self.cxx)
491 if cxx_path is not None:
492 symbolizer_search_paths = os.path.dirname(cxx_path) + \
493 os.pathsep + symbolizer_search_paths
494 llvm_symbolizer = lit.util.which('llvm-symbolizer',
495 symbolizer_search_paths)
496 # Setup the sanitizer compile flags
Eric Fiselier0425c7c2014-11-14 22:18:03 +0000497 self.compile_flags += ['-g', '-fno-omit-frame-pointer']
Eric Fiselier460b2242014-10-23 22:57:56 +0000498 if sys.platform.startswith('linux'):
Eric Fiselier062e6ee2014-10-23 02:54:15 +0000499 self.link_flags += ['-ldl']
Dan Albertae2526b2014-08-21 17:30:44 +0000500 if san == 'Address':
501 self.compile_flags += ['-fsanitize=address']
Eric Fiselierb941b502014-11-14 02:47:08 +0000502 if llvm_symbolizer is not None:
503 self.env['ASAN_SYMBOLIZER_PATH'] = llvm_symbolizer
Dan Albertae2526b2014-08-21 17:30:44 +0000504 self.config.available_features.add('asan')
505 elif san == 'Memory' or san == 'MemoryWithOrigins':
506 self.compile_flags += ['-fsanitize=memory']
507 if san == 'MemoryWithOrigins':
508 self.compile_flags += ['-fsanitize-memory-track-origins']
Eric Fiselierb941b502014-11-14 02:47:08 +0000509 if llvm_symbolizer is not None:
510 self.env['MSAN_SYMBOLIZER_PATH'] = llvm_symbolizer
Dan Albertae2526b2014-08-21 17:30:44 +0000511 self.config.available_features.add('msan')
Eric Fiselier04c1b742014-10-16 23:21:59 +0000512 elif san == 'Undefined':
513 self.compile_flags += ['-fsanitize=undefined',
514 '-fno-sanitize=vptr,function',
Eric Fiselierbc2d6322014-11-14 02:07:52 +0000515 '-fno-sanitize-recover', '-O3']
Eric Fiselier04c1b742014-10-16 23:21:59 +0000516 self.config.available_features.add('ubsan')
Eric Fiselier9b681f62014-11-18 21:26:45 +0000517 elif san == 'Thread':
518 self.compile_flags += ['-fsanitize=thread']
519 self.config.available_features.add('tsan')
Dan Albertae2526b2014-08-21 17:30:44 +0000520 else:
521 self.lit_config.fatal('unsupported value for '
Eric Fiselier561dfb52014-08-23 04:02:21 +0000522 'libcxx_use_san: {0}'.format(san))
Dan Albertae2526b2014-08-21 17:30:44 +0000523
524 def configure_triple(self):
525 # Get or infer the target triple.
526 self.config.target_triple = self.get_lit_conf('target_triple')
527 # If no target triple was given, try to infer it from the compiler
528 # under test.
529 if not self.config.target_triple:
Eric Fiselierbb191412014-10-27 22:14:25 +0000530 target_triple = lit.util.capture(
Dan Albertae2526b2014-08-21 17:30:44 +0000531 [self.cxx, '-dumpmachine']).strip()
Eric Fiselierbb191412014-10-27 22:14:25 +0000532 # Drop sub-major version components from the triple, because the
533 # current XFAIL handling expects exact matches for feature checks.
Eric Fiselierd6b46b42014-10-28 18:03:38 +0000534 # Example: x86_64-apple-darwin14.0.0 -> x86_64-apple-darwin14
Eric Fiselierbb191412014-10-27 22:14:25 +0000535 # The 5th group handles triples greater than 3 parts
536 # (ex x86_64-pc-linux-gnu).
537 target_triple = re.sub(r'([^-]+)-([^-]+)-([^.]+)([^-]*)(.*)',
538 r'\1-\2-\3\5', target_triple)
539 # linux-gnu is needed in the triple to properly identify linuxes
540 # that use GLIBC. Handle redhat and opensuse triples as special
541 # cases and append the missing `-gnu` portion.
542 if target_triple.endswith('redhat-linux') or \
543 target_triple.endswith('suse-linux'):
544 target_triple += '-gnu'
545 self.config.target_triple = target_triple
Dan Albertae2526b2014-08-21 17:30:44 +0000546 self.lit_config.note(
547 "inferred target_triple as: %r" % self.config.target_triple)
548
Eric Fiselierb967e322014-12-07 00:34:23 +0000549 def configure_env(self):
550 if sys.platform == 'darwin' and not self.use_system_lib:
551 self.env['DYLD_LIBRARY_PATH'] = os.path.join(self.obj_root, 'lib')
Dan Albertae2526b2014-08-21 17:30:44 +0000552
Daniel Dunbar42ea4632010-09-15 03:57:04 +0000553# name: The name of this test suite.
554config.name = 'libc++'
555
556# suffixes: A list of file extensions to treat as test files.
557config.suffixes = ['.cpp']
558
559# test_source_root: The root path where tests are located.
560config.test_source_root = os.path.dirname(__file__)
561
Dan Albert86b75a42014-11-24 22:24:06 +0000562cfg_variant = getattr(config, 'configuration_variant', '')
563if cfg_variant:
564 print 'Using configuration variant: %s' % cfg_variant
565
566# Construct an object of the type named `<VARIANT>Configuration`.
567configuration = globals()['%sConfiguration' % cfg_variant](lit_config, config)
Dan Albertae2526b2014-08-21 17:30:44 +0000568configuration.configure()
569config.test_format = configuration.get_test_format()