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