Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | """ |
| 4 | Run the test suite using a separate process for each test file. |
Vince Harron | ede5965 | 2015-01-08 02:11:26 +0000 | [diff] [blame] | 5 | |
Siva Chandra | 2d7832e | 2015-05-08 23:08:53 +0000 | [diff] [blame] | 6 | Each test will run with a time limit of 10 minutes by default. |
Vince Harron | ede5965 | 2015-01-08 02:11:26 +0000 | [diff] [blame] | 7 | |
Siva Chandra | 2d7832e | 2015-05-08 23:08:53 +0000 | [diff] [blame] | 8 | Override the default time limit of 10 minutes by setting |
Vince Harron | ede5965 | 2015-01-08 02:11:26 +0000 | [diff] [blame] | 9 | the environment variable LLDB_TEST_TIMEOUT. |
| 10 | |
| 11 | E.g., export LLDB_TEST_TIMEOUT=10m |
| 12 | |
| 13 | Override the time limit for individual tests by setting |
| 14 | the environment variable LLDB_[TEST NAME]_TIMEOUT. |
| 15 | |
| 16 | E.g., export LLDB_TESTCONCURRENTEVENTS_TIMEOUT=2m |
| 17 | |
| 18 | Set to "0" to run without time limit. |
| 19 | |
| 20 | E.g., export LLDB_TEST_TIMEOUT=0 |
| 21 | or export LLDB_TESTCONCURRENTEVENTS_TIMEOUT=0 |
Vince Harron | dcc2b9f | 2015-05-27 04:40:36 +0000 | [diff] [blame] | 22 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 23 | To collect core files for timed out tests, |
| 24 | do the following before running dosep.py |
Vince Harron | dcc2b9f | 2015-05-27 04:40:36 +0000 | [diff] [blame] | 25 | |
| 26 | OSX |
| 27 | ulimit -c unlimited |
| 28 | sudo sysctl -w kern.corefile=core.%P |
| 29 | |
| 30 | Linux: |
| 31 | ulimit -c unlimited |
| 32 | echo core.%p | sudo tee /proc/sys/kernel/core_pattern |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 33 | """ |
| 34 | |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 35 | from __future__ import print_function |
Zachary Turner | c1b7cd7 | 2015-11-05 19:22:28 +0000 | [diff] [blame] | 36 | from __future__ import absolute_import |
Zachary Turner | 814236d | 2015-10-21 17:48:52 +0000 | [diff] [blame] | 37 | |
Todd Fiala | 2d3754d | 2015-09-29 22:19:06 +0000 | [diff] [blame] | 38 | # system packages and modules |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 39 | import asyncore |
Todd Fiala | 83c32e3 | 2015-09-22 21:19:40 +0000 | [diff] [blame] | 40 | import distutils.version |
Vince Harron | dcc2b9f | 2015-05-27 04:40:36 +0000 | [diff] [blame] | 41 | import fnmatch |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 42 | import multiprocessing |
| 43 | import multiprocessing.pool |
| 44 | import os |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 45 | import platform |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 46 | import re |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 47 | import signal |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 48 | import sys |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 49 | import threading |
Todd Fiala | 2d3754d | 2015-09-29 22:19:06 +0000 | [diff] [blame] | 50 | |
Zachary Turner | 814236d | 2015-10-21 17:48:52 +0000 | [diff] [blame] | 51 | from six.moves import queue |
| 52 | |
Todd Fiala | 2d3754d | 2015-09-29 22:19:06 +0000 | [diff] [blame] | 53 | # Our packages and modules |
Zachary Turner | c1b7cd7 | 2015-11-05 19:22:28 +0000 | [diff] [blame] | 54 | import lldbsuite.support.seven as seven |
| 55 | |
| 56 | from . import dotest_channels |
| 57 | from . import dotest_args |
| 58 | |
| 59 | # Todo: Convert this folder layout to be relative-import friendly and don't hack up |
| 60 | # sys.path like this |
| 61 | sys.path.append(os.path.join(os.path.dirname(__file__), "test_runner", "lib")) |
Todd Fiala | 2d3754d | 2015-09-29 22:19:06 +0000 | [diff] [blame] | 62 | import lldb_utils |
| 63 | import process_control |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 64 | |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 65 | # Status codes for running command with timeout. |
| 66 | eTimedOut, ePassed, eFailed = 124, 0, 1 |
| 67 | |
Chaoren Lin | 5e3ab2b | 2015-06-01 17:49:25 +0000 | [diff] [blame] | 68 | output_lock = None |
| 69 | test_counter = None |
| 70 | total_tests = None |
Chaoren Lin | ffc63b0 | 2015-08-12 18:02:49 +0000 | [diff] [blame] | 71 | test_name_len = None |
Pavel Labath | 05ab237 | 2015-07-06 15:57:52 +0000 | [diff] [blame] | 72 | dotest_options = None |
Zachary Turner | 38e6417 | 2015-08-10 17:46:11 +0000 | [diff] [blame] | 73 | output_on_success = False |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 74 | RESULTS_FORMATTER = None |
| 75 | RUNNER_PROCESS_ASYNC_MAP = None |
| 76 | RESULTS_LISTENER_CHANNEL = None |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 77 | |
Todd Fiala | 33896a9 | 2015-09-18 21:01:13 +0000 | [diff] [blame] | 78 | """Contains an optional function pointer that can return the worker index |
| 79 | for the given thread/process calling it. Returns a 0-based index.""" |
| 80 | GET_WORKER_INDEX = None |
| 81 | |
Todd Fiala | 1cc97b4 | 2015-09-21 05:42:26 +0000 | [diff] [blame] | 82 | |
Todd Fiala | 33896a9 | 2015-09-18 21:01:13 +0000 | [diff] [blame] | 83 | def setup_global_variables( |
| 84 | lock, counter, total, name_len, options, worker_index_map): |
Chaoren Lin | ffc63b0 | 2015-08-12 18:02:49 +0000 | [diff] [blame] | 85 | global output_lock, test_counter, total_tests, test_name_len |
| 86 | global dotest_options |
Chaoren Lin | 5e3ab2b | 2015-06-01 17:49:25 +0000 | [diff] [blame] | 87 | output_lock = lock |
| 88 | test_counter = counter |
| 89 | total_tests = total |
Chaoren Lin | ffc63b0 | 2015-08-12 18:02:49 +0000 | [diff] [blame] | 90 | test_name_len = name_len |
Pavel Labath | 05ab237 | 2015-07-06 15:57:52 +0000 | [diff] [blame] | 91 | dotest_options = options |
Chaoren Lin | 5e3ab2b | 2015-06-01 17:49:25 +0000 | [diff] [blame] | 92 | |
Todd Fiala | 33896a9 | 2015-09-18 21:01:13 +0000 | [diff] [blame] | 93 | if worker_index_map is not None: |
| 94 | # We'll use the output lock for this to avoid sharing another lock. |
| 95 | # This won't be used much. |
| 96 | index_lock = lock |
| 97 | |
| 98 | def get_worker_index_use_pid(): |
| 99 | """Returns a 0-based, process-unique index for the worker.""" |
| 100 | pid = os.getpid() |
| 101 | with index_lock: |
| 102 | if pid not in worker_index_map: |
| 103 | worker_index_map[pid] = len(worker_index_map) |
| 104 | return worker_index_map[pid] |
| 105 | |
| 106 | global GET_WORKER_INDEX |
| 107 | GET_WORKER_INDEX = get_worker_index_use_pid |
| 108 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 109 | |
Zachary Turner | 38e6417 | 2015-08-10 17:46:11 +0000 | [diff] [blame] | 110 | def report_test_failure(name, command, output): |
| 111 | global output_lock |
| 112 | with output_lock: |
Greg Clayton | 1827fc2 | 2015-09-19 00:39:09 +0000 | [diff] [blame] | 113 | if not (RESULTS_FORMATTER and RESULTS_FORMATTER.is_using_terminal()): |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 114 | print(file=sys.stderr) |
| 115 | print(output, file=sys.stderr) |
| 116 | print("[%s FAILED]" % name, file=sys.stderr) |
| 117 | print("Command invoked: %s" % ' '.join(command), file=sys.stderr) |
Chaoren Lin | ffc63b0 | 2015-08-12 18:02:49 +0000 | [diff] [blame] | 118 | update_progress(name) |
Zachary Turner | 38e6417 | 2015-08-10 17:46:11 +0000 | [diff] [blame] | 119 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 120 | |
Zachary Turner | 38e6417 | 2015-08-10 17:46:11 +0000 | [diff] [blame] | 121 | def report_test_pass(name, output): |
| 122 | global output_lock, output_on_success |
| 123 | with output_lock: |
Greg Clayton | 1827fc2 | 2015-09-19 00:39:09 +0000 | [diff] [blame] | 124 | if not (RESULTS_FORMATTER and RESULTS_FORMATTER.is_using_terminal()): |
| 125 | if output_on_success: |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 126 | print(file=sys.stderr) |
| 127 | print(output, file=sys.stderr) |
| 128 | print("[%s PASSED]" % name, file=sys.stderr) |
Chaoren Lin | ffc63b0 | 2015-08-12 18:02:49 +0000 | [diff] [blame] | 129 | update_progress(name) |
Zachary Turner | 38e6417 | 2015-08-10 17:46:11 +0000 | [diff] [blame] | 130 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 131 | |
Chaoren Lin | ffc63b0 | 2015-08-12 18:02:49 +0000 | [diff] [blame] | 132 | def update_progress(test_name=""): |
| 133 | global output_lock, test_counter, total_tests, test_name_len |
Chaoren Lin | 5e3ab2b | 2015-06-01 17:49:25 +0000 | [diff] [blame] | 134 | with output_lock: |
Chaoren Lin | ffc63b0 | 2015-08-12 18:02:49 +0000 | [diff] [blame] | 135 | counter_len = len(str(total_tests)) |
Greg Clayton | 1827fc2 | 2015-09-19 00:39:09 +0000 | [diff] [blame] | 136 | if not (RESULTS_FORMATTER and RESULTS_FORMATTER.is_using_terminal()): |
| 137 | sys.stderr.write( |
| 138 | "\r%*d out of %d test suites processed - %-*s" % |
| 139 | (counter_len, test_counter.value, total_tests, |
| 140 | test_name_len.value, test_name)) |
Chaoren Lin | ffc63b0 | 2015-08-12 18:02:49 +0000 | [diff] [blame] | 141 | if len(test_name) > test_name_len.value: |
| 142 | test_name_len.value = len(test_name) |
Chaoren Lin | 5e3ab2b | 2015-06-01 17:49:25 +0000 | [diff] [blame] | 143 | test_counter.value += 1 |
Zachary Turner | 38e6417 | 2015-08-10 17:46:11 +0000 | [diff] [blame] | 144 | sys.stdout.flush() |
| 145 | sys.stderr.flush() |
Chaoren Lin | 5e3ab2b | 2015-06-01 17:49:25 +0000 | [diff] [blame] | 146 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 147 | |
Zachary Turner | c7a7c8a | 2015-05-28 19:56:26 +0000 | [diff] [blame] | 148 | def parse_test_results(output): |
| 149 | passes = 0 |
| 150 | failures = 0 |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 151 | unexpected_successes = 0 |
Zachary Turner | c7a7c8a | 2015-05-28 19:56:26 +0000 | [diff] [blame] | 152 | for result in output: |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 153 | pass_count = re.search("^RESULT:.*([0-9]+) passes", |
| 154 | result, re.MULTILINE) |
| 155 | fail_count = re.search("^RESULT:.*([0-9]+) failures", |
| 156 | result, re.MULTILINE) |
| 157 | error_count = re.search("^RESULT:.*([0-9]+) errors", |
| 158 | result, re.MULTILINE) |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 159 | unexpected_success_count = re.search("^RESULT:.*([0-9]+) unexpected successes", |
| 160 | result, re.MULTILINE) |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 161 | if pass_count is not None: |
Zachary Turner | c7a7c8a | 2015-05-28 19:56:26 +0000 | [diff] [blame] | 162 | passes = passes + int(pass_count.group(1)) |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 163 | if fail_count is not None: |
Zachary Turner | c7a7c8a | 2015-05-28 19:56:26 +0000 | [diff] [blame] | 164 | failures = failures + int(fail_count.group(1)) |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 165 | if unexpected_success_count is not None: |
| 166 | unexpected_successes = unexpected_successes + int(unexpected_success_count.group(1)) |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 167 | if error_count is not None: |
Zachary Turner | c7a7c8a | 2015-05-28 19:56:26 +0000 | [diff] [blame] | 168 | failures = failures + int(error_count.group(1)) |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 169 | return passes, failures, unexpected_successes |
Zachary Turner | c7a7c8a | 2015-05-28 19:56:26 +0000 | [diff] [blame] | 170 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 171 | |
Todd Fiala | 2d3754d | 2015-09-29 22:19:06 +0000 | [diff] [blame] | 172 | class DoTestProcessDriver(process_control.ProcessDriver): |
| 173 | """Drives the dotest.py inferior process and handles bookkeeping.""" |
| 174 | def __init__(self, output_file, output_file_lock, pid_events, file_name, |
| 175 | soft_terminate_timeout): |
| 176 | super(DoTestProcessDriver, self).__init__( |
| 177 | soft_terminate_timeout=soft_terminate_timeout) |
| 178 | self.output_file = output_file |
| 179 | self.output_lock = lldb_utils.OptionalWith(output_file_lock) |
| 180 | self.pid_events = pid_events |
| 181 | self.results = None |
| 182 | self.file_name = file_name |
| 183 | |
| 184 | def write(self, content): |
| 185 | with self.output_lock: |
| 186 | self.output_file.write(content) |
| 187 | |
| 188 | def on_process_started(self): |
| 189 | if self.pid_events: |
| 190 | self.pid_events.put_nowait(('created', self.process.pid)) |
| 191 | |
| 192 | def on_process_exited(self, command, output, was_timeout, exit_status): |
| 193 | if self.pid_events: |
| 194 | # No point in culling out those with no exit_status (i.e. |
| 195 | # those we failed to kill). That would just cause |
| 196 | # downstream code to try to kill it later on a Ctrl-C. At |
| 197 | # this point, a best-effort-to-kill already took place. So |
| 198 | # call it destroyed here. |
| 199 | self.pid_events.put_nowait(('destroyed', self.process.pid)) |
| 200 | |
| 201 | # Override the exit status if it was a timeout. |
| 202 | if was_timeout: |
| 203 | exit_status = eTimedOut |
| 204 | |
| 205 | # If we didn't end up with any output, call it empty for |
| 206 | # stdout/stderr. |
| 207 | if output is None: |
| 208 | output = ('', '') |
| 209 | |
| 210 | # Now parse the output. |
| 211 | passes, failures, unexpected_successes = parse_test_results(output) |
| 212 | if exit_status == 0: |
| 213 | # stdout does not have any useful information from 'dotest.py', |
| 214 | # only stderr does. |
| 215 | report_test_pass(self.file_name, output[1]) |
| 216 | else: |
| 217 | report_test_failure(self.file_name, command, output[1]) |
| 218 | |
| 219 | # Save off the results for the caller. |
| 220 | self.results = ( |
| 221 | self.file_name, |
| 222 | exit_status, |
| 223 | passes, |
| 224 | failures, |
| 225 | unexpected_successes) |
| 226 | |
| 227 | |
| 228 | def get_soft_terminate_timeout(): |
| 229 | # Defaults to 10 seconds, but can set |
| 230 | # LLDB_TEST_SOFT_TERMINATE_TIMEOUT to a floating point |
| 231 | # number in seconds. This value indicates how long |
| 232 | # the test runner will wait for the dotest inferior to |
| 233 | # handle a timeout via a soft terminate before it will |
| 234 | # assume that failed and do a hard terminate. |
| 235 | |
| 236 | # TODO plumb through command-line option |
| 237 | return float(os.environ.get('LLDB_TEST_SOFT_TERMINATE_TIMEOUT', 10.0)) |
| 238 | |
| 239 | |
| 240 | def want_core_on_soft_terminate(): |
| 241 | # TODO plumb through command-line option |
| 242 | if platform.system() == 'Linux': |
| 243 | return True |
| 244 | else: |
| 245 | return False |
Todd Fiala | da817b6 | 2015-09-22 18:05:11 +0000 | [diff] [blame] | 246 | |
| 247 | |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 248 | def call_with_timeout(command, timeout, name, inferior_pid_events): |
Todd Fiala | 2d3754d | 2015-09-29 22:19:06 +0000 | [diff] [blame] | 249 | # Add our worker index (if we have one) to all test events |
| 250 | # from this inferior. |
Todd Fiala | 33896a9 | 2015-09-18 21:01:13 +0000 | [diff] [blame] | 251 | if GET_WORKER_INDEX is not None: |
Todd Fiala | e83f140 | 2015-09-18 22:45:31 +0000 | [diff] [blame] | 252 | try: |
| 253 | worker_index = GET_WORKER_INDEX() |
| 254 | command.extend([ |
Todd Fiala | 2d3754d | 2015-09-29 22:19:06 +0000 | [diff] [blame] | 255 | "--event-add-entries", |
| 256 | "worker_index={}:int".format(worker_index)]) |
| 257 | except: # pylint: disable=bare-except |
| 258 | # Ctrl-C does bad things to multiprocessing.Manager.dict() |
| 259 | # lookup. Just swallow it. |
Todd Fiala | e83f140 | 2015-09-18 22:45:31 +0000 | [diff] [blame] | 260 | pass |
| 261 | |
Todd Fiala | 2d3754d | 2015-09-29 22:19:06 +0000 | [diff] [blame] | 262 | # Create the inferior dotest.py ProcessDriver. |
| 263 | soft_terminate_timeout = get_soft_terminate_timeout() |
| 264 | want_core = want_core_on_soft_terminate() |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 265 | |
Todd Fiala | 2d3754d | 2015-09-29 22:19:06 +0000 | [diff] [blame] | 266 | process_driver = DoTestProcessDriver( |
| 267 | sys.stdout, |
| 268 | output_lock, |
| 269 | inferior_pid_events, |
| 270 | name, |
| 271 | soft_terminate_timeout) |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 272 | |
Todd Fiala | 2d3754d | 2015-09-29 22:19:06 +0000 | [diff] [blame] | 273 | # Run it with a timeout. |
| 274 | process_driver.run_command_with_timeout(command, timeout, want_core) |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 275 | |
Todd Fiala | 2d3754d | 2015-09-29 22:19:06 +0000 | [diff] [blame] | 276 | # Return the results. |
| 277 | if not process_driver.results: |
| 278 | # This is truly exceptional. Even a failing or timed out |
| 279 | # binary should have called the results-generation code. |
| 280 | raise Exception("no test results were generated whatsoever") |
| 281 | return process_driver.results |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 282 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 283 | |
Zachary Turner | 7d56454 | 2015-11-02 19:19:49 +0000 | [diff] [blame] | 284 | def process_dir(root, files, dotest_argv, inferior_pid_events): |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 285 | """Examine a directory for tests, and invoke any found within it.""" |
Chaoren Lin | e80372a | 2015-08-12 18:02:53 +0000 | [diff] [blame] | 286 | results = [] |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 287 | for name in files: |
Zachary Turner | 7d56454 | 2015-11-02 19:19:49 +0000 | [diff] [blame] | 288 | import __main__ as main |
| 289 | script_file = main.__file__ |
Zachary Turner | f6896b0 | 2015-01-05 19:37:03 +0000 | [diff] [blame] | 290 | command = ([sys.executable, script_file] + |
Vince Harron | 41657cc | 2015-05-21 18:15:09 +0000 | [diff] [blame] | 291 | dotest_argv + |
Todd Fiala | fed9566 | 2015-09-03 18:58:44 +0000 | [diff] [blame] | 292 | ["--inferior", "-p", name, root]) |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 293 | |
| 294 | timeout_name = os.path.basename(os.path.splitext(name)[0]).upper() |
| 295 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 296 | timeout = (os.getenv("LLDB_%s_TIMEOUT" % timeout_name) or |
| 297 | getDefaultTimeout(dotest_options.lldb_platform_name)) |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 298 | |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 299 | results.append(call_with_timeout( |
| 300 | command, timeout, name, inferior_pid_events)) |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 301 | |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 302 | # result = (name, status, passes, failures, unexpected_successes) |
| 303 | timed_out = [name for name, status, _, _, _ in results |
Chaoren Lin | e80372a | 2015-08-12 18:02:53 +0000 | [diff] [blame] | 304 | if status == eTimedOut] |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 305 | passed = [name for name, status, _, _, _ in results |
Chaoren Lin | e80372a | 2015-08-12 18:02:53 +0000 | [diff] [blame] | 306 | if status == ePassed] |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 307 | failed = [name for name, status, _, _, _ in results |
Chaoren Lin | e80372a | 2015-08-12 18:02:53 +0000 | [diff] [blame] | 308 | if status != ePassed] |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 309 | unexpected_passes = [name for name, _, _, _, unexpected_successes in results |
| 310 | if unexpected_successes > 0] |
Todd Fiala | fed9566 | 2015-09-03 18:58:44 +0000 | [diff] [blame] | 311 | |
Chaoren Lin | e80372a | 2015-08-12 18:02:53 +0000 | [diff] [blame] | 312 | pass_count = sum([result[2] for result in results]) |
| 313 | fail_count = sum([result[3] for result in results]) |
Zachary Turner | c7a7c8a | 2015-05-28 19:56:26 +0000 | [diff] [blame] | 314 | |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 315 | return (timed_out, passed, failed, unexpected_passes, pass_count, fail_count) |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 316 | |
| 317 | in_q = None |
| 318 | out_q = None |
| 319 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 320 | |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 321 | def process_dir_worker_multiprocessing( |
| 322 | a_output_lock, a_test_counter, a_total_tests, a_test_name_len, |
Todd Fiala | 33896a9 | 2015-09-18 21:01:13 +0000 | [diff] [blame] | 323 | a_dotest_options, job_queue, result_queue, inferior_pid_events, |
| 324 | worker_index_map): |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 325 | """Worker thread main loop when in multiprocessing mode. |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 326 | Takes one directory specification at a time and works on it.""" |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 327 | |
| 328 | # Shut off interrupt handling in the child process. |
| 329 | signal.signal(signal.SIGINT, signal.SIG_IGN) |
Ying Chen | d93aa10 | 2015-09-23 21:53:18 +0000 | [diff] [blame] | 330 | if hasattr(signal, 'SIGHUP'): |
| 331 | signal.signal(signal.SIGHUP, signal.SIG_IGN) |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 332 | |
| 333 | # Setup the global state for the worker process. |
| 334 | setup_global_variables( |
| 335 | a_output_lock, a_test_counter, a_total_tests, a_test_name_len, |
Todd Fiala | 33896a9 | 2015-09-18 21:01:13 +0000 | [diff] [blame] | 336 | a_dotest_options, worker_index_map) |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 337 | |
| 338 | # Keep grabbing entries from the queue until done. |
| 339 | while not job_queue.empty(): |
| 340 | try: |
| 341 | job = job_queue.get(block=False) |
Pavel Labath | 48c6b52 | 2015-11-02 20:54:25 +0000 | [diff] [blame] | 342 | result = process_dir(job[0], job[1], job[2], |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 343 | inferior_pid_events) |
| 344 | result_queue.put(result) |
Zachary Turner | 814236d | 2015-10-21 17:48:52 +0000 | [diff] [blame] | 345 | except queue.Empty: |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 346 | # Fine, we're done. |
| 347 | pass |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 348 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 349 | |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 350 | def process_dir_worker_multiprocessing_pool(args): |
| 351 | return process_dir(*args) |
| 352 | |
| 353 | |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 354 | def process_dir_worker_threading(job_queue, result_queue, inferior_pid_events): |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 355 | """Worker thread main loop when in threading mode. |
| 356 | |
| 357 | This one supports the hand-rolled pooling support. |
| 358 | |
| 359 | Takes one directory specification at a time and works on it.""" |
| 360 | |
| 361 | # Keep grabbing entries from the queue until done. |
| 362 | while not job_queue.empty(): |
| 363 | try: |
| 364 | job = job_queue.get(block=False) |
Pavel Labath | 48c6b52 | 2015-11-02 20:54:25 +0000 | [diff] [blame] | 365 | result = process_dir(job[0], job[1], job[2], |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 366 | inferior_pid_events) |
| 367 | result_queue.put(result) |
Zachary Turner | 814236d | 2015-10-21 17:48:52 +0000 | [diff] [blame] | 368 | except queue.Empty: |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 369 | # Fine, we're done. |
| 370 | pass |
| 371 | |
| 372 | |
| 373 | def process_dir_worker_threading_pool(args): |
| 374 | return process_dir(*args) |
| 375 | |
| 376 | |
| 377 | def process_dir_mapper_inprocess(args): |
| 378 | """Map adapter for running the subprocess-based, non-threaded test runner. |
| 379 | |
| 380 | @param args the process work item tuple |
| 381 | @return the test result tuple |
| 382 | """ |
| 383 | return process_dir(*args) |
| 384 | |
| 385 | |
| 386 | def collect_active_pids_from_pid_events(event_queue): |
| 387 | """ |
| 388 | Returns the set of what should be active inferior pids based on |
| 389 | the event stream. |
| 390 | |
| 391 | @param event_queue a multiprocessing.Queue containing events of the |
| 392 | form: |
| 393 | ('created', pid) |
| 394 | ('destroyed', pid) |
| 395 | |
| 396 | @return set of inferior dotest.py pids activated but never completed. |
| 397 | """ |
| 398 | active_pid_set = set() |
| 399 | while not event_queue.empty(): |
| 400 | pid_event = event_queue.get_nowait() |
| 401 | if pid_event[0] == 'created': |
| 402 | active_pid_set.add(pid_event[1]) |
| 403 | elif pid_event[0] == 'destroyed': |
| 404 | active_pid_set.remove(pid_event[1]) |
| 405 | return active_pid_set |
| 406 | |
| 407 | |
| 408 | def kill_all_worker_processes(workers, inferior_pid_events): |
| 409 | """ |
| 410 | Kills all specified worker processes and their process tree. |
| 411 | |
| 412 | @param workers a list of multiprocess.Process worker objects. |
| 413 | @param inferior_pid_events a multiprocess.Queue that contains |
| 414 | all inferior create and destroy events. Used to construct |
| 415 | the list of child pids still outstanding that need to be killed. |
| 416 | """ |
| 417 | for worker in workers: |
| 418 | worker.terminate() |
| 419 | worker.join() |
| 420 | |
| 421 | # Add all the child test pids created. |
| 422 | active_pid_set = collect_active_pids_from_pid_events( |
| 423 | inferior_pid_events) |
| 424 | for inferior_pid in active_pid_set: |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 425 | print("killing inferior pid {}".format(inferior_pid)) |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 426 | os.kill(inferior_pid, signal.SIGKILL) |
| 427 | |
| 428 | |
| 429 | def kill_all_worker_threads(workers, inferior_pid_events): |
| 430 | """ |
| 431 | Kills all specified worker threads and their process tree. |
| 432 | |
| 433 | @param workers a list of multiprocess.Process worker objects. |
| 434 | @param inferior_pid_events a multiprocess.Queue that contains |
| 435 | all inferior create and destroy events. Used to construct |
| 436 | the list of child pids still outstanding that need to be killed. |
| 437 | """ |
| 438 | |
| 439 | # Add all the child test pids created. |
| 440 | active_pid_set = collect_active_pids_from_pid_events( |
| 441 | inferior_pid_events) |
| 442 | for inferior_pid in active_pid_set: |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 443 | print("killing inferior pid {}".format(inferior_pid)) |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 444 | os.kill(inferior_pid, signal.SIGKILL) |
| 445 | |
| 446 | # We don't have a way to nuke the threads. However, since we killed |
| 447 | # all the inferiors, and we drained the job queue, this will be |
| 448 | # good enough. Wait cleanly for each worker thread to wrap up. |
| 449 | for worker in workers: |
| 450 | worker.join() |
| 451 | |
| 452 | |
| 453 | def find_test_files_in_dir_tree(dir_root, found_func): |
| 454 | """Calls found_func for all the test files in the given dir hierarchy. |
| 455 | |
| 456 | @param dir_root the path to the directory to start scanning |
| 457 | for test files. All files in this directory and all its children |
| 458 | directory trees will be searched. |
| 459 | |
| 460 | @param found_func a callable object that will be passed |
| 461 | the parent directory (relative to dir_root) and the list of |
| 462 | test files from within that directory. |
| 463 | """ |
| 464 | for root, _, files in os.walk(dir_root, topdown=False): |
| 465 | def is_test_filename(test_dir, base_filename): |
| 466 | """Returns True if the given filename matches the test name format. |
| 467 | |
| 468 | @param test_dir the directory to check. Should be absolute or |
| 469 | relative to current working directory. |
| 470 | |
| 471 | @param base_filename the base name of the filename to check for a |
| 472 | dherence to the python test case filename format. |
| 473 | |
| 474 | @return True if name matches the python test case filename format. |
| 475 | """ |
| 476 | # Not interested in symbolically linked files. |
| 477 | if os.path.islink(os.path.join(test_dir, base_filename)): |
| 478 | return False |
| 479 | # Only interested in test files with the "Test*.py" naming pattern. |
| 480 | return (base_filename.startswith("Test") and |
| 481 | base_filename.endswith(".py")) |
| 482 | |
| 483 | tests = [filename for filename in files |
| 484 | if is_test_filename(root, filename)] |
| 485 | if tests: |
| 486 | found_func(root, tests) |
| 487 | |
| 488 | |
| 489 | def initialize_global_vars_common(num_threads, test_work_items): |
| 490 | global total_tests, test_counter, test_name_len |
Greg Clayton | 1827fc2 | 2015-09-19 00:39:09 +0000 | [diff] [blame] | 491 | |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 492 | total_tests = sum([len(item[1]) for item in test_work_items]) |
| 493 | test_counter = multiprocessing.Value('i', 0) |
| 494 | test_name_len = multiprocessing.Value('i', 0) |
Greg Clayton | 1827fc2 | 2015-09-19 00:39:09 +0000 | [diff] [blame] | 495 | if not (RESULTS_FORMATTER and RESULTS_FORMATTER.is_using_terminal()): |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 496 | print("Testing: %d test suites, %d thread%s" % ( |
| 497 | total_tests, num_threads, (num_threads > 1) * "s"), file=sys.stderr) |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 498 | update_progress() |
| 499 | |
| 500 | |
| 501 | def initialize_global_vars_multiprocessing(num_threads, test_work_items): |
| 502 | # Initialize the global state we'll use to communicate with the |
| 503 | # rest of the flat module. |
| 504 | global output_lock |
| 505 | output_lock = multiprocessing.RLock() |
Todd Fiala | 33896a9 | 2015-09-18 21:01:13 +0000 | [diff] [blame] | 506 | |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 507 | initialize_global_vars_common(num_threads, test_work_items) |
| 508 | |
| 509 | |
| 510 | def initialize_global_vars_threading(num_threads, test_work_items): |
Todd Fiala | 33896a9 | 2015-09-18 21:01:13 +0000 | [diff] [blame] | 511 | """Initializes global variables used in threading mode. |
| 512 | @param num_threads specifies the number of workers used. |
| 513 | @param test_work_items specifies all the work items |
| 514 | that will be processed. |
| 515 | """ |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 516 | # Initialize the global state we'll use to communicate with the |
| 517 | # rest of the flat module. |
| 518 | global output_lock |
| 519 | output_lock = threading.RLock() |
Todd Fiala | 33896a9 | 2015-09-18 21:01:13 +0000 | [diff] [blame] | 520 | |
| 521 | index_lock = threading.RLock() |
| 522 | index_map = {} |
| 523 | |
| 524 | def get_worker_index_threading(): |
| 525 | """Returns a 0-based, thread-unique index for the worker thread.""" |
| 526 | thread_id = threading.current_thread().ident |
| 527 | with index_lock: |
| 528 | if thread_id not in index_map: |
| 529 | index_map[thread_id] = len(index_map) |
| 530 | return index_map[thread_id] |
| 531 | |
| 532 | |
| 533 | global GET_WORKER_INDEX |
| 534 | GET_WORKER_INDEX = get_worker_index_threading |
| 535 | |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 536 | initialize_global_vars_common(num_threads, test_work_items) |
| 537 | |
| 538 | |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 539 | def ctrl_c_loop(main_op_func, done_func, ctrl_c_handler): |
| 540 | """Provides a main loop that is Ctrl-C protected. |
| 541 | |
| 542 | The main loop calls the main_op_func() repeatedly until done_func() |
| 543 | returns true. The ctrl_c_handler() method is called with a single |
| 544 | int parameter that contains the number of times the ctrl_c has been |
| 545 | hit (starting with 1). The ctrl_c_handler() should mutate whatever |
| 546 | it needs to have the done_func() return True as soon as it is desired |
| 547 | to exit the loop. |
| 548 | """ |
| 549 | done = False |
| 550 | ctrl_c_count = 0 |
| 551 | |
| 552 | while not done: |
| 553 | try: |
| 554 | # See if we're done. Start with done check since it is |
| 555 | # the first thing executed after a Ctrl-C handler in the |
| 556 | # following loop. |
| 557 | done = done_func() |
| 558 | if not done: |
| 559 | # Run the main op once. |
| 560 | main_op_func() |
| 561 | |
| 562 | except KeyboardInterrupt: |
| 563 | ctrl_c_count += 1 |
| 564 | ctrl_c_handler(ctrl_c_count) |
| 565 | |
| 566 | |
| 567 | def pump_workers_and_asyncore_map(workers, asyncore_map): |
| 568 | """Prunes out completed workers and maintains the asyncore loop. |
| 569 | |
| 570 | The asyncore loop contains the optional socket listener |
| 571 | and handlers. When all workers are complete, this method |
| 572 | takes care of stopping the listener. It also runs the |
| 573 | asyncore loop for the given async map for 10 iterations. |
| 574 | |
| 575 | @param workers the list of worker Thread/Process instances. |
| 576 | |
| 577 | @param asyncore_map the asyncore threading-aware map that |
| 578 | indicates which channels are in use and still alive. |
| 579 | """ |
| 580 | |
| 581 | # Check on all the workers, removing them from the workers |
| 582 | # list as they complete. |
| 583 | dead_workers = [] |
| 584 | for worker in workers: |
| 585 | # This non-blocking join call is what allows us |
| 586 | # to still receive keyboard interrupts. |
| 587 | worker.join(0.01) |
| 588 | if not worker.is_alive(): |
| 589 | dead_workers.append(worker) |
| 590 | # Clear out the completed workers |
| 591 | for dead_worker in dead_workers: |
| 592 | workers.remove(dead_worker) |
| 593 | |
| 594 | # If there are no more workers and there is a listener, |
| 595 | # close the listener. |
| 596 | global RESULTS_LISTENER_CHANNEL |
| 597 | if len(workers) == 0 and RESULTS_LISTENER_CHANNEL is not None: |
| 598 | RESULTS_LISTENER_CHANNEL.close() |
| 599 | RESULTS_LISTENER_CHANNEL = None |
| 600 | |
| 601 | # Pump the asyncore map if it isn't empty. |
| 602 | if len(asyncore_map) > 0: |
| 603 | asyncore.loop(0.1, False, asyncore_map, 10) |
| 604 | |
| 605 | |
| 606 | def handle_ctrl_c(ctrl_c_count, job_queue, workers, inferior_pid_events, |
| 607 | stop_all_inferiors_func): |
| 608 | """Performs the appropriate ctrl-c action for non-pool parallel test runners |
| 609 | |
| 610 | @param ctrl_c_count starting with 1, indicates the number of times ctrl-c |
| 611 | has been intercepted. The value is 1 on the first intercept, 2 on the |
| 612 | second, etc. |
| 613 | |
| 614 | @param job_queue a Queue object that contains the work still outstanding |
| 615 | (i.e. hasn't been assigned to a worker yet). |
| 616 | |
| 617 | @param workers list of Thread or Process workers. |
| 618 | |
| 619 | @param inferior_pid_events specifies a Queue of inferior process |
| 620 | construction and destruction events. Used to build the list of inferior |
| 621 | processes that should be killed if we get that far. |
| 622 | |
| 623 | @param stop_all_inferiors_func a callable object that takes the |
| 624 | workers and inferior_pid_events parameters (in that order) if a hard |
| 625 | stop is to be used on the workers. |
| 626 | """ |
| 627 | |
| 628 | # Print out which Ctrl-C we're handling. |
| 629 | key_name = [ |
| 630 | "first", |
| 631 | "second", |
| 632 | "third", |
| 633 | "many"] |
| 634 | |
| 635 | if ctrl_c_count < len(key_name): |
| 636 | name_index = ctrl_c_count - 1 |
| 637 | else: |
| 638 | name_index = len(key_name) - 1 |
| 639 | message = "\nHandling {} KeyboardInterrupt".format(key_name[name_index]) |
| 640 | with output_lock: |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 641 | print(message) |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 642 | |
| 643 | if ctrl_c_count == 1: |
| 644 | # Remove all outstanding items from the work queue so we stop |
| 645 | # doing any more new work. |
| 646 | while not job_queue.empty(): |
| 647 | try: |
| 648 | # Just drain it to stop more work from being started. |
| 649 | job_queue.get_nowait() |
Zachary Turner | 814236d | 2015-10-21 17:48:52 +0000 | [diff] [blame] | 650 | except queue.Empty: |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 651 | pass |
| 652 | with output_lock: |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 653 | print("Stopped more work from being started.") |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 654 | elif ctrl_c_count == 2: |
| 655 | # Try to stop all inferiors, even the ones currently doing work. |
| 656 | stop_all_inferiors_func(workers, inferior_pid_events) |
| 657 | else: |
| 658 | with output_lock: |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 659 | print("All teardown activities kicked off, should finish soon.") |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 660 | |
| 661 | |
| 662 | def workers_and_async_done(workers, async_map): |
| 663 | """Returns True if the workers list and asyncore channels are all done. |
| 664 | |
| 665 | @param workers list of workers (threads/processes). These must adhere |
| 666 | to the threading Thread or multiprocessing.Process interface. |
| 667 | |
| 668 | @param async_map the threading-aware asyncore channel map to check |
| 669 | for live channels. |
| 670 | |
| 671 | @return False if the workers list exists and has any entries in it, or |
| 672 | if the async_map exists and has any entries left in it; otherwise, True. |
| 673 | """ |
| 674 | if workers is not None and len(workers) > 0: |
| 675 | # We're not done if we still have workers left. |
| 676 | return False |
| 677 | if async_map is not None and len(async_map) > 0: |
| 678 | return False |
| 679 | # We're done. |
| 680 | return True |
| 681 | |
| 682 | |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 683 | def multiprocessing_test_runner(num_threads, test_work_items): |
| 684 | """Provides hand-wrapped pooling test runner adapter with Ctrl-C support. |
| 685 | |
| 686 | This concurrent test runner is based on the multiprocessing |
| 687 | library, and rolls its own worker pooling strategy so it |
| 688 | can handle Ctrl-C properly. |
| 689 | |
| 690 | This test runner is known to have an issue running on |
| 691 | Windows platforms. |
| 692 | |
| 693 | @param num_threads the number of worker processes to use. |
| 694 | |
| 695 | @param test_work_items the iterable of test work item tuples |
| 696 | to run. |
| 697 | """ |
| 698 | |
| 699 | # Initialize our global state. |
| 700 | initialize_global_vars_multiprocessing(num_threads, test_work_items) |
| 701 | |
| 702 | # Create jobs. |
| 703 | job_queue = multiprocessing.Queue(len(test_work_items)) |
| 704 | for test_work_item in test_work_items: |
| 705 | job_queue.put(test_work_item) |
| 706 | |
| 707 | result_queue = multiprocessing.Queue(len(test_work_items)) |
| 708 | |
| 709 | # Create queues for started child pids. Terminating |
| 710 | # the multiprocess processes does not terminate the |
| 711 | # child processes they spawn. We can remove this tracking |
| 712 | # if/when we move to having the multiprocess process directly |
| 713 | # perform the test logic. The Queue size needs to be able to |
| 714 | # hold 2 * (num inferior dotest.py processes started) entries. |
| 715 | inferior_pid_events = multiprocessing.Queue(4096) |
| 716 | |
Todd Fiala | 33896a9 | 2015-09-18 21:01:13 +0000 | [diff] [blame] | 717 | # Worker dictionary allows each worker to figure out its worker index. |
| 718 | manager = multiprocessing.Manager() |
| 719 | worker_index_map = manager.dict() |
| 720 | |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 721 | # Create workers. We don't use multiprocessing.Pool due to |
| 722 | # challenges with handling ^C keyboard interrupts. |
| 723 | workers = [] |
| 724 | for _ in range(num_threads): |
| 725 | worker = multiprocessing.Process( |
| 726 | target=process_dir_worker_multiprocessing, |
| 727 | args=(output_lock, |
| 728 | test_counter, |
| 729 | total_tests, |
| 730 | test_name_len, |
| 731 | dotest_options, |
| 732 | job_queue, |
| 733 | result_queue, |
Todd Fiala | 33896a9 | 2015-09-18 21:01:13 +0000 | [diff] [blame] | 734 | inferior_pid_events, |
| 735 | worker_index_map)) |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 736 | worker.start() |
| 737 | workers.append(worker) |
| 738 | |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 739 | # Main loop: wait for all workers to finish and wait for |
| 740 | # the socket handlers to wrap up. |
| 741 | ctrl_c_loop( |
| 742 | # Main operation of loop |
| 743 | lambda: pump_workers_and_asyncore_map( |
| 744 | workers, RUNNER_PROCESS_ASYNC_MAP), |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 745 | |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 746 | # Return True when we're done with the main loop. |
| 747 | lambda: workers_and_async_done(workers, RUNNER_PROCESS_ASYNC_MAP), |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 748 | |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 749 | # Indicate what we do when we receive one or more Ctrl-Cs. |
| 750 | lambda ctrl_c_count: handle_ctrl_c( |
| 751 | ctrl_c_count, job_queue, workers, inferior_pid_events, |
| 752 | kill_all_worker_processes)) |
| 753 | |
| 754 | # Reap the test results. |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 755 | test_results = [] |
| 756 | while not result_queue.empty(): |
| 757 | test_results.append(result_queue.get(block=False)) |
| 758 | return test_results |
| 759 | |
| 760 | |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 761 | def map_async_run_loop(future, channel_map, listener_channel): |
| 762 | """Blocks until the Pool.map_async completes and the channel completes. |
| 763 | |
| 764 | @param future an AsyncResult instance from a Pool.map_async() call. |
| 765 | |
| 766 | @param channel_map the asyncore dispatch channel map that should be pumped. |
| 767 | Optional: may be None. |
| 768 | |
| 769 | @param listener_channel the channel representing a listener that should be |
| 770 | closed once the map_async results are available. |
| 771 | |
| 772 | @return the results from the async_result instance. |
| 773 | """ |
| 774 | map_results = None |
| 775 | |
| 776 | done = False |
| 777 | while not done: |
| 778 | # Check if we need to reap the map results. |
| 779 | if map_results is None: |
| 780 | if future.ready(): |
| 781 | # Get the results. |
| 782 | map_results = future.get() |
| 783 | |
| 784 | # Close the runner process listener channel if we have |
| 785 | # one: no more connections will be incoming. |
| 786 | if listener_channel is not None: |
| 787 | listener_channel.close() |
| 788 | |
| 789 | # Pump the asyncore loop if we have a listener socket. |
| 790 | if channel_map is not None: |
| 791 | asyncore.loop(0.01, False, channel_map, 10) |
| 792 | |
| 793 | # Figure out if we're done running. |
| 794 | done = map_results is not None |
| 795 | if channel_map is not None: |
| 796 | # We have a runner process async map. Check if it |
| 797 | # is complete. |
| 798 | if len(channel_map) > 0: |
| 799 | # We still have an asyncore channel running. Not done yet. |
| 800 | done = False |
| 801 | |
| 802 | return map_results |
| 803 | |
| 804 | |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 805 | def multiprocessing_test_runner_pool(num_threads, test_work_items): |
| 806 | # Initialize our global state. |
| 807 | initialize_global_vars_multiprocessing(num_threads, test_work_items) |
| 808 | |
Todd Fiala | 33896a9 | 2015-09-18 21:01:13 +0000 | [diff] [blame] | 809 | manager = multiprocessing.Manager() |
| 810 | worker_index_map = manager.dict() |
| 811 | |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 812 | pool = multiprocessing.Pool( |
| 813 | num_threads, |
| 814 | initializer=setup_global_variables, |
| 815 | initargs=(output_lock, test_counter, total_tests, test_name_len, |
Todd Fiala | 33896a9 | 2015-09-18 21:01:13 +0000 | [diff] [blame] | 816 | dotest_options, worker_index_map)) |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 817 | |
| 818 | # Start the map operation (async mode). |
| 819 | map_future = pool.map_async( |
| 820 | process_dir_worker_multiprocessing_pool, test_work_items) |
| 821 | return map_async_run_loop( |
| 822 | map_future, RUNNER_PROCESS_ASYNC_MAP, RESULTS_LISTENER_CHANNEL) |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 823 | |
| 824 | |
| 825 | def threading_test_runner(num_threads, test_work_items): |
| 826 | """Provides hand-wrapped pooling threading-based test runner adapter |
| 827 | with Ctrl-C support. |
| 828 | |
| 829 | This concurrent test runner is based on the threading |
| 830 | library, and rolls its own worker pooling strategy so it |
| 831 | can handle Ctrl-C properly. |
| 832 | |
| 833 | @param num_threads the number of worker processes to use. |
| 834 | |
| 835 | @param test_work_items the iterable of test work item tuples |
| 836 | to run. |
| 837 | """ |
| 838 | |
| 839 | # Initialize our global state. |
| 840 | initialize_global_vars_threading(num_threads, test_work_items) |
| 841 | |
| 842 | # Create jobs. |
Zachary Turner | 814236d | 2015-10-21 17:48:52 +0000 | [diff] [blame] | 843 | job_queue = queue.Queue() |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 844 | for test_work_item in test_work_items: |
| 845 | job_queue.put(test_work_item) |
| 846 | |
Zachary Turner | 814236d | 2015-10-21 17:48:52 +0000 | [diff] [blame] | 847 | result_queue = queue.Queue() |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 848 | |
| 849 | # Create queues for started child pids. Terminating |
| 850 | # the threading threads does not terminate the |
| 851 | # child processes they spawn. |
Zachary Turner | 814236d | 2015-10-21 17:48:52 +0000 | [diff] [blame] | 852 | inferior_pid_events = queue.Queue() |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 853 | |
| 854 | # Create workers. We don't use multiprocessing.pool.ThreadedPool |
| 855 | # due to challenges with handling ^C keyboard interrupts. |
| 856 | workers = [] |
| 857 | for _ in range(num_threads): |
| 858 | worker = threading.Thread( |
| 859 | target=process_dir_worker_threading, |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 860 | args=(job_queue, |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 861 | result_queue, |
| 862 | inferior_pid_events)) |
| 863 | worker.start() |
| 864 | workers.append(worker) |
| 865 | |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 866 | # Main loop: wait for all workers to finish and wait for |
| 867 | # the socket handlers to wrap up. |
| 868 | ctrl_c_loop( |
| 869 | # Main operation of loop |
| 870 | lambda: pump_workers_and_asyncore_map( |
| 871 | workers, RUNNER_PROCESS_ASYNC_MAP), |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 872 | |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 873 | # Return True when we're done with the main loop. |
| 874 | lambda: workers_and_async_done(workers, RUNNER_PROCESS_ASYNC_MAP), |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 875 | |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 876 | # Indicate what we do when we receive one or more Ctrl-Cs. |
| 877 | lambda ctrl_c_count: handle_ctrl_c( |
| 878 | ctrl_c_count, job_queue, workers, inferior_pid_events, |
| 879 | kill_all_worker_threads)) |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 880 | |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 881 | # Reap the test results. |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 882 | test_results = [] |
| 883 | while not result_queue.empty(): |
| 884 | test_results.append(result_queue.get(block=False)) |
| 885 | return test_results |
| 886 | |
| 887 | |
| 888 | def threading_test_runner_pool(num_threads, test_work_items): |
| 889 | # Initialize our global state. |
| 890 | initialize_global_vars_threading(num_threads, test_work_items) |
| 891 | |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 892 | pool = multiprocessing.pool.ThreadPool(num_threads) |
| 893 | map_future = pool.map_async( |
| 894 | process_dir_worker_threading_pool, test_work_items) |
| 895 | |
| 896 | return map_async_run_loop( |
| 897 | map_future, RUNNER_PROCESS_ASYNC_MAP, RESULTS_LISTENER_CHANNEL) |
| 898 | |
| 899 | |
| 900 | def asyncore_run_loop(channel_map): |
| 901 | try: |
| 902 | asyncore.loop(None, False, channel_map) |
| 903 | except: |
| 904 | # Swallow it, we're seeing: |
| 905 | # error: (9, 'Bad file descriptor') |
| 906 | # when the listener channel is closed. Shouldn't be the case. |
| 907 | pass |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 908 | |
| 909 | |
| 910 | def inprocess_exec_test_runner(test_work_items): |
| 911 | # Initialize our global state. |
| 912 | initialize_global_vars_multiprocessing(1, test_work_items) |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 913 | |
Todd Fiala | 33896a9 | 2015-09-18 21:01:13 +0000 | [diff] [blame] | 914 | # We're always worker index 0 |
| 915 | global GET_WORKER_INDEX |
| 916 | GET_WORKER_INDEX = lambda: 0 |
| 917 | |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 918 | # Run the listener and related channel maps in a separate thread. |
| 919 | # global RUNNER_PROCESS_ASYNC_MAP |
| 920 | global RESULTS_LISTENER_CHANNEL |
| 921 | if RESULTS_LISTENER_CHANNEL is not None: |
| 922 | socket_thread = threading.Thread( |
| 923 | target=lambda: asyncore_run_loop(RUNNER_PROCESS_ASYNC_MAP)) |
| 924 | socket_thread.start() |
| 925 | |
| 926 | # Do the work. |
Zachary Turner | 1c4059a | 2015-10-22 20:39:59 +0000 | [diff] [blame] | 927 | test_results = list(map(process_dir_mapper_inprocess, test_work_items)) |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 928 | |
| 929 | # If we have a listener channel, shut it down here. |
| 930 | if RESULTS_LISTENER_CHANNEL is not None: |
| 931 | # Close down the channel. |
| 932 | RESULTS_LISTENER_CHANNEL.close() |
| 933 | RESULTS_LISTENER_CHANNEL = None |
| 934 | |
| 935 | # Wait for the listener and handlers to complete. |
| 936 | socket_thread.join() |
| 937 | |
| 938 | return test_results |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 939 | |
| 940 | def walk_and_invoke(test_directory, test_subdir, dotest_argv, |
Todd Fiala | 871b2e5 | 2015-09-22 22:47:34 +0000 | [diff] [blame] | 941 | num_workers, test_runner_func): |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 942 | """Look for matched files and invoke test driver on each one. |
| 943 | In single-threaded mode, each test driver is invoked directly. |
| 944 | In multi-threaded mode, submit each test driver to a worker |
Vince Harron | e06a7a8 | 2015-05-12 23:12:19 +0000 | [diff] [blame] | 945 | queue, and then wait for all to complete. |
| 946 | |
| 947 | test_directory - lldb/test/ directory |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 948 | test_subdir - lldb/test/ or a subfolder with the tests we're interested in |
| 949 | running |
Vince Harron | e06a7a8 | 2015-05-12 23:12:19 +0000 | [diff] [blame] | 950 | """ |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 951 | # The async_map is important to keep all thread-related asyncore |
| 952 | # channels distinct when we call asyncore.loop() later on. |
| 953 | global RESULTS_LISTENER_CHANNEL, RUNNER_PROCESS_ASYNC_MAP |
| 954 | RUNNER_PROCESS_ASYNC_MAP = {} |
| 955 | |
| 956 | # If we're outputting side-channel test results, create the socket |
| 957 | # listener channel and tell the inferior to send results to the |
| 958 | # port on which we'll be listening. |
| 959 | if RESULTS_FORMATTER is not None: |
Todd Fiala | e83f140 | 2015-09-18 22:45:31 +0000 | [diff] [blame] | 960 | forwarding_func = RESULTS_FORMATTER.handle_event |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 961 | RESULTS_LISTENER_CHANNEL = ( |
| 962 | dotest_channels.UnpicklingForwardingListenerChannel( |
Todd Fiala | 871b2e5 | 2015-09-22 22:47:34 +0000 | [diff] [blame] | 963 | RUNNER_PROCESS_ASYNC_MAP, "localhost", 0, |
| 964 | 2 * num_workers, forwarding_func)) |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 965 | dotest_argv.append("--results-port") |
| 966 | dotest_argv.append(str(RESULTS_LISTENER_CHANNEL.address[1])) |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 967 | |
| 968 | # Collect the test files that we'll run. |
| 969 | test_work_items = [] |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 970 | find_test_files_in_dir_tree( |
| 971 | test_subdir, lambda testdir, test_files: test_work_items.append([ |
Zachary Turner | 7d56454 | 2015-11-02 19:19:49 +0000 | [diff] [blame] | 972 | test_subdir, test_files, dotest_argv, None])) |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 973 | |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 974 | # Convert test work items into test results using whatever |
| 975 | # was provided as the test run function. |
| 976 | test_results = test_runner_func(test_work_items) |
Chaoren Lin | ffc63b0 | 2015-08-12 18:02:49 +0000 | [diff] [blame] | 977 | |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 978 | # Summarize the results and return to caller. |
Chaoren Lin | e80372a | 2015-08-12 18:02:53 +0000 | [diff] [blame] | 979 | timed_out = sum([result[0] for result in test_results], []) |
| 980 | passed = sum([result[1] for result in test_results], []) |
| 981 | failed = sum([result[2] for result in test_results], []) |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 982 | unexpected_successes = sum([result[3] for result in test_results], []) |
| 983 | pass_count = sum([result[4] for result in test_results]) |
| 984 | fail_count = sum([result[5] for result in test_results]) |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 985 | |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 986 | return (timed_out, passed, failed, unexpected_successes, pass_count, |
| 987 | fail_count) |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 988 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 989 | |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 990 | def getExpectedTimeouts(platform_name): |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 991 | # returns a set of test filenames that might timeout |
| 992 | # are we running against a remote target? |
Chaoren Lin | febef1b | 2015-08-19 17:22:12 +0000 | [diff] [blame] | 993 | host = sys.platform |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 994 | if platform_name is None: |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 995 | target = sys.platform |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 996 | else: |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 997 | m = re.search(r'remote-(\w+)', platform_name) |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 998 | target = m.group(1) |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 999 | |
| 1000 | expected_timeout = set() |
| 1001 | |
| 1002 | if target.startswith("linux"): |
| 1003 | expected_timeout |= { |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 1004 | "TestConnectRemote.py", |
| 1005 | "TestCreateAfterAttach.py", |
Tamas Berghammer | 0d0ec9f | 2015-05-19 10:49:40 +0000 | [diff] [blame] | 1006 | "TestEvents.py", |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 1007 | "TestExitDuringStep.py", |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 1008 | |
| 1009 | # Times out in ~10% of the times on the build bot |
| 1010 | "TestHelloWorld.py", |
Oleksiy Vyalov | 18f4c9f | 2015-06-10 01:34:25 +0000 | [diff] [blame] | 1011 | "TestMultithreaded.py", |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 1012 | "TestRegisters.py", # ~12/600 dosep runs (build 3120-3122) |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 1013 | "TestThreadStepOut.py", |
| 1014 | } |
| 1015 | elif target.startswith("android"): |
| 1016 | expected_timeout |= { |
| 1017 | "TestExitDuringStep.py", |
| 1018 | "TestHelloWorld.py", |
| 1019 | } |
Chaoren Lin | febef1b | 2015-08-19 17:22:12 +0000 | [diff] [blame] | 1020 | if host.startswith("win32"): |
| 1021 | expected_timeout |= { |
| 1022 | "TestEvents.py", |
| 1023 | "TestThreadStates.py", |
| 1024 | } |
Ed Maste | 4dd8fba | 2015-05-14 16:25:52 +0000 | [diff] [blame] | 1025 | elif target.startswith("freebsd"): |
| 1026 | expected_timeout |= { |
| 1027 | "TestBreakpointConditions.py", |
Ed Maste | 0894813 | 2015-05-28 18:45:30 +0000 | [diff] [blame] | 1028 | "TestChangeProcessGroup.py", |
Ed Maste | bfd0563 | 2015-05-27 19:11:29 +0000 | [diff] [blame] | 1029 | "TestValueObjectRecursion.py", |
Ed Maste | 4dd8fba | 2015-05-14 16:25:52 +0000 | [diff] [blame] | 1030 | "TestWatchpointConditionAPI.py", |
| 1031 | } |
Vince Harron | 0f173ac | 2015-05-18 19:36:33 +0000 | [diff] [blame] | 1032 | elif target.startswith("darwin"): |
| 1033 | expected_timeout |= { |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 1034 | # times out on MBP Retina, Mid 2012 |
| 1035 | "TestThreadSpecificBreakpoint.py", |
Chaoren Lin | d904371 | 2015-08-19 17:13:02 +0000 | [diff] [blame] | 1036 | "TestExitDuringStep.py", |
Chaoren Lin | 99f25be | 2015-08-20 01:26:57 +0000 | [diff] [blame] | 1037 | "TestIntegerTypesExpr.py", |
Vince Harron | 0f173ac | 2015-05-18 19:36:33 +0000 | [diff] [blame] | 1038 | } |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 1039 | return expected_timeout |
| 1040 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 1041 | |
Pavel Labath | fad30cf | 2015-06-29 14:16:51 +0000 | [diff] [blame] | 1042 | def getDefaultTimeout(platform_name): |
| 1043 | if os.getenv("LLDB_TEST_TIMEOUT"): |
| 1044 | return os.getenv("LLDB_TEST_TIMEOUT") |
| 1045 | |
| 1046 | if platform_name is None: |
| 1047 | platform_name = sys.platform |
| 1048 | |
| 1049 | if platform_name.startswith("remote-"): |
| 1050 | return "10m" |
| 1051 | else: |
| 1052 | return "4m" |
| 1053 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 1054 | |
Vince Harron | 0b9dbb5 | 2015-05-21 18:18:52 +0000 | [diff] [blame] | 1055 | def touch(fname, times=None): |
Greg Clayton | 8c3f9c9 | 2015-08-11 21:01:32 +0000 | [diff] [blame] | 1056 | if os.path.exists(fname): |
Vince Harron | 0b9dbb5 | 2015-05-21 18:18:52 +0000 | [diff] [blame] | 1057 | os.utime(fname, times) |
| 1058 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 1059 | |
Vince Harron | dcc2b9f | 2015-05-27 04:40:36 +0000 | [diff] [blame] | 1060 | def find(pattern, path): |
| 1061 | result = [] |
| 1062 | for root, dirs, files in os.walk(path): |
| 1063 | for name in files: |
| 1064 | if fnmatch.fnmatch(name, pattern): |
| 1065 | result.append(os.path.join(root, name)) |
| 1066 | return result |
| 1067 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 1068 | |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 1069 | def get_test_runner_strategies(num_threads): |
| 1070 | """Returns the test runner strategies by name in a dictionary. |
| 1071 | |
| 1072 | @param num_threads specifies the number of threads/processes |
| 1073 | that will be used for concurrent test runners. |
| 1074 | |
| 1075 | @return dictionary with key as test runner strategy name and |
| 1076 | value set to a callable object that takes the test work item |
| 1077 | and returns a test result tuple. |
| 1078 | """ |
| 1079 | return { |
| 1080 | # multiprocessing supports ctrl-c and does not use |
| 1081 | # multiprocessing.Pool. |
| 1082 | "multiprocessing": |
| 1083 | (lambda work_items: multiprocessing_test_runner( |
| 1084 | num_threads, work_items)), |
| 1085 | |
| 1086 | # multiprocessing-pool uses multiprocessing.Pool but |
| 1087 | # does not support Ctrl-C. |
| 1088 | "multiprocessing-pool": |
| 1089 | (lambda work_items: multiprocessing_test_runner_pool( |
| 1090 | num_threads, work_items)), |
| 1091 | |
| 1092 | # threading uses a hand-rolled worker pool much |
| 1093 | # like multiprocessing, but instead uses in-process |
| 1094 | # worker threads. This one supports Ctrl-C. |
| 1095 | "threading": |
| 1096 | (lambda work_items: threading_test_runner(num_threads, work_items)), |
| 1097 | |
| 1098 | # threading-pool uses threading for the workers (in-process) |
| 1099 | # and uses the multiprocessing.pool thread-enabled pool. |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 1100 | # This does not properly support Ctrl-C. |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 1101 | "threading-pool": |
| 1102 | (lambda work_items: threading_test_runner_pool( |
| 1103 | num_threads, work_items)), |
| 1104 | |
| 1105 | # serial uses the subprocess-based, single process |
| 1106 | # test runner. This provides process isolation but |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 1107 | # no concurrent test execution. |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 1108 | "serial": |
| 1109 | inprocess_exec_test_runner |
| 1110 | } |
| 1111 | |
| 1112 | |
Todd Fiala | ea73624 | 2015-09-23 15:21:28 +0000 | [diff] [blame] | 1113 | def _remove_option( |
| 1114 | args, long_option_name, short_option_name, takes_arg): |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 1115 | """Removes option and related option arguments from args array. |
Todd Fiala | ea73624 | 2015-09-23 15:21:28 +0000 | [diff] [blame] | 1116 | |
| 1117 | This method removes all short/long options that match the given |
| 1118 | arguments. |
| 1119 | |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 1120 | @param args the array of command line arguments (in/out) |
Todd Fiala | ea73624 | 2015-09-23 15:21:28 +0000 | [diff] [blame] | 1121 | |
| 1122 | @param long_option_name the full command line representation of the |
| 1123 | long-form option that will be removed (including '--'). |
| 1124 | |
| 1125 | @param short_option_name the short version of the command line option |
| 1126 | that will be removed (including '-'). |
| 1127 | |
| 1128 | @param takes_arg True if the option takes an argument. |
| 1129 | |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 1130 | """ |
Todd Fiala | ea73624 | 2015-09-23 15:21:28 +0000 | [diff] [blame] | 1131 | if long_option_name is not None: |
| 1132 | regex_string = "^" + long_option_name + "=" |
| 1133 | long_regex = re.compile(regex_string) |
| 1134 | if short_option_name is not None: |
| 1135 | # Short options we only match the -X and assume |
| 1136 | # any arg is one command line argument jammed together. |
| 1137 | # i.e. -O--abc=1 is a single argument in the args list. |
| 1138 | # We don't handle -O --abc=1, as argparse doesn't handle |
| 1139 | # it, either. |
| 1140 | regex_string = "^" + short_option_name |
| 1141 | short_regex = re.compile(regex_string) |
| 1142 | |
| 1143 | def remove_long_internal(): |
| 1144 | """Removes one matching long option from args. |
| 1145 | @returns True if one was found and removed; False otherwise. |
| 1146 | """ |
| 1147 | try: |
| 1148 | index = args.index(long_option_name) |
| 1149 | # Handle the exact match case. |
| 1150 | if takes_arg: |
| 1151 | removal_count = 2 |
| 1152 | else: |
| 1153 | removal_count = 1 |
| 1154 | del args[index:index+removal_count] |
| 1155 | return True |
| 1156 | except ValueError: |
| 1157 | # Thanks to argparse not handling options with known arguments |
| 1158 | # like other options parsing libraries (see |
| 1159 | # https://bugs.python.org/issue9334), we need to support the |
| 1160 | # --results-formatter-options={second-level-arguments} (note |
| 1161 | # the equal sign to fool the first-level arguments parser into |
| 1162 | # not treating the second-level arguments as first-level |
| 1163 | # options). We're certainly at risk of getting this wrong |
| 1164 | # since now we're forced into the business of trying to figure |
| 1165 | # out what is an argument (although I think this |
| 1166 | # implementation will suffice). |
| 1167 | for index in range(len(args)): |
| 1168 | match = long_regex.search(args[index]) |
| 1169 | if match: |
| 1170 | del args[index] |
| 1171 | return True |
| 1172 | return False |
| 1173 | |
| 1174 | def remove_short_internal(): |
| 1175 | """Removes one matching short option from args. |
| 1176 | @returns True if one was found and removed; False otherwise. |
| 1177 | """ |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 1178 | for index in range(len(args)): |
Todd Fiala | ea73624 | 2015-09-23 15:21:28 +0000 | [diff] [blame] | 1179 | match = short_regex.search(args[index]) |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 1180 | if match: |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 1181 | del args[index] |
Todd Fiala | ea73624 | 2015-09-23 15:21:28 +0000 | [diff] [blame] | 1182 | return True |
| 1183 | return False |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 1184 | |
Todd Fiala | ea73624 | 2015-09-23 15:21:28 +0000 | [diff] [blame] | 1185 | removal_count = 0 |
| 1186 | while long_option_name is not None and remove_long_internal(): |
| 1187 | removal_count += 1 |
| 1188 | while short_option_name is not None and remove_short_internal(): |
| 1189 | removal_count += 1 |
| 1190 | if removal_count == 0: |
| 1191 | raise Exception( |
| 1192 | "failed to find at least one of '{}', '{}' in options".format( |
| 1193 | long_option_name, short_option_name)) |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 1194 | |
| 1195 | |
| 1196 | def adjust_inferior_options(dotest_argv): |
| 1197 | """Adjusts the commandline args array for inferiors. |
| 1198 | |
| 1199 | This method adjusts the inferior dotest commandline options based |
| 1200 | on the parallel test runner's options. Some of the inferior options |
| 1201 | will need to change to properly handle aggregation functionality. |
| 1202 | """ |
| 1203 | global dotest_options |
| 1204 | |
| 1205 | # If we don't have a session directory, create one. |
| 1206 | if not dotest_options.s: |
| 1207 | # no session log directory, we need to add this to prevent |
| 1208 | # every dotest invocation from creating its own directory |
| 1209 | import datetime |
| 1210 | # The windows platforms don't like ':' in the pathname. |
Zachary Turner | af383ff | 2015-10-27 22:33:47 +0000 | [diff] [blame] | 1211 | timestamp_started = datetime.datetime.now().strftime("%Y-%m-%d-%H_%M_%S") |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 1212 | dotest_argv.append('-s') |
| 1213 | dotest_argv.append(timestamp_started) |
| 1214 | dotest_options.s = timestamp_started |
| 1215 | |
| 1216 | # Adjust inferior results formatter options - if the parallel |
| 1217 | # test runner is collecting into the user-specified test results, |
| 1218 | # we'll have inferiors spawn with the --results-port option and |
| 1219 | # strip the original test runner options. |
| 1220 | if dotest_options.results_file is not None: |
Todd Fiala | ea73624 | 2015-09-23 15:21:28 +0000 | [diff] [blame] | 1221 | _remove_option(dotest_argv, "--results-file", None, True) |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 1222 | if dotest_options.results_port is not None: |
Todd Fiala | ea73624 | 2015-09-23 15:21:28 +0000 | [diff] [blame] | 1223 | _remove_option(dotest_argv, "--results-port", None, True) |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 1224 | if dotest_options.results_formatter is not None: |
Todd Fiala | ea73624 | 2015-09-23 15:21:28 +0000 | [diff] [blame] | 1225 | _remove_option(dotest_argv, "--results-formatter", None, True) |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 1226 | if dotest_options.results_formatter_options is not None: |
Todd Fiala | ea73624 | 2015-09-23 15:21:28 +0000 | [diff] [blame] | 1227 | _remove_option(dotest_argv, "--results-formatter-option", "-O", |
| 1228 | True) |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 1229 | |
Todd Fiala | cee6a6a | 2015-11-09 18:51:04 +0000 | [diff] [blame^] | 1230 | # Remove the --curses shortcut if specified. |
| 1231 | if dotest_options.curses: |
| 1232 | _remove_option(dotest_argv, "--curses", None, False) |
| 1233 | |
Todd Fiala | 33896a9 | 2015-09-18 21:01:13 +0000 | [diff] [blame] | 1234 | # Remove test runner name if present. |
| 1235 | if dotest_options.test_runner_name is not None: |
Todd Fiala | ea73624 | 2015-09-23 15:21:28 +0000 | [diff] [blame] | 1236 | _remove_option(dotest_argv, "--test-runner-name", None, True) |
Todd Fiala | 33896a9 | 2015-09-18 21:01:13 +0000 | [diff] [blame] | 1237 | |
| 1238 | |
Todd Fiala | 83c32e3 | 2015-09-22 21:19:40 +0000 | [diff] [blame] | 1239 | def is_darwin_version_lower_than(target_version): |
| 1240 | """Checks that os is Darwin and version is lower than target_version. |
| 1241 | |
| 1242 | @param target_version the StrictVersion indicating the version |
| 1243 | we're checking against. |
| 1244 | |
| 1245 | @return True if the OS is Darwin (OS X) and the version number of |
| 1246 | the OS is less than target_version; False in all other cases. |
| 1247 | """ |
| 1248 | if platform.system() != 'Darwin': |
| 1249 | # Can't be Darwin lower than a certain version. |
| 1250 | return False |
| 1251 | |
| 1252 | system_version = distutils.version.StrictVersion(platform.mac_ver()[0]) |
Zachary Turner | bac6e4f | 2015-11-03 21:37:27 +0000 | [diff] [blame] | 1253 | return seven.cmp_(system_version, target_version) < 0 |
Todd Fiala | 83c32e3 | 2015-09-22 21:19:40 +0000 | [diff] [blame] | 1254 | |
| 1255 | |
| 1256 | def default_test_runner_name(num_threads): |
| 1257 | """Returns the default test runner name for the configuration. |
| 1258 | |
| 1259 | @param num_threads the number of threads/workers this test runner is |
| 1260 | supposed to use. |
| 1261 | |
| 1262 | @return the test runner name that should be used by default when |
| 1263 | no test runner was explicitly called out on the command line. |
| 1264 | """ |
| 1265 | if num_threads == 1: |
| 1266 | # Use the serial runner. |
| 1267 | test_runner_name = "serial" |
| 1268 | elif os.name == "nt": |
Adrian McCarthy | 040b31d | 2015-10-12 14:46:57 +0000 | [diff] [blame] | 1269 | # On Windows, Python uses CRT with a low limit on the number of open |
| 1270 | # files. If you have a lot of cores, the threading-pool runner will |
Zachary Turner | f0c3f68 | 2015-11-06 18:14:31 +0000 | [diff] [blame] | 1271 | # often fail because it exceeds that limit. It's not clear what the |
| 1272 | # right balance is, so until we can investigate it more deeply, |
| 1273 | # just use the one that works |
| 1274 | test_runner_name = "multiprocessing-pool" |
Todd Fiala | 83c32e3 | 2015-09-22 21:19:40 +0000 | [diff] [blame] | 1275 | elif is_darwin_version_lower_than( |
| 1276 | distutils.version.StrictVersion("10.10.0")): |
| 1277 | # OS X versions before 10.10 appear to have an issue using |
| 1278 | # the threading test runner. Fall back to multiprocessing. |
| 1279 | # Supports Ctrl-C. |
| 1280 | test_runner_name = "multiprocessing" |
| 1281 | else: |
| 1282 | # For everyone else, use the ctrl-c-enabled threading support. |
| 1283 | # Should use fewer system resources than the multprocessing |
| 1284 | # variant. |
| 1285 | test_runner_name = "threading" |
| 1286 | return test_runner_name |
| 1287 | |
| 1288 | |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 1289 | def main(print_details_on_success, num_threads, test_subdir, |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 1290 | test_runner_name, results_formatter): |
Todd Fiala | fed9566 | 2015-09-03 18:58:44 +0000 | [diff] [blame] | 1291 | """Run dotest.py in inferior mode in parallel. |
| 1292 | |
| 1293 | @param print_details_on_success the parsed value of the output-on-success |
| 1294 | command line argument. When True, details of a successful dotest inferior |
| 1295 | are printed even when everything succeeds. The normal behavior is to |
| 1296 | not print any details when all the inferior tests pass. |
| 1297 | |
| 1298 | @param num_threads the parsed value of the num-threads command line |
| 1299 | argument. |
| 1300 | |
| 1301 | @param test_subdir optionally specifies a subdir to limit testing |
| 1302 | within. May be None if the entire test tree is to be used. This subdir |
| 1303 | is assumed to be relative to the lldb/test root of the test hierarchy. |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 1304 | |
| 1305 | @param test_runner_name if specified, contains the test runner |
| 1306 | name which selects the strategy used to run the isolated and |
| 1307 | optionally concurrent test runner. Specify None to allow the |
| 1308 | system to choose the most appropriate test runner given desired |
| 1309 | thread count and OS type. |
| 1310 | |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 1311 | @param results_formatter if specified, provides the TestResultsFormatter |
| 1312 | instance that will format and output test result data from the |
| 1313 | side-channel test results. When specified, inferior dotest calls |
| 1314 | will send test results side-channel data over a socket to the parallel |
| 1315 | test runner, which will forward them on to results_formatter. |
Todd Fiala | fed9566 | 2015-09-03 18:58:44 +0000 | [diff] [blame] | 1316 | """ |
| 1317 | |
Todd Fiala | 1cc97b4 | 2015-09-21 05:42:26 +0000 | [diff] [blame] | 1318 | # Do not shut down on sighup. |
Ying Chen | d93aa10 | 2015-09-23 21:53:18 +0000 | [diff] [blame] | 1319 | if hasattr(signal, 'SIGHUP'): |
| 1320 | signal.signal(signal.SIGHUP, signal.SIG_IGN) |
Todd Fiala | 1cc97b4 | 2015-09-21 05:42:26 +0000 | [diff] [blame] | 1321 | |
Todd Fiala | fed9566 | 2015-09-03 18:58:44 +0000 | [diff] [blame] | 1322 | dotest_argv = sys.argv[1:] |
| 1323 | |
Greg Clayton | b0d148e | 2015-09-21 17:25:01 +0000 | [diff] [blame] | 1324 | global output_on_success, RESULTS_FORMATTER |
Todd Fiala | fed9566 | 2015-09-03 18:58:44 +0000 | [diff] [blame] | 1325 | output_on_success = print_details_on_success |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 1326 | RESULTS_FORMATTER = results_formatter |
Todd Fiala | fed9566 | 2015-09-03 18:58:44 +0000 | [diff] [blame] | 1327 | |
Vince Harron | d5fa102 | 2015-05-10 15:24:12 +0000 | [diff] [blame] | 1328 | # We can't use sys.path[0] to determine the script directory |
| 1329 | # because it doesn't work under a debugger |
Vince Harron | 8994fed | 2015-05-22 19:49:23 +0000 | [diff] [blame] | 1330 | parser = dotest_args.create_parser() |
Pavel Labath | 05ab237 | 2015-07-06 15:57:52 +0000 | [diff] [blame] | 1331 | global dotest_options |
Vince Harron | 8994fed | 2015-05-22 19:49:23 +0000 | [diff] [blame] | 1332 | dotest_options = dotest_args.parse_args(parser, dotest_argv) |
| 1333 | |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 1334 | adjust_inferior_options(dotest_argv) |
Vince Harron | 0b9dbb5 | 2015-05-21 18:18:52 +0000 | [diff] [blame] | 1335 | |
| 1336 | session_dir = os.path.join(os.getcwd(), dotest_options.s) |
Ed Maste | cec2a5b | 2014-11-21 02:41:25 +0000 | [diff] [blame] | 1337 | |
Vince Harron | e06a7a8 | 2015-05-12 23:12:19 +0000 | [diff] [blame] | 1338 | # The root directory was specified on the command line |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 1339 | test_directory = os.path.dirname(os.path.realpath(__file__)) |
Todd Fiala | fed9566 | 2015-09-03 18:58:44 +0000 | [diff] [blame] | 1340 | if test_subdir and len(test_subdir) > 0: |
| 1341 | test_subdir = os.path.join(test_directory, test_subdir) |
Vince Harron | e06a7a8 | 2015-05-12 23:12:19 +0000 | [diff] [blame] | 1342 | else: |
Todd Fiala | fed9566 | 2015-09-03 18:58:44 +0000 | [diff] [blame] | 1343 | test_subdir = test_directory |
Vince Harron | e06a7a8 | 2015-05-12 23:12:19 +0000 | [diff] [blame] | 1344 | |
Vince Harron | dcc2b9f | 2015-05-27 04:40:36 +0000 | [diff] [blame] | 1345 | # clean core files in test tree from previous runs (Linux) |
| 1346 | cores = find('core.*', test_subdir) |
| 1347 | for core in cores: |
| 1348 | os.unlink(core) |
| 1349 | |
Daniel Malea | b42556f | 2013-04-19 18:32:53 +0000 | [diff] [blame] | 1350 | system_info = " ".join(platform.uname()) |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 1351 | |
| 1352 | # Figure out which testrunner strategy we'll use. |
| 1353 | runner_strategies_by_name = get_test_runner_strategies(num_threads) |
| 1354 | |
| 1355 | # If the user didn't specify a test runner strategy, determine |
| 1356 | # the default now based on number of threads and OS type. |
| 1357 | if not test_runner_name: |
Todd Fiala | 83c32e3 | 2015-09-22 21:19:40 +0000 | [diff] [blame] | 1358 | test_runner_name = default_test_runner_name(num_threads) |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 1359 | |
| 1360 | if test_runner_name not in runner_strategies_by_name: |
Todd Fiala | 83c32e3 | 2015-09-22 21:19:40 +0000 | [diff] [blame] | 1361 | raise Exception( |
| 1362 | "specified testrunner name '{}' unknown. Valid choices: {}".format( |
| 1363 | test_runner_name, |
Zachary Turner | 606e1e3 | 2015-10-23 17:53:51 +0000 | [diff] [blame] | 1364 | list(runner_strategies_by_name.keys()))) |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 1365 | test_runner_func = runner_strategies_by_name[test_runner_name] |
| 1366 | |
| 1367 | summary_results = walk_and_invoke( |
Todd Fiala | 871b2e5 | 2015-09-22 22:47:34 +0000 | [diff] [blame] | 1368 | test_directory, test_subdir, dotest_argv, |
| 1369 | num_threads, test_runner_func) |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 1370 | |
| 1371 | (timed_out, passed, failed, unexpected_successes, pass_count, |
| 1372 | fail_count) = summary_results |
Zachary Turner | c7a7c8a | 2015-05-28 19:56:26 +0000 | [diff] [blame] | 1373 | |
Todd Fiala | de9a44e | 2015-09-22 00:15:50 +0000 | [diff] [blame] | 1374 | # The results formatter - if present - is done now. Tell it to |
| 1375 | # terminate. |
| 1376 | if results_formatter is not None: |
| 1377 | results_formatter.send_terminate_as_needed() |
| 1378 | |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 1379 | timed_out = set(timed_out) |
Chaoren Lin | e80372a | 2015-08-12 18:02:53 +0000 | [diff] [blame] | 1380 | num_test_files = len(passed) + len(failed) |
| 1381 | num_test_cases = pass_count + fail_count |
Daniel Malea | b42556f | 2013-04-19 18:32:53 +0000 | [diff] [blame] | 1382 | |
Vince Harron | dcc2b9f | 2015-05-27 04:40:36 +0000 | [diff] [blame] | 1383 | # move core files into session dir |
| 1384 | cores = find('core.*', test_subdir) |
| 1385 | for core in cores: |
| 1386 | dst = core.replace(test_directory, "")[1:] |
| 1387 | dst = dst.replace(os.path.sep, "-") |
| 1388 | os.rename(core, os.path.join(session_dir, dst)) |
| 1389 | |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 1390 | # remove expected timeouts from failures |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 1391 | expected_timeout = getExpectedTimeouts(dotest_options.lldb_platform_name) |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 1392 | for xtime in expected_timeout: |
| 1393 | if xtime in timed_out: |
| 1394 | timed_out.remove(xtime) |
| 1395 | failed.remove(xtime) |
Vince Harron | 0b9dbb5 | 2015-05-21 18:18:52 +0000 | [diff] [blame] | 1396 | result = "ExpectedTimeout" |
| 1397 | elif xtime in passed: |
| 1398 | result = "UnexpectedCompletion" |
| 1399 | else: |
| 1400 | result = None # failed |
| 1401 | |
| 1402 | if result: |
| 1403 | test_name = os.path.splitext(xtime)[0] |
| 1404 | touch(os.path.join(session_dir, "{}-{}".format(result, test_name))) |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 1405 | |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 1406 | print() |
Chaoren Lin | 5a59e46 | 2015-08-12 18:02:51 +0000 | [diff] [blame] | 1407 | sys.stdout.write("Ran %d test suites" % num_test_files) |
| 1408 | if num_test_files > 0: |
| 1409 | sys.stdout.write(" (%d failed) (%f%%)" % ( |
| 1410 | len(failed), 100.0 * len(failed) / num_test_files)) |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 1411 | print() |
Chaoren Lin | e80372a | 2015-08-12 18:02:53 +0000 | [diff] [blame] | 1412 | sys.stdout.write("Ran %d test cases" % num_test_cases) |
| 1413 | if num_test_cases > 0: |
Chaoren Lin | 5a59e46 | 2015-08-12 18:02:51 +0000 | [diff] [blame] | 1414 | sys.stdout.write(" (%d failed) (%f%%)" % ( |
Chaoren Lin | e80372a | 2015-08-12 18:02:53 +0000 | [diff] [blame] | 1415 | fail_count, 100.0 * fail_count / num_test_cases)) |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 1416 | print() |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 1417 | exit_code = 0 |
| 1418 | |
Daniel Malea | cbaef26 | 2013-02-15 21:31:37 +0000 | [diff] [blame] | 1419 | if len(failed) > 0: |
Shawn Best | 13491c4 | 2014-10-22 19:29:00 +0000 | [diff] [blame] | 1420 | failed.sort() |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 1421 | print("Failing Tests (%d)" % len(failed)) |
Daniel Malea | cbaef26 | 2013-02-15 21:31:37 +0000 | [diff] [blame] | 1422 | for f in failed: |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 1423 | print("%s: LLDB (suite) :: %s (%s)" % ( |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 1424 | "TIMEOUT" if f in timed_out else "FAIL", f, system_info |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 1425 | )) |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 1426 | exit_code = 1 |
| 1427 | |
| 1428 | if len(unexpected_successes) > 0: |
| 1429 | unexpected_successes.sort() |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 1430 | print("\nUnexpected Successes (%d)" % len(unexpected_successes)) |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 1431 | for u in unexpected_successes: |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 1432 | print("UNEXPECTED SUCCESS: LLDB (suite) :: %s (%s)" % (u, system_info)) |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 1433 | |
| 1434 | sys.exit(exit_code) |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 1435 | |
| 1436 | if __name__ == '__main__': |
Todd Fiala | fed9566 | 2015-09-03 18:58:44 +0000 | [diff] [blame] | 1437 | sys.stderr.write( |
| 1438 | "error: dosep.py no longer supports being called directly. " |
| 1439 | "Please call dotest.py directly. The dosep.py-specific arguments " |
| 1440 | "have been added under the Parallel processing arguments.\n") |
| 1441 | sys.exit(128) |