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