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 | |
Greg Clayton | 2256d0d | 2014-03-24 23:01:57 +0000 | [diff] [blame] | 35 | import multiprocessing |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 36 | import os |
Vince Harron | dcc2b9f | 2015-05-27 04:40:36 +0000 | [diff] [blame] | 37 | import fnmatch |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 38 | import platform |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 39 | import re |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 40 | import dotest_args |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 41 | import shlex |
| 42 | import subprocess |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 43 | import sys |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 44 | |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 45 | from optparse import OptionParser |
| 46 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 47 | |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 48 | def get_timeout_command(): |
Vince Harron | ede5965 | 2015-01-08 02:11:26 +0000 | [diff] [blame] | 49 | """Search for a suitable timeout command.""" |
Ying Chen | 93190c4 | 2015-07-20 20:04:22 +0000 | [diff] [blame] | 50 | if not sys.platform.startswith("win32"): |
| 51 | try: |
| 52 | subprocess.call("timeout", stderr=subprocess.PIPE) |
| 53 | return "timeout" |
| 54 | except OSError: |
| 55 | pass |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 56 | try: |
Chaoren Lin | 45c17ff | 2015-05-28 23:00:10 +0000 | [diff] [blame] | 57 | subprocess.call("gtimeout", stderr=subprocess.PIPE) |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 58 | return "gtimeout" |
| 59 | except OSError: |
| 60 | pass |
| 61 | return None |
| 62 | |
| 63 | timeout_command = get_timeout_command() |
| 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 |
Chaoren Lin | 5e3ab2b | 2015-06-01 17:49:25 +0000 | [diff] [blame] | 74 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 75 | |
Chaoren Lin | ffc63b0 | 2015-08-12 18:02:49 +0000 | [diff] [blame] | 76 | def setup_global_variables(lock, counter, total, name_len, options): |
| 77 | global output_lock, test_counter, total_tests, test_name_len |
| 78 | global dotest_options |
Chaoren Lin | 5e3ab2b | 2015-06-01 17:49:25 +0000 | [diff] [blame] | 79 | output_lock = lock |
| 80 | test_counter = counter |
| 81 | total_tests = total |
Chaoren Lin | ffc63b0 | 2015-08-12 18:02:49 +0000 | [diff] [blame] | 82 | test_name_len = name_len |
Pavel Labath | 05ab237 | 2015-07-06 15:57:52 +0000 | [diff] [blame] | 83 | dotest_options = options |
Chaoren Lin | 5e3ab2b | 2015-06-01 17:49:25 +0000 | [diff] [blame] | 84 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 85 | |
Zachary Turner | 38e6417 | 2015-08-10 17:46:11 +0000 | [diff] [blame] | 86 | def report_test_failure(name, command, output): |
| 87 | global output_lock |
| 88 | with output_lock: |
Chaoren Lin | ffc63b0 | 2015-08-12 18:02:49 +0000 | [diff] [blame] | 89 | print >> sys.stderr |
Zachary Turner | 38e6417 | 2015-08-10 17:46:11 +0000 | [diff] [blame] | 90 | print >> sys.stderr, output |
Chaoren Lin | ffc63b0 | 2015-08-12 18:02:49 +0000 | [diff] [blame] | 91 | print >> sys.stderr, "[%s FAILED]" % name |
Zachary Turner | 38e6417 | 2015-08-10 17:46:11 +0000 | [diff] [blame] | 92 | print >> sys.stderr, "Command invoked: %s" % ' '.join(command) |
Chaoren Lin | ffc63b0 | 2015-08-12 18:02:49 +0000 | [diff] [blame] | 93 | update_progress(name) |
Zachary Turner | 38e6417 | 2015-08-10 17:46:11 +0000 | [diff] [blame] | 94 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 95 | |
Zachary Turner | 38e6417 | 2015-08-10 17:46:11 +0000 | [diff] [blame] | 96 | def report_test_pass(name, output): |
| 97 | global output_lock, output_on_success |
| 98 | with output_lock: |
| 99 | if output_on_success: |
Chaoren Lin | ffc63b0 | 2015-08-12 18:02:49 +0000 | [diff] [blame] | 100 | print >> sys.stderr |
Zachary Turner | 38e6417 | 2015-08-10 17:46:11 +0000 | [diff] [blame] | 101 | print >> sys.stderr, output |
Chaoren Lin | ffc63b0 | 2015-08-12 18:02:49 +0000 | [diff] [blame] | 102 | print >> sys.stderr, "[%s PASSED]" % name |
| 103 | update_progress(name) |
Zachary Turner | 38e6417 | 2015-08-10 17:46:11 +0000 | [diff] [blame] | 104 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 105 | |
Chaoren Lin | ffc63b0 | 2015-08-12 18:02:49 +0000 | [diff] [blame] | 106 | def update_progress(test_name=""): |
| 107 | global output_lock, test_counter, total_tests, test_name_len |
Chaoren Lin | 5e3ab2b | 2015-06-01 17:49:25 +0000 | [diff] [blame] | 108 | with output_lock: |
Chaoren Lin | ffc63b0 | 2015-08-12 18:02:49 +0000 | [diff] [blame] | 109 | counter_len = len(str(total_tests)) |
| 110 | sys.stderr.write( |
| 111 | "\r%*d out of %d test suites processed - %-*s" % |
| 112 | (counter_len, test_counter.value, total_tests, |
| 113 | test_name_len.value, test_name)) |
| 114 | if len(test_name) > test_name_len.value: |
| 115 | test_name_len.value = len(test_name) |
Chaoren Lin | 5e3ab2b | 2015-06-01 17:49:25 +0000 | [diff] [blame] | 116 | test_counter.value += 1 |
Zachary Turner | 38e6417 | 2015-08-10 17:46:11 +0000 | [diff] [blame] | 117 | sys.stdout.flush() |
| 118 | sys.stderr.flush() |
Chaoren Lin | 5e3ab2b | 2015-06-01 17:49:25 +0000 | [diff] [blame] | 119 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 120 | |
Zachary Turner | c7a7c8a | 2015-05-28 19:56:26 +0000 | [diff] [blame] | 121 | def parse_test_results(output): |
| 122 | passes = 0 |
| 123 | failures = 0 |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 124 | unexpected_successes = 0 |
Zachary Turner | c7a7c8a | 2015-05-28 19:56:26 +0000 | [diff] [blame] | 125 | for result in output: |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 126 | pass_count = re.search("^RESULT:.*([0-9]+) passes", |
| 127 | result, re.MULTILINE) |
| 128 | fail_count = re.search("^RESULT:.*([0-9]+) failures", |
| 129 | result, re.MULTILINE) |
| 130 | error_count = re.search("^RESULT:.*([0-9]+) errors", |
| 131 | result, re.MULTILINE) |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 132 | unexpected_success_count = re.search("^RESULT:.*([0-9]+) unexpected successes", |
| 133 | result, re.MULTILINE) |
Zachary Turner | c7a7c8a | 2015-05-28 19:56:26 +0000 | [diff] [blame] | 134 | this_fail_count = 0 |
| 135 | this_error_count = 0 |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 136 | if pass_count is not None: |
Zachary Turner | c7a7c8a | 2015-05-28 19:56:26 +0000 | [diff] [blame] | 137 | passes = passes + int(pass_count.group(1)) |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 138 | if fail_count is not None: |
Zachary Turner | c7a7c8a | 2015-05-28 19:56:26 +0000 | [diff] [blame] | 139 | failures = failures + int(fail_count.group(1)) |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 140 | if unexpected_success_count is not None: |
| 141 | unexpected_successes = unexpected_successes + int(unexpected_success_count.group(1)) |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 142 | if error_count is not None: |
Zachary Turner | c7a7c8a | 2015-05-28 19:56:26 +0000 | [diff] [blame] | 143 | failures = failures + int(error_count.group(1)) |
| 144 | pass |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 145 | return passes, failures, unexpected_successes |
Zachary Turner | c7a7c8a | 2015-05-28 19:56:26 +0000 | [diff] [blame] | 146 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 147 | |
Chaoren Lin | 5e3ab2b | 2015-06-01 17:49:25 +0000 | [diff] [blame] | 148 | def call_with_timeout(command, timeout, name): |
Vince Harron | ede5965 | 2015-01-08 02:11:26 +0000 | [diff] [blame] | 149 | """Run command with a timeout if possible.""" |
Vince Harron | dcc2b9f | 2015-05-27 04:40:36 +0000 | [diff] [blame] | 150 | """-s QUIT will create a coredump if they are enabled on your system""" |
Zachary Turner | c7a7c8a | 2015-05-28 19:56:26 +0000 | [diff] [blame] | 151 | process = None |
| 152 | if timeout_command and timeout != "0": |
| 153 | command = [timeout_command, '-s', 'QUIT', timeout] + command |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 154 | # Specifying a value for close_fds is unsupported on Windows when using |
| 155 | # subprocess.PIPE |
Zachary Turner | dc494d5 | 2015-02-07 00:14:55 +0000 | [diff] [blame] | 156 | if os.name != "nt": |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 157 | process = subprocess.Popen(command, |
| 158 | stdin=subprocess.PIPE, |
| 159 | stdout=subprocess.PIPE, |
| 160 | stderr=subprocess.PIPE, |
| 161 | close_fds=True) |
Zachary Turner | dc494d5 | 2015-02-07 00:14:55 +0000 | [diff] [blame] | 162 | else: |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 163 | process = subprocess.Popen(command, |
| 164 | stdin=subprocess.PIPE, |
| 165 | stdout=subprocess.PIPE, |
| 166 | stderr=subprocess.PIPE) |
Zachary Turner | c7a7c8a | 2015-05-28 19:56:26 +0000 | [diff] [blame] | 167 | output = process.communicate() |
| 168 | exit_status = process.returncode |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 169 | passes, failures, unexpected_successes = parse_test_results(output) |
Zachary Turner | 38e6417 | 2015-08-10 17:46:11 +0000 | [diff] [blame] | 170 | if exit_status == 0: |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 171 | # stdout does not have any useful information from 'dotest.py', |
| 172 | # only stderr does. |
Zachary Turner | 38e6417 | 2015-08-10 17:46:11 +0000 | [diff] [blame] | 173 | report_test_pass(name, output[1]) |
| 174 | else: |
| 175 | report_test_failure(name, command, output[1]) |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 176 | return name, exit_status, passes, failures, unexpected_successes |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 177 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 178 | |
Vince Harron | 41657cc | 2015-05-21 18:15:09 +0000 | [diff] [blame] | 179 | def process_dir(root, files, test_root, dotest_argv): |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 180 | """Examine a directory for tests, and invoke any found within it.""" |
Chaoren Lin | e80372a | 2015-08-12 18:02:53 +0000 | [diff] [blame] | 181 | results = [] |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 182 | for name in files: |
Zachary Turner | f6896b0 | 2015-01-05 19:37:03 +0000 | [diff] [blame] | 183 | script_file = os.path.join(test_root, "dotest.py") |
Zachary Turner | f6896b0 | 2015-01-05 19:37:03 +0000 | [diff] [blame] | 184 | command = ([sys.executable, script_file] + |
Vince Harron | 41657cc | 2015-05-21 18:15:09 +0000 | [diff] [blame] | 185 | dotest_argv + |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 186 | ["-p", name, root]) |
| 187 | |
| 188 | timeout_name = os.path.basename(os.path.splitext(name)[0]).upper() |
| 189 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 190 | timeout = (os.getenv("LLDB_%s_TIMEOUT" % timeout_name) or |
| 191 | getDefaultTimeout(dotest_options.lldb_platform_name)) |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 192 | |
Chaoren Lin | e80372a | 2015-08-12 18:02:53 +0000 | [diff] [blame] | 193 | results.append(call_with_timeout(command, timeout, name)) |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 194 | |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 195 | # result = (name, status, passes, failures, unexpected_successes) |
| 196 | timed_out = [name for name, status, _, _, _ in results |
Chaoren Lin | e80372a | 2015-08-12 18:02:53 +0000 | [diff] [blame] | 197 | if status == eTimedOut] |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 198 | passed = [name for name, status, _, _, _ in results |
Chaoren Lin | e80372a | 2015-08-12 18:02:53 +0000 | [diff] [blame] | 199 | if status == ePassed] |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 200 | failed = [name for name, status, _, _, _ in results |
Chaoren Lin | e80372a | 2015-08-12 18:02:53 +0000 | [diff] [blame] | 201 | if status != ePassed] |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 202 | unexpected_passes = [name for name, _, _, _, unexpected_successes in results |
| 203 | if unexpected_successes > 0] |
| 204 | |
Chaoren Lin | e80372a | 2015-08-12 18:02:53 +0000 | [diff] [blame] | 205 | pass_count = sum([result[2] for result in results]) |
| 206 | fail_count = sum([result[3] for result in results]) |
Zachary Turner | c7a7c8a | 2015-05-28 19:56:26 +0000 | [diff] [blame] | 207 | |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 208 | return (timed_out, passed, failed, unexpected_passes, pass_count, fail_count) |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 209 | |
| 210 | in_q = None |
| 211 | out_q = None |
| 212 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 213 | |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 214 | def process_dir_worker(arg_tuple): |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 215 | """Worker thread main loop when in multithreaded mode. |
| 216 | Takes one directory specification at a time and works on it.""" |
Chaoren Lin | e80372a | 2015-08-12 18:02:53 +0000 | [diff] [blame] | 217 | return process_dir(*arg_tuple) |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 218 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 219 | |
Vince Harron | 41657cc | 2015-05-21 18:15:09 +0000 | [diff] [blame] | 220 | def walk_and_invoke(test_directory, test_subdir, dotest_argv, num_threads): |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 221 | """Look for matched files and invoke test driver on each one. |
| 222 | In single-threaded mode, each test driver is invoked directly. |
| 223 | In multi-threaded mode, submit each test driver to a worker |
Vince Harron | e06a7a8 | 2015-05-12 23:12:19 +0000 | [diff] [blame] | 224 | queue, and then wait for all to complete. |
| 225 | |
| 226 | test_directory - lldb/test/ directory |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 227 | test_subdir - lldb/test/ or a subfolder with the tests we're interested in |
| 228 | running |
Vince Harron | e06a7a8 | 2015-05-12 23:12:19 +0000 | [diff] [blame] | 229 | """ |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 230 | |
| 231 | # Collect the test files that we'll run. |
| 232 | test_work_items = [] |
Vince Harron | e06a7a8 | 2015-05-12 23:12:19 +0000 | [diff] [blame] | 233 | for root, dirs, files in os.walk(test_subdir, topdown=False): |
Chaoren Lin | ffc63b0 | 2015-08-12 18:02:49 +0000 | [diff] [blame] | 234 | def is_test(name): |
| 235 | # Not interested in symbolically linked files. |
| 236 | if os.path.islink(os.path.join(root, name)): |
| 237 | return False |
| 238 | # Only interested in test files with the "Test*.py" naming pattern. |
| 239 | return name.startswith("Test") and name.endswith(".py") |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 240 | |
Chaoren Lin | ffc63b0 | 2015-08-12 18:02:49 +0000 | [diff] [blame] | 241 | tests = filter(is_test, files) |
| 242 | test_work_items.append((root, tests, test_directory, dotest_argv)) |
| 243 | |
| 244 | global output_lock, test_counter, total_tests, test_name_len |
Zachary Turner | 38e6417 | 2015-08-10 17:46:11 +0000 | [diff] [blame] | 245 | output_lock = multiprocessing.RLock() |
Chaoren Lin | ffc63b0 | 2015-08-12 18:02:49 +0000 | [diff] [blame] | 246 | # item = (root, tests, test_directory, dotest_argv) |
| 247 | total_tests = sum([len(item[1]) for item in test_work_items]) |
Chaoren Lin | 5e3ab2b | 2015-06-01 17:49:25 +0000 | [diff] [blame] | 248 | test_counter = multiprocessing.Value('i', 0) |
Chaoren Lin | ffc63b0 | 2015-08-12 18:02:49 +0000 | [diff] [blame] | 249 | test_name_len = multiprocessing.Value('i', 0) |
| 250 | print >> sys.stderr, "Testing: %d test suites, %d thread%s" % ( |
| 251 | total_tests, num_threads, (num_threads > 1) * "s") |
| 252 | update_progress() |
Chaoren Lin | 5e3ab2b | 2015-06-01 17:49:25 +0000 | [diff] [blame] | 253 | |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 254 | # Run the items, either in a pool (for multicore speedup) or |
| 255 | # calling each individually. |
| 256 | if num_threads > 1: |
Chaoren Lin | ffc63b0 | 2015-08-12 18:02:49 +0000 | [diff] [blame] | 257 | pool = multiprocessing.Pool( |
| 258 | num_threads, |
| 259 | initializer=setup_global_variables, |
| 260 | initargs=(output_lock, test_counter, total_tests, test_name_len, |
| 261 | dotest_options)) |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 262 | test_results = pool.map(process_dir_worker, test_work_items) |
| 263 | else: |
Chaoren Lin | e80372a | 2015-08-12 18:02:53 +0000 | [diff] [blame] | 264 | test_results = map(process_dir_worker, test_work_items) |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 265 | |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 266 | # result = (timed_out, failed, passed, unexpected_successes, fail_count, pass_count) |
Chaoren Lin | e80372a | 2015-08-12 18:02:53 +0000 | [diff] [blame] | 267 | timed_out = sum([result[0] for result in test_results], []) |
| 268 | passed = sum([result[1] for result in test_results], []) |
| 269 | failed = sum([result[2] for result in test_results], []) |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 270 | unexpected_successes = sum([result[3] for result in test_results], []) |
| 271 | pass_count = sum([result[4] for result in test_results]) |
| 272 | fail_count = sum([result[5] for result in test_results]) |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 273 | |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 274 | return (timed_out, passed, failed, unexpected_successes, pass_count, fail_count) |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 275 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 276 | |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 277 | def getExpectedTimeouts(platform_name): |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 278 | # returns a set of test filenames that might timeout |
| 279 | # are we running against a remote target? |
Chaoren Lin | febef1b | 2015-08-19 17:22:12 +0000 | [diff] [blame] | 280 | host = sys.platform |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 281 | if platform_name is None: |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 282 | target = sys.platform |
| 283 | remote = False |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 284 | else: |
| 285 | m = re.search('remote-(\w+)', platform_name) |
| 286 | target = m.group(1) |
| 287 | remote = True |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 288 | |
| 289 | expected_timeout = set() |
| 290 | |
| 291 | if target.startswith("linux"): |
| 292 | expected_timeout |= { |
Vince Harron | de92b52 | 2015-05-13 23:59:03 +0000 | [diff] [blame] | 293 | "TestAttachDenied.py", |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 294 | "TestAttachResume.py", |
Chaoren Lin | 0b8bb3d | 2015-07-22 20:52:17 +0000 | [diff] [blame] | 295 | "TestProcessAttach.py", |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 296 | "TestConnectRemote.py", |
| 297 | "TestCreateAfterAttach.py", |
Tamas Berghammer | 0d0ec9f | 2015-05-19 10:49:40 +0000 | [diff] [blame] | 298 | "TestEvents.py", |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 299 | "TestExitDuringStep.py", |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 300 | |
| 301 | # Times out in ~10% of the times on the build bot |
| 302 | "TestHelloWorld.py", |
Oleksiy Vyalov | 18f4c9f | 2015-06-10 01:34:25 +0000 | [diff] [blame] | 303 | "TestMultithreaded.py", |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 304 | "TestRegisters.py", # ~12/600 dosep runs (build 3120-3122) |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 305 | "TestThreadStepOut.py", |
Chaoren Lin | b013802 | 2015-08-19 18:39:25 +0000 | [diff] [blame] | 306 | "TestChangeProcessGroup.py", |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 307 | } |
| 308 | elif target.startswith("android"): |
| 309 | expected_timeout |= { |
| 310 | "TestExitDuringStep.py", |
| 311 | "TestHelloWorld.py", |
| 312 | } |
Chaoren Lin | febef1b | 2015-08-19 17:22:12 +0000 | [diff] [blame] | 313 | if host.startswith("win32"): |
| 314 | expected_timeout |= { |
| 315 | "TestEvents.py", |
| 316 | "TestThreadStates.py", |
| 317 | } |
Ed Maste | 4dd8fba | 2015-05-14 16:25:52 +0000 | [diff] [blame] | 318 | elif target.startswith("freebsd"): |
| 319 | expected_timeout |= { |
| 320 | "TestBreakpointConditions.py", |
Ed Maste | 0894813 | 2015-05-28 18:45:30 +0000 | [diff] [blame] | 321 | "TestChangeProcessGroup.py", |
Ed Maste | bfd0563 | 2015-05-27 19:11:29 +0000 | [diff] [blame] | 322 | "TestValueObjectRecursion.py", |
Ed Maste | 4dd8fba | 2015-05-14 16:25:52 +0000 | [diff] [blame] | 323 | "TestWatchpointConditionAPI.py", |
| 324 | } |
Vince Harron | 0f173ac | 2015-05-18 19:36:33 +0000 | [diff] [blame] | 325 | elif target.startswith("darwin"): |
| 326 | expected_timeout |= { |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 327 | # times out on MBP Retina, Mid 2012 |
| 328 | "TestThreadSpecificBreakpoint.py", |
Chaoren Lin | d904371 | 2015-08-19 17:13:02 +0000 | [diff] [blame] | 329 | "TestExitDuringStep.py", |
Chaoren Lin | 99f25be | 2015-08-20 01:26:57 +0000 | [diff] [blame^] | 330 | "TestIntegerTypesExpr.py", |
Vince Harron | 0f173ac | 2015-05-18 19:36:33 +0000 | [diff] [blame] | 331 | } |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 332 | return expected_timeout |
| 333 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 334 | |
Pavel Labath | fad30cf | 2015-06-29 14:16:51 +0000 | [diff] [blame] | 335 | def getDefaultTimeout(platform_name): |
| 336 | if os.getenv("LLDB_TEST_TIMEOUT"): |
| 337 | return os.getenv("LLDB_TEST_TIMEOUT") |
| 338 | |
| 339 | if platform_name is None: |
| 340 | platform_name = sys.platform |
| 341 | |
| 342 | if platform_name.startswith("remote-"): |
| 343 | return "10m" |
| 344 | else: |
| 345 | return "4m" |
| 346 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 347 | |
Vince Harron | 0b9dbb5 | 2015-05-21 18:18:52 +0000 | [diff] [blame] | 348 | def touch(fname, times=None): |
Greg Clayton | 8c3f9c9 | 2015-08-11 21:01:32 +0000 | [diff] [blame] | 349 | if os.path.exists(fname): |
Vince Harron | 0b9dbb5 | 2015-05-21 18:18:52 +0000 | [diff] [blame] | 350 | os.utime(fname, times) |
| 351 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 352 | |
Vince Harron | dcc2b9f | 2015-05-27 04:40:36 +0000 | [diff] [blame] | 353 | def find(pattern, path): |
| 354 | result = [] |
| 355 | for root, dirs, files in os.walk(path): |
| 356 | for name in files: |
| 357 | if fnmatch.fnmatch(name, pattern): |
| 358 | result.append(os.path.join(root, name)) |
| 359 | return result |
| 360 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 361 | |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 362 | def main(): |
Vince Harron | d5fa102 | 2015-05-10 15:24:12 +0000 | [diff] [blame] | 363 | # We can't use sys.path[0] to determine the script directory |
| 364 | # because it doesn't work under a debugger |
Vince Harron | e06a7a8 | 2015-05-12 23:12:19 +0000 | [diff] [blame] | 365 | test_directory = os.path.dirname(os.path.realpath(__file__)) |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 366 | parser = OptionParser(usage="""\ |
| 367 | Run lldb test suite using a separate process for each test file. |
Vince Harron | ede5965 | 2015-01-08 02:11:26 +0000 | [diff] [blame] | 368 | |
Siva Chandra | 2d7832e | 2015-05-08 23:08:53 +0000 | [diff] [blame] | 369 | 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] | 370 | |
Siva Chandra | 2d7832e | 2015-05-08 23:08:53 +0000 | [diff] [blame] | 371 | Override the default time limit of 10 minutes by setting |
Vince Harron | ede5965 | 2015-01-08 02:11:26 +0000 | [diff] [blame] | 372 | the environment variable LLDB_TEST_TIMEOUT. |
| 373 | |
| 374 | E.g., export LLDB_TEST_TIMEOUT=10m |
| 375 | |
| 376 | Override the time limit for individual tests by setting |
| 377 | the environment variable LLDB_[TEST NAME]_TIMEOUT. |
| 378 | |
| 379 | E.g., export LLDB_TESTCONCURRENTEVENTS_TIMEOUT=2m |
| 380 | |
| 381 | Set to "0" to run without time limit. |
| 382 | |
| 383 | E.g., export LLDB_TEST_TIMEOUT=0 |
| 384 | or export LLDB_TESTCONCURRENTEVENTS_TIMEOUT=0 |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 385 | """) |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 386 | parser.add_option( |
| 387 | '-o', '--options', |
| 388 | type='string', action='store', |
| 389 | dest='dotest_options', |
| 390 | help="""The options passed to 'dotest.py' if specified.""") |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 391 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 392 | parser.add_option( |
| 393 | '-s', '--output-on-success', |
| 394 | action='store_true', |
| 395 | dest='output_on_success', |
| 396 | default=False, |
| 397 | help="""Print full output of 'dotest.py' even when it succeeds.""") |
Zachary Turner | 38e6417 | 2015-08-10 17:46:11 +0000 | [diff] [blame] | 398 | |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 399 | parser.add_option( |
| 400 | '-t', '--threads', |
| 401 | type='int', |
| 402 | dest='num_threads', |
| 403 | help="""The number of threads to use when running tests separately.""") |
Greg Clayton | 2256d0d | 2014-03-24 23:01:57 +0000 | [diff] [blame] | 404 | |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 405 | opts, args = parser.parse_args() |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 406 | dotest_option_string = opts.dotest_options |
| 407 | |
Vince Harron | 41657cc | 2015-05-21 18:15:09 +0000 | [diff] [blame] | 408 | is_posix = (os.name == "posix") |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 409 | dotest_argv = (shlex.split(dotest_option_string, posix=is_posix) |
| 410 | if dotest_option_string |
| 411 | else []) |
Vince Harron | 8994fed | 2015-05-22 19:49:23 +0000 | [diff] [blame] | 412 | |
| 413 | parser = dotest_args.create_parser() |
Pavel Labath | 05ab237 | 2015-07-06 15:57:52 +0000 | [diff] [blame] | 414 | global dotest_options |
Zachary Turner | 38e6417 | 2015-08-10 17:46:11 +0000 | [diff] [blame] | 415 | global output_on_success |
| 416 | output_on_success = opts.output_on_success |
Vince Harron | 8994fed | 2015-05-22 19:49:23 +0000 | [diff] [blame] | 417 | dotest_options = dotest_args.parse_args(parser, dotest_argv) |
| 418 | |
Vince Harron | 41657cc | 2015-05-21 18:15:09 +0000 | [diff] [blame] | 419 | if not dotest_options.s: |
| 420 | # no session log directory, we need to add this to prevent |
| 421 | # every dotest invocation from creating its own directory |
| 422 | import datetime |
| 423 | # The windows platforms don't like ':' in the pathname. |
Chaoren Lin | b6325d0 | 2015-08-12 18:02:54 +0000 | [diff] [blame] | 424 | timestamp_started = datetime.datetime.now().strftime("%F-%H_%M_%S") |
Vince Harron | 41657cc | 2015-05-21 18:15:09 +0000 | [diff] [blame] | 425 | dotest_argv.append('-s') |
| 426 | dotest_argv.append(timestamp_started) |
Vince Harron | 0b9dbb5 | 2015-05-21 18:18:52 +0000 | [diff] [blame] | 427 | dotest_options.s = timestamp_started |
| 428 | |
| 429 | session_dir = os.path.join(os.getcwd(), dotest_options.s) |
Ed Maste | cec2a5b | 2014-11-21 02:41:25 +0000 | [diff] [blame] | 430 | |
Vince Harron | e06a7a8 | 2015-05-12 23:12:19 +0000 | [diff] [blame] | 431 | # The root directory was specified on the command line |
| 432 | if len(args) == 0: |
| 433 | test_subdir = test_directory |
| 434 | else: |
| 435 | test_subdir = os.path.join(test_directory, args[0]) |
| 436 | |
Vince Harron | dcc2b9f | 2015-05-27 04:40:36 +0000 | [diff] [blame] | 437 | # clean core files in test tree from previous runs (Linux) |
| 438 | cores = find('core.*', test_subdir) |
| 439 | for core in cores: |
| 440 | os.unlink(core) |
| 441 | |
Ed Maste | cec2a5b | 2014-11-21 02:41:25 +0000 | [diff] [blame] | 442 | if opts.num_threads: |
| 443 | num_threads = opts.num_threads |
| 444 | else: |
Greg Clayton | 2256d0d | 2014-03-24 23:01:57 +0000 | [diff] [blame] | 445 | num_threads_str = os.environ.get("LLDB_TEST_THREADS") |
| 446 | if num_threads_str: |
| 447 | num_threads = int(num_threads_str) |
Greg Clayton | 2256d0d | 2014-03-24 23:01:57 +0000 | [diff] [blame] | 448 | else: |
Ed Maste | cec2a5b | 2014-11-21 02:41:25 +0000 | [diff] [blame] | 449 | num_threads = multiprocessing.cpu_count() |
| 450 | if num_threads < 1: |
| 451 | num_threads = 1 |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 452 | |
Daniel Malea | b42556f | 2013-04-19 18:32:53 +0000 | [diff] [blame] | 453 | system_info = " ".join(platform.uname()) |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 454 | (timed_out, passed, failed, unexpected_successes, pass_count, fail_count) = walk_and_invoke( |
Chaoren Lin | e80372a | 2015-08-12 18:02:53 +0000 | [diff] [blame] | 455 | test_directory, test_subdir, dotest_argv, num_threads) |
Zachary Turner | c7a7c8a | 2015-05-28 19:56:26 +0000 | [diff] [blame] | 456 | |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 457 | timed_out = set(timed_out) |
Chaoren Lin | e80372a | 2015-08-12 18:02:53 +0000 | [diff] [blame] | 458 | num_test_files = len(passed) + len(failed) |
| 459 | num_test_cases = pass_count + fail_count |
Daniel Malea | b42556f | 2013-04-19 18:32:53 +0000 | [diff] [blame] | 460 | |
Vince Harron | dcc2b9f | 2015-05-27 04:40:36 +0000 | [diff] [blame] | 461 | # move core files into session dir |
| 462 | cores = find('core.*', test_subdir) |
| 463 | for core in cores: |
| 464 | dst = core.replace(test_directory, "")[1:] |
| 465 | dst = dst.replace(os.path.sep, "-") |
| 466 | os.rename(core, os.path.join(session_dir, dst)) |
| 467 | |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 468 | # remove expected timeouts from failures |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 469 | expected_timeout = getExpectedTimeouts(dotest_options.lldb_platform_name) |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 470 | for xtime in expected_timeout: |
| 471 | if xtime in timed_out: |
| 472 | timed_out.remove(xtime) |
| 473 | failed.remove(xtime) |
Vince Harron | 0b9dbb5 | 2015-05-21 18:18:52 +0000 | [diff] [blame] | 474 | result = "ExpectedTimeout" |
| 475 | elif xtime in passed: |
| 476 | result = "UnexpectedCompletion" |
| 477 | else: |
| 478 | result = None # failed |
| 479 | |
| 480 | if result: |
| 481 | test_name = os.path.splitext(xtime)[0] |
| 482 | touch(os.path.join(session_dir, "{}-{}".format(result, test_name))) |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 483 | |
Chaoren Lin | 5e3ab2b | 2015-06-01 17:49:25 +0000 | [diff] [blame] | 484 | print |
Chaoren Lin | 5a59e46 | 2015-08-12 18:02:51 +0000 | [diff] [blame] | 485 | sys.stdout.write("Ran %d test suites" % num_test_files) |
| 486 | if num_test_files > 0: |
| 487 | sys.stdout.write(" (%d failed) (%f%%)" % ( |
| 488 | len(failed), 100.0 * len(failed) / num_test_files)) |
| 489 | print |
Chaoren Lin | e80372a | 2015-08-12 18:02:53 +0000 | [diff] [blame] | 490 | sys.stdout.write("Ran %d test cases" % num_test_cases) |
| 491 | if num_test_cases > 0: |
Chaoren Lin | 5a59e46 | 2015-08-12 18:02:51 +0000 | [diff] [blame] | 492 | sys.stdout.write(" (%d failed) (%f%%)" % ( |
Chaoren Lin | e80372a | 2015-08-12 18:02:53 +0000 | [diff] [blame] | 493 | fail_count, 100.0 * fail_count / num_test_cases)) |
Chaoren Lin | 5a59e46 | 2015-08-12 18:02:51 +0000 | [diff] [blame] | 494 | print |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 495 | exit_code = 0 |
| 496 | |
Daniel Malea | cbaef26 | 2013-02-15 21:31:37 +0000 | [diff] [blame] | 497 | if len(failed) > 0: |
Shawn Best | 13491c4 | 2014-10-22 19:29:00 +0000 | [diff] [blame] | 498 | failed.sort() |
Ying Chen | 10ed1a9 | 2015-05-28 23:51:49 +0000 | [diff] [blame] | 499 | print "Failing Tests (%d)" % len(failed) |
Daniel Malea | cbaef26 | 2013-02-15 21:31:37 +0000 | [diff] [blame] | 500 | for f in failed: |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 501 | print "%s: LLDB (suite) :: %s (%s)" % ( |
| 502 | "TIMEOUT" if f in timed_out else "FAIL", f, system_info |
| 503 | ) |
Zachary Turner | 4cceca7 | 2015-08-14 16:45:32 +0000 | [diff] [blame] | 504 | exit_code = 1 |
| 505 | |
| 506 | if len(unexpected_successes) > 0: |
| 507 | unexpected_successes.sort() |
| 508 | print "\nUnexpected Successes (%d)" % len(unexpected_successes) |
| 509 | for u in unexpected_successes: |
| 510 | print "UNEXPECTED SUCCESS: LLDB (suite) :: %s (%s)" % (u, system_info) |
| 511 | |
| 512 | sys.exit(exit_code) |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 513 | |
| 514 | if __name__ == '__main__': |
| 515 | main() |