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