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 | |
Justin Bogner | 33a2a2e | 2014-09-03 04:32:08 +0000 | [diff] [blame] | 31 | def __init__(self, cxx_under_test, use_verify_for_fail, |
| 32 | cpp_flags, ld_flags, exec_env): |
Daniel Dunbar | bc9a848 | 2010-09-15 04:11:29 +0000 | [diff] [blame] | 33 | self.cxx_under_test = cxx_under_test |
Justin Bogner | 33a2a2e | 2014-09-03 04:32:08 +0000 | [diff] [blame] | 34 | self.use_verify_for_fail = use_verify_for_fail |
Daniel Dunbar | 5f09d9e0 | 2010-09-15 04:31:58 +0000 | [diff] [blame] | 35 | self.cpp_flags = list(cpp_flags) |
| 36 | self.ld_flags = list(ld_flags) |
Daniel Dunbar | 8495871 | 2013-02-05 18:03:49 +0000 | [diff] [blame] | 37 | self.exec_env = dict(exec_env) |
Daniel Dunbar | 42ea463 | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 38 | |
Howard Hinnant | 3778f27 | 2013-01-14 17:12:54 +0000 | [diff] [blame] | 39 | def execute_command(self, command, in_dir=None): |
| 40 | kwargs = { |
| 41 | 'stdin' :subprocess.PIPE, |
| 42 | 'stdout':subprocess.PIPE, |
| 43 | 'stderr':subprocess.PIPE, |
| 44 | } |
| 45 | if in_dir: |
| 46 | kwargs['cwd'] = in_dir |
| 47 | p = subprocess.Popen(command, **kwargs) |
Daniel Dunbar | 42ea463 | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 48 | out,err = p.communicate() |
| 49 | exitCode = p.wait() |
| 50 | |
| 51 | # Detect Ctrl-C in subprocess. |
| 52 | if exitCode == -signal.SIGINT: |
| 53 | raise KeyboardInterrupt |
| 54 | |
| 55 | return out, err, exitCode |
| 56 | |
| 57 | def execute(self, test, lit_config): |
Howard Hinnant | 3778f27 | 2013-01-14 17:12:54 +0000 | [diff] [blame] | 58 | while True: |
| 59 | try: |
| 60 | return self._execute(test, lit_config) |
| 61 | except OSError, oe: |
| 62 | if oe.errno != errno.ETXTBSY: |
| 63 | raise |
| 64 | time.sleep(0.1) |
| 65 | |
| 66 | def _execute(self, test, lit_config): |
Daniel Dunbar | f51f031 | 2013-02-05 21:03:25 +0000 | [diff] [blame] | 67 | # Extract test metadata from the test file. |
Daniel Dunbar | f51f031 | 2013-02-05 21:03:25 +0000 | [diff] [blame] | 68 | requires = [] |
Eric Fiselier | 339bdc3 | 2014-08-18 06:43:06 +0000 | [diff] [blame] | 69 | unsupported = [] |
Justin Bogner | 2cfd1fe | 2014-09-03 06:01:52 +0000 | [diff] [blame] | 70 | use_verify = False |
Daniel Dunbar | f51f031 | 2013-02-05 21:03:25 +0000 | [diff] [blame] | 71 | with open(test.getSourcePath()) as f: |
| 72 | for ln in f: |
| 73 | if 'XFAIL:' in ln: |
| 74 | items = ln[ln.index('XFAIL:') + 6:].split(',') |
Daniel Dunbar | 019c590 | 2013-08-21 23:06:32 +0000 | [diff] [blame] | 75 | test.xfails.extend([s.strip() for s in items]) |
Daniel Dunbar | f51f031 | 2013-02-05 21:03:25 +0000 | [diff] [blame] | 76 | elif 'REQUIRES:' in ln: |
| 77 | items = ln[ln.index('REQUIRES:') + 9:].split(',') |
| 78 | requires.extend([s.strip() for s in items]) |
Eric Fiselier | 339bdc3 | 2014-08-18 06:43:06 +0000 | [diff] [blame] | 79 | elif 'UNSUPPORTED:' in ln: |
| 80 | items = ln[ln.index('UNSUPPORTED:') + 12:].split(',') |
| 81 | unsupported.extend([s.strip() for s in items]) |
Justin Bogner | 2cfd1fe | 2014-09-03 06:01:52 +0000 | [diff] [blame] | 82 | elif 'USE_VERIFY' in ln and self.use_verify_for_fail: |
| 83 | use_verify = True |
Eric Fiselier | 993dfb1 | 2014-07-31 22:56:52 +0000 | [diff] [blame] | 84 | elif not ln.strip().startswith("//") and ln.strip(): |
Daniel Dunbar | f51f031 | 2013-02-05 21:03:25 +0000 | [diff] [blame] | 85 | # Stop at the first non-empty line that is not a C++ |
| 86 | # comment. |
| 87 | break |
| 88 | |
| 89 | # Check that we have the required features. |
| 90 | # |
| 91 | # FIXME: For now, this is cribbed from lit.TestRunner, to avoid |
| 92 | # introducing a dependency there. What we more ideally would like to do |
Daniel Dunbar | 019c590 | 2013-08-21 23:06:32 +0000 | [diff] [blame] | 93 | # is lift the "requires" handling to be a core lit framework feature. |
Daniel Dunbar | f51f031 | 2013-02-05 21:03:25 +0000 | [diff] [blame] | 94 | missing_required_features = [f for f in requires |
| 95 | if f not in test.config.available_features] |
| 96 | if missing_required_features: |
| 97 | return (lit.Test.UNSUPPORTED, |
| 98 | "Test requires the following features: %s" % ( |
| 99 | ', '.join(missing_required_features),)) |
| 100 | |
Eric Fiselier | 339bdc3 | 2014-08-18 06:43:06 +0000 | [diff] [blame] | 101 | unsupported_features = [f for f in unsupported |
| 102 | if f in test.config.available_features] |
| 103 | if unsupported_features: |
| 104 | return (lit.Test.UNSUPPORTED, |
| 105 | "Test is unsupported with the following features: %s" % ( |
| 106 | ', '.join(unsupported_features),)) |
| 107 | |
Daniel Dunbar | f51f031 | 2013-02-05 21:03:25 +0000 | [diff] [blame] | 108 | # Evaluate the test. |
Justin Bogner | 2cfd1fe | 2014-09-03 06:01:52 +0000 | [diff] [blame] | 109 | return self._evaluate_test(test, use_verify, lit_config) |
Daniel Dunbar | f51f031 | 2013-02-05 21:03:25 +0000 | [diff] [blame] | 110 | |
Justin Bogner | 2cfd1fe | 2014-09-03 06:01:52 +0000 | [diff] [blame] | 111 | def _evaluate_test(self, test, use_verify, lit_config): |
Daniel Dunbar | 42ea463 | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 112 | name = test.path_in_suite[-1] |
| 113 | source_path = test.getSourcePath() |
Howard Hinnant | 3778f27 | 2013-01-14 17:12:54 +0000 | [diff] [blame] | 114 | source_dir = os.path.dirname(source_path) |
Daniel Dunbar | 42ea463 | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 115 | |
| 116 | # Check what kind of test this is. |
| 117 | assert name.endswith('.pass.cpp') or name.endswith('.fail.cpp') |
| 118 | expected_compile_fail = name.endswith('.fail.cpp') |
| 119 | |
| 120 | # If this is a compile (failure) test, build it and check for failure. |
| 121 | if expected_compile_fail: |
| 122 | cmd = [self.cxx_under_test, '-c', |
Daniel Dunbar | 5f09d9e0 | 2010-09-15 04:31:58 +0000 | [diff] [blame] | 123 | '-o', '/dev/null', source_path] + self.cpp_flags |
Justin Bogner | 33a2a2e | 2014-09-03 04:32:08 +0000 | [diff] [blame] | 124 | expected_rc = 1 |
Justin Bogner | 2cfd1fe | 2014-09-03 06:01:52 +0000 | [diff] [blame] | 125 | if use_verify: |
Justin Bogner | 33a2a2e | 2014-09-03 04:32:08 +0000 | [diff] [blame] | 126 | cmd += ['-Xclang', '-verify'] |
| 127 | expected_rc = 0 |
| 128 | out, err, rc = self.execute_command(cmd) |
| 129 | if rc == expected_rc: |
Daniel Dunbar | 42ea463 | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 130 | return lit.Test.PASS, "" |
| 131 | else: |
| 132 | report = """Command: %s\n""" % ' '.join(["'%s'" % a |
| 133 | for a in cmd]) |
Justin Bogner | 33a2a2e | 2014-09-03 04:32:08 +0000 | [diff] [blame] | 134 | report += """Exit Code: %d\n""" % rc |
Daniel Dunbar | 42ea463 | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 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\nExpected compilation to fail!" |
Daniel Dunbar | 5f09d9e0 | 2010-09-15 04:31:58 +0000 | [diff] [blame] | 140 | return lit.Test.FAIL, report |
Daniel Dunbar | 42ea463 | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 141 | else: |
| 142 | exec_file = tempfile.NamedTemporaryFile(suffix="exe", delete=False) |
| 143 | exec_path = exec_file.name |
| 144 | exec_file.close() |
| 145 | |
| 146 | try: |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 147 | compile_cmd = [self.cxx_under_test, '-o', exec_path, |
Daniel Dunbar | 5f09d9e0 | 2010-09-15 04:31:58 +0000 | [diff] [blame] | 148 | source_path] + self.cpp_flags + self.ld_flags |
Michael J. Spencer | f5799be | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 149 | cmd = compile_cmd |
Daniel Dunbar | 42ea463 | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 150 | out, err, exitCode = self.execute_command(cmd) |
| 151 | if exitCode != 0: |
Daniel Dunbar | 42ea463 | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 152 | report = """Command: %s\n""" % ' '.join(["'%s'" % a |
| 153 | for a in cmd]) |
| 154 | report += """Exit Code: %d\n""" % exitCode |
| 155 | if out: |
| 156 | report += """Standard Output:\n--\n%s--""" % out |
| 157 | if err: |
| 158 | report += """Standard Error:\n--\n%s--""" % err |
| 159 | report += "\n\nCompilation failed unexpectedly!" |
| 160 | return lit.Test.FAIL, report |
| 161 | |
Daniel Dunbar | 8495871 | 2013-02-05 18:03:49 +0000 | [diff] [blame] | 162 | cmd = [] |
| 163 | if self.exec_env: |
| 164 | cmd.append('env') |
| 165 | cmd.extend('%s=%s' % (name, value) |
| 166 | for name,value in self.exec_env.items()) |
| 167 | cmd.append(exec_path) |
Howard Hinnant | c1a45fb | 2012-08-02 18:36:47 +0000 | [diff] [blame] | 168 | if lit_config.useValgrind: |
| 169 | cmd = lit_config.valgrindArgs + cmd |
Howard Hinnant | 3778f27 | 2013-01-14 17:12:54 +0000 | [diff] [blame] | 170 | out, err, exitCode = self.execute_command(cmd, source_dir) |
Daniel Dunbar | 42ea463 | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 171 | if exitCode != 0: |
Daniel Dunbar | 62b9439 | 2013-02-12 19:28:51 +0000 | [diff] [blame] | 172 | report = """Compiled With: %s\n""" % \ |
| 173 | ' '.join(["'%s'" % a for a in compile_cmd]) |
| 174 | report += """Command: %s\n""" % \ |
| 175 | ' '.join(["'%s'" % a for a in cmd]) |
Daniel Dunbar | 42ea463 | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 176 | report += """Exit Code: %d\n""" % exitCode |
| 177 | if out: |
| 178 | report += """Standard Output:\n--\n%s--""" % out |
| 179 | if err: |
| 180 | report += """Standard Error:\n--\n%s--""" % err |
| 181 | report += "\n\nCompiled test failed unexpectedly!" |
| 182 | return lit.Test.FAIL, report |
| 183 | finally: |
| 184 | try: |
| 185 | os.remove(exec_path) |
| 186 | except: |
| 187 | pass |
| 188 | return lit.Test.PASS, "" |
| 189 | |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 190 | |
| 191 | class Configuration(object): |
| 192 | def __init__(self, lit_config, config): |
| 193 | self.lit_config = lit_config |
| 194 | self.config = config |
| 195 | self.cxx = None |
| 196 | self.src_root = None |
| 197 | self.obj_root = None |
| 198 | self.env = {} |
| 199 | self.compile_flags = [] |
Eric Fiselier | 6f9da55 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 200 | self.library_paths = [] |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 201 | self.link_flags = [] |
| 202 | self.use_system_lib = False |
Justin Bogner | 33a2a2e | 2014-09-03 04:32:08 +0000 | [diff] [blame] | 203 | self.use_clang_verify = False |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 204 | |
| 205 | if platform.system() not in ('Darwin', 'FreeBSD', 'Linux'): |
| 206 | self.lit_config.fatal("unrecognized system") |
| 207 | |
| 208 | def get_lit_conf(self, name, default=None): |
| 209 | val = self.lit_config.params.get(name, None) |
| 210 | if val is None: |
| 211 | val = getattr(self.config, name, None) |
| 212 | if val is None: |
| 213 | val = default |
| 214 | return val |
| 215 | |
Justin Bogner | 33a2a2e | 2014-09-03 04:32:08 +0000 | [diff] [blame] | 216 | def get_lit_bool(self, name): |
| 217 | conf = self.get_lit_conf(name) |
| 218 | if conf is None: |
| 219 | return None |
| 220 | if conf.lower() in ('1', 'true'): |
| 221 | return True |
| 222 | if conf.lower() in ('', '0', 'false'): |
| 223 | return False |
| 224 | self.lit_config.fatal( |
| 225 | "parameter '{}' should be true or false".format(name)) |
| 226 | |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 227 | def configure(self): |
| 228 | self.configure_cxx() |
| 229 | self.configure_triple() |
| 230 | self.configure_src_root() |
| 231 | self.configure_obj_root() |
| 232 | self.configure_use_system_lib() |
Justin Bogner | 33a2a2e | 2014-09-03 04:32:08 +0000 | [diff] [blame] | 233 | self.configure_use_clang_verify() |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 234 | self.configure_env() |
| 235 | self.configure_std_flag() |
| 236 | self.configure_compile_flags() |
| 237 | self.configure_link_flags() |
| 238 | self.configure_sanitizer() |
| 239 | self.configure_features() |
| 240 | |
| 241 | def get_test_format(self): |
| 242 | return LibcxxTestFormat( |
| 243 | self.cxx, |
Justin Bogner | 33a2a2e | 2014-09-03 04:32:08 +0000 | [diff] [blame] | 244 | self.use_clang_verify, |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 245 | cpp_flags=['-nostdinc++'] + self.compile_flags, |
| 246 | ld_flags=['-nodefaultlibs'] + self.link_flags, |
| 247 | exec_env=self.env) |
| 248 | |
| 249 | def configure_cxx(self): |
| 250 | # Gather various compiler parameters. |
| 251 | self.cxx = self.get_lit_conf('cxx_under_test') |
| 252 | |
| 253 | # If no specific cxx_under_test was given, attempt to infer it as |
| 254 | # clang++. |
| 255 | if self.cxx is None: |
| 256 | clangxx = lit.util.which('clang++', |
| 257 | self.config.environment['PATH']) |
| 258 | if clangxx: |
| 259 | self.cxx = clangxx |
| 260 | self.lit_config.note( |
| 261 | "inferred cxx_under_test as: %r" % self.cxx) |
| 262 | if not self.cxx: |
| 263 | self.lit_config.fatal('must specify user parameter cxx_under_test ' |
| 264 | '(e.g., --param=cxx_under_test=clang++)') |
| 265 | |
| 266 | def configure_src_root(self): |
| 267 | self.src_root = self.get_lit_conf( |
| 268 | 'libcxx_src_root', os.path.dirname(self.config.test_source_root)) |
| 269 | |
| 270 | def configure_obj_root(self): |
| 271 | self.obj_root = self.get_lit_conf('libcxx_obj_root', self.src_root) |
| 272 | |
| 273 | def configure_use_system_lib(self): |
| 274 | # This test suite supports testing against either the system library or |
| 275 | # the locally built one; the former mode is useful for testing ABI |
| 276 | # compatibility between the current headers and a shipping dynamic |
| 277 | # library. |
Justin Bogner | 33a2a2e | 2014-09-03 04:32:08 +0000 | [diff] [blame] | 278 | self.use_system_lib = self.get_lit_bool('use_system_lib') |
| 279 | if self.use_system_lib is None: |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 280 | # Default to testing against the locally built libc++ library. |
| 281 | self.use_system_lib = False |
| 282 | self.lit_config.note( |
| 283 | "inferred use_system_lib as: %r" % self.use_system_lib) |
| 284 | |
Justin Bogner | 33a2a2e | 2014-09-03 04:32:08 +0000 | [diff] [blame] | 285 | def configure_use_clang_verify(self): |
| 286 | '''If set, run clang with -verify on failing tests.''' |
| 287 | self.use_clang_verify = self.get_lit_bool('use_clang_verify') |
| 288 | if self.use_clang_verify is None: |
| 289 | # TODO: Default this to True when using clang. |
| 290 | self.use_clang_verify = False |
| 291 | self.lit_config.note( |
| 292 | "inferred use_clang_verify as: %r" % self.use_clang_verify) |
| 293 | |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 294 | def configure_features(self): |
Jonathan Roelofs | b352db7 | 2014-09-05 19:03:46 +0000 | [diff] [blame] | 295 | additional_features = self.get_lit_conf('additional_features') |
| 296 | if additional_features: |
| 297 | for f in additional_features.split(','): |
| 298 | self.config.available_features.add(f.strip()) |
Jonathan Roelofs | 3547c54 | 2014-09-05 17:21:57 +0000 | [diff] [blame] | 299 | |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 300 | # Figure out which of the required locales we support |
| 301 | locales = { |
| 302 | 'Darwin': { |
| 303 | 'en_US.UTF-8': 'en_US.UTF-8', |
| 304 | 'cs_CZ.ISO8859-2': 'cs_CZ.ISO8859-2', |
| 305 | 'fr_FR.UTF-8': 'fr_FR.UTF-8', |
| 306 | 'fr_CA.ISO8859-1': 'cs_CZ.ISO8859-1', |
| 307 | 'ru_RU.UTF-8': 'ru_RU.UTF-8', |
| 308 | 'zh_CN.UTF-8': 'zh_CN.UTF-8', |
| 309 | }, |
| 310 | 'FreeBSD': { |
| 311 | 'en_US.UTF-8': 'en_US.UTF-8', |
| 312 | 'cs_CZ.ISO8859-2': 'cs_CZ.ISO8859-2', |
| 313 | 'fr_FR.UTF-8': 'fr_FR.UTF-8', |
| 314 | 'fr_CA.ISO8859-1': 'fr_CA.ISO8859-1', |
| 315 | 'ru_RU.UTF-8': 'ru_RU.UTF-8', |
| 316 | 'zh_CN.UTF-8': 'zh_CN.UTF-8', |
| 317 | }, |
| 318 | 'Linux': { |
| 319 | 'en_US.UTF-8': 'en_US.UTF-8', |
| 320 | 'cs_CZ.ISO8859-2': 'cs_CZ.ISO-8859-2', |
| 321 | 'fr_FR.UTF-8': 'fr_FR.UTF-8', |
| 322 | 'fr_CA.ISO8859-1': 'fr_CA.ISO-8859-1', |
| 323 | 'ru_RU.UTF-8': 'ru_RU.UTF-8', |
| 324 | 'zh_CN.UTF-8': 'zh_CN.UTF-8', |
| 325 | }, |
| 326 | 'Windows': { |
| 327 | 'en_US.UTF-8': 'English_United States.1252', |
| 328 | 'cs_CZ.ISO8859-2': 'Czech_Czech Republic.1250', |
| 329 | 'fr_FR.UTF-8': 'French_France.1252', |
| 330 | 'fr_CA.ISO8859-1': 'French_Canada.1252', |
| 331 | 'ru_RU.UTF-8': 'Russian_Russia.1251', |
| 332 | 'zh_CN.UTF-8': 'Chinese_China.936', |
| 333 | }, |
| 334 | } |
| 335 | |
| 336 | default_locale = locale.setlocale(locale.LC_ALL) |
| 337 | for feature, loc in locales[platform.system()].items(): |
| 338 | try: |
| 339 | locale.setlocale(locale.LC_ALL, loc) |
Eric Fiselier | 561dfb5 | 2014-08-23 04:02:21 +0000 | [diff] [blame] | 340 | self.config.available_features.add('locale.{0}'.format(feature)) |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 341 | except: |
Eric Fiselier | 561dfb5 | 2014-08-23 04:02:21 +0000 | [diff] [blame] | 342 | self.lit_config.warning('The locale {0} is not supported by ' |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 343 | 'your platform. Some tests will be ' |
| 344 | 'unsupported.'.format(loc)) |
| 345 | locale.setlocale(locale.LC_ALL, default_locale) |
| 346 | |
| 347 | # Write an "available feature" that combines the triple when |
| 348 | # use_system_lib is enabled. This is so that we can easily write XFAIL |
| 349 | # markers for tests that are known to fail with versions of libc++ as |
| 350 | # were shipped with a particular triple. |
| 351 | if self.use_system_lib: |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 352 | self.config.available_features.add( |
Eric Fiselier | bb19141 | 2014-10-27 22:14:25 +0000 | [diff] [blame] | 353 | 'with_system_lib=%s' % self.config.target_triple) |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 354 | |
Jonathan Roelofs | 3547c54 | 2014-09-05 17:21:57 +0000 | [diff] [blame] | 355 | if 'libcpp-has-no-threads' in self.config.available_features: |
| 356 | self.compile_flags += ['-D_LIBCPP_HAS_NO_THREADS'] |
| 357 | |
| 358 | if 'libcpp-has-no-monotonic-clock' in self.config.available_features: |
| 359 | self.compile_flags += ['-D_LIBCPP_HAS_NO_MONOTONIC_CLOCK'] |
| 360 | |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 361 | def configure_compile_flags(self): |
| 362 | # Configure extra compiler flags. |
| 363 | self.compile_flags += ['-I' + self.src_root + '/include', |
| 364 | '-I' + self.src_root + '/test/support'] |
Eric Fiselier | 460b224 | 2014-10-23 22:57:56 +0000 | [diff] [blame] | 365 | if sys.platform.startswith('linux'): |
Eric Fiselier | 6f9da55 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 366 | self.compile_flags += ['-D__STDC_FORMAT_MACROS', |
| 367 | '-D__STDC_LIMIT_MACROS', |
| 368 | '-D__STDC_CONSTANT_MACROS'] |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 369 | |
| 370 | def configure_link_flags(self): |
Eric Fiselier | 6f9da55 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 371 | # Configure library search paths |
Eric Fiselier | a63c149 | 2014-10-19 00:42:41 +0000 | [diff] [blame] | 372 | abi_library_path = self.get_lit_conf('abi_library_path', '') |
Eric Fiselier | 6f9da55 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 373 | self.link_flags += ['-L' + self.obj_root + '/lib'] |
Eric Fiselier | a63c149 | 2014-10-19 00:42:41 +0000 | [diff] [blame] | 374 | if not self.use_system_lib: |
| 375 | self.link_flags += ['-Wl,-rpath', '-Wl,' + self.obj_root + '/lib'] |
| 376 | if abi_library_path: |
| 377 | self.link_flags += ['-L' + abi_library_path, |
| 378 | '-Wl,-rpath', '-Wl,' + abi_library_path] |
Eric Fiselier | 6f9da55 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 379 | # Configure libraries |
| 380 | self.link_flags += ['-lc++'] |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 381 | link_flags_str = self.get_lit_conf('link_flags') |
| 382 | if link_flags_str is None: |
| 383 | cxx_abi = self.get_lit_conf('cxx_abi', 'libcxxabi') |
| 384 | if cxx_abi == 'libstdc++': |
| 385 | self.link_flags += ['-lstdc++'] |
| 386 | elif cxx_abi == 'libsupc++': |
| 387 | self.link_flags += ['-lsupc++'] |
| 388 | elif cxx_abi == 'libcxxabi': |
| 389 | self.link_flags += ['-lc++abi'] |
| 390 | elif cxx_abi == 'libcxxrt': |
| 391 | self.link_flags += ['-lcxxrt'] |
| 392 | elif cxx_abi == 'none': |
| 393 | pass |
| 394 | else: |
| 395 | self.lit_config.fatal( |
| 396 | 'C++ ABI setting %s unsupported for tests' % cxx_abi) |
| 397 | |
| 398 | if sys.platform == 'darwin': |
| 399 | self.link_flags += ['-lSystem'] |
Eric Fiselier | 460b224 | 2014-10-23 22:57:56 +0000 | [diff] [blame] | 400 | elif sys.platform.startswith('linux'): |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 401 | self.link_flags += ['-lgcc_eh', '-lc', '-lm', '-lpthread', |
| 402 | '-lrt', '-lgcc_s'] |
| 403 | elif sys.platform.startswith('freebsd'): |
| 404 | self.link_flags += ['-lc', '-lm', '-pthread', '-lgcc_s'] |
| 405 | else: |
Eric Fiselier | 6f9da55 | 2014-10-18 01:15:17 +0000 | [diff] [blame] | 406 | self.lit_config.fatal("unrecognized system: %r" % sys.platform) |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 407 | |
| 408 | self.lit_config.note( |
| 409 | "inferred link_flags as: %r" % self.link_flags) |
| 410 | if link_flags_str: |
| 411 | self.link_flags += shlex.split(link_flags_str) |
| 412 | |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 413 | |
| 414 | def configure_std_flag(self): |
| 415 | # Try and get the std version from the command line. Fall back to |
| 416 | # default given in lit.site.cfg is not present. If default is not |
| 417 | # present then force c++11. |
| 418 | std = self.get_lit_conf('std') |
| 419 | if std is None: |
| 420 | std = 'c++11' |
| 421 | self.lit_config.note('using default std: \'-std=c++11\'') |
Eric Fiselier | 561dfb5 | 2014-08-23 04:02:21 +0000 | [diff] [blame] | 422 | self.compile_flags += ['-std={0}'.format(std)] |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 423 | self.config.available_features.add(std) |
| 424 | |
| 425 | def configure_sanitizer(self): |
| 426 | san = self.get_lit_conf('llvm_use_sanitizer', '').strip() |
| 427 | if san: |
| 428 | self.compile_flags += ['-fno-omit-frame-pointer'] |
Eric Fiselier | 460b224 | 2014-10-23 22:57:56 +0000 | [diff] [blame] | 429 | if sys.platform.startswith('linux'): |
Eric Fiselier | 062e6ee | 2014-10-23 02:54:15 +0000 | [diff] [blame] | 430 | self.link_flags += ['-ldl'] |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 431 | if san == 'Address': |
| 432 | self.compile_flags += ['-fsanitize=address'] |
| 433 | self.config.available_features.add('asan') |
| 434 | elif san == 'Memory' or san == 'MemoryWithOrigins': |
| 435 | self.compile_flags += ['-fsanitize=memory'] |
| 436 | if san == 'MemoryWithOrigins': |
| 437 | self.compile_flags += ['-fsanitize-memory-track-origins'] |
| 438 | self.config.available_features.add('msan') |
Eric Fiselier | 04c1b74 | 2014-10-16 23:21:59 +0000 | [diff] [blame] | 439 | elif san == 'Undefined': |
| 440 | self.compile_flags += ['-fsanitize=undefined', |
| 441 | '-fno-sanitize=vptr,function', |
Eric Fiselier | bc2d632 | 2014-11-14 02:07:52 +0000 | [diff] [blame^] | 442 | '-fno-sanitize-recover', '-O3'] |
Eric Fiselier | 04c1b74 | 2014-10-16 23:21:59 +0000 | [diff] [blame] | 443 | self.config.available_features.add('ubsan') |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 444 | else: |
| 445 | self.lit_config.fatal('unsupported value for ' |
Eric Fiselier | 561dfb5 | 2014-08-23 04:02:21 +0000 | [diff] [blame] | 446 | 'libcxx_use_san: {0}'.format(san)) |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 447 | |
| 448 | def configure_triple(self): |
| 449 | # Get or infer the target triple. |
| 450 | self.config.target_triple = self.get_lit_conf('target_triple') |
| 451 | # If no target triple was given, try to infer it from the compiler |
| 452 | # under test. |
| 453 | if not self.config.target_triple: |
Eric Fiselier | bb19141 | 2014-10-27 22:14:25 +0000 | [diff] [blame] | 454 | target_triple = lit.util.capture( |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 455 | [self.cxx, '-dumpmachine']).strip() |
Eric Fiselier | bb19141 | 2014-10-27 22:14:25 +0000 | [diff] [blame] | 456 | # Drop sub-major version components from the triple, because the |
| 457 | # current XFAIL handling expects exact matches for feature checks. |
Eric Fiselier | d6b46b4 | 2014-10-28 18:03:38 +0000 | [diff] [blame] | 458 | # Example: x86_64-apple-darwin14.0.0 -> x86_64-apple-darwin14 |
Eric Fiselier | bb19141 | 2014-10-27 22:14:25 +0000 | [diff] [blame] | 459 | # The 5th group handles triples greater than 3 parts |
| 460 | # (ex x86_64-pc-linux-gnu). |
| 461 | target_triple = re.sub(r'([^-]+)-([^-]+)-([^.]+)([^-]*)(.*)', |
| 462 | r'\1-\2-\3\5', target_triple) |
| 463 | # linux-gnu is needed in the triple to properly identify linuxes |
| 464 | # that use GLIBC. Handle redhat and opensuse triples as special |
| 465 | # cases and append the missing `-gnu` portion. |
| 466 | if target_triple.endswith('redhat-linux') or \ |
| 467 | target_triple.endswith('suse-linux'): |
| 468 | target_triple += '-gnu' |
| 469 | self.config.target_triple = target_triple |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 470 | self.lit_config.note( |
| 471 | "inferred target_triple as: %r" % self.config.target_triple) |
| 472 | |
| 473 | def configure_env(self): |
| 474 | # Configure extra linker parameters. |
| 475 | if sys.platform == 'darwin': |
| 476 | if not self.use_system_lib: |
| 477 | self.env['DYLD_LIBRARY_PATH'] = os.path.join(self.obj_root, |
| 478 | 'lib') |
| 479 | |
| 480 | |
Daniel Dunbar | 42ea463 | 2010-09-15 03:57:04 +0000 | [diff] [blame] | 481 | # name: The name of this test suite. |
| 482 | config.name = 'libc++' |
| 483 | |
| 484 | # suffixes: A list of file extensions to treat as test files. |
| 485 | config.suffixes = ['.cpp'] |
| 486 | |
| 487 | # test_source_root: The root path where tests are located. |
| 488 | config.test_source_root = os.path.dirname(__file__) |
| 489 | |
Dan Albert | ae2526b | 2014-08-21 17:30:44 +0000 | [diff] [blame] | 490 | configuration = Configuration(lit_config, config) |
| 491 | configuration.configure() |
| 492 | config.test_format = configuration.get_test_format() |