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