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