head	1.2;
access;
symbols
	perseant-exfatfs-base-20250801:1.2
	perseant-exfatfs-base-20240630:1.2
	perseant-exfatfs:1.2.0.4
	perseant-exfatfs-base:1.2
	netbsd-8-3-RELEASE:1.1.1.6
	netbsd-9-4-RELEASE:1.1.1.6
	netbsd-9-3-RELEASE:1.1.1.6
	cjep_sun2x:1.2.0.2
	cjep_sun2x-base:1.2
	cjep_staticlib_x-base1:1.2
	netbsd-9-2-RELEASE:1.1.1.6
	cjep_staticlib_x:1.1.1.6.0.22
	cjep_staticlib_x-base:1.1.1.6
	netbsd-9-1-RELEASE:1.1.1.6
	phil-wifi-20200421:1.1.1.6
	phil-wifi-20200411:1.1.1.6
	is-mlppp:1.1.1.6.0.20
	is-mlppp-base:1.1.1.6
	phil-wifi-20200406:1.1.1.6
	netbsd-8-2-RELEASE:1.1.1.6
	netbsd-9-0-RELEASE:1.1.1.6
	netbsd-9-0-RC2:1.1.1.6
	netbsd-9-0-RC1:1.1.1.6
	phil-wifi-20191119:1.1.1.6
	netbsd-9:1.1.1.6.0.18
	netbsd-9-base:1.1.1.6
	phil-wifi-20190609:1.1.1.6
	netbsd-8-1-RELEASE:1.1.1.6
	netbsd-8-1-RC1:1.1.1.6
	pgoyette-compat-merge-20190127:1.1.1.6
	pgoyette-compat-20190127:1.1.1.6
	pgoyette-compat-20190118:1.1.1.6
	pgoyette-compat-1226:1.1.1.6
	pgoyette-compat-1126:1.1.1.6
	pgoyette-compat-1020:1.1.1.6
	pgoyette-compat-0930:1.1.1.6
	pgoyette-compat-0906:1.1.1.6
	netbsd-7-2-RELEASE:1.1.1.5
	pgoyette-compat-0728:1.1.1.6
	netbsd-8-0-RELEASE:1.1.1.6
	phil-wifi:1.1.1.6.0.16
	phil-wifi-base:1.1.1.6
	pgoyette-compat-0625:1.1.1.6
	netbsd-8-0-RC2:1.1.1.6
	pgoyette-compat-0521:1.1.1.6
	pgoyette-compat-0502:1.1.1.6
	pgoyette-compat-0422:1.1.1.6
	netbsd-8-0-RC1:1.1.1.6
	pgoyette-compat-0415:1.1.1.6
	pgoyette-compat-0407:1.1.1.6
	pgoyette-compat-0330:1.1.1.6
	pgoyette-compat-0322:1.1.1.6
	pgoyette-compat-0315:1.1.1.6
	netbsd-7-1-2-RELEASE:1.1.1.5
	pgoyette-compat:1.1.1.6.0.14
	pgoyette-compat-base:1.1.1.6
	netbsd-7-1-1-RELEASE:1.1.1.5
	matt-nb8-mediatek:1.1.1.6.0.12
	matt-nb8-mediatek-base:1.1.1.6
	perseant-stdc-iso10646:1.1.1.6.0.10
	perseant-stdc-iso10646-base:1.1.1.6
	netbsd-8:1.1.1.6.0.8
	netbsd-8-base:1.1.1.6
	prg-localcount2-base3:1.1.1.6
	prg-localcount2-base2:1.1.1.6
	prg-localcount2-base1:1.1.1.6
	prg-localcount2:1.1.1.6.0.6
	prg-localcount2-base:1.1.1.6
	pgoyette-localcount-20170426:1.1.1.6
	bouyer-socketcan-base1:1.1.1.6
	pgoyette-localcount-20170320:1.1.1.6
	netbsd-7-1:1.1.1.5.0.8
	netbsd-7-1-RELEASE:1.1.1.5
	netbsd-7-1-RC2:1.1.1.5
	netbsd-7-nhusb-base-20170116:1.1.1.5
	bouyer-socketcan:1.1.1.6.0.4
	bouyer-socketcan-base:1.1.1.6
	pgoyette-localcount-20170107:1.1.1.6
	netbsd-7-1-RC1:1.1.1.5
	pgoyette-localcount-20161104:1.1.1.6
	netbsd-7-0-2-RELEASE:1.1.1.5
	localcount-20160914:1.1.1.6
	netbsd-7-nhusb:1.1.1.5.0.6
	netbsd-7-nhusb-base:1.1.1.5
	pgoyette-localcount-20160806:1.1.1.6
	pgoyette-localcount-20160726:1.1.1.6
	pgoyette-localcount:1.1.1.6.0.2
	pgoyette-localcount-base:1.1.1.6
	netbsd-7-0-1-RELEASE:1.1.1.5
	netbsd-7-0:1.1.1.5.0.4
	netbsd-7-0-RELEASE:1.1.1.5
	libcxx-245547:1.1.1.6
	netbsd-7-0-RC3:1.1.1.5
	netbsd-7-0-RC2:1.1.1.5
	netbsd-7-0-RC1:1.1.1.5
	netbsd-7:1.1.1.5.0.2
	netbsd-7-base:1.1.1.5
	libcxx-215289:1.1.1.5
	libcxx-209785:1.1.1.4
	yamt-pagecache:1.1.1.4.0.2
	libcxx-208870:1.1.1.4
	yamt-pagecache-base9:1.1.1.3
	tls-earlyentropy:1.1.1.3.0.2
	tls-earlyentropy-base:1.1.1.4
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.1.1.3
	riastradh-drm2-base3:1.1.1.3
	libcxx-198773:1.1.1.3
	libcxx-198452:1.1.1.3
	libcxx-195694:1.1.1.3
	libcxx-194207:1.1.1.3
	libcxx-188475:1.1.1.2
	riastradh-drm2-base2:1.1.1.1
	riastradh-drm2-base1:1.1.1.1
	riastradh-drm2:1.1.1.1.0.4
	riastradh-drm2-base:1.1.1.1
	libcxx-185674:1.1.1.1
	tls-maxphys-base:1.1.1.5
	tls-maxphys:1.1.1.1.0.2
	libcxx-182162:1.1.1.1
	LLVM:1.1.1;
locks; strict;
comment	@# @;


1.2
date	2021.05.30.03.26.35;	author joerg;	state dead;
branches;
next	1.1;
commitid	Z2BWNc6JrDmRz7VC;

1.1
date	2013.05.17.23.02.29;	author joerg;	state Exp;
branches
	1.1.1.1;
next	;
commitid	5RZzZYRawlqwq2Qw;

1.1.1.1
date	2013.05.17.23.02.29;	author joerg;	state Exp;
branches
	1.1.1.1.2.1;
next	1.1.1.2;
commitid	5RZzZYRawlqwq2Qw;

1.1.1.2
date	2013.08.15.22.38.19;	author joerg;	state Exp;
branches;
next	1.1.1.3;
commitid	XzkpFPFnGVFXoB1x;

1.1.1.3
date	2013.11.11.23.42.23;	author joerg;	state Exp;
branches
	1.1.1.3.2.1;
next	1.1.1.4;
commitid	9tiT6SEsEN83VUcx;

1.1.1.4
date	2014.05.15.23.53.11;	author joerg;	state Exp;
branches
	1.1.1.4.2.1;
next	1.1.1.5;
commitid	GaGFKjw76FPm2HAx;

1.1.1.5
date	2014.08.09.19.03.43;	author joerg;	state Exp;
branches;
next	1.1.1.6;
commitid	tcPf3DW6rhsCFILx;

1.1.1.6
date	2015.08.20.09.31.49;	author joerg;	state Exp;
branches
	1.1.1.6.22.1;
next	;
commitid	ejnZ8WhR0kK5qZxy;

1.1.1.1.2.1
date	2013.05.17.23.02.29;	author tls;	state dead;
branches;
next	1.1.1.1.2.2;
commitid	OnlO1cBgtQRcIHUw;

1.1.1.1.2.2
date	2013.06.23.06.26.40;	author tls;	state Exp;
branches;
next	1.1.1.1.2.3;
commitid	OnlO1cBgtQRcIHUw;

1.1.1.1.2.3
date	2014.08.19.23.46.51;	author tls;	state Exp;
branches;
next	;
commitid	jTnpym9Qu0o4R1Nx;

1.1.1.3.2.1
date	2014.08.10.07.07.26;	author tls;	state Exp;
branches;
next	;
commitid	xYWlO1qKJE4jGMLx;

1.1.1.4.2.1
date	2014.05.15.23.53.11;	author yamt;	state dead;
branches;
next	1.1.1.4.2.2;
commitid	5gylMoBTXvvB7yBx;

1.1.1.4.2.2
date	2014.05.22.15.46.10;	author yamt;	state Exp;
branches;
next	;
commitid	5gylMoBTXvvB7yBx;

1.1.1.6.22.1
date	2021.05.31.22.10.16;	author cjep;	state dead;
branches;
next	;
commitid	eWz9SBW0XqKjJlVC;


desc
@@


1.2
log
@Remove old version of libc++, migrated to external/apache2/dist/libcxx
to match the rest of the mono-repo imports.
@
text
@# -*- Python -*- vim: set syntax=python tabstop=4 expandtab cc=80:

# Configuration file for the 'lit' test runner.

import os
import sys
import platform
import tempfile
import signal
import subprocess
import errno
import time
import shlex

# FIXME: For now, this is cribbed from lit.TestRunner, to avoid introducing a
# dependency there. What we more ideally would like to do is lift the "xfail"
# and "requires" handling to be a core lit framework feature.
def isExpectedFail(test, xfails):
    # Check if any of the xfails match an available feature or the target.
    for item in xfails:
        # If this is the wildcard, it always fails.
        if item == '*':
            return True

        # If this is a part of any of the features, it fails.
        for feature in test.config.available_features:
            if item in feature:
                return True

        # If this is a part of the target triple, it fails.
        if item in test.suite.config.target_triple:
            return True

    return False

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.
    """

    def __init__(self, cxx_under_test, cpp_flags, ld_flags, exec_env):
        self.cxx_under_test = cxx_under_test
        self.cpp_flags = list(cpp_flags)
        self.ld_flags = list(ld_flags)
        self.exec_env = dict(exec_env)

    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)
        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):
        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):
        # Extract test metadata from the test file.
        xfails = []
        requires = []
        with open(test.getSourcePath()) as f:
            for ln in f:
                if 'XFAIL:' in ln:
                    items = ln[ln.index('XFAIL:') + 6:].split(',')
                    xfails.extend([s.strip() for s in items])
                elif 'REQUIRES:' in ln:
                    items = ln[ln.index('REQUIRES:') + 9:].split(',')
                    requires.extend([s.strip() for s in items])
                elif not ln.startswith("//") and ln.strip():
                    # 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
        # is lift the "xfail" and "requires" handling to be a core lit
        # framework feature.
        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),))

        # Determine if this test is an expected failure.
        isXFail = isExpectedFail(test, xfails)

        # Evaluate the test.
        result, report = self._evaluate_test(test, lit_config)

        # Convert the test result based on whether this is an expected failure.
        if isXFail:
            if result != lit.Test.FAIL:
                report += "\n\nTest was expected to FAIL, but did not.\n"
                result = lit.Test.XPASS
            else:
                result = lit.Test.XFAIL

        return result, report

    def _evaluate_test(self, test, lit_config):
        name = test.path_in_suite[-1]
        source_path = test.getSourcePath()
        source_dir = os.path.dirname(source_path)

        # 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',
                   '-o', '/dev/null', source_path] + self.cpp_flags
            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!"
                return lit.Test.FAIL, report
        else:
            exec_file = tempfile.NamedTemporaryFile(suffix="exe", delete=False)
            exec_path = exec_file.name
            exec_file.close()

            try:
                compile_cmd = [self.cxx_under_test, '-o', exec_path,
                       source_path] + self.cpp_flags + self.ld_flags
                cmd = compile_cmd
                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

                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)
                if lit_config.useValgrind:
                    cmd = lit_config.valgrindArgs + cmd
                out, err, exitCode = self.execute_command(cmd, source_dir)
                if exitCode != 0:
                    report = """Compiled With: %s\n""" % \
                        ' '.join(["'%s'" % a for a in compile_cmd])
                    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\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__)

# Gather various compiler parameters.
cxx_under_test = lit.params.get('cxx_under_test', None)
if cxx_under_test is None:
    cxx_under_test = getattr(config, 'cxx_under_test', None)

    # If no specific cxx_under_test was given, attempt to infer it as clang++.
    clangxx = lit.util.which('clang++', config.environment['PATH'])
    if clangxx is not None:
        cxx_under_test = clangxx
        lit.note("inferred cxx_under_test as: %r" % (cxx_under_test,))
if cxx_under_test is None:
    lit.fatal('must specify user parameter cxx_under_test '
              '(e.g., --param=cxx_under_test=clang++)')

libcxx_src_root = lit.params.get('libcxx_src_root', None)
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)

libcxx_obj_root = lit.params.get('libcxx_obj_root', None)
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

cxx_has_stdcxx0x_flag_str = lit.params.get('cxx_has_stdcxx0x_flag', None)
if cxx_has_stdcxx0x_flag_str is not None:
    if cxx_has_stdcxx0x_flag_str.lower() in ('1', 'true'):
        cxx_has_stdcxx0x_flag = True
    elif cxx_has_stdcxx0x_flag_str.lower() in ('', '0', 'false'):
        cxx_has_stdcxx0x_flag = False
    else:
        lit.fatal('user parameter cxx_has_stdcxx0x_flag_str should be 0 or 1')
else:
    cxx_has_stdcxx0x_flag = getattr(config, 'cxx_has_stdcxx0x_flag', True)

# This test suite supports testing against either the system library or the
# locally built one; the former mode is useful for testing ABI compatibility
# between the current headers and a shipping dynamic library.
use_system_lib_str = lit.params.get('use_system_lib', None)
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:
        lit.fatal('user parameter use_system_lib should be 0 or 1')
else:
    # Default to testing against the locally built libc++ library.
    use_system_lib = False
    lit.note("inferred use_system_lib as: %r" % (use_system_lib,))

link_flags = []
link_flags_str = lit.params.get('link_flags', None)
if link_flags_str is None:
    link_flags_str = getattr(config, 'link_flags', None)
    if link_flags_str is None:
        if sys.platform == 'darwin':
            link_flags += ['-lSystem']
        elif sys.platform == 'linux2':
            link_flags += ['-lsupc++', '-lgcc_eh', '-lc', '-lm', '-lpthread',
                '-lrt', '-lgcc_s']
        else:
            lit.fatal("unrecognized system")
        lit.note("inferred link_flags as: %r" % (link_flags,))
if not link_flags_str is None:
    link_flags += shlex.split(link_flags_str)

# Configure extra compiler flags.
include_paths = ['-I' + libcxx_src_root + '/include',
    '-I' + libcxx_src_root + '/test/support']
library_paths = ['-L' + libcxx_obj_root + '/lib']
compile_flags = []
if cxx_has_stdcxx0x_flag:
    compile_flags += ['-std=c++0x']

# Configure extra linker parameters.
exec_env = {}
if sys.platform == 'darwin':
    if not use_system_lib:
        exec_env['DYLD_LIBRARY_PATH'] = os.path.join(libcxx_obj_root, 'lib')
elif sys.platform == 'linux2':
    if not use_system_lib:
        link_flags += ['-Wl,-R', libcxx_obj_root + '/lib']
    compile_flags += ['-D__STDC_FORMAT_MACROS', '-D__STDC_LIMIT_MACROS',
        '-D__STDC_CONSTANT_MACROS']
else:
    lit.fatal("unrecognized system")

config.test_format = LibcxxTestFormat(
    cxx_under_test,
    cpp_flags = ['-nostdinc++'] + compile_flags + include_paths,
    ld_flags = ['-nodefaultlibs'] + library_paths + ['-lc++'] + link_flags,
    exec_env = exec_env)

# Get or infer the target triple.
config.target_triple = lit.params.get('target_triple', None)
# 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()
    lit.note("inferred target_triple as: %r" % (config.target_triple,))

# 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:
    config.available_features.add('with_system_lib=%s' % (
            config.target_triple,))
@


1.1
log
@Initial revision
@
text
@@


1.1.1.1
log
@Import libc++ from http://llvm.org/svn/llvm-project, r182162.
@
text
@@


1.1.1.2
log
@Import libc++ r188413. More support for current C++ development and
various bugfixes.
@
text
@a14 4
import lit.Test
import lit.formats
import lit.util

d210 1
a210 1
cxx_under_test = lit_config.params.get('cxx_under_test', None)
d218 1
a218 1
        lit_config.note("inferred cxx_under_test as: %r" % (cxx_under_test,))
d220 2
a221 2
    lit_config.fatal('must specify user parameter cxx_under_test '
                     '(e.g., --param=cxx_under_test=clang++)')
d223 1
a223 1
libcxx_src_root = lit_config.params.get('libcxx_src_root', None)
d229 1
a229 1
libcxx_obj_root = lit_config.params.get('libcxx_obj_root', None)
d235 1
a235 1
cxx_has_stdcxx0x_flag_str = lit_config.params.get('cxx_has_stdcxx0x_flag', None)
d242 1
a242 2
        lit_config.fatal(
            'user parameter cxx_has_stdcxx0x_flag_str should be 0 or 1')
d249 1
a249 1
use_system_lib_str = lit_config.params.get('use_system_lib', None)
d256 1
a256 1
        lit_config.fatal('user parameter use_system_lib should be 0 or 1')
d260 1
a260 1
    lit_config.note("inferred use_system_lib as: %r" % (use_system_lib,))
d263 1
a263 1
link_flags_str = lit_config.params.get('link_flags', None)
d273 2
a274 2
            lit_config.fatal("unrecognized system")
        lit_config.note("inferred link_flags as: %r" % (link_flags,))
d297 1
a297 1
    lit_config.fatal("unrecognized system")
d306 1
a306 1
config.target_triple = lit_config.params.get('target_triple', None)
d311 1
a311 1
    lit_config.note("inferred target_triple as: %r" % (config.target_triple,))
@


1.1.1.3
log
@Import libc++ r194207. This brings in various bug fixes, a good chunk of
support for the up-coming C++14 and improved compatibility with various
compilers other than Clang.
@
text
@a4 1
import errno
d6 1
d8 1
a8 2
import re
import shlex
d11 1
a11 2
import sys
import tempfile
d13 1
d19 21
d85 1
d91 1
a91 1
                    test.xfails.extend([s.strip() for s in items])
d104 2
a105 1
        # is lift the "requires" handling to be a core lit framework feature.
d113 3
d117 11
a127 1
        return self._evaluate_test(test, lit_config)
d272 8
a279 21
      cxx_abi = getattr(config, 'cxx_abi', 'libcxxabi')
      if cxx_abi == 'libstdc++':
        link_flags += ['-lstdc++']
      elif cxx_abi == 'libsupc++':
        link_flags += ['-lsupc++']
      elif cxx_abi == 'libcxxabi':
        link_flags += ['-lc++abi']
      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']
      else:
        lit_config.fatal("unrecognized system")

      lit_config.note("inferred link_flags as: %r" % (link_flags,))
d323 2
a324 5
    # 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,))
@


1.1.1.3.2.1
log
@Rebase.
@
text
@d184 4
a187 5
    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,))
@


1.1.1.4
log
@Import libc++ r208870. Improves const use, fixes a few cases of missing
assign-to-self support and increase support for GCC.
@
text
@d184 4
a187 5
    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,))
@


1.1.1.5
log
@Import libc++ r215289. This brings a number of bug fixes as well as
further changes from the upcoming C++14 like string_view.
@
text
@a5 1
import locale
d74 1
a74 1
                elif not ln.strip().startswith("//") and ln.strip():
a177 36
# 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',
    },
    '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:
        lit_config.warning('The locale {} is not supported by your platform. '
                           'Some tests will be unsupported.'.format(loc))

@


1.1.1.6
log
@Import libc++ r245547. Various bugfixes, improvements to the C++14
support and some experimental features from the library standard track.
@
text
@d1 2
a2 1
# -*- Python -*- vim: set ft=python ts=4 sw=4 expandtab tw=79:
d4 3
d8 161
a168 9
import site

site.addsitedir(os.path.dirname(__file__))


# Tell pylint that we know config and lit_config exist somewhere.
if 'PYLINT_IMPORT' in os.environ:
    config = object()
    lit_config = object()
d174 1
a174 1
config.suffixes = ['.pass.cpp', '.fail.cpp', '.sh.cpp']
d179 165
a343 29
# Infer the test_exec_root from the libcxx_object root.
obj_root = getattr(config, 'libcxx_obj_root', None)

# Check that the test exec root is known.
if obj_root is None:
    import libcxx.test.config
    libcxx.test.config.loadSiteConfig(lit_config, config, 'libcxx_site_config',
                                      'LIBCXX_SITE_CONFIG')
    obj_root = getattr(config, 'libcxx_obj_root', None)
    if obj_root is None:
        import tempfile
        obj_root = tempfile.mkdtemp(prefix='libcxx-testsuite-')
        lit_config.warning('Creating temporary directory for object root: %s' %
                           obj_root)

config.test_exec_root = os.path.join(obj_root, 'test')

cfg_variant = getattr(config, 'configuration_variant', 'libcxx')
if cfg_variant:
    lit_config.note('Using configuration variant: %s' % cfg_variant)

# Load the Configuration class from the module name <cfg_variant>.test.config.
config_module_name = '.'.join([cfg_variant, 'test', 'config'])
config_module = __import__(config_module_name, fromlist=['Configuration'])

configuration = config_module.Configuration(lit_config, config)
configuration.configure()
configuration.print_config_info()
config.test_format = configuration.get_test_format()
@


1.1.1.6.22.1
log
@sync with head
@
text
@@


1.1.1.4.2.1
log
@file lit.cfg was added on branch yamt-pagecache on 2014-05-22 15:46:10 +0000
@
text
@d1 306
@


1.1.1.4.2.2
log
@sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs.  ("Protocol error: too many arguments")
@
text
@a0 305
# -*- Python -*- vim: set syntax=python tabstop=4 expandtab cc=80:

# Configuration file for the 'lit' test runner.

import errno
import os
import platform
import re
import shlex
import signal
import subprocess
import sys
import tempfile
import time

import lit.Test
import lit.formats
import lit.util

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.
    """

    def __init__(self, cxx_under_test, cpp_flags, ld_flags, exec_env):
        self.cxx_under_test = cxx_under_test
        self.cpp_flags = list(cpp_flags)
        self.ld_flags = list(ld_flags)
        self.exec_env = dict(exec_env)

    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)
        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):
        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):
        # 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(',')
                    test.xfails.extend([s.strip() for s in items])
                elif 'REQUIRES:' in ln:
                    items = ln[ln.index('REQUIRES:') + 9:].split(',')
                    requires.extend([s.strip() for s in items])
                elif not ln.startswith("//") and ln.strip():
                    # 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
        # is lift the "requires" handling to be a core lit framework feature.
        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.
        return self._evaluate_test(test, lit_config)

    def _evaluate_test(self, test, lit_config):
        name = test.path_in_suite[-1]
        source_path = test.getSourcePath()
        source_dir = os.path.dirname(source_path)

        # 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',
                   '-o', '/dev/null', source_path] + self.cpp_flags
            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!"
                return lit.Test.FAIL, report
        else:
            exec_file = tempfile.NamedTemporaryFile(suffix="exe", delete=False)
            exec_path = exec_file.name
            exec_file.close()

            try:
                compile_cmd = [self.cxx_under_test, '-o', exec_path,
                       source_path] + self.cpp_flags + self.ld_flags
                cmd = compile_cmd
                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

                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)
                if lit_config.useValgrind:
                    cmd = lit_config.valgrindArgs + cmd
                out, err, exitCode = self.execute_command(cmd, source_dir)
                if exitCode != 0:
                    report = """Compiled With: %s\n""" % \
                        ' '.join(["'%s'" % a for a in compile_cmd])
                    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\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__)

# Gather various compiler parameters.
cxx_under_test = lit_config.params.get('cxx_under_test', None)
if cxx_under_test is None:
    cxx_under_test = getattr(config, 'cxx_under_test', None)

    # If no specific cxx_under_test was given, attempt to infer it as clang++.
    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,))
if cxx_under_test is None:
    lit_config.fatal('must specify user parameter cxx_under_test '
                     '(e.g., --param=cxx_under_test=clang++)')

libcxx_src_root = lit_config.params.get('libcxx_src_root', None)
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)

libcxx_obj_root = lit_config.params.get('libcxx_obj_root', None)
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

cxx_has_stdcxx0x_flag_str = lit_config.params.get('cxx_has_stdcxx0x_flag', None)
if cxx_has_stdcxx0x_flag_str is not None:
    if cxx_has_stdcxx0x_flag_str.lower() in ('1', 'true'):
        cxx_has_stdcxx0x_flag = True
    elif cxx_has_stdcxx0x_flag_str.lower() in ('', '0', 'false'):
        cxx_has_stdcxx0x_flag = False
    else:
        lit_config.fatal(
            'user parameter cxx_has_stdcxx0x_flag_str should be 0 or 1')
else:
    cxx_has_stdcxx0x_flag = getattr(config, 'cxx_has_stdcxx0x_flag', True)

# This test suite supports testing against either the system library or the
# locally built one; the former mode is useful for testing ABI compatibility
# between the current headers and a shipping dynamic library.
use_system_lib_str = lit_config.params.get('use_system_lib', None)
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:
        lit_config.fatal('user parameter use_system_lib should be 0 or 1')
else:
    # Default to testing against the locally built libc++ library.
    use_system_lib = False
    lit_config.note("inferred use_system_lib as: %r" % (use_system_lib,))

link_flags = []
link_flags_str = lit_config.params.get('link_flags', None)
if link_flags_str is None:
    link_flags_str = getattr(config, 'link_flags', None)
    if link_flags_str is None:
      cxx_abi = getattr(config, 'cxx_abi', 'libcxxabi')
      if cxx_abi == 'libstdc++':
        link_flags += ['-lstdc++']
      elif cxx_abi == 'libsupc++':
        link_flags += ['-lsupc++']
      elif cxx_abi == 'libcxxabi':
        link_flags += ['-lc++abi']
      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']
      else:
        lit_config.fatal("unrecognized system")

      lit_config.note("inferred link_flags as: %r" % (link_flags,))
if not link_flags_str is None:
    link_flags += shlex.split(link_flags_str)

# Configure extra compiler flags.
include_paths = ['-I' + libcxx_src_root + '/include',
    '-I' + libcxx_src_root + '/test/support']
library_paths = ['-L' + libcxx_obj_root + '/lib']
compile_flags = []
if cxx_has_stdcxx0x_flag:
    compile_flags += ['-std=c++0x']

# Configure extra linker parameters.
exec_env = {}
if sys.platform == 'darwin':
    if not use_system_lib:
        exec_env['DYLD_LIBRARY_PATH'] = os.path.join(libcxx_obj_root, 'lib')
elif sys.platform == 'linux2':
    if not use_system_lib:
        link_flags += ['-Wl,-R', libcxx_obj_root + '/lib']
    compile_flags += ['-D__STDC_FORMAT_MACROS', '-D__STDC_LIMIT_MACROS',
        '-D__STDC_CONSTANT_MACROS']
else:
    lit_config.fatal("unrecognized system")

config.test_format = LibcxxTestFormat(
    cxx_under_test,
    cpp_flags = ['-nostdinc++'] + compile_flags + include_paths,
    ld_flags = ['-nodefaultlibs'] + library_paths + ['-lc++'] + link_flags,
    exec_env = exec_env)

# Get or infer the target triple.
config.target_triple = lit_config.params.get('target_triple', None)
# 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()
    lit_config.note("inferred target_triple as: %r" % (config.target_triple,))

# 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:
    # 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,))
@


1.1.1.1.2.1
log
@file lit.cfg was added on branch tls-maxphys on 2013-06-23 06:26:40 +0000
@
text
@d1 319
@


1.1.1.1.2.2
log
@resync from head
@
text
@a0 319
# -*- Python -*- vim: set syntax=python tabstop=4 expandtab cc=80:

# Configuration file for the 'lit' test runner.

import os
import sys
import platform
import tempfile
import signal
import subprocess
import errno
import time
import shlex

# FIXME: For now, this is cribbed from lit.TestRunner, to avoid introducing a
# dependency there. What we more ideally would like to do is lift the "xfail"
# and "requires" handling to be a core lit framework feature.
def isExpectedFail(test, xfails):
    # Check if any of the xfails match an available feature or the target.
    for item in xfails:
        # If this is the wildcard, it always fails.
        if item == '*':
            return True

        # If this is a part of any of the features, it fails.
        for feature in test.config.available_features:
            if item in feature:
                return True

        # If this is a part of the target triple, it fails.
        if item in test.suite.config.target_triple:
            return True

    return False

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.
    """

    def __init__(self, cxx_under_test, cpp_flags, ld_flags, exec_env):
        self.cxx_under_test = cxx_under_test
        self.cpp_flags = list(cpp_flags)
        self.ld_flags = list(ld_flags)
        self.exec_env = dict(exec_env)

    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)
        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):
        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):
        # Extract test metadata from the test file.
        xfails = []
        requires = []
        with open(test.getSourcePath()) as f:
            for ln in f:
                if 'XFAIL:' in ln:
                    items = ln[ln.index('XFAIL:') + 6:].split(',')
                    xfails.extend([s.strip() for s in items])
                elif 'REQUIRES:' in ln:
                    items = ln[ln.index('REQUIRES:') + 9:].split(',')
                    requires.extend([s.strip() for s in items])
                elif not ln.startswith("//") and ln.strip():
                    # 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
        # is lift the "xfail" and "requires" handling to be a core lit
        # framework feature.
        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),))

        # Determine if this test is an expected failure.
        isXFail = isExpectedFail(test, xfails)

        # Evaluate the test.
        result, report = self._evaluate_test(test, lit_config)

        # Convert the test result based on whether this is an expected failure.
        if isXFail:
            if result != lit.Test.FAIL:
                report += "\n\nTest was expected to FAIL, but did not.\n"
                result = lit.Test.XPASS
            else:
                result = lit.Test.XFAIL

        return result, report

    def _evaluate_test(self, test, lit_config):
        name = test.path_in_suite[-1]
        source_path = test.getSourcePath()
        source_dir = os.path.dirname(source_path)

        # 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',
                   '-o', '/dev/null', source_path] + self.cpp_flags
            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!"
                return lit.Test.FAIL, report
        else:
            exec_file = tempfile.NamedTemporaryFile(suffix="exe", delete=False)
            exec_path = exec_file.name
            exec_file.close()

            try:
                compile_cmd = [self.cxx_under_test, '-o', exec_path,
                       source_path] + self.cpp_flags + self.ld_flags
                cmd = compile_cmd
                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

                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)
                if lit_config.useValgrind:
                    cmd = lit_config.valgrindArgs + cmd
                out, err, exitCode = self.execute_command(cmd, source_dir)
                if exitCode != 0:
                    report = """Compiled With: %s\n""" % \
                        ' '.join(["'%s'" % a for a in compile_cmd])
                    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\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__)

# Gather various compiler parameters.
cxx_under_test = lit.params.get('cxx_under_test', None)
if cxx_under_test is None:
    cxx_under_test = getattr(config, 'cxx_under_test', None)

    # If no specific cxx_under_test was given, attempt to infer it as clang++.
    clangxx = lit.util.which('clang++', config.environment['PATH'])
    if clangxx is not None:
        cxx_under_test = clangxx
        lit.note("inferred cxx_under_test as: %r" % (cxx_under_test,))
if cxx_under_test is None:
    lit.fatal('must specify user parameter cxx_under_test '
              '(e.g., --param=cxx_under_test=clang++)')

libcxx_src_root = lit.params.get('libcxx_src_root', None)
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)

libcxx_obj_root = lit.params.get('libcxx_obj_root', None)
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

cxx_has_stdcxx0x_flag_str = lit.params.get('cxx_has_stdcxx0x_flag', None)
if cxx_has_stdcxx0x_flag_str is not None:
    if cxx_has_stdcxx0x_flag_str.lower() in ('1', 'true'):
        cxx_has_stdcxx0x_flag = True
    elif cxx_has_stdcxx0x_flag_str.lower() in ('', '0', 'false'):
        cxx_has_stdcxx0x_flag = False
    else:
        lit.fatal('user parameter cxx_has_stdcxx0x_flag_str should be 0 or 1')
else:
    cxx_has_stdcxx0x_flag = getattr(config, 'cxx_has_stdcxx0x_flag', True)

# This test suite supports testing against either the system library or the
# locally built one; the former mode is useful for testing ABI compatibility
# between the current headers and a shipping dynamic library.
use_system_lib_str = lit.params.get('use_system_lib', None)
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:
        lit.fatal('user parameter use_system_lib should be 0 or 1')
else:
    # Default to testing against the locally built libc++ library.
    use_system_lib = False
    lit.note("inferred use_system_lib as: %r" % (use_system_lib,))

link_flags = []
link_flags_str = lit.params.get('link_flags', None)
if link_flags_str is None:
    link_flags_str = getattr(config, 'link_flags', None)
    if link_flags_str is None:
        if sys.platform == 'darwin':
            link_flags += ['-lSystem']
        elif sys.platform == 'linux2':
            link_flags += ['-lsupc++', '-lgcc_eh', '-lc', '-lm', '-lpthread',
                '-lrt', '-lgcc_s']
        else:
            lit.fatal("unrecognized system")
        lit.note("inferred link_flags as: %r" % (link_flags,))
if not link_flags_str is None:
    link_flags += shlex.split(link_flags_str)

# Configure extra compiler flags.
include_paths = ['-I' + libcxx_src_root + '/include',
    '-I' + libcxx_src_root + '/test/support']
library_paths = ['-L' + libcxx_obj_root + '/lib']
compile_flags = []
if cxx_has_stdcxx0x_flag:
    compile_flags += ['-std=c++0x']

# Configure extra linker parameters.
exec_env = {}
if sys.platform == 'darwin':
    if not use_system_lib:
        exec_env['DYLD_LIBRARY_PATH'] = os.path.join(libcxx_obj_root, 'lib')
elif sys.platform == 'linux2':
    if not use_system_lib:
        link_flags += ['-Wl,-R', libcxx_obj_root + '/lib']
    compile_flags += ['-D__STDC_FORMAT_MACROS', '-D__STDC_LIMIT_MACROS',
        '-D__STDC_CONSTANT_MACROS']
else:
    lit.fatal("unrecognized system")

config.test_format = LibcxxTestFormat(
    cxx_under_test,
    cpp_flags = ['-nostdinc++'] + compile_flags + include_paths,
    ld_flags = ['-nodefaultlibs'] + library_paths + ['-lc++'] + link_flags,
    exec_env = exec_env)

# Get or infer the target triple.
config.target_triple = lit.params.get('target_triple', None)
# 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()
    lit.note("inferred target_triple as: %r" % (config.target_triple,))

# 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:
    config.available_features.add('with_system_lib=%s' % (
            config.target_triple,))
@


1.1.1.1.2.3
log
@Rebase to HEAD as of a few days ago.
@
text
@a4 2
import errno
import locale
d6 1
d8 1
a8 2
import re
import shlex
d11 1
a11 2
import sys
import tempfile
d13 1
d15 20
a34 3
import lit.Test
import lit.formats
import lit.util
d81 1
d87 1
a87 1
                    test.xfails.extend([s.strip() for s in items])
d91 1
a91 1
                elif not ln.strip().startswith("//") and ln.strip():
d100 2
a101 1
        # is lift the "requires" handling to be a core lit framework feature.
d109 3
d113 11
a123 1
        return self._evaluate_test(test, lit_config)
a208 36
# 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',
    },
    '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:
        lit_config.warning('The locale {} is not supported by your platform. '
                           'Some tests will be unsupported.'.format(loc))

d210 1
a210 1
cxx_under_test = lit_config.params.get('cxx_under_test', None)
d215 4
a218 5
    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,))
d220 2
a221 2
    lit_config.fatal('must specify user parameter cxx_under_test '
                     '(e.g., --param=cxx_under_test=clang++)')
d223 1
a223 1
libcxx_src_root = lit_config.params.get('libcxx_src_root', None)
d229 1
a229 1
libcxx_obj_root = lit_config.params.get('libcxx_obj_root', None)
d235 1
a235 1
cxx_has_stdcxx0x_flag_str = lit_config.params.get('cxx_has_stdcxx0x_flag', None)
d242 1
a242 2
        lit_config.fatal(
            'user parameter cxx_has_stdcxx0x_flag_str should be 0 or 1')
d249 1
a249 1
use_system_lib_str = lit_config.params.get('use_system_lib', None)
d256 1
a256 1
        lit_config.fatal('user parameter use_system_lib should be 0 or 1')
d260 1
a260 1
    lit_config.note("inferred use_system_lib as: %r" % (use_system_lib,))
d263 1
a263 1
link_flags_str = lit_config.params.get('link_flags', None)
d267 8
a274 21
      cxx_abi = getattr(config, 'cxx_abi', 'libcxxabi')
      if cxx_abi == 'libstdc++':
        link_flags += ['-lstdc++']
      elif cxx_abi == 'libsupc++':
        link_flags += ['-lsupc++']
      elif cxx_abi == 'libcxxabi':
        link_flags += ['-lc++abi']
      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']
      else:
        lit_config.fatal("unrecognized system")

      lit_config.note("inferred link_flags as: %r" % (link_flags,))
d297 1
a297 1
    lit_config.fatal("unrecognized system")
d306 1
a306 1
config.target_triple = lit_config.params.get('target_triple', None)
d311 1
a311 1
    lit_config.note("inferred target_triple as: %r" % (config.target_triple,))
d318 2
a319 5
    # 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,))
@


