Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1 | """ |
| 2 | A simple testing framework for lldb using python's unit testing framework. |
| 3 | |
| 4 | Tests for lldb are written as python scripts which take advantage of the script |
| 5 | bridging provided by LLDB.framework to interact with lldb core. |
| 6 | |
| 7 | A specific naming pattern is followed by the .py script to be recognized as |
| 8 | a module which implements a test scenario, namely, Test*.py. |
| 9 | |
| 10 | To specify the directories where "Test*.py" python test scripts are located, |
| 11 | you need to pass in a list of directory names. By default, the current |
| 12 | working directory is searched if nothing is specified on the command line. |
| 13 | |
| 14 | Type: |
| 15 | |
| 16 | ./dotest.py -h |
| 17 | |
| 18 | for available options. |
| 19 | """ |
| 20 | |
Zachary Turner | c1b7cd7 | 2015-11-05 19:22:28 +0000 | [diff] [blame] | 21 | from __future__ import absolute_import |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 22 | from __future__ import print_function |
Zachary Turner | c1b7cd7 | 2015-11-05 19:22:28 +0000 | [diff] [blame] | 23 | |
| 24 | # System modules |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 25 | import atexit |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 26 | import os |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 27 | import errno |
| 28 | import platform |
Francis Ricci | 6951707 | 2016-09-23 21:32:47 +0000 | [diff] [blame] | 29 | import re |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 30 | import signal |
| 31 | import socket |
| 32 | import subprocess |
| 33 | import sys |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 34 | |
Zachary Turner | c1b7cd7 | 2015-11-05 19:22:28 +0000 | [diff] [blame] | 35 | # Third-party modules |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 36 | import six |
Zachary Turner | c1b7cd7 | 2015-11-05 19:22:28 +0000 | [diff] [blame] | 37 | import unittest2 |
| 38 | |
| 39 | # LLDB Modules |
| 40 | import lldbsuite |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 41 | from . import configuration |
Zachary Turner | c1b7cd7 | 2015-11-05 19:22:28 +0000 | [diff] [blame] | 42 | from . import dotest_args |
| 43 | from . import lldbtest_config |
| 44 | from . import test_categories |
Todd Fiala | 49d3c15 | 2016-04-20 16:27:27 +0000 | [diff] [blame] | 45 | from lldbsuite.test_event import formatter |
Zachary Turner | b4733e6 | 2015-12-08 01:15:44 +0000 | [diff] [blame] | 46 | from . import test_result |
Todd Fiala | 49d3c15 | 2016-04-20 16:27:27 +0000 | [diff] [blame] | 47 | from lldbsuite.test_event.event_builder import EventBuilder |
Zachary Turner | c1b7cd7 | 2015-11-05 19:22:28 +0000 | [diff] [blame] | 48 | from ..support import seven |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 49 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 50 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 51 | def is_exe(fpath): |
| 52 | """Returns true if fpath is an executable.""" |
| 53 | return os.path.isfile(fpath) and os.access(fpath, os.X_OK) |
| 54 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 55 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 56 | def which(program): |
| 57 | """Returns the full path to a program; None otherwise.""" |
| 58 | fpath, fname = os.path.split(program) |
| 59 | if fpath: |
| 60 | if is_exe(program): |
| 61 | return program |
| 62 | else: |
| 63 | for path in os.environ["PATH"].split(os.pathsep): |
| 64 | exe_file = os.path.join(path, program) |
| 65 | if is_exe(exe_file): |
| 66 | return exe_file |
| 67 | return None |
| 68 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 69 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 70 | class _WritelnDecorator(object): |
| 71 | """Used to decorate file-like objects with a handy 'writeln' method""" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 72 | |
| 73 | def __init__(self, stream): |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 74 | self.stream = stream |
| 75 | |
| 76 | def __getattr__(self, attr): |
| 77 | if attr in ('stream', '__getstate__'): |
| 78 | raise AttributeError(attr) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 79 | return getattr(self.stream, attr) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 80 | |
| 81 | def writeln(self, arg=None): |
| 82 | if arg: |
| 83 | self.write(arg) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 84 | self.write('\n') # text-mode streams translate to \r\n if needed |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 85 | |
| 86 | # |
| 87 | # Global variables: |
| 88 | # |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 89 | |
| 90 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 91 | def usage(parser): |
| 92 | parser.print_help() |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 93 | if configuration.verbose > 0: |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 94 | print(""" |
| 95 | Examples: |
| 96 | |
| 97 | This is an example of using the -f option to pinpoint to a specific test class |
| 98 | and test method to be run: |
| 99 | |
| 100 | $ ./dotest.py -f ClassTypesTestCase.test_with_dsym_and_run_command |
| 101 | ---------------------------------------------------------------------- |
| 102 | Collected 1 test |
| 103 | |
| 104 | test_with_dsym_and_run_command (TestClassTypes.ClassTypesTestCase) |
| 105 | Test 'frame variable this' when stopped on a class constructor. ... ok |
| 106 | |
| 107 | ---------------------------------------------------------------------- |
| 108 | Ran 1 test in 1.396s |
| 109 | |
| 110 | OK |
| 111 | |
| 112 | And this is an example of using the -p option to run a single file (the filename |
| 113 | matches the pattern 'ObjC' and it happens to be 'TestObjCMethods.py'): |
| 114 | |
| 115 | $ ./dotest.py -v -p ObjC |
| 116 | ---------------------------------------------------------------------- |
| 117 | Collected 4 tests |
| 118 | |
| 119 | test_break_with_dsym (TestObjCMethods.FoundationTestCase) |
| 120 | Test setting objc breakpoints using '_regexp-break' and 'breakpoint set'. ... ok |
| 121 | test_break_with_dwarf (TestObjCMethods.FoundationTestCase) |
| 122 | Test setting objc breakpoints using '_regexp-break' and 'breakpoint set'. ... ok |
| 123 | test_data_type_and_expr_with_dsym (TestObjCMethods.FoundationTestCase) |
| 124 | Lookup objective-c data types and evaluate expressions. ... ok |
| 125 | test_data_type_and_expr_with_dwarf (TestObjCMethods.FoundationTestCase) |
| 126 | Lookup objective-c data types and evaluate expressions. ... ok |
| 127 | |
| 128 | ---------------------------------------------------------------------- |
| 129 | Ran 4 tests in 16.661s |
| 130 | |
| 131 | OK |
| 132 | |
| 133 | Running of this script also sets up the LLDB_TEST environment variable so that |
| 134 | individual test cases can locate their supporting files correctly. The script |
| 135 | tries to set up Python's search paths for modules by looking at the build tree |
| 136 | relative to this script. See also the '-i' option in the following example. |
| 137 | |
| 138 | Finally, this is an example of using the lldb.py module distributed/installed by |
| 139 | Xcode4 to run against the tests under the 'forward' directory, and with the '-w' |
| 140 | option to add some delay between two tests. It uses ARCH=x86_64 to specify that |
| 141 | as the architecture and CC=clang to specify the compiler used for the test run: |
| 142 | |
| 143 | $ PYTHONPATH=/Xcode4/Library/PrivateFrameworks/LLDB.framework/Versions/A/Resources/Python ARCH=x86_64 CC=clang ./dotest.py -v -w -i forward |
| 144 | |
| 145 | Session logs for test failures/errors will go into directory '2010-11-11-13_56_16' |
| 146 | ---------------------------------------------------------------------- |
| 147 | Collected 2 tests |
| 148 | |
| 149 | test_with_dsym_and_run_command (TestForwardDeclaration.ForwardDeclarationTestCase) |
| 150 | Display *bar_ptr when stopped on a function with forward declaration of struct bar. ... ok |
| 151 | test_with_dwarf_and_run_command (TestForwardDeclaration.ForwardDeclarationTestCase) |
| 152 | Display *bar_ptr when stopped on a function with forward declaration of struct bar. ... ok |
| 153 | |
| 154 | ---------------------------------------------------------------------- |
| 155 | Ran 2 tests in 5.659s |
| 156 | |
| 157 | OK |
| 158 | |
| 159 | The 'Session ...' verbiage is recently introduced (see also the '-s' option) to |
| 160 | notify the directory containing the session logs for test failures or errors. |
| 161 | In case there is any test failure/error, a similar message is appended at the |
| 162 | end of the stderr output for your convenience. |
| 163 | |
| 164 | ENABLING LOGS FROM TESTS |
| 165 | |
| 166 | Option 1: |
| 167 | |
| 168 | Writing logs into different files per test case:: |
| 169 | |
| 170 | This option is particularly useful when multiple dotest instances are created |
| 171 | by dosep.py |
| 172 | |
| 173 | $ ./dotest.py --channel "lldb all" |
| 174 | |
| 175 | $ ./dotest.py --channel "lldb all" --channel "gdb-remote packets" |
| 176 | |
| 177 | These log files are written to: |
| 178 | |
| 179 | <session-dir>/<test-id>-host.log (logs from lldb host process) |
| 180 | <session-dir>/<test-id>-server.log (logs from debugserver/lldb-server) |
| 181 | <session-dir>/<test-id>-<test-result>.log (console logs) |
| 182 | |
| 183 | By default, logs from successful runs are deleted. Use the --log-success flag |
| 184 | to create reference logs for debugging. |
| 185 | |
| 186 | $ ./dotest.py --log-success |
| 187 | |
| 188 | Option 2: (DEPRECATED) |
| 189 | |
| 190 | The following options can only enable logs from the host lldb process. |
| 191 | Only categories from the "lldb" or "gdb-remote" channels can be enabled |
| 192 | They also do not automatically enable logs in locally running debug servers. |
| 193 | Also, logs from all test case are written into each log file |
| 194 | |
| 195 | o LLDB_LOG: if defined, specifies the log file pathname for the 'lldb' subsystem |
| 196 | with a default option of 'event process' if LLDB_LOG_OPTION is not defined. |
| 197 | |
| 198 | o GDB_REMOTE_LOG: if defined, specifies the log file pathname for the |
| 199 | 'process.gdb-remote' subsystem with a default option of 'packets' if |
| 200 | GDB_REMOTE_LOG_OPTION is not defined. |
| 201 | |
| 202 | """) |
| 203 | sys.exit(0) |
| 204 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 205 | |
Francis Ricci | 6951707 | 2016-09-23 21:32:47 +0000 | [diff] [blame] | 206 | def parseExclusion(exclusion_file): |
| 207 | """Parse an exclusion file, of the following format, where |
| 208 | 'skip files', 'skip methods', 'xfail files', and 'xfail methods' |
| 209 | are the possible list heading values: |
| 210 | |
| 211 | skip files |
| 212 | <file name> |
| 213 | <file name> |
| 214 | |
| 215 | xfail methods |
| 216 | <method name> |
| 217 | """ |
| 218 | excl_type = None |
Francis Ricci | 6951707 | 2016-09-23 21:32:47 +0000 | [diff] [blame] | 219 | |
| 220 | with open(exclusion_file) as f: |
| 221 | for line in f: |
Francis Ricci | f833f17 | 2016-10-04 18:48:00 +0000 | [diff] [blame] | 222 | line = line.strip() |
Francis Ricci | 6951707 | 2016-09-23 21:32:47 +0000 | [diff] [blame] | 223 | if not excl_type: |
Francis Ricci | f833f17 | 2016-10-04 18:48:00 +0000 | [diff] [blame] | 224 | excl_type = line |
Francis Ricci | 6951707 | 2016-09-23 21:32:47 +0000 | [diff] [blame] | 225 | continue |
| 226 | |
Francis Ricci | 6951707 | 2016-09-23 21:32:47 +0000 | [diff] [blame] | 227 | if not line: |
| 228 | excl_type = None |
Francis Ricci | f833f17 | 2016-10-04 18:48:00 +0000 | [diff] [blame] | 229 | elif excl_type == 'skip': |
| 230 | if not configuration.skip_tests: |
| 231 | configuration.skip_tests = [] |
| 232 | configuration.skip_tests.append(line) |
| 233 | elif excl_type == 'xfail': |
| 234 | if not configuration.xfail_tests: |
| 235 | configuration.xfail_tests = [] |
| 236 | configuration.xfail_tests.append(line) |
Francis Ricci | 6951707 | 2016-09-23 21:32:47 +0000 | [diff] [blame] | 237 | |
| 238 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 239 | def parseOptionsAndInitTestdirs(): |
| 240 | """Initialize the list of directories containing our unittest scripts. |
| 241 | |
| 242 | '-h/--help as the first option prints out usage info and exit the program. |
| 243 | """ |
| 244 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 245 | do_help = False |
| 246 | |
| 247 | platform_system = platform.system() |
| 248 | platform_machine = platform.machine() |
| 249 | |
| 250 | parser = dotest_args.create_parser() |
| 251 | args = dotest_args.parse_args(parser, sys.argv[1:]) |
| 252 | |
| 253 | if args.unset_env_varnames: |
| 254 | for env_var in args.unset_env_varnames: |
| 255 | if env_var in os.environ: |
| 256 | # From Python Doc: When unsetenv() is supported, deletion of items in os.environ |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 257 | # is automatically translated into a corresponding call to |
| 258 | # unsetenv(). |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 259 | del os.environ[env_var] |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 260 | # os.unsetenv(env_var) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 261 | |
| 262 | if args.set_env_vars: |
| 263 | for env_var in args.set_env_vars: |
| 264 | parts = env_var.split('=', 1) |
| 265 | if len(parts) == 1: |
| 266 | os.environ[parts[0]] = "" |
| 267 | else: |
| 268 | os.environ[parts[0]] = parts[1] |
| 269 | |
| 270 | # only print the args if being verbose (and parsable is off) |
| 271 | if args.v and not args.q: |
| 272 | print(sys.argv) |
| 273 | |
| 274 | if args.h: |
| 275 | do_help = True |
| 276 | |
Pavel Labath | 6de25ec | 2017-03-15 08:51:59 +0000 | [diff] [blame^] | 277 | if args.compiler: |
| 278 | configuration.compiler = args.compiler |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 279 | else: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 280 | # Use a compiler appropriate appropriate for the Apple SDK if one was |
| 281 | # specified |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 282 | if platform_system == 'Darwin' and args.apple_sdk: |
Pavel Labath | 6de25ec | 2017-03-15 08:51:59 +0000 | [diff] [blame^] | 283 | configuration.compiler = seven.get_command_output( |
| 284 | 'xcrun -sdk "%s" -find clang 2> /dev/null' % |
| 285 | (args.apple_sdk)) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 286 | else: |
| 287 | # 'clang' on ubuntu 14.04 is 3.4 so we try clang-3.5 first |
| 288 | candidateCompilers = ['clang-3.5', 'clang', 'gcc'] |
| 289 | for candidate in candidateCompilers: |
| 290 | if which(candidate): |
Pavel Labath | 6de25ec | 2017-03-15 08:51:59 +0000 | [diff] [blame^] | 291 | configuration.compiler = candidate |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 292 | break |
| 293 | |
| 294 | if args.channels: |
| 295 | lldbtest_config.channels = args.channels |
| 296 | |
| 297 | if args.log_success: |
| 298 | lldbtest_config.log_success = args.log_success |
| 299 | |
| 300 | # Set SDKROOT if we are using an Apple SDK |
| 301 | if platform_system == 'Darwin' and args.apple_sdk: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 302 | os.environ['SDKROOT'] = seven.get_command_output( |
| 303 | 'xcrun --sdk "%s" --show-sdk-path 2> /dev/null' % |
| 304 | (args.apple_sdk)) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 305 | |
Pavel Labath | 6de25ec | 2017-03-15 08:51:59 +0000 | [diff] [blame^] | 306 | if args.arch: |
| 307 | configuration.arch = args.arch |
| 308 | if configuration.arch.startswith( |
| 309 | 'arm') and platform_system == 'Darwin' and not args.apple_sdk: |
| 310 | os.environ['SDKROOT'] = seven.get_command_output( |
| 311 | 'xcrun --sdk iphoneos.internal --show-sdk-path 2> /dev/null') |
| 312 | if not os.path.exists(os.environ['SDKROOT']): |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 313 | os.environ['SDKROOT'] = seven.get_command_output( |
Pavel Labath | 6de25ec | 2017-03-15 08:51:59 +0000 | [diff] [blame^] | 314 | 'xcrun --sdk iphoneos --show-sdk-path 2> /dev/null') |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 315 | else: |
Pavel Labath | 6de25ec | 2017-03-15 08:51:59 +0000 | [diff] [blame^] | 316 | configuration.arch = platform_machine |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 317 | |
| 318 | if args.categoriesList: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 319 | configuration.categoriesList = set( |
| 320 | test_categories.validate( |
| 321 | args.categoriesList, False)) |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 322 | configuration.useCategories = True |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 323 | else: |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 324 | configuration.categoriesList = [] |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 325 | |
| 326 | if args.skipCategories: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 327 | configuration.skipCategories = test_categories.validate( |
| 328 | args.skipCategories, False) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 329 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 330 | if args.E: |
| 331 | cflags_extras = args.E |
| 332 | os.environ['CFLAGS_EXTRAS'] = cflags_extras |
| 333 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 334 | if args.d: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 335 | sys.stdout.write( |
| 336 | "Suspending the process %d to wait for debugger to attach...\n" % |
| 337 | os.getpid()) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 338 | sys.stdout.flush() |
| 339 | os.kill(os.getpid(), signal.SIGSTOP) |
| 340 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 341 | if args.f: |
| 342 | if any([x.startswith('-') for x in args.f]): |
| 343 | usage(parser) |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 344 | configuration.filters.extend(args.f) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 345 | # Shut off multiprocessing mode when additional filters are specified. |
| 346 | # The rational is that the user is probably going after a very specific |
| 347 | # test and doesn't need a bunch of parallel test runners all looking for |
| 348 | # it in a frenzy. Also, '-v' now spits out all test run output even |
| 349 | # on success, so the standard recipe for redoing a failing test (with -v |
| 350 | # and a -f to filter to the specific test) now causes all test scanning |
| 351 | # (in parallel) to print results for do-nothing runs in a very distracting |
| 352 | # manner. If we really need filtered parallel runs in the future, consider |
| 353 | # adding a --no-output-on-success that prevents -v from setting |
| 354 | # output-on-success. |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 355 | configuration.no_multiprocess_test_runner = True |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 356 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 357 | if args.l: |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 358 | configuration.skip_long_running_test = False |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 359 | |
| 360 | if args.framework: |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 361 | configuration.lldbFrameworkPath = args.framework |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 362 | |
| 363 | if args.executable: |
Francis Ricci | cef04a2 | 2016-04-25 20:36:22 +0000 | [diff] [blame] | 364 | lldbtest_config.lldbExec = os.path.realpath(args.executable) |
Chris Bieneman | 265ca53 | 2017-03-14 20:04:46 +0000 | [diff] [blame] | 365 | |
| 366 | if args.server: |
| 367 | os.environ['LLDB_DEBUGSERVER_PATH'] = args.server |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 368 | |
Francis Ricci | 6951707 | 2016-09-23 21:32:47 +0000 | [diff] [blame] | 369 | if args.excluded: |
Francis Ricci | f833f17 | 2016-10-04 18:48:00 +0000 | [diff] [blame] | 370 | for excl_file in args.excluded: |
| 371 | parseExclusion(excl_file) |
Francis Ricci | 6951707 | 2016-09-23 21:32:47 +0000 | [diff] [blame] | 372 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 373 | if args.p: |
| 374 | if args.p.startswith('-'): |
| 375 | usage(parser) |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 376 | configuration.regexp = args.p |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 377 | |
| 378 | if args.q: |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 379 | configuration.parsable = True |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 380 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 381 | if args.s: |
| 382 | if args.s.startswith('-'): |
| 383 | usage(parser) |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 384 | configuration.sdir_name = args.s |
Zachary Turner | 8d4d151 | 2016-05-17 18:02:34 +0000 | [diff] [blame] | 385 | configuration.session_file_format = args.session_file_format |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 386 | |
| 387 | if args.t: |
| 388 | os.environ['LLDB_COMMAND_TRACE'] = 'YES' |
| 389 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 390 | if args.v: |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 391 | configuration.verbose = 2 |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 392 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 393 | # argparse makes sure we have a number |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 394 | if args.sharp: |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 395 | configuration.count = args.sharp |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 396 | |
| 397 | if sys.platform.startswith('win32'): |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 398 | os.environ['LLDB_DISABLE_CRASH_DIALOG'] = str( |
| 399 | args.disable_crash_dialog) |
Zachary Turner | 80310c2 | 2015-12-10 18:51:02 +0000 | [diff] [blame] | 400 | os.environ['LLDB_LAUNCH_INFERIORS_WITHOUT_CONSOLE'] = str(True) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 401 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 402 | if do_help: |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 403 | usage(parser) |
| 404 | |
| 405 | if args.no_multiprocess: |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 406 | configuration.no_multiprocess_test_runner = True |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 407 | |
| 408 | if args.inferior: |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 409 | configuration.is_inferior_test_runner = True |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 410 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 411 | if args.num_threads: |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 412 | configuration.num_threads = args.num_threads |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 413 | |
| 414 | if args.test_subdir: |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 415 | configuration.multiprocess_test_subdir = args.test_subdir |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 416 | |
| 417 | if args.test_runner_name: |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 418 | configuration.test_runner_name = args.test_runner_name |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 419 | |
| 420 | # Capture test results-related args. |
Todd Fiala | cee6a6a | 2015-11-09 18:51:04 +0000 | [diff] [blame] | 421 | if args.curses and not args.inferior: |
| 422 | # Act as if the following args were set. |
Todd Fiala | 49d3c15 | 2016-04-20 16:27:27 +0000 | [diff] [blame] | 423 | args.results_formatter = "lldbsuite.test_event.formatter.curses.Curses" |
Todd Fiala | cee6a6a | 2015-11-09 18:51:04 +0000 | [diff] [blame] | 424 | args.results_file = "stdout" |
| 425 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 426 | if args.results_file: |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 427 | configuration.results_filename = args.results_file |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 428 | |
| 429 | if args.results_port: |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 430 | configuration.results_port = args.results_port |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 431 | |
| 432 | if args.results_file and args.results_port: |
| 433 | sys.stderr.write( |
| 434 | "only one of --results-file and --results-port should " |
| 435 | "be specified\n") |
| 436 | usage(args) |
| 437 | |
| 438 | if args.results_formatter: |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 439 | configuration.results_formatter_name = args.results_formatter |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 440 | if args.results_formatter_options: |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 441 | configuration.results_formatter_options = args.results_formatter_options |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 442 | |
Todd Fiala | b68dbfa2 | 2015-12-11 22:29:34 +0000 | [diff] [blame] | 443 | # Default to using the BasicResultsFormatter if no formatter is specified |
| 444 | # and we're not a test inferior. |
| 445 | if not args.inferior and configuration.results_formatter_name is None: |
| 446 | configuration.results_formatter_name = ( |
Todd Fiala | 49d3c15 | 2016-04-20 16:27:27 +0000 | [diff] [blame] | 447 | "lldbsuite.test_event.formatter.results_formatter.ResultsFormatter") |
Todd Fiala | b68dbfa2 | 2015-12-11 22:29:34 +0000 | [diff] [blame] | 448 | |
Todd Fiala | 9315392 | 2015-12-12 19:26:56 +0000 | [diff] [blame] | 449 | # rerun-related arguments |
| 450 | configuration.rerun_all_issues = args.rerun_all_issues |
Todd Fiala | 685a757 | 2015-12-14 21:28:46 +0000 | [diff] [blame] | 451 | configuration.rerun_max_file_threshold = args.rerun_max_file_threshold |
Todd Fiala | 9315392 | 2015-12-12 19:26:56 +0000 | [diff] [blame] | 452 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 453 | if args.lldb_platform_name: |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 454 | configuration.lldb_platform_name = args.lldb_platform_name |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 455 | if args.lldb_platform_url: |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 456 | configuration.lldb_platform_url = args.lldb_platform_url |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 457 | if args.lldb_platform_working_dir: |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 458 | configuration.lldb_platform_working_dir = args.lldb_platform_working_dir |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 459 | |
| 460 | if args.event_add_entries and len(args.event_add_entries) > 0: |
| 461 | entries = {} |
| 462 | # Parse out key=val pairs, separated by comma |
| 463 | for keyval in args.event_add_entries.split(","): |
| 464 | key_val_entry = keyval.split("=") |
| 465 | if len(key_val_entry) == 2: |
| 466 | (key, val) = key_val_entry |
| 467 | val_parts = val.split(':') |
| 468 | if len(val_parts) > 1: |
| 469 | (val, val_type) = val_parts |
| 470 | if val_type == 'int': |
| 471 | val = int(val) |
| 472 | entries[key] = val |
| 473 | # Tell the event builder to create all events with these |
| 474 | # key/val pairs in them. |
| 475 | if len(entries) > 0: |
Todd Fiala | 49d3c15 | 2016-04-20 16:27:27 +0000 | [diff] [blame] | 476 | EventBuilder.add_entries_to_all_events(entries) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 477 | |
| 478 | # Gather all the dirs passed on the command line. |
| 479 | if len(args.args) > 0: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 480 | configuration.testdirs = list( |
| 481 | map(lambda x: os.path.realpath(os.path.abspath(x)), args.args)) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 482 | # Shut off multiprocessing mode when test directories are specified. |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 483 | configuration.no_multiprocess_test_runner = True |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 484 | |
Chris Bieneman | 7ba5581 | 2016-10-21 22:13:55 +0000 | [diff] [blame] | 485 | lldbtest_config.codesign_identity = args.codesign_identity |
| 486 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 487 | #print("testdirs:", testdirs) |
| 488 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 489 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 490 | def getXcodeOutputPaths(lldbRootDirectory): |
| 491 | result = [] |
| 492 | |
| 493 | # These are for xcode build directories. |
| 494 | xcode3_build_dir = ['build'] |
| 495 | xcode4_build_dir = ['build', 'lldb', 'Build', 'Products'] |
| 496 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 497 | configurations = [ |
| 498 | ['Debug'], |
| 499 | ['DebugClang'], |
| 500 | ['Release'], |
| 501 | ['BuildAndIntegration']] |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 502 | xcode_build_dirs = [xcode3_build_dir, xcode4_build_dir] |
| 503 | for configuration in configurations: |
| 504 | for xcode_build_dir in xcode_build_dirs: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 505 | outputPath = os.path.join( |
| 506 | lldbRootDirectory, *(xcode_build_dir + configuration)) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 507 | result.append(outputPath) |
| 508 | |
| 509 | return result |
| 510 | |
| 511 | |
| 512 | def createSocketToLocalPort(port): |
| 513 | def socket_closer(s): |
| 514 | """Close down an opened socket properly.""" |
| 515 | s.shutdown(socket.SHUT_RDWR) |
| 516 | s.close() |
| 517 | |
| 518 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 519 | sock.connect(("localhost", port)) |
| 520 | return (sock, lambda: socket_closer(sock)) |
| 521 | |
| 522 | |
| 523 | def setupTestResults(): |
| 524 | """Sets up test results-related objects based on arg settings.""" |
Todd Fiala | 5183147 | 2015-12-09 06:45:43 +0000 | [diff] [blame] | 525 | # Setup the results formatter configuration. |
Todd Fiala | 49d3c15 | 2016-04-20 16:27:27 +0000 | [diff] [blame] | 526 | formatter_config = formatter.FormatterConfig() |
Todd Fiala | 5183147 | 2015-12-09 06:45:43 +0000 | [diff] [blame] | 527 | formatter_config.filename = configuration.results_filename |
| 528 | formatter_config.formatter_name = configuration.results_formatter_name |
| 529 | formatter_config.formatter_options = ( |
| 530 | configuration.results_formatter_options) |
| 531 | formatter_config.port = configuration.results_port |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 532 | |
Todd Fiala | de02939 | 2015-12-08 00:53:56 +0000 | [diff] [blame] | 533 | # Create the results formatter. |
Todd Fiala | 49d3c15 | 2016-04-20 16:27:27 +0000 | [diff] [blame] | 534 | formatter_spec = formatter.create_results_formatter( |
Todd Fiala | 5183147 | 2015-12-09 06:45:43 +0000 | [diff] [blame] | 535 | formatter_config) |
Todd Fiala | de02939 | 2015-12-08 00:53:56 +0000 | [diff] [blame] | 536 | if formatter_spec is not None and formatter_spec.formatter is not None: |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 537 | configuration.results_formatter_object = formatter_spec.formatter |
Todd Fiala | 194913f | 2015-12-02 21:12:17 +0000 | [diff] [blame] | 538 | |
Todd Fiala | 49d3c15 | 2016-04-20 16:27:27 +0000 | [diff] [blame] | 539 | # Send an initialize message to the formatter. |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 540 | initialize_event = EventBuilder.bare_event("initialize") |
| 541 | if isMultiprocessTestRunner(): |
Todd Fiala | 5183147 | 2015-12-09 06:45:43 +0000 | [diff] [blame] | 542 | if (configuration.test_runner_name is not None and |
| 543 | configuration.test_runner_name == "serial"): |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 544 | # Only one worker queue here. |
| 545 | worker_count = 1 |
| 546 | else: |
| 547 | # Workers will be the number of threads specified. |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 548 | worker_count = configuration.num_threads |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 549 | else: |
| 550 | worker_count = 1 |
| 551 | initialize_event["worker_count"] = worker_count |
| 552 | |
Todd Fiala | de02939 | 2015-12-08 00:53:56 +0000 | [diff] [blame] | 553 | formatter_spec.formatter.handle_event(initialize_event) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 554 | |
Todd Fiala | de02939 | 2015-12-08 00:53:56 +0000 | [diff] [blame] | 555 | # Make sure we clean up the formatter on shutdown. |
| 556 | if formatter_spec.cleanup_func is not None: |
| 557 | atexit.register(formatter_spec.cleanup_func) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 558 | |
| 559 | |
| 560 | def getOutputPaths(lldbRootDirectory): |
| 561 | """ |
| 562 | Returns typical build output paths for the lldb executable |
| 563 | |
| 564 | lldbDirectory - path to the root of the lldb svn/git repo |
| 565 | """ |
| 566 | result = [] |
| 567 | |
| 568 | if sys.platform == 'darwin': |
| 569 | result.extend(getXcodeOutputPaths(lldbRootDirectory)) |
| 570 | |
| 571 | # cmake builds? look for build or build/host folder next to llvm directory |
| 572 | # lldb is located in llvm/tools/lldb so we need to go up three levels |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 573 | llvmParentDir = os.path.abspath( |
| 574 | os.path.join( |
| 575 | lldbRootDirectory, |
| 576 | os.pardir, |
| 577 | os.pardir, |
| 578 | os.pardir)) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 579 | result.append(os.path.join(llvmParentDir, 'build', 'bin')) |
| 580 | result.append(os.path.join(llvmParentDir, 'build', 'host', 'bin')) |
| 581 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 582 | # some cmake developers keep their build directory beside their lldb |
| 583 | # directory |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 584 | lldbParentDir = os.path.abspath(os.path.join(lldbRootDirectory, os.pardir)) |
| 585 | result.append(os.path.join(lldbParentDir, 'build', 'bin')) |
| 586 | result.append(os.path.join(lldbParentDir, 'build', 'host', 'bin')) |
| 587 | |
| 588 | return result |
| 589 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 590 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 591 | def setupSysPath(): |
| 592 | """ |
| 593 | Add LLDB.framework/Resources/Python to the search paths for modules. |
| 594 | As a side effect, we also discover the 'lldb' executable and export it here. |
| 595 | """ |
| 596 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 597 | # Get the directory containing the current script. |
| 598 | if "DOTEST_PROFILE" in os.environ and "DOTEST_SCRIPT_DIR" in os.environ: |
| 599 | scriptPath = os.environ["DOTEST_SCRIPT_DIR"] |
| 600 | else: |
| 601 | scriptPath = os.path.dirname(os.path.realpath(__file__)) |
| 602 | if not scriptPath.endswith('test'): |
| 603 | print("This script expects to reside in lldb's test directory.") |
| 604 | sys.exit(-1) |
| 605 | |
Zachary Turner | 6a188e6 | 2015-12-11 19:21:34 +0000 | [diff] [blame] | 606 | os.environ["LLDB_TEST"] = scriptPath |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 607 | |
| 608 | # Set up the LLDB_SRC environment variable, so that the tests can locate |
| 609 | # the LLDB source code. |
| 610 | os.environ["LLDB_SRC"] = lldbsuite.lldb_root |
| 611 | |
| 612 | pluginPath = os.path.join(scriptPath, 'plugins') |
| 613 | toolsLLDBMIPath = os.path.join(scriptPath, 'tools', 'lldb-mi') |
| 614 | toolsLLDBServerPath = os.path.join(scriptPath, 'tools', 'lldb-server') |
| 615 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 616 | # Insert script dir, plugin dir, lldb-mi dir and lldb-server dir to the |
| 617 | # sys.path. |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 618 | sys.path.insert(0, pluginPath) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 619 | # Adding test/tools/lldb-mi to the path makes it easy |
| 620 | sys.path.insert(0, toolsLLDBMIPath) |
| 621 | # to "import lldbmi_testcase" from the MI tests |
| 622 | # Adding test/tools/lldb-server to the path makes it easy |
| 623 | sys.path.insert(0, toolsLLDBServerPath) |
| 624 | # to "import lldbgdbserverutils" from the lldb-server tests |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 625 | |
| 626 | # This is the root of the lldb git/svn checkout |
| 627 | # When this changes over to a package instead of a standalone script, this |
| 628 | # will be `lldbsuite.lldb_root` |
| 629 | lldbRootDirectory = lldbsuite.lldb_root |
| 630 | |
| 631 | # Some of the tests can invoke the 'lldb' command directly. |
| 632 | # We'll try to locate the appropriate executable right here. |
| 633 | |
| 634 | # The lldb executable can be set from the command line |
| 635 | # if it's not set, we try to find it now |
| 636 | # first, we try the environment |
| 637 | if not lldbtest_config.lldbExec: |
| 638 | # First, you can define an environment variable LLDB_EXEC specifying the |
| 639 | # full pathname of the lldb executable. |
| 640 | if "LLDB_EXEC" in os.environ: |
| 641 | lldbtest_config.lldbExec = os.environ["LLDB_EXEC"] |
| 642 | |
| 643 | if not lldbtest_config.lldbExec: |
| 644 | outputPaths = getOutputPaths(lldbRootDirectory) |
| 645 | for outputPath in outputPaths: |
| 646 | candidatePath = os.path.join(outputPath, 'lldb') |
| 647 | if is_exe(candidatePath): |
| 648 | lldbtest_config.lldbExec = candidatePath |
| 649 | break |
| 650 | |
| 651 | if not lldbtest_config.lldbExec: |
| 652 | # Last, check the path |
| 653 | lldbtest_config.lldbExec = which('lldb') |
| 654 | |
| 655 | if lldbtest_config.lldbExec and not is_exe(lldbtest_config.lldbExec): |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 656 | print( |
| 657 | "'{}' is not a path to a valid executable".format( |
| 658 | lldbtest_config.lldbExec)) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 659 | lldbtest_config.lldbExec = None |
| 660 | |
| 661 | if not lldbtest_config.lldbExec: |
| 662 | print("The 'lldb' executable cannot be located. Some of the tests may not be run as a result.") |
| 663 | sys.exit(-1) |
| 664 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 665 | # confusingly, this is the "bin" directory |
| 666 | lldbLibDir = os.path.dirname(lldbtest_config.lldbExec) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 667 | os.environ["LLDB_LIB_DIR"] = lldbLibDir |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 668 | lldbImpLibDir = os.path.join( |
| 669 | lldbLibDir, |
| 670 | '..', |
| 671 | 'lib') if sys.platform.startswith('win32') else lldbLibDir |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 672 | os.environ["LLDB_IMPLIB_DIR"] = lldbImpLibDir |
Zachary Turner | 35a7610 | 2015-12-09 20:48:42 +0000 | [diff] [blame] | 673 | print("LLDB library dir:", os.environ["LLDB_LIB_DIR"]) |
| 674 | print("LLDB import library dir:", os.environ["LLDB_IMPLIB_DIR"]) |
| 675 | os.system('%s -v' % lldbtest_config.lldbExec) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 676 | |
| 677 | # Assume lldb-mi is in same place as lldb |
| 678 | # If not found, disable the lldb-mi tests |
Chris Bieneman | 35e5457 | 2016-10-12 20:15:46 +0000 | [diff] [blame] | 679 | # TODO: Append .exe on Windows |
| 680 | # - this will be in a separate commit in case the mi tests fail horribly |
| 681 | lldbDir = os.path.dirname(lldbtest_config.lldbExec) |
| 682 | lldbMiExec = os.path.join(lldbDir, "lldb-mi") |
| 683 | if is_exe(lldbMiExec): |
| 684 | os.environ["LLDBMI_EXEC"] = lldbMiExec |
| 685 | else: |
Zachary Turner | b4733e6 | 2015-12-08 01:15:44 +0000 | [diff] [blame] | 686 | if not configuration.shouldSkipBecauseOfCategories(["lldb-mi"]): |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 687 | print( |
| 688 | "The 'lldb-mi' executable cannot be located. The lldb-mi tests can not be run as a result.") |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 689 | configuration.skipCategories.append("lldb-mi") |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 690 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 691 | lldbPythonDir = None # The directory that contains 'lldb/__init__.py' |
Chris Bieneman | 5d51a76 | 2016-10-31 22:06:52 +0000 | [diff] [blame] | 692 | if not configuration.lldbFrameworkPath and os.path.exists(os.path.join(lldbLibDir, "LLDB.framework")): |
| 693 | configuration.lldbFrameworkPath = os.path.join(lldbLibDir, "LLDB.framework") |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 694 | if configuration.lldbFrameworkPath: |
Chris Bieneman | bd6d699 | 2016-10-31 04:48:10 +0000 | [diff] [blame] | 695 | lldbtest_config.lldbFrameworkPath = configuration.lldbFrameworkPath |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 696 | candidatePath = os.path.join( |
| 697 | configuration.lldbFrameworkPath, 'Resources', 'Python') |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 698 | if os.path.isfile(os.path.join(candidatePath, 'lldb/__init__.py')): |
| 699 | lldbPythonDir = candidatePath |
| 700 | if not lldbPythonDir: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 701 | print( |
| 702 | 'Resources/Python/lldb/__init__.py was not found in ' + |
| 703 | configuration.lldbFrameworkPath) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 704 | sys.exit(-1) |
| 705 | else: |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 706 | # If our lldb supports the -P option, use it to find the python path: |
| 707 | init_in_python_dir = os.path.join('lldb', '__init__.py') |
| 708 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 709 | lldb_dash_p_result = subprocess.check_output( |
| 710 | [lldbtest_config.lldbExec, "-P"], stderr=subprocess.STDOUT, universal_newlines=True) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 711 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 712 | if lldb_dash_p_result and not lldb_dash_p_result.startswith( |
| 713 | ("<", "lldb: invalid option:")) and not lldb_dash_p_result.startswith("Traceback"): |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 714 | lines = lldb_dash_p_result.splitlines() |
| 715 | |
| 716 | # Workaround for readline vs libedit issue on FreeBSD. If stdout |
| 717 | # is not a terminal Python executes |
| 718 | # rl_variable_bind ("enable-meta-key", "off"); |
| 719 | # This produces a warning with FreeBSD's libedit because the |
| 720 | # enable-meta-key variable is unknown. Not an issue on Apple |
| 721 | # because cpython commit f0ab6f9f0603 added a #ifndef __APPLE__ |
| 722 | # around the call. See http://bugs.python.org/issue19884 for more |
| 723 | # information. For now we just discard the warning output. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 724 | if len(lines) >= 1 and lines[0].startswith( |
| 725 | "bind: Invalid command"): |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 726 | lines.pop(0) |
| 727 | |
| 728 | # Taking the last line because lldb outputs |
| 729 | # 'Cannot read termcap database;\nusing dumb terminal settings.\n' |
| 730 | # before the path |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 731 | if len(lines) >= 1 and os.path.isfile( |
| 732 | os.path.join(lines[-1], init_in_python_dir)): |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 733 | lldbPythonDir = lines[-1] |
| 734 | if "freebsd" in sys.platform or "linux" in sys.platform: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 735 | os.environ['LLDB_LIB_DIR'] = os.path.join( |
| 736 | lldbPythonDir, '..', '..') |
| 737 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 738 | if not lldbPythonDir: |
| 739 | if platform.system() == "Darwin": |
| 740 | python_resource_dir = ['LLDB.framework', 'Resources', 'Python'] |
Saleem Abdulrasool | 81eadde | 2016-05-16 03:13:05 +0000 | [diff] [blame] | 741 | outputPaths = getXcodeOutputPaths(lldbRootDirectory) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 742 | for outputPath in outputPaths: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 743 | candidatePath = os.path.join( |
| 744 | outputPath, *python_resource_dir) |
| 745 | if os.path.isfile( |
| 746 | os.path.join( |
| 747 | candidatePath, |
| 748 | init_in_python_dir)): |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 749 | lldbPythonDir = candidatePath |
| 750 | break |
| 751 | |
| 752 | if not lldbPythonDir: |
Saleem Abdulrasool | 0eadc53 | 2016-05-16 03:13:12 +0000 | [diff] [blame] | 753 | print("lldb.py is not found, some tests may fail.") |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 754 | else: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 755 | print( |
| 756 | "Unable to load lldb extension module. Possible reasons for this include:") |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 757 | print(" 1) LLDB was built with LLDB_DISABLE_PYTHON=1") |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 758 | print( |
| 759 | " 2) PYTHONPATH and PYTHONHOME are not set correctly. PYTHONHOME should refer to") |
| 760 | print( |
| 761 | " the version of Python that LLDB built and linked against, and PYTHONPATH") |
| 762 | print( |
| 763 | " should contain the Lib directory for the same python distro, as well as the") |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 764 | print(" location of LLDB\'s site-packages folder.") |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 765 | print( |
| 766 | " 3) A different version of Python than that which was built against is exported in") |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 767 | print(" the system\'s PATH environment variable, causing conflicts.") |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 768 | print( |
| 769 | " 4) The executable '%s' could not be found. Please check " % |
| 770 | lldbtest_config.lldbExec) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 771 | print(" that it exists and is executable.") |
| 772 | |
| 773 | if lldbPythonDir: |
| 774 | lldbPythonDir = os.path.normpath(lldbPythonDir) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 775 | # Some of the code that uses this path assumes it hasn't resolved the Versions... link. |
| 776 | # If the path we've constructed looks like that, then we'll strip out |
| 777 | # the Versions/A part. |
| 778 | (before, frameWithVersion, after) = lldbPythonDir.rpartition( |
| 779 | "LLDB.framework/Versions/A") |
| 780 | if frameWithVersion != "": |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 781 | lldbPythonDir = before + "LLDB.framework" + after |
| 782 | |
| 783 | lldbPythonDir = os.path.abspath(lldbPythonDir) |
| 784 | |
| 785 | # If tests need to find LLDB_FRAMEWORK, now they can do it |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 786 | os.environ["LLDB_FRAMEWORK"] = os.path.dirname( |
| 787 | os.path.dirname(lldbPythonDir)) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 788 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 789 | # This is to locate the lldb.py module. Insert it right after |
| 790 | # sys.path[0]. |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 791 | sys.path[1:1] = [lldbPythonDir] |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 792 | |
Todd Fiala | 7c5f7ca | 2016-05-13 21:36:26 +0000 | [diff] [blame] | 793 | |
| 794 | def visit_file(dir, name): |
| 795 | # Try to match the regexp pattern, if specified. |
| 796 | if configuration.regexp: |
Todd Fiala | 7c5f7ca | 2016-05-13 21:36:26 +0000 | [diff] [blame] | 797 | if not re.search(configuration.regexp, name): |
| 798 | # We didn't match the regex, we're done. |
| 799 | return |
| 800 | |
Francis Ricci | f833f17 | 2016-10-04 18:48:00 +0000 | [diff] [blame] | 801 | if configuration.skip_tests: |
| 802 | for file_regexp in configuration.skip_tests: |
Francis Ricci | 6951707 | 2016-09-23 21:32:47 +0000 | [diff] [blame] | 803 | if re.search(file_regexp, name): |
| 804 | return |
| 805 | |
Todd Fiala | 7c5f7ca | 2016-05-13 21:36:26 +0000 | [diff] [blame] | 806 | # We found a match for our test. Add it to the suite. |
| 807 | |
| 808 | # Update the sys.path first. |
| 809 | if not sys.path.count(dir): |
| 810 | sys.path.insert(0, dir) |
| 811 | base = os.path.splitext(name)[0] |
| 812 | |
| 813 | # Thoroughly check the filterspec against the base module and admit |
| 814 | # the (base, filterspec) combination only when it makes sense. |
| 815 | filterspec = None |
| 816 | for filterspec in configuration.filters: |
| 817 | # Optimistically set the flag to True. |
| 818 | filtered = True |
| 819 | module = __import__(base) |
| 820 | parts = filterspec.split('.') |
| 821 | obj = module |
| 822 | for part in parts: |
| 823 | try: |
| 824 | parent, obj = obj, getattr(obj, part) |
| 825 | except AttributeError: |
| 826 | # The filterspec has failed. |
| 827 | filtered = False |
| 828 | break |
| 829 | |
| 830 | # If filtered, we have a good filterspec. Add it. |
| 831 | if filtered: |
| 832 | # print("adding filter spec %s to module %s" % (filterspec, module)) |
| 833 | configuration.suite.addTests( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 834 | unittest2.defaultTestLoader.loadTestsFromName( |
| 835 | filterspec, module)) |
Todd Fiala | 7c5f7ca | 2016-05-13 21:36:26 +0000 | [diff] [blame] | 836 | continue |
| 837 | |
| 838 | # Forgo this module if the (base, filterspec) combo is invalid |
| 839 | if configuration.filters and not filtered: |
| 840 | return |
| 841 | |
| 842 | if not filterspec or not filtered: |
| 843 | # Add the entire file's worth of tests since we're not filtered. |
| 844 | # Also the fail-over case when the filterspec branch |
| 845 | # (base, filterspec) combo doesn't make sense. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 846 | configuration.suite.addTests( |
| 847 | unittest2.defaultTestLoader.loadTestsFromName(base)) |
Todd Fiala | 7c5f7ca | 2016-05-13 21:36:26 +0000 | [diff] [blame] | 848 | |
| 849 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 850 | def visit(prefix, dir, names): |
| 851 | """Visitor function for os.path.walk(path, visit, arg).""" |
| 852 | |
Zachary Turner | 5067158 | 2015-12-08 20:36:22 +0000 | [diff] [blame] | 853 | dir_components = set(dir.split(os.sep)) |
| 854 | excluded_components = set(['.svn', '.git']) |
| 855 | if dir_components.intersection(excluded_components): |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 856 | return |
| 857 | |
Todd Fiala | 7c5f7ca | 2016-05-13 21:36:26 +0000 | [diff] [blame] | 858 | # Gather all the Python test file names that follow the Test*.py pattern. |
| 859 | python_test_files = [ |
| 860 | name |
| 861 | for name in names |
| 862 | if name.endswith('.py') and name.startswith(prefix)] |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 863 | |
Todd Fiala | 7c5f7ca | 2016-05-13 21:36:26 +0000 | [diff] [blame] | 864 | # Visit all the python test files. |
| 865 | for name in python_test_files: |
| 866 | try: |
| 867 | # Ensure we error out if we have multiple tests with the same |
| 868 | # base name. |
| 869 | # Future improvement: find all the places where we work with base |
| 870 | # names and convert to full paths. We have directory structure |
| 871 | # to disambiguate these, so we shouldn't need this constraint. |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 872 | if name in configuration.all_tests: |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 873 | raise Exception("Found multiple tests with the name %s" % name) |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 874 | configuration.all_tests.add(name) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 875 | |
Todd Fiala | 7c5f7ca | 2016-05-13 21:36:26 +0000 | [diff] [blame] | 876 | # Run the relevant tests in the python file. |
| 877 | visit_file(dir, name) |
| 878 | except Exception as ex: |
| 879 | # Convert this exception to a test event error for the file. |
| 880 | test_filename = os.path.abspath(os.path.join(dir, name)) |
| 881 | if configuration.results_formatter_object is not None: |
| 882 | # Grab the backtrace for the exception. |
| 883 | import traceback |
| 884 | backtrace = traceback.format_exc() |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 885 | |
Todd Fiala | 7c5f7ca | 2016-05-13 21:36:26 +0000 | [diff] [blame] | 886 | # Generate the test event. |
| 887 | configuration.results_formatter_object.handle_event( |
| 888 | EventBuilder.event_for_job_test_add_error( |
| 889 | test_filename, ex, backtrace)) |
| 890 | raise |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 891 | |
| 892 | |
| 893 | def disabledynamics(): |
| 894 | import lldb |
| 895 | ci = lldb.DBG.GetCommandInterpreter() |
| 896 | res = lldb.SBCommandReturnObject() |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 897 | ci.HandleCommand( |
| 898 | "setting set target.prefer-dynamic-value no-dynamic-values", |
| 899 | res, |
| 900 | False) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 901 | if not res.Succeeded(): |
| 902 | raise Exception('disabling dynamic type support failed') |
| 903 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 904 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 905 | def lldbLoggings(): |
| 906 | import lldb |
| 907 | """Check and do lldb loggings if necessary.""" |
| 908 | |
| 909 | # Turn on logging for debugging purposes if ${LLDB_LOG} environment variable is |
| 910 | # defined. Use ${LLDB_LOG} to specify the log file. |
| 911 | ci = lldb.DBG.GetCommandInterpreter() |
| 912 | res = lldb.SBCommandReturnObject() |
| 913 | if ("LLDB_LOG" in os.environ): |
| 914 | open(os.environ["LLDB_LOG"], 'w').close() |
| 915 | if ("LLDB_LOG_OPTION" in os.environ): |
| 916 | lldb_log_option = os.environ["LLDB_LOG_OPTION"] |
| 917 | else: |
| 918 | lldb_log_option = "event process expr state api" |
| 919 | ci.HandleCommand( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 920 | "log enable -n -f " + |
| 921 | os.environ["LLDB_LOG"] + |
| 922 | " lldb " + |
| 923 | lldb_log_option, |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 924 | res) |
| 925 | if not res.Succeeded(): |
| 926 | raise Exception('log enable failed (check LLDB_LOG env variable)') |
| 927 | |
| 928 | if ("LLDB_LINUX_LOG" in os.environ): |
| 929 | open(os.environ["LLDB_LINUX_LOG"], 'w').close() |
| 930 | if ("LLDB_LINUX_LOG_OPTION" in os.environ): |
| 931 | lldb_log_option = os.environ["LLDB_LINUX_LOG_OPTION"] |
| 932 | else: |
| 933 | lldb_log_option = "event process expr state api" |
| 934 | ci.HandleCommand( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 935 | "log enable -n -f " + |
| 936 | os.environ["LLDB_LINUX_LOG"] + |
| 937 | " linux " + |
| 938 | lldb_log_option, |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 939 | res) |
| 940 | if not res.Succeeded(): |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 941 | raise Exception( |
| 942 | 'log enable failed (check LLDB_LINUX_LOG env variable)') |
| 943 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 944 | # Ditto for gdb-remote logging if ${GDB_REMOTE_LOG} environment variable is defined. |
| 945 | # Use ${GDB_REMOTE_LOG} to specify the log file. |
| 946 | if ("GDB_REMOTE_LOG" in os.environ): |
| 947 | if ("GDB_REMOTE_LOG_OPTION" in os.environ): |
| 948 | gdb_remote_log_option = os.environ["GDB_REMOTE_LOG_OPTION"] |
| 949 | else: |
| 950 | gdb_remote_log_option = "packets process" |
| 951 | ci.HandleCommand( |
| 952 | "log enable -n -f " + os.environ["GDB_REMOTE_LOG"] + " gdb-remote " |
| 953 | + gdb_remote_log_option, |
| 954 | res) |
| 955 | if not res.Succeeded(): |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 956 | raise Exception( |
| 957 | 'log enable failed (check GDB_REMOTE_LOG env variable)') |
| 958 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 959 | |
| 960 | def getMyCommandLine(): |
| 961 | return ' '.join(sys.argv) |
| 962 | |
| 963 | # ======================================== # |
| 964 | # # |
| 965 | # Execution of the test driver starts here # |
| 966 | # # |
| 967 | # ======================================== # |
| 968 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 969 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 970 | def checkDsymForUUIDIsNotOn(): |
| 971 | cmd = ["defaults", "read", "com.apple.DebugSymbols"] |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 972 | pipe = subprocess.Popen( |
| 973 | cmd, |
| 974 | stdout=subprocess.PIPE, |
| 975 | stderr=subprocess.STDOUT) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 976 | cmd_output = pipe.stdout.read() |
| 977 | if cmd_output and "DBGFileMappedPaths = " in cmd_output: |
| 978 | print("%s =>" % ' '.join(cmd)) |
| 979 | print(cmd_output) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 980 | print( |
| 981 | "Disable automatic lookup and caching of dSYMs before running the test suite!") |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 982 | print("Exiting...") |
| 983 | sys.exit(0) |
| 984 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 985 | |
| 986 | def exitTestSuite(exitCode=None): |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 987 | import lldb |
| 988 | lldb.SBDebugger.Terminate() |
| 989 | if exitCode: |
| 990 | sys.exit(exitCode) |
| 991 | |
| 992 | |
| 993 | def isMultiprocessTestRunner(): |
| 994 | # We're not multiprocess when we're either explicitly |
| 995 | # the inferior (as specified by the multiprocess test |
| 996 | # runner) OR we've been told to skip using the multiprocess |
| 997 | # test runner |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 998 | return not ( |
| 999 | configuration.is_inferior_test_runner or configuration.no_multiprocess_test_runner) |
| 1000 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1001 | |
Enrico Granata | 5f92a13 | 2015-11-05 00:46:25 +0000 | [diff] [blame] | 1002 | def getVersionForSDK(sdk): |
| 1003 | sdk = str.lower(sdk) |
| 1004 | full_path = seven.get_command_output('xcrun -sdk %s --show-sdk-path' % sdk) |
| 1005 | basename = os.path.basename(full_path) |
| 1006 | basename = os.path.splitext(basename)[0] |
| 1007 | basename = str.lower(basename) |
| 1008 | ver = basename.replace(sdk, '') |
| 1009 | return ver |
| 1010 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1011 | |
Enrico Granata | 5f92a13 | 2015-11-05 00:46:25 +0000 | [diff] [blame] | 1012 | def getPathForSDK(sdk): |
| 1013 | sdk = str.lower(sdk) |
| 1014 | full_path = seven.get_command_output('xcrun -sdk %s --show-sdk-path' % sdk) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1015 | if os.path.exists(full_path): |
| 1016 | return full_path |
Enrico Granata | 5f92a13 | 2015-11-05 00:46:25 +0000 | [diff] [blame] | 1017 | return None |
| 1018 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1019 | |
Enrico Granata | 5f92a13 | 2015-11-05 00:46:25 +0000 | [diff] [blame] | 1020 | def setDefaultTripleForPlatform(): |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 1021 | if configuration.lldb_platform_name == 'ios-simulator': |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1022 | triple_str = 'x86_64-apple-ios%s' % ( |
| 1023 | getVersionForSDK('iphonesimulator')) |
Enrico Granata | 5f92a13 | 2015-11-05 00:46:25 +0000 | [diff] [blame] | 1024 | os.environ['TRIPLE'] = triple_str |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1025 | return {'TRIPLE': triple_str} |
Enrico Granata | 5f92a13 | 2015-11-05 00:46:25 +0000 | [diff] [blame] | 1026 | return {} |
| 1027 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1028 | |
Pavel Labath | 6de25ec | 2017-03-15 08:51:59 +0000 | [diff] [blame^] | 1029 | def checkCompiler(): |
| 1030 | # Add some intervention here to sanity check that the compiler requested is sane. |
| 1031 | # If found not to be an executable program, we abort. |
| 1032 | c = configuration.compiler |
| 1033 | if which(c): |
| 1034 | return |
| 1035 | |
| 1036 | if not sys.platform.startswith("darwin"): |
| 1037 | raise Exception(c + " is not a valid compiler") |
| 1038 | |
| 1039 | pipe = subprocess.Popen( |
| 1040 | ['xcrun', '-find', c], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 1041 | cmd_output = pipe.stdout.read() |
| 1042 | if not cmd_output or "not found" in cmd_output: |
| 1043 | raise Exception(c + " is not a valid compiler") |
| 1044 | |
| 1045 | configuration.compiler = cmd_output.split('\n')[0] |
| 1046 | print("'xcrun -find %s' returning %s" % (c, configuration.compiler)) |
| 1047 | |
| 1048 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1049 | def run_suite(): |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1050 | # On MacOS X, check to make sure that domain for com.apple.DebugSymbols defaults |
| 1051 | # does not exist before proceeding to running the test suite. |
| 1052 | if sys.platform.startswith("darwin"): |
| 1053 | checkDsymForUUIDIsNotOn() |
| 1054 | |
| 1055 | # |
| 1056 | # Start the actions by first parsing the options while setting up the test |
| 1057 | # directories, followed by setting up the search paths for lldb utilities; |
| 1058 | # then, we walk the directory trees and collect the tests into our test suite. |
| 1059 | # |
| 1060 | parseOptionsAndInitTestdirs() |
| 1061 | |
| 1062 | # Setup test results (test results formatter and output handling). |
| 1063 | setupTestResults() |
| 1064 | |
| 1065 | # If we are running as the multiprocess test runner, kick off the |
| 1066 | # multiprocess test runner here. |
| 1067 | if isMultiprocessTestRunner(): |
Zachary Turner | c1b7cd7 | 2015-11-05 19:22:28 +0000 | [diff] [blame] | 1068 | from . import dosep |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1069 | dosep.main( |
| 1070 | configuration.num_threads, |
| 1071 | configuration.multiprocess_test_subdir, |
| 1072 | configuration.test_runner_name, |
| 1073 | configuration.results_formatter_object) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1074 | raise Exception("should never get here") |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 1075 | elif configuration.is_inferior_test_runner: |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1076 | # Shut off Ctrl-C processing in inferiors. The parallel |
| 1077 | # test runner handles this more holistically. |
| 1078 | signal.signal(signal.SIGINT, signal.SIG_IGN) |
| 1079 | |
| 1080 | setupSysPath() |
Pavel Labath | 9cbf7dd | 2015-12-08 13:32:07 +0000 | [diff] [blame] | 1081 | configuration.setupCrashInfoHook() |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1082 | |
| 1083 | # |
| 1084 | # If '-l' is specified, do not skip the long running tests. |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 1085 | if not configuration.skip_long_running_test: |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1086 | os.environ["LLDB_SKIP_LONG_RUNNING_TEST"] = "NO" |
| 1087 | |
| 1088 | # For the time being, let's bracket the test runner within the |
| 1089 | # lldb.SBDebugger.Initialize()/Terminate() pair. |
| 1090 | import lldb |
| 1091 | |
| 1092 | # Create a singleton SBDebugger in the lldb namespace. |
| 1093 | lldb.DBG = lldb.SBDebugger.Create() |
| 1094 | |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 1095 | if configuration.lldb_platform_name: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1096 | print("Setting up remote platform '%s'" % |
| 1097 | (configuration.lldb_platform_name)) |
| 1098 | lldb.remote_platform = lldb.SBPlatform( |
| 1099 | configuration.lldb_platform_name) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1100 | if not lldb.remote_platform.IsValid(): |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1101 | print( |
| 1102 | "error: unable to create the LLDB platform named '%s'." % |
| 1103 | (configuration.lldb_platform_name)) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1104 | exitTestSuite(1) |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 1105 | if configuration.lldb_platform_url: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1106 | # We must connect to a remote platform if a LLDB platform URL was |
| 1107 | # specified |
| 1108 | print( |
| 1109 | "Connecting to remote platform '%s' at '%s'..." % |
| 1110 | (configuration.lldb_platform_name, configuration.lldb_platform_url)) |
| 1111 | platform_connect_options = lldb.SBPlatformConnectOptions( |
| 1112 | configuration.lldb_platform_url) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1113 | err = lldb.remote_platform.ConnectRemote(platform_connect_options) |
| 1114 | if err.Success(): |
| 1115 | print("Connected.") |
| 1116 | else: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1117 | print("error: failed to connect to remote platform using URL '%s': %s" % ( |
| 1118 | configuration.lldb_platform_url, err)) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1119 | exitTestSuite(1) |
| 1120 | else: |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 1121 | configuration.lldb_platform_url = None |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1122 | |
Enrico Granata | 5f92a13 | 2015-11-05 00:46:25 +0000 | [diff] [blame] | 1123 | platform_changes = setDefaultTripleForPlatform() |
| 1124 | first = True |
| 1125 | for key in platform_changes: |
| 1126 | if first: |
| 1127 | print("Environment variables setup for platform support:") |
| 1128 | first = False |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1129 | print("%s = %s" % (key, platform_changes[key])) |
Enrico Granata | 5f92a13 | 2015-11-05 00:46:25 +0000 | [diff] [blame] | 1130 | |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 1131 | if configuration.lldb_platform_working_dir: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1132 | print("Setting remote platform working directory to '%s'..." % |
| 1133 | (configuration.lldb_platform_working_dir)) |
| 1134 | lldb.remote_platform.SetWorkingDirectory( |
| 1135 | configuration.lldb_platform_working_dir) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1136 | lldb.DBG.SetSelectedPlatform(lldb.remote_platform) |
| 1137 | else: |
| 1138 | lldb.remote_platform = None |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 1139 | configuration.lldb_platform_working_dir = None |
| 1140 | configuration.lldb_platform_url = None |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1141 | |
| 1142 | target_platform = lldb.DBG.GetSelectedPlatform().GetTriple().split('-')[2] |
| 1143 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1144 | # Don't do debugserver tests on everything except OS X. |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 1145 | configuration.dont_do_debugserver_test = "linux" in target_platform or "freebsd" in target_platform or "windows" in target_platform |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1146 | |
| 1147 | # Don't do lldb-server (llgs) tests on anything except Linux. |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 1148 | configuration.dont_do_llgs_test = not ("linux" in target_platform) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1149 | |
| 1150 | # |
| 1151 | # Walk through the testdirs while collecting tests. |
| 1152 | # |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 1153 | for testdir in configuration.testdirs: |
Zachary Turner | e6ba053 | 2015-11-05 01:33:54 +0000 | [diff] [blame] | 1154 | for (dirpath, dirnames, filenames) in os.walk(testdir): |
| 1155 | visit('Test', dirpath, filenames) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1156 | |
| 1157 | # |
| 1158 | # Now that we have loaded all the test cases, run the whole test suite. |
| 1159 | # |
| 1160 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1161 | # Turn on lldb loggings if necessary. |
| 1162 | lldbLoggings() |
| 1163 | |
| 1164 | # Disable default dynamic types for testing purposes |
| 1165 | disabledynamics() |
| 1166 | |
| 1167 | # Install the control-c handler. |
| 1168 | unittest2.signals.installHandler() |
| 1169 | |
| 1170 | # If sdir_name is not specified through the '-s sdir_name' option, get a |
| 1171 | # timestamp string and export it as LLDB_SESSION_DIR environment var. This will |
| 1172 | # be used when/if we want to dump the session info of individual test cases |
| 1173 | # later on. |
| 1174 | # |
| 1175 | # See also TestBase.dumpSessionInfo() in lldbtest.py. |
| 1176 | import datetime |
| 1177 | # The windows platforms don't like ':' in the pathname. |
| 1178 | timestamp_started = datetime.datetime.now().strftime("%Y-%m-%d-%H_%M_%S") |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 1179 | if not configuration.sdir_name: |
| 1180 | configuration.sdir_name = timestamp_started |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1181 | os.environ["LLDB_SESSION_DIRNAME"] = os.path.join( |
| 1182 | os.getcwd(), configuration.sdir_name) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1183 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1184 | sys.stderr.write( |
| 1185 | "\nSession logs for test failures/errors/unexpected successes" |
| 1186 | " will go into directory '%s'\n" % |
| 1187 | configuration.sdir_name) |
Zachary Turner | 35a7610 | 2015-12-09 20:48:42 +0000 | [diff] [blame] | 1188 | sys.stderr.write("Command invoked: %s\n" % getMyCommandLine()) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1189 | |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 1190 | if not os.path.isdir(configuration.sdir_name): |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1191 | try: |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 1192 | os.mkdir(configuration.sdir_name) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1193 | except OSError as exception: |
| 1194 | if exception.errno != errno.EEXIST: |
| 1195 | raise |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1196 | |
| 1197 | # |
Pavel Labath | 6de25ec | 2017-03-15 08:51:59 +0000 | [diff] [blame^] | 1198 | # Invoke the default TextTestRunner to run the test suite |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1199 | # |
Pavel Labath | 6de25ec | 2017-03-15 08:51:59 +0000 | [diff] [blame^] | 1200 | checkCompiler() |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1201 | |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 1202 | if not configuration.parsable: |
Pavel Labath | 6de25ec | 2017-03-15 08:51:59 +0000 | [diff] [blame^] | 1203 | print("compiler=%s" % configuration.compiler) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1204 | |
| 1205 | # Iterating over all possible architecture and compiler combinations. |
Pavel Labath | 6de25ec | 2017-03-15 08:51:59 +0000 | [diff] [blame^] | 1206 | os.environ["ARCH"] = configuration.arch |
| 1207 | os.environ["CC"] = configuration.compiler |
| 1208 | configString = "arch=%s compiler=%s" % (configuration.arch, |
| 1209 | configuration.compiler) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1210 | |
Pavel Labath | 6de25ec | 2017-03-15 08:51:59 +0000 | [diff] [blame^] | 1211 | # Translate ' ' to '-' for pathname component. |
| 1212 | if six.PY2: |
| 1213 | import string |
| 1214 | tbl = string.maketrans(' ', '-') |
| 1215 | else: |
| 1216 | tbl = str.maketrans(' ', '-') |
| 1217 | configPostfix = configString.translate(tbl) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1218 | |
Pavel Labath | 6de25ec | 2017-03-15 08:51:59 +0000 | [diff] [blame^] | 1219 | # Output the configuration. |
| 1220 | if not configuration.parsable: |
| 1221 | sys.stderr.write("\nConfiguration: " + configString + "\n") |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1222 | |
Pavel Labath | 6de25ec | 2017-03-15 08:51:59 +0000 | [diff] [blame^] | 1223 | # First, write out the number of collected test cases. |
| 1224 | if not configuration.parsable: |
| 1225 | sys.stderr.write(configuration.separator + "\n") |
| 1226 | sys.stderr.write( |
| 1227 | "Collected %d test%s\n\n" % |
| 1228 | (configuration.suite.countTestCases(), |
| 1229 | configuration.suite.countTestCases() != 1 and "s" or "")) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1230 | |
Pavel Labath | 6de25ec | 2017-03-15 08:51:59 +0000 | [diff] [blame^] | 1231 | if configuration.parsable: |
| 1232 | v = 0 |
| 1233 | else: |
| 1234 | v = configuration.verbose |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1235 | |
Pavel Labath | 6de25ec | 2017-03-15 08:51:59 +0000 | [diff] [blame^] | 1236 | # Invoke the test runner. |
| 1237 | if configuration.count == 1: |
| 1238 | result = unittest2.TextTestRunner( |
| 1239 | stream=sys.stderr, |
| 1240 | verbosity=v, |
| 1241 | resultclass=test_result.LLDBTestResult).run( |
| 1242 | configuration.suite) |
| 1243 | else: |
| 1244 | # We are invoking the same test suite more than once. In this case, |
| 1245 | # mark __ignore_singleton__ flag as True so the signleton pattern is |
| 1246 | # not enforced. |
| 1247 | test_result.LLDBTestResult.__ignore_singleton__ = True |
| 1248 | for i in range(configuration.count): |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1249 | |
Pavel Labath | 6de25ec | 2017-03-15 08:51:59 +0000 | [diff] [blame^] | 1250 | result = unittest2.TextTestRunner( |
| 1251 | stream=sys.stderr, |
| 1252 | verbosity=v, |
| 1253 | resultclass=test_result.LLDBTestResult).run( |
| 1254 | configuration.suite) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1255 | |
Pavel Labath | 6de25ec | 2017-03-15 08:51:59 +0000 | [diff] [blame^] | 1256 | configuration.failed = not result.wasSuccessful() |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1257 | |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 1258 | if configuration.sdir_has_content and not configuration.parsable: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1259 | sys.stderr.write( |
| 1260 | "Session logs for test failures/errors/unexpected successes" |
| 1261 | " can be found in directory '%s'\n" % |
| 1262 | configuration.sdir_name) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1263 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1264 | if configuration.useCategories and len( |
| 1265 | configuration.failuresPerCategory) > 0: |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1266 | sys.stderr.write("Failures per category:\n") |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 1267 | for category in configuration.failuresPerCategory: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1268 | sys.stderr.write( |
| 1269 | "%s - %d\n" % |
| 1270 | (category, configuration.failuresPerCategory[category])) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1271 | |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1272 | # Terminate the test suite if ${LLDB_TESTSUITE_FORCE_FINISH} is defined. |
| 1273 | # This should not be necessary now. |
| 1274 | if ("LLDB_TESTSUITE_FORCE_FINISH" in os.environ): |
| 1275 | print("Terminating Test suite...") |
| 1276 | subprocess.Popen(["/bin/sh", "-c", "kill %s; exit 0" % (os.getpid())]) |
| 1277 | |
| 1278 | # Exiting. |
Zachary Turner | 606e3a5 | 2015-12-08 01:15:30 +0000 | [diff] [blame] | 1279 | exitTestSuite(configuration.failed) |
Zachary Turner | c432c8f | 2015-10-28 17:43:26 +0000 | [diff] [blame] | 1280 | |
| 1281 | if __name__ == "__main__": |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1282 | print( |
| 1283 | __file__ + |
| 1284 | " is for use as a module only. It should not be run as a standalone script.") |
Zachary Turner | 7d56454 | 2015-11-02 19:19:49 +0000 | [diff] [blame] | 1285 | sys.exit(-1) |