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