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