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