2013-02-12 20:28:51 +01:00
|
|
|
# -*- Python -*- vim: set syntax=python tabstop=4 expandtab cc=80:
|
2010-09-15 05:57:04 +02:00
|
|
|
|
|
|
|
# Configuration file for the 'lit' test runner.
|
|
|
|
|
2013-08-30 21:52:12 +02:00
|
|
|
import errno
|
2014-08-04 20:44:48 +02:00
|
|
|
import locale
|
2010-09-15 05:57:04 +02:00
|
|
|
import os
|
|
|
|
import platform
|
2013-08-30 21:52:12 +02:00
|
|
|
import re
|
|
|
|
import shlex
|
2010-09-15 05:57:04 +02:00
|
|
|
import signal
|
|
|
|
import subprocess
|
2013-08-30 21:52:12 +02:00
|
|
|
import sys
|
|
|
|
import tempfile
|
2013-01-14 18:12:54 +01:00
|
|
|
import time
|
2010-09-15 05:57:04 +02:00
|
|
|
|
2013-08-09 16:44:11 +02:00
|
|
|
import lit.Test
|
|
|
|
import lit.formats
|
|
|
|
import lit.util
|
|
|
|
|
2010-09-15 05:57:04 +02:00
|
|
|
class LibcxxTestFormat(lit.formats.FileBasedTest):
|
|
|
|
"""
|
|
|
|
Custom test format handler for use with the test format use by libc++.
|
|
|
|
|
|
|
|
Tests fall into two categories:
|
|
|
|
FOO.pass.cpp - Executable test which should compile, run, and exit with
|
|
|
|
code 0.
|
|
|
|
FOO.fail.cpp - Negative test case which is expected to fail compilation.
|
|
|
|
"""
|
|
|
|
|
2013-02-05 19:03:49 +01:00
|
|
|
def __init__(self, cxx_under_test, cpp_flags, ld_flags, exec_env):
|
2010-09-15 06:11:29 +02:00
|
|
|
self.cxx_under_test = cxx_under_test
|
2010-09-15 06:31:58 +02:00
|
|
|
self.cpp_flags = list(cpp_flags)
|
|
|
|
self.ld_flags = list(ld_flags)
|
2013-02-05 19:03:49 +01:00
|
|
|
self.exec_env = dict(exec_env)
|
2010-09-15 05:57:04 +02:00
|
|
|
|
2013-01-14 18:12:54 +01:00
|
|
|
def execute_command(self, command, in_dir=None):
|
|
|
|
kwargs = {
|
|
|
|
'stdin' :subprocess.PIPE,
|
|
|
|
'stdout':subprocess.PIPE,
|
|
|
|
'stderr':subprocess.PIPE,
|
|
|
|
}
|
|
|
|
if in_dir:
|
|
|
|
kwargs['cwd'] = in_dir
|
|
|
|
p = subprocess.Popen(command, **kwargs)
|
2010-09-15 05:57:04 +02:00
|
|
|
out,err = p.communicate()
|
|
|
|
exitCode = p.wait()
|
|
|
|
|
|
|
|
# Detect Ctrl-C in subprocess.
|
|
|
|
if exitCode == -signal.SIGINT:
|
|
|
|
raise KeyboardInterrupt
|
|
|
|
|
|
|
|
return out, err, exitCode
|
|
|
|
|
|
|
|
def execute(self, test, lit_config):
|
2013-01-14 18:12:54 +01:00
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
return self._execute(test, lit_config)
|
|
|
|
except OSError, oe:
|
|
|
|
if oe.errno != errno.ETXTBSY:
|
|
|
|
raise
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
|
|
|
def _execute(self, test, lit_config):
|
2013-02-05 22:03:25 +01:00
|
|
|
# Extract test metadata from the test file.
|
|
|
|
requires = []
|
|
|
|
with open(test.getSourcePath()) as f:
|
|
|
|
for ln in f:
|
|
|
|
if 'XFAIL:' in ln:
|
|
|
|
items = ln[ln.index('XFAIL:') + 6:].split(',')
|
2013-08-22 01:06:32 +02:00
|
|
|
test.xfails.extend([s.strip() for s in items])
|
2013-02-05 22:03:25 +01:00
|
|
|
elif 'REQUIRES:' in ln:
|
|
|
|
items = ln[ln.index('REQUIRES:') + 9:].split(',')
|
|
|
|
requires.extend([s.strip() for s in items])
|
2014-08-01 00:56:52 +02:00
|
|
|
elif not ln.strip().startswith("//") and ln.strip():
|
2013-02-05 22:03:25 +01:00
|
|
|
# Stop at the first non-empty line that is not a C++
|
|
|
|
# comment.
|
|
|
|
break
|
|
|
|
|
|
|
|
# Check that we have the required features.
|
|
|
|
#
|
|
|
|
# FIXME: For now, this is cribbed from lit.TestRunner, to avoid
|
|
|
|
# introducing a dependency there. What we more ideally would like to do
|
2013-08-22 01:06:32 +02:00
|
|
|
# is lift the "requires" handling to be a core lit framework feature.
|
2013-02-05 22:03:25 +01:00
|
|
|
missing_required_features = [f for f in requires
|
|
|
|
if f not in test.config.available_features]
|
|
|
|
if missing_required_features:
|
|
|
|
return (lit.Test.UNSUPPORTED,
|
|
|
|
"Test requires the following features: %s" % (
|
|
|
|
', '.join(missing_required_features),))
|
|
|
|
|
|
|
|
# Evaluate the test.
|
2013-08-22 01:06:32 +02:00
|
|
|
return self._evaluate_test(test, lit_config)
|
2013-02-05 22:03:25 +01:00
|
|
|
|
|
|
|
def _evaluate_test(self, test, lit_config):
|
2010-09-15 05:57:04 +02:00
|
|
|
name = test.path_in_suite[-1]
|
|
|
|
source_path = test.getSourcePath()
|
2013-01-14 18:12:54 +01:00
|
|
|
source_dir = os.path.dirname(source_path)
|
2010-09-15 05:57:04 +02:00
|
|
|
|
|
|
|
# Check what kind of test this is.
|
|
|
|
assert name.endswith('.pass.cpp') or name.endswith('.fail.cpp')
|
|
|
|
expected_compile_fail = name.endswith('.fail.cpp')
|
|
|
|
|
|
|
|
# If this is a compile (failure) test, build it and check for failure.
|
|
|
|
if expected_compile_fail:
|
|
|
|
cmd = [self.cxx_under_test, '-c',
|
2010-09-15 06:31:58 +02:00
|
|
|
'-o', '/dev/null', source_path] + self.cpp_flags
|
2010-09-15 05:57:04 +02:00
|
|
|
out, err, exitCode = self.execute_command(cmd)
|
|
|
|
if exitCode == 1:
|
|
|
|
return lit.Test.PASS, ""
|
|
|
|
else:
|
|
|
|
report = """Command: %s\n""" % ' '.join(["'%s'" % a
|
|
|
|
for a in cmd])
|
|
|
|
report += """Exit Code: %d\n""" % exitCode
|
|
|
|
if out:
|
|
|
|
report += """Standard Output:\n--\n%s--""" % out
|
|
|
|
if err:
|
|
|
|
report += """Standard Error:\n--\n%s--""" % err
|
|
|
|
report += "\n\nExpected compilation to fail!"
|
2010-09-15 06:31:58 +02:00
|
|
|
return lit.Test.FAIL, report
|
2010-09-15 05:57:04 +02:00
|
|
|
else:
|
|
|
|
exec_file = tempfile.NamedTemporaryFile(suffix="exe", delete=False)
|
|
|
|
exec_path = exec_file.name
|
|
|
|
exec_file.close()
|
|
|
|
|
|
|
|
try:
|
2010-12-10 20:47:54 +01:00
|
|
|
compile_cmd = [self.cxx_under_test, '-o', exec_path,
|
2010-09-15 06:31:58 +02:00
|
|
|
source_path] + self.cpp_flags + self.ld_flags
|
2010-12-10 20:47:54 +01:00
|
|
|
cmd = compile_cmd
|
2010-09-15 05:57:04 +02:00
|
|
|
out, err, exitCode = self.execute_command(cmd)
|
|
|
|
if exitCode != 0:
|
|
|
|
report = """Command: %s\n""" % ' '.join(["'%s'" % a
|
|
|
|
for a in cmd])
|
|
|
|
report += """Exit Code: %d\n""" % exitCode
|
|
|
|
if out:
|
|
|
|
report += """Standard Output:\n--\n%s--""" % out
|
|
|
|
if err:
|
|
|
|
report += """Standard Error:\n--\n%s--""" % err
|
|
|
|
report += "\n\nCompilation failed unexpectedly!"
|
|
|
|
return lit.Test.FAIL, report
|
|
|
|
|
2013-02-05 19:03:49 +01:00
|
|
|
cmd = []
|
|
|
|
if self.exec_env:
|
|
|
|
cmd.append('env')
|
|
|
|
cmd.extend('%s=%s' % (name, value)
|
|
|
|
for name,value in self.exec_env.items())
|
|
|
|
cmd.append(exec_path)
|
2012-08-02 20:36:47 +02:00
|
|
|
if lit_config.useValgrind:
|
|
|
|
cmd = lit_config.valgrindArgs + cmd
|
2013-01-14 18:12:54 +01:00
|
|
|
out, err, exitCode = self.execute_command(cmd, source_dir)
|
2010-09-15 05:57:04 +02:00
|
|
|
if exitCode != 0:
|
2013-02-12 20:28:51 +01:00
|
|
|
report = """Compiled With: %s\n""" % \
|
|
|
|
' '.join(["'%s'" % a for a in compile_cmd])
|
|
|
|
report += """Command: %s\n""" % \
|
|
|
|
' '.join(["'%s'" % a for a in cmd])
|
2010-09-15 05:57:04 +02:00
|
|
|
report += """Exit Code: %d\n""" % exitCode
|
|
|
|
if out:
|
|
|
|
report += """Standard Output:\n--\n%s--""" % out
|
|
|
|
if err:
|
|
|
|
report += """Standard Error:\n--\n%s--""" % err
|
|
|
|
report += "\n\nCompiled test failed unexpectedly!"
|
|
|
|
return lit.Test.FAIL, report
|
|
|
|
finally:
|
|
|
|
try:
|
|
|
|
os.remove(exec_path)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
return lit.Test.PASS, ""
|
|
|
|
|
|
|
|
# name: The name of this test suite.
|
|
|
|
config.name = 'libc++'
|
|
|
|
|
|
|
|
# suffixes: A list of file extensions to treat as test files.
|
|
|
|
config.suffixes = ['.cpp']
|
|
|
|
|
|
|
|
# test_source_root: The root path where tests are located.
|
|
|
|
config.test_source_root = os.path.dirname(__file__)
|
|
|
|
|
2014-08-04 20:44:48 +02:00
|
|
|
# Figure out which of the required locales we support
|
|
|
|
locales = {
|
|
|
|
'Darwin': {
|
|
|
|
'en_US.UTF-8': 'en_US.UTF-8',
|
|
|
|
'cs_CZ.ISO8859-2': 'cs_CZ.ISO8859-2',
|
|
|
|
'fr_FR.UTF-8': 'fr_FR.UTF-8',
|
|
|
|
'fr_CA.ISO8859-1': 'cs_CZ.ISO8859-1',
|
|
|
|
'ru_RU.UTF-8': 'ru_RU.UTF-8',
|
|
|
|
'zh_CN.UTF-8': 'zh_CN.UTF-8',
|
|
|
|
},
|
2014-08-16 01:24:00 +02:00
|
|
|
'FreeBSD' : {
|
|
|
|
'en_US.UTF-8': 'en_US.UTF-8',
|
|
|
|
'cs_CZ.ISO8859-2': 'cs_CZ.ISO8859-2',
|
|
|
|
'fr_FR.UTF-8': 'fr_FR.UTF-8',
|
|
|
|
'fr_CA.ISO8859-1': 'fr_CA.ISO8859-1',
|
|
|
|
'ru_RU.UTF-8': 'ru_RU.UTF-8',
|
|
|
|
'zh_CN.UTF-8': 'zh_CN.UTF-8',
|
|
|
|
},
|
2014-08-04 20:44:48 +02:00
|
|
|
'Linux': {
|
|
|
|
'en_US.UTF-8': 'en_US.UTF-8',
|
|
|
|
'cs_CZ.ISO8859-2': 'cs_CZ.ISO-8859-2',
|
|
|
|
'fr_FR.UTF-8': 'fr_FR.UTF-8',
|
|
|
|
'fr_CA.ISO8859-1': 'fr_CA.ISO-8859-1',
|
|
|
|
'ru_RU.UTF-8': 'ru_RU.UTF-8',
|
|
|
|
'zh_CN.UTF-8': 'zh_CN.UTF-8',
|
|
|
|
},
|
|
|
|
'Windows': {
|
|
|
|
'en_US.UTF-8': 'English_United States.1252',
|
|
|
|
'cs_CZ.ISO8859-2': 'Czech_Czech Republic.1250',
|
|
|
|
'fr_FR.UTF-8': 'French_France.1252',
|
|
|
|
'fr_CA.ISO8859-1': 'French_Canada.1252',
|
|
|
|
'ru_RU.UTF-8': 'Russian_Russia.1251',
|
|
|
|
'zh_CN.UTF-8': 'Chinese_China.936',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for feature, loc in locales[platform.system()].items():
|
|
|
|
try:
|
|
|
|
locale.setlocale(locale.LC_ALL, loc)
|
|
|
|
config.available_features.add('locale.{}'.format(feature))
|
|
|
|
except:
|
2014-08-04 22:27:45 +02:00
|
|
|
lit_config.warning('The locale {} is not supported by your platform. '
|
2014-08-04 20:44:48 +02:00
|
|
|
'Some tests will be unsupported.'.format(loc))
|
|
|
|
|
2012-11-28 00:56:28 +01:00
|
|
|
# Gather various compiler parameters.
|
2013-08-09 16:44:11 +02:00
|
|
|
cxx_under_test = lit_config.params.get('cxx_under_test', None)
|
2010-09-15 05:57:04 +02:00
|
|
|
if cxx_under_test is None:
|
2010-12-10 20:47:54 +01:00
|
|
|
cxx_under_test = getattr(config, 'cxx_under_test', None)
|
2013-02-06 21:24:23 +01:00
|
|
|
|
|
|
|
# If no specific cxx_under_test was given, attempt to infer it as clang++.
|
2014-01-29 02:54:52 +01:00
|
|
|
if cxx_under_test is None:
|
|
|
|
clangxx = lit.util.which('clang++', config.environment['PATH'])
|
|
|
|
if clangxx is not None:
|
|
|
|
cxx_under_test = clangxx
|
|
|
|
lit_config.note("inferred cxx_under_test as: %r" % (cxx_under_test,))
|
2013-02-06 21:24:23 +01:00
|
|
|
if cxx_under_test is None:
|
2013-08-09 16:44:11 +02:00
|
|
|
lit_config.fatal('must specify user parameter cxx_under_test '
|
|
|
|
'(e.g., --param=cxx_under_test=clang++)')
|
2010-12-10 20:47:54 +01:00
|
|
|
|
2013-08-09 16:44:11 +02:00
|
|
|
libcxx_src_root = lit_config.params.get('libcxx_src_root', None)
|
2012-11-28 00:56:28 +01:00
|
|
|
if libcxx_src_root is None:
|
|
|
|
libcxx_src_root = getattr(config, 'libcxx_src_root', None)
|
|
|
|
if libcxx_src_root is None:
|
|
|
|
libcxx_src_root = os.path.dirname(config.test_source_root)
|
|
|
|
|
2013-08-09 16:44:11 +02:00
|
|
|
libcxx_obj_root = lit_config.params.get('libcxx_obj_root', None)
|
2012-11-28 00:56:28 +01:00
|
|
|
if libcxx_obj_root is None:
|
|
|
|
libcxx_obj_root = getattr(config, 'libcxx_obj_root', None)
|
|
|
|
if libcxx_obj_root is None:
|
|
|
|
libcxx_obj_root = libcxx_src_root
|
|
|
|
|
2013-02-05 19:03:49 +01:00
|
|
|
# This test suite supports testing against either the system library or the
|
|
|
|
# locally built one; the former mode is useful for testing ABI compatibility
|
2013-02-06 18:47:08 +01:00
|
|
|
# between the current headers and a shipping dynamic library.
|
2013-08-09 16:44:11 +02:00
|
|
|
use_system_lib_str = lit_config.params.get('use_system_lib', None)
|
2013-02-05 19:03:49 +01:00
|
|
|
if use_system_lib_str is not None:
|
|
|
|
if use_system_lib_str.lower() in ('1', 'true'):
|
|
|
|
use_system_lib = True
|
|
|
|
elif use_system_lib_str.lower() in ('', '0', 'false'):
|
|
|
|
use_system_lib = False
|
|
|
|
else:
|
2013-08-09 16:44:11 +02:00
|
|
|
lit_config.fatal('user parameter use_system_lib should be 0 or 1')
|
2013-02-05 19:03:49 +01:00
|
|
|
else:
|
2013-02-06 18:47:08 +01:00
|
|
|
# Default to testing against the locally built libc++ library.
|
|
|
|
use_system_lib = False
|
2013-08-09 16:44:11 +02:00
|
|
|
lit_config.note("inferred use_system_lib as: %r" % (use_system_lib,))
|
2013-02-05 19:03:49 +01:00
|
|
|
|
2013-02-12 20:28:51 +01:00
|
|
|
link_flags = []
|
2013-08-09 16:44:11 +02:00
|
|
|
link_flags_str = lit_config.params.get('link_flags', None)
|
2013-02-12 20:28:51 +01:00
|
|
|
if link_flags_str is None:
|
|
|
|
link_flags_str = getattr(config, 'link_flags', None)
|
|
|
|
if link_flags_str is None:
|
2013-10-14 20:02:02 +02:00
|
|
|
cxx_abi = getattr(config, 'cxx_abi', 'libcxxabi')
|
2013-10-07 00:13:19 +02:00
|
|
|
if cxx_abi == 'libstdc++':
|
|
|
|
link_flags += ['-lstdc++']
|
|
|
|
elif cxx_abi == 'libsupc++':
|
|
|
|
link_flags += ['-lsupc++']
|
|
|
|
elif cxx_abi == 'libcxxabi':
|
|
|
|
link_flags += ['-lc++abi']
|
2014-08-16 01:24:00 +02:00
|
|
|
elif cxx_abi == 'libcxxrt':
|
|
|
|
link_flags += ['-lcxxrt']
|
2013-10-07 00:13:19 +02:00
|
|
|
elif cxx_abi == 'none':
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
lit_config.fatal('C++ ABI setting %s unsupported for tests' % cxx_abi)
|
|
|
|
|
|
|
|
if sys.platform == 'darwin':
|
|
|
|
link_flags += ['-lSystem']
|
|
|
|
elif sys.platform == 'linux2':
|
|
|
|
link_flags += [ '-lgcc_eh', '-lc', '-lm', '-lpthread',
|
|
|
|
'-lrt', '-lgcc_s']
|
2014-08-16 01:24:00 +02:00
|
|
|
elif sys.platform.startswith('freebsd'):
|
|
|
|
link_flags += ['-lc', '-lm', '-pthread', '-lgcc_s']
|
2013-10-07 00:13:19 +02:00
|
|
|
else:
|
|
|
|
lit_config.fatal("unrecognized system")
|
|
|
|
|
|
|
|
lit_config.note("inferred link_flags as: %r" % (link_flags,))
|
2013-02-12 20:28:51 +01:00
|
|
|
if not link_flags_str is None:
|
|
|
|
link_flags += shlex.split(link_flags_str)
|
|
|
|
|
2011-01-23 02:05:20 +01:00
|
|
|
# Configure extra compiler flags.
|
2013-02-12 20:28:51 +01:00
|
|
|
include_paths = ['-I' + libcxx_src_root + '/include',
|
|
|
|
'-I' + libcxx_src_root + '/test/support']
|
2012-11-28 00:56:28 +01:00
|
|
|
library_paths = ['-L' + libcxx_obj_root + '/lib']
|
2011-01-23 02:05:20 +01:00
|
|
|
compile_flags = []
|
2014-08-16 03:35:36 +02:00
|
|
|
|
|
|
|
# Try and get the std version from the command line. Fall back to default given
|
|
|
|
# in lit.site.cfg is not present. If default is not present then force c++11.
|
|
|
|
std = lit_config.params.get('std', None)
|
|
|
|
if std is None:
|
|
|
|
std = getattr(config, 'std', None)
|
|
|
|
if std is None:
|
|
|
|
std = 'c++11'
|
|
|
|
lit_config.note('using default std: \'-std=c++11\'')
|
|
|
|
else:
|
|
|
|
lit_config.note('using user specified std: \'-std={}\''.format(std))
|
|
|
|
compile_flags += ['-std={}'.format(std)]
|
2011-01-23 02:05:20 +01:00
|
|
|
|
2013-02-12 20:28:51 +01:00
|
|
|
# Configure extra linker parameters.
|
2013-02-05 19:03:49 +01:00
|
|
|
exec_env = {}
|
2010-12-10 20:47:54 +01:00
|
|
|
if sys.platform == 'darwin':
|
2013-02-05 19:03:49 +01:00
|
|
|
if not use_system_lib:
|
|
|
|
exec_env['DYLD_LIBRARY_PATH'] = os.path.join(libcxx_obj_root, 'lib')
|
|
|
|
elif sys.platform == 'linux2':
|
2013-02-06 18:45:53 +01:00
|
|
|
if not use_system_lib:
|
2013-02-12 20:28:51 +01:00
|
|
|
link_flags += ['-Wl,-R', libcxx_obj_root + '/lib']
|
|
|
|
compile_flags += ['-D__STDC_FORMAT_MACROS', '-D__STDC_LIMIT_MACROS',
|
|
|
|
'-D__STDC_CONSTANT_MACROS']
|
2014-08-16 01:24:00 +02:00
|
|
|
elif sys.platform.startswith('freebsd'):
|
|
|
|
if not use_system_lib:
|
|
|
|
link_flags += ['-Wl,-R', libcxx_obj_root + '/lib']
|
2013-02-05 19:03:49 +01:00
|
|
|
else:
|
2013-08-09 16:44:11 +02:00
|
|
|
lit_config.fatal("unrecognized system")
|
2010-12-10 20:47:54 +01:00
|
|
|
|
2012-11-28 00:56:28 +01:00
|
|
|
config.test_format = LibcxxTestFormat(
|
|
|
|
cxx_under_test,
|
|
|
|
cpp_flags = ['-nostdinc++'] + compile_flags + include_paths,
|
2013-02-12 20:28:51 +01:00
|
|
|
ld_flags = ['-nodefaultlibs'] + library_paths + ['-lc++'] + link_flags,
|
2013-02-05 19:03:49 +01:00
|
|
|
exec_env = exec_env)
|
2010-09-15 05:57:04 +02:00
|
|
|
|
2013-02-05 23:28:03 +01:00
|
|
|
# Get or infer the target triple.
|
2013-08-09 16:44:11 +02:00
|
|
|
config.target_triple = lit_config.params.get('target_triple', None)
|
2013-02-05 23:28:03 +01:00
|
|
|
# If no target triple was given, try to infer it from the compiler under test.
|
|
|
|
if config.target_triple is None:
|
|
|
|
config.target_triple = lit.util.capture(
|
|
|
|
[cxx_under_test, '-dumpmachine']).strip()
|
2013-08-09 16:44:11 +02:00
|
|
|
lit_config.note("inferred target_triple as: %r" % (config.target_triple,))
|
2013-02-05 22:43:30 +01:00
|
|
|
|
|
|
|
# Write an "available feature" that combines the triple when use_system_lib is
|
|
|
|
# enabled. This is so that we can easily write XFAIL markers for tests that are
|
|
|
|
# known to fail with versions of libc++ as were shipped with a particular
|
|
|
|
# triple.
|
|
|
|
if use_system_lib:
|
2013-08-30 21:52:12 +02:00
|
|
|
# Drop sub-major version components from the triple, because the current
|
|
|
|
# XFAIL handling expects exact matches for feature checks.
|
|
|
|
sanitized_triple = re.sub(r"([^-]+)-([^-]+)-([^-.]+).*", r"\1-\2-\3",
|
|
|
|
config.target_triple)
|
|
|
|
config.available_features.add('with_system_lib=%s' % (sanitized_triple,))
|