Daniel Dunbar | 3bc6a98 | 2013-02-12 19:28:51 +0000 | [diff] [blame] | 1 | # -*- Python -*- vim: set syntax=python tabstop=4 expandtab cc=80: |
Daniel Dunbar | f5eadcd | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 2 | |
| 3 | # Configuration file for the 'lit' test runner. |
| 4 | |
Daniel Dunbar | 9e9d076 | 2013-08-30 19:52:12 +0000 | [diff] [blame] | 5 | import errno |
Dan Albert | b4ed5ca | 2014-08-04 18:44:48 +0000 | [diff] [blame^] | 6 | import locale |
Daniel Dunbar | f5eadcd | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 7 | import os |
| 8 | import platform |
Daniel Dunbar | 9e9d076 | 2013-08-30 19:52:12 +0000 | [diff] [blame] | 9 | import re |
| 10 | import shlex |
Daniel Dunbar | f5eadcd | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 11 | import signal |
| 12 | import subprocess |
Daniel Dunbar | 9e9d076 | 2013-08-30 19:52:12 +0000 | [diff] [blame] | 13 | import sys |
| 14 | import tempfile |
Howard Hinnant | b4ebb0e | 2013-01-14 17:12:54 +0000 | [diff] [blame] | 15 | import time |
Daniel Dunbar | f5eadcd | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 16 | |
Daniel Dunbar | bd7b48a | 2013-08-09 14:44:11 +0000 | [diff] [blame] | 17 | import lit.Test |
| 18 | import lit.formats |
| 19 | import lit.util |
| 20 | |
Daniel Dunbar | f5eadcd | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 21 | class 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 | |
Daniel Dunbar | cccf255 | 2013-02-05 18:03:49 +0000 | [diff] [blame] | 31 | def __init__(self, cxx_under_test, cpp_flags, ld_flags, exec_env): |
Daniel Dunbar | 7e0c57b | 2010-09-15 04:11:29 +0000 | [diff] [blame] | 32 | self.cxx_under_test = cxx_under_test |
Daniel Dunbar | 611581b | 2010-09-15 04:31:58 +0000 | [diff] [blame] | 33 | self.cpp_flags = list(cpp_flags) |
| 34 | self.ld_flags = list(ld_flags) |
Daniel Dunbar | cccf255 | 2013-02-05 18:03:49 +0000 | [diff] [blame] | 35 | self.exec_env = dict(exec_env) |
Daniel Dunbar | f5eadcd | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 36 | |
Howard Hinnant | b4ebb0e | 2013-01-14 17:12:54 +0000 | [diff] [blame] | 37 | def execute_command(self, command, in_dir=None): |
| 38 | kwargs = { |
| 39 | 'stdin' :subprocess.PIPE, |
| 40 | 'stdout':subprocess.PIPE, |
| 41 | 'stderr':subprocess.PIPE, |
| 42 | } |
| 43 | if in_dir: |
| 44 | kwargs['cwd'] = in_dir |
| 45 | p = subprocess.Popen(command, **kwargs) |
Daniel Dunbar | f5eadcd | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 46 | out,err = p.communicate() |
| 47 | exitCode = p.wait() |
| 48 | |
| 49 | # Detect Ctrl-C in subprocess. |
| 50 | if exitCode == -signal.SIGINT: |
| 51 | raise KeyboardInterrupt |
| 52 | |
| 53 | return out, err, exitCode |
| 54 | |
| 55 | def execute(self, test, lit_config): |
Howard Hinnant | b4ebb0e | 2013-01-14 17:12:54 +0000 | [diff] [blame] | 56 | while True: |
| 57 | try: |
| 58 | return self._execute(test, lit_config) |
| 59 | except OSError, oe: |
| 60 | if oe.errno != errno.ETXTBSY: |
| 61 | raise |
| 62 | time.sleep(0.1) |
| 63 | |
| 64 | def _execute(self, test, lit_config): |
Daniel Dunbar | 81d1ef7 | 2013-02-05 21:03:25 +0000 | [diff] [blame] | 65 | # Extract test metadata from the test file. |
Daniel Dunbar | 81d1ef7 | 2013-02-05 21:03:25 +0000 | [diff] [blame] | 66 | requires = [] |
| 67 | with open(test.getSourcePath()) as f: |
| 68 | for ln in f: |
| 69 | if 'XFAIL:' in ln: |
| 70 | items = ln[ln.index('XFAIL:') + 6:].split(',') |
Daniel Dunbar | 585b48d | 2013-08-21 23:06:32 +0000 | [diff] [blame] | 71 | test.xfails.extend([s.strip() for s in items]) |
Daniel Dunbar | 81d1ef7 | 2013-02-05 21:03:25 +0000 | [diff] [blame] | 72 | elif 'REQUIRES:' in ln: |
| 73 | items = ln[ln.index('REQUIRES:') + 9:].split(',') |
| 74 | requires.extend([s.strip() for s in items]) |
Eric Fiselier | d3d01ea | 2014-07-31 22:56:52 +0000 | [diff] [blame] | 75 | elif not ln.strip().startswith("//") and ln.strip(): |
Daniel Dunbar | 81d1ef7 | 2013-02-05 21:03:25 +0000 | [diff] [blame] | 76 | # Stop at the first non-empty line that is not a C++ |
| 77 | # comment. |
| 78 | break |
| 79 | |
| 80 | # Check that we have the required features. |
| 81 | # |
| 82 | # FIXME: For now, this is cribbed from lit.TestRunner, to avoid |
| 83 | # introducing a dependency there. What we more ideally would like to do |
Daniel Dunbar | 585b48d | 2013-08-21 23:06:32 +0000 | [diff] [blame] | 84 | # is lift the "requires" handling to be a core lit framework feature. |
Daniel Dunbar | 81d1ef7 | 2013-02-05 21:03:25 +0000 | [diff] [blame] | 85 | missing_required_features = [f for f in requires |
| 86 | if f not in test.config.available_features] |
| 87 | if missing_required_features: |
| 88 | return (lit.Test.UNSUPPORTED, |
| 89 | "Test requires the following features: %s" % ( |
| 90 | ', '.join(missing_required_features),)) |
| 91 | |
Daniel Dunbar | 81d1ef7 | 2013-02-05 21:03:25 +0000 | [diff] [blame] | 92 | # Evaluate the test. |
Daniel Dunbar | 585b48d | 2013-08-21 23:06:32 +0000 | [diff] [blame] | 93 | return self._evaluate_test(test, lit_config) |
Daniel Dunbar | 81d1ef7 | 2013-02-05 21:03:25 +0000 | [diff] [blame] | 94 | |
| 95 | def _evaluate_test(self, test, lit_config): |
Daniel Dunbar | f5eadcd | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 96 | name = test.path_in_suite[-1] |
| 97 | source_path = test.getSourcePath() |
Howard Hinnant | b4ebb0e | 2013-01-14 17:12:54 +0000 | [diff] [blame] | 98 | source_dir = os.path.dirname(source_path) |
Daniel Dunbar | f5eadcd | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 99 | |
| 100 | # Check what kind of test this is. |
| 101 | assert name.endswith('.pass.cpp') or name.endswith('.fail.cpp') |
| 102 | expected_compile_fail = name.endswith('.fail.cpp') |
| 103 | |
| 104 | # If this is a compile (failure) test, build it and check for failure. |
| 105 | if expected_compile_fail: |
| 106 | cmd = [self.cxx_under_test, '-c', |
Daniel Dunbar | 611581b | 2010-09-15 04:31:58 +0000 | [diff] [blame] | 107 | '-o', '/dev/null', source_path] + self.cpp_flags |
Daniel Dunbar | f5eadcd | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 108 | out, err, exitCode = self.execute_command(cmd) |
| 109 | if exitCode == 1: |
| 110 | return lit.Test.PASS, "" |
| 111 | else: |
| 112 | report = """Command: %s\n""" % ' '.join(["'%s'" % a |
| 113 | for a in cmd]) |
| 114 | report += """Exit Code: %d\n""" % exitCode |
| 115 | if out: |
| 116 | report += """Standard Output:\n--\n%s--""" % out |
| 117 | if err: |
| 118 | report += """Standard Error:\n--\n%s--""" % err |
| 119 | report += "\n\nExpected compilation to fail!" |
Daniel Dunbar | 611581b | 2010-09-15 04:31:58 +0000 | [diff] [blame] | 120 | return lit.Test.FAIL, report |
Daniel Dunbar | f5eadcd | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 121 | else: |
| 122 | exec_file = tempfile.NamedTemporaryFile(suffix="exe", delete=False) |
| 123 | exec_path = exec_file.name |
| 124 | exec_file.close() |
| 125 | |
| 126 | try: |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 127 | compile_cmd = [self.cxx_under_test, '-o', exec_path, |
Daniel Dunbar | 611581b | 2010-09-15 04:31:58 +0000 | [diff] [blame] | 128 | source_path] + self.cpp_flags + self.ld_flags |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 129 | cmd = compile_cmd |
Daniel Dunbar | f5eadcd | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 130 | out, err, exitCode = self.execute_command(cmd) |
| 131 | if exitCode != 0: |
Daniel Dunbar | f5eadcd | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 132 | report = """Command: %s\n""" % ' '.join(["'%s'" % a |
| 133 | for a in cmd]) |
| 134 | report += """Exit Code: %d\n""" % exitCode |
| 135 | if out: |
| 136 | report += """Standard Output:\n--\n%s--""" % out |
| 137 | if err: |
| 138 | report += """Standard Error:\n--\n%s--""" % err |
| 139 | report += "\n\nCompilation failed unexpectedly!" |
| 140 | return lit.Test.FAIL, report |
| 141 | |
Daniel Dunbar | cccf255 | 2013-02-05 18:03:49 +0000 | [diff] [blame] | 142 | cmd = [] |
| 143 | if self.exec_env: |
| 144 | cmd.append('env') |
| 145 | cmd.extend('%s=%s' % (name, value) |
| 146 | for name,value in self.exec_env.items()) |
| 147 | cmd.append(exec_path) |
Howard Hinnant | 63b2f4f | 2012-08-02 18:36:47 +0000 | [diff] [blame] | 148 | if lit_config.useValgrind: |
| 149 | cmd = lit_config.valgrindArgs + cmd |
Howard Hinnant | b4ebb0e | 2013-01-14 17:12:54 +0000 | [diff] [blame] | 150 | out, err, exitCode = self.execute_command(cmd, source_dir) |
Daniel Dunbar | f5eadcd | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 151 | if exitCode != 0: |
Daniel Dunbar | 3bc6a98 | 2013-02-12 19:28:51 +0000 | [diff] [blame] | 152 | report = """Compiled With: %s\n""" % \ |
| 153 | ' '.join(["'%s'" % a for a in compile_cmd]) |
| 154 | report += """Command: %s\n""" % \ |
| 155 | ' '.join(["'%s'" % a for a in cmd]) |
Daniel Dunbar | f5eadcd | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 156 | report += """Exit Code: %d\n""" % exitCode |
| 157 | if out: |
| 158 | report += """Standard Output:\n--\n%s--""" % out |
| 159 | if err: |
| 160 | report += """Standard Error:\n--\n%s--""" % err |
| 161 | report += "\n\nCompiled test failed unexpectedly!" |
| 162 | return lit.Test.FAIL, report |
| 163 | finally: |
| 164 | try: |
| 165 | os.remove(exec_path) |
| 166 | except: |
| 167 | pass |
| 168 | return lit.Test.PASS, "" |
| 169 | |
| 170 | # name: The name of this test suite. |
| 171 | config.name = 'libc++' |
| 172 | |
| 173 | # suffixes: A list of file extensions to treat as test files. |
| 174 | config.suffixes = ['.cpp'] |
| 175 | |
| 176 | # test_source_root: The root path where tests are located. |
| 177 | config.test_source_root = os.path.dirname(__file__) |
| 178 | |
Dan Albert | b4ed5ca | 2014-08-04 18:44:48 +0000 | [diff] [blame^] | 179 | # Figure out which of the required locales we support |
| 180 | locales = { |
| 181 | 'Darwin': { |
| 182 | 'en_US.UTF-8': 'en_US.UTF-8', |
| 183 | 'cs_CZ.ISO8859-2': 'cs_CZ.ISO8859-2', |
| 184 | 'fr_FR.UTF-8': 'fr_FR.UTF-8', |
| 185 | 'fr_CA.ISO8859-1': 'cs_CZ.ISO8859-1', |
| 186 | 'ru_RU.UTF-8': 'ru_RU.UTF-8', |
| 187 | 'zh_CN.UTF-8': 'zh_CN.UTF-8', |
| 188 | }, |
| 189 | 'Linux': { |
| 190 | 'en_US.UTF-8': 'en_US.UTF-8', |
| 191 | 'cs_CZ.ISO8859-2': 'cs_CZ.ISO-8859-2', |
| 192 | 'fr_FR.UTF-8': 'fr_FR.UTF-8', |
| 193 | 'fr_CA.ISO8859-1': 'fr_CA.ISO-8859-1', |
| 194 | 'ru_RU.UTF-8': 'ru_RU.UTF-8', |
| 195 | 'zh_CN.UTF-8': 'zh_CN.UTF-8', |
| 196 | }, |
| 197 | 'Windows': { |
| 198 | 'en_US.UTF-8': 'English_United States.1252', |
| 199 | 'cs_CZ.ISO8859-2': 'Czech_Czech Republic.1250', |
| 200 | 'fr_FR.UTF-8': 'French_France.1252', |
| 201 | 'fr_CA.ISO8859-1': 'French_Canada.1252', |
| 202 | 'ru_RU.UTF-8': 'Russian_Russia.1251', |
| 203 | 'zh_CN.UTF-8': 'Chinese_China.936', |
| 204 | }, |
| 205 | } |
| 206 | |
| 207 | for feature, loc in locales[platform.system()].items(): |
| 208 | try: |
| 209 | locale.setlocale(locale.LC_ALL, loc) |
| 210 | config.available_features.add('locale.{}'.format(feature)) |
| 211 | except: |
| 212 | lit_config.warning('The locale {} is not supported by your platoform. ' |
| 213 | 'Some tests will be unsupported.'.format(loc)) |
| 214 | |
Daniel Dunbar | af01e70 | 2012-11-27 23:56:28 +0000 | [diff] [blame] | 215 | # Gather various compiler parameters. |
Daniel Dunbar | bd7b48a | 2013-08-09 14:44:11 +0000 | [diff] [blame] | 216 | cxx_under_test = lit_config.params.get('cxx_under_test', None) |
Daniel Dunbar | f5eadcd | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 217 | if cxx_under_test is None: |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 218 | cxx_under_test = getattr(config, 'cxx_under_test', None) |
Daniel Dunbar | 7fa0ca7 | 2013-02-06 20:24:23 +0000 | [diff] [blame] | 219 | |
| 220 | # If no specific cxx_under_test was given, attempt to infer it as clang++. |
David Fang | a612c62 | 2014-01-29 01:54:52 +0000 | [diff] [blame] | 221 | if cxx_under_test is None: |
| 222 | clangxx = lit.util.which('clang++', config.environment['PATH']) |
| 223 | if clangxx is not None: |
| 224 | cxx_under_test = clangxx |
| 225 | lit_config.note("inferred cxx_under_test as: %r" % (cxx_under_test,)) |
Daniel Dunbar | 7fa0ca7 | 2013-02-06 20:24:23 +0000 | [diff] [blame] | 226 | if cxx_under_test is None: |
Daniel Dunbar | bd7b48a | 2013-08-09 14:44:11 +0000 | [diff] [blame] | 227 | lit_config.fatal('must specify user parameter cxx_under_test ' |
| 228 | '(e.g., --param=cxx_under_test=clang++)') |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 229 | |
Daniel Dunbar | bd7b48a | 2013-08-09 14:44:11 +0000 | [diff] [blame] | 230 | libcxx_src_root = lit_config.params.get('libcxx_src_root', None) |
Daniel Dunbar | af01e70 | 2012-11-27 23:56:28 +0000 | [diff] [blame] | 231 | if libcxx_src_root is None: |
| 232 | libcxx_src_root = getattr(config, 'libcxx_src_root', None) |
| 233 | if libcxx_src_root is None: |
| 234 | libcxx_src_root = os.path.dirname(config.test_source_root) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 235 | |
Daniel Dunbar | bd7b48a | 2013-08-09 14:44:11 +0000 | [diff] [blame] | 236 | libcxx_obj_root = lit_config.params.get('libcxx_obj_root', None) |
Daniel Dunbar | af01e70 | 2012-11-27 23:56:28 +0000 | [diff] [blame] | 237 | if libcxx_obj_root is None: |
| 238 | libcxx_obj_root = getattr(config, 'libcxx_obj_root', None) |
| 239 | if libcxx_obj_root is None: |
| 240 | libcxx_obj_root = libcxx_src_root |
| 241 | |
Daniel Dunbar | bd7b48a | 2013-08-09 14:44:11 +0000 | [diff] [blame] | 242 | cxx_has_stdcxx0x_flag_str = lit_config.params.get('cxx_has_stdcxx0x_flag', None) |
Daniel Dunbar | af01e70 | 2012-11-27 23:56:28 +0000 | [diff] [blame] | 243 | if cxx_has_stdcxx0x_flag_str is not None: |
Daniel Dunbar | cccf255 | 2013-02-05 18:03:49 +0000 | [diff] [blame] | 244 | if cxx_has_stdcxx0x_flag_str.lower() in ('1', 'true'): |
Daniel Dunbar | af01e70 | 2012-11-27 23:56:28 +0000 | [diff] [blame] | 245 | cxx_has_stdcxx0x_flag = True |
Daniel Dunbar | cccf255 | 2013-02-05 18:03:49 +0000 | [diff] [blame] | 246 | elif cxx_has_stdcxx0x_flag_str.lower() in ('', '0', 'false'): |
Daniel Dunbar | af01e70 | 2012-11-27 23:56:28 +0000 | [diff] [blame] | 247 | cxx_has_stdcxx0x_flag = False |
| 248 | else: |
Daniel Dunbar | bd7b48a | 2013-08-09 14:44:11 +0000 | [diff] [blame] | 249 | lit_config.fatal( |
| 250 | 'user parameter cxx_has_stdcxx0x_flag_str should be 0 or 1') |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 251 | else: |
Daniel Dunbar | af01e70 | 2012-11-27 23:56:28 +0000 | [diff] [blame] | 252 | cxx_has_stdcxx0x_flag = getattr(config, 'cxx_has_stdcxx0x_flag', True) |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 253 | |
Daniel Dunbar | cccf255 | 2013-02-05 18:03:49 +0000 | [diff] [blame] | 254 | # This test suite supports testing against either the system library or the |
| 255 | # locally built one; the former mode is useful for testing ABI compatibility |
Daniel Dunbar | 88dec1e | 2013-02-06 17:47:08 +0000 | [diff] [blame] | 256 | # between the current headers and a shipping dynamic library. |
Daniel Dunbar | bd7b48a | 2013-08-09 14:44:11 +0000 | [diff] [blame] | 257 | use_system_lib_str = lit_config.params.get('use_system_lib', None) |
Daniel Dunbar | cccf255 | 2013-02-05 18:03:49 +0000 | [diff] [blame] | 258 | if use_system_lib_str is not None: |
| 259 | if use_system_lib_str.lower() in ('1', 'true'): |
| 260 | use_system_lib = True |
| 261 | elif use_system_lib_str.lower() in ('', '0', 'false'): |
| 262 | use_system_lib = False |
| 263 | else: |
Daniel Dunbar | bd7b48a | 2013-08-09 14:44:11 +0000 | [diff] [blame] | 264 | lit_config.fatal('user parameter use_system_lib should be 0 or 1') |
Daniel Dunbar | cccf255 | 2013-02-05 18:03:49 +0000 | [diff] [blame] | 265 | else: |
Daniel Dunbar | 88dec1e | 2013-02-06 17:47:08 +0000 | [diff] [blame] | 266 | # Default to testing against the locally built libc++ library. |
| 267 | use_system_lib = False |
Daniel Dunbar | bd7b48a | 2013-08-09 14:44:11 +0000 | [diff] [blame] | 268 | lit_config.note("inferred use_system_lib as: %r" % (use_system_lib,)) |
Daniel Dunbar | cccf255 | 2013-02-05 18:03:49 +0000 | [diff] [blame] | 269 | |
Daniel Dunbar | 3bc6a98 | 2013-02-12 19:28:51 +0000 | [diff] [blame] | 270 | link_flags = [] |
Daniel Dunbar | bd7b48a | 2013-08-09 14:44:11 +0000 | [diff] [blame] | 271 | link_flags_str = lit_config.params.get('link_flags', None) |
Daniel Dunbar | 3bc6a98 | 2013-02-12 19:28:51 +0000 | [diff] [blame] | 272 | if link_flags_str is None: |
| 273 | link_flags_str = getattr(config, 'link_flags', None) |
| 274 | if link_flags_str is None: |
Howard Hinnant | 71b5215 | 2013-10-14 18:02:02 +0000 | [diff] [blame] | 275 | cxx_abi = getattr(config, 'cxx_abi', 'libcxxabi') |
Peter Collingbourne | d0d308f | 2013-10-06 22:13:19 +0000 | [diff] [blame] | 276 | if cxx_abi == 'libstdc++': |
| 277 | link_flags += ['-lstdc++'] |
| 278 | elif cxx_abi == 'libsupc++': |
| 279 | link_flags += ['-lsupc++'] |
| 280 | elif cxx_abi == 'libcxxabi': |
| 281 | link_flags += ['-lc++abi'] |
| 282 | elif cxx_abi == 'none': |
| 283 | pass |
| 284 | else: |
| 285 | lit_config.fatal('C++ ABI setting %s unsupported for tests' % cxx_abi) |
| 286 | |
| 287 | if sys.platform == 'darwin': |
| 288 | link_flags += ['-lSystem'] |
| 289 | elif sys.platform == 'linux2': |
| 290 | link_flags += [ '-lgcc_eh', '-lc', '-lm', '-lpthread', |
| 291 | '-lrt', '-lgcc_s'] |
| 292 | else: |
| 293 | lit_config.fatal("unrecognized system") |
| 294 | |
| 295 | lit_config.note("inferred link_flags as: %r" % (link_flags,)) |
Daniel Dunbar | 3bc6a98 | 2013-02-12 19:28:51 +0000 | [diff] [blame] | 296 | if not link_flags_str is None: |
| 297 | link_flags += shlex.split(link_flags_str) |
| 298 | |
Chandler Carruth | e76496c | 2011-01-23 01:05:20 +0000 | [diff] [blame] | 299 | # Configure extra compiler flags. |
Daniel Dunbar | 3bc6a98 | 2013-02-12 19:28:51 +0000 | [diff] [blame] | 300 | include_paths = ['-I' + libcxx_src_root + '/include', |
| 301 | '-I' + libcxx_src_root + '/test/support'] |
Daniel Dunbar | af01e70 | 2012-11-27 23:56:28 +0000 | [diff] [blame] | 302 | library_paths = ['-L' + libcxx_obj_root + '/lib'] |
Chandler Carruth | e76496c | 2011-01-23 01:05:20 +0000 | [diff] [blame] | 303 | compile_flags = [] |
Daniel Dunbar | af01e70 | 2012-11-27 23:56:28 +0000 | [diff] [blame] | 304 | if cxx_has_stdcxx0x_flag: |
Daniel Dunbar | cccf255 | 2013-02-05 18:03:49 +0000 | [diff] [blame] | 305 | compile_flags += ['-std=c++0x'] |
Chandler Carruth | e76496c | 2011-01-23 01:05:20 +0000 | [diff] [blame] | 306 | |
Daniel Dunbar | 3bc6a98 | 2013-02-12 19:28:51 +0000 | [diff] [blame] | 307 | # Configure extra linker parameters. |
Daniel Dunbar | cccf255 | 2013-02-05 18:03:49 +0000 | [diff] [blame] | 308 | exec_env = {} |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 309 | if sys.platform == 'darwin': |
Daniel Dunbar | cccf255 | 2013-02-05 18:03:49 +0000 | [diff] [blame] | 310 | if not use_system_lib: |
| 311 | exec_env['DYLD_LIBRARY_PATH'] = os.path.join(libcxx_obj_root, 'lib') |
| 312 | elif sys.platform == 'linux2': |
Daniel Dunbar | 6b8b992 | 2013-02-06 17:45:53 +0000 | [diff] [blame] | 313 | if not use_system_lib: |
Daniel Dunbar | 3bc6a98 | 2013-02-12 19:28:51 +0000 | [diff] [blame] | 314 | link_flags += ['-Wl,-R', libcxx_obj_root + '/lib'] |
| 315 | compile_flags += ['-D__STDC_FORMAT_MACROS', '-D__STDC_LIMIT_MACROS', |
| 316 | '-D__STDC_CONSTANT_MACROS'] |
Daniel Dunbar | cccf255 | 2013-02-05 18:03:49 +0000 | [diff] [blame] | 317 | else: |
Daniel Dunbar | bd7b48a | 2013-08-09 14:44:11 +0000 | [diff] [blame] | 318 | lit_config.fatal("unrecognized system") |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 319 | |
Daniel Dunbar | af01e70 | 2012-11-27 23:56:28 +0000 | [diff] [blame] | 320 | config.test_format = LibcxxTestFormat( |
| 321 | cxx_under_test, |
| 322 | cpp_flags = ['-nostdinc++'] + compile_flags + include_paths, |
Daniel Dunbar | 3bc6a98 | 2013-02-12 19:28:51 +0000 | [diff] [blame] | 323 | ld_flags = ['-nodefaultlibs'] + library_paths + ['-lc++'] + link_flags, |
Daniel Dunbar | cccf255 | 2013-02-05 18:03:49 +0000 | [diff] [blame] | 324 | exec_env = exec_env) |
Daniel Dunbar | f5eadcd | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 325 | |
Daniel Dunbar | 4cceb7a | 2013-02-05 22:28:03 +0000 | [diff] [blame] | 326 | # Get or infer the target triple. |
Daniel Dunbar | bd7b48a | 2013-08-09 14:44:11 +0000 | [diff] [blame] | 327 | config.target_triple = lit_config.params.get('target_triple', None) |
Daniel Dunbar | 4cceb7a | 2013-02-05 22:28:03 +0000 | [diff] [blame] | 328 | # If no target triple was given, try to infer it from the compiler under test. |
| 329 | if config.target_triple is None: |
| 330 | config.target_triple = lit.util.capture( |
| 331 | [cxx_under_test, '-dumpmachine']).strip() |
Daniel Dunbar | bd7b48a | 2013-08-09 14:44:11 +0000 | [diff] [blame] | 332 | lit_config.note("inferred target_triple as: %r" % (config.target_triple,)) |
Daniel Dunbar | a5b5196 | 2013-02-05 21:43:30 +0000 | [diff] [blame] | 333 | |
| 334 | # Write an "available feature" that combines the triple when use_system_lib is |
| 335 | # enabled. This is so that we can easily write XFAIL markers for tests that are |
| 336 | # known to fail with versions of libc++ as were shipped with a particular |
| 337 | # triple. |
| 338 | if use_system_lib: |
Daniel Dunbar | 9e9d076 | 2013-08-30 19:52:12 +0000 | [diff] [blame] | 339 | # Drop sub-major version components from the triple, because the current |
| 340 | # XFAIL handling expects exact matches for feature checks. |
| 341 | sanitized_triple = re.sub(r"([^-]+)-([^-]+)-([^-.]+).*", r"\1-\2-\3", |
| 342 | config.target_triple) |
| 343 | config.available_features.add('with_system_lib=%s' % (sanitized_triple,)) |