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 |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 22 | """ |
| 23 | |
Greg Clayton | 2256d0d | 2014-03-24 23:01:57 +0000 | [diff] [blame] | 24 | import multiprocessing |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 25 | import os |
| 26 | import platform |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 27 | import re |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 28 | import dotest_args |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 29 | import shlex |
| 30 | import subprocess |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 31 | import sys |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 32 | |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 33 | from optparse import OptionParser |
| 34 | |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 35 | def get_timeout_command(): |
Vince Harron | ede5965 | 2015-01-08 02:11:26 +0000 | [diff] [blame] | 36 | """Search for a suitable timeout command.""" |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 37 | if sys.platform.startswith("win32"): |
| 38 | return None |
| 39 | try: |
| 40 | subprocess.call("timeout") |
| 41 | return "timeout" |
| 42 | except OSError: |
| 43 | pass |
| 44 | try: |
| 45 | subprocess.call("gtimeout") |
| 46 | return "gtimeout" |
| 47 | except OSError: |
| 48 | pass |
| 49 | return None |
| 50 | |
| 51 | timeout_command = get_timeout_command() |
| 52 | |
Siva Chandra | 2d7832e | 2015-05-08 23:08:53 +0000 | [diff] [blame] | 53 | default_timeout = os.getenv("LLDB_TEST_TIMEOUT") or "10m" |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 54 | |
| 55 | # Status codes for running command with timeout. |
| 56 | eTimedOut, ePassed, eFailed = 124, 0, 1 |
| 57 | |
| 58 | def call_with_timeout(command, timeout): |
Vince Harron | ede5965 | 2015-01-08 02:11:26 +0000 | [diff] [blame] | 59 | """Run command with a timeout if possible.""" |
Zachary Turner | dc494d5 | 2015-02-07 00:14:55 +0000 | [diff] [blame] | 60 | if os.name != "nt": |
| 61 | if timeout_command and timeout != "0": |
| 62 | return subprocess.call([timeout_command, timeout] + command, |
| 63 | stdin=subprocess.PIPE, close_fds=True) |
| 64 | return (ePassed if subprocess.call(command, stdin=subprocess.PIPE, close_fds=True) == 0 |
| 65 | else eFailed) |
| 66 | else: |
| 67 | if timeout_command and timeout != "0": |
| 68 | return subprocess.call([timeout_command, timeout] + command, |
| 69 | stdin=subprocess.PIPE) |
| 70 | return (ePassed if subprocess.call(command, stdin=subprocess.PIPE) == 0 |
| 71 | else eFailed) |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 72 | |
Vince Harron | 41657cc | 2015-05-21 18:15:09 +0000 | [diff] [blame] | 73 | def process_dir(root, files, test_root, dotest_argv): |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 74 | """Examine a directory for tests, and invoke any found within it.""" |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 75 | timed_out = [] |
Daniel Malea | cbaef26 | 2013-02-15 21:31:37 +0000 | [diff] [blame] | 76 | failed = [] |
| 77 | passed = [] |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 78 | for name in files: |
| 79 | path = os.path.join(root, name) |
| 80 | |
| 81 | # We're only interested in the test file with the "Test*.py" naming pattern. |
| 82 | if not name.startswith("Test") or not name.endswith(".py"): |
| 83 | continue |
| 84 | |
| 85 | # Neither a symbolically linked file. |
| 86 | if os.path.islink(path): |
| 87 | continue |
| 88 | |
Zachary Turner | f6896b0 | 2015-01-05 19:37:03 +0000 | [diff] [blame] | 89 | script_file = os.path.join(test_root, "dotest.py") |
Zachary Turner | f6896b0 | 2015-01-05 19:37:03 +0000 | [diff] [blame] | 90 | command = ([sys.executable, script_file] + |
Vince Harron | 41657cc | 2015-05-21 18:15:09 +0000 | [diff] [blame] | 91 | dotest_argv + |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 92 | ["-p", name, root]) |
| 93 | |
| 94 | timeout_name = os.path.basename(os.path.splitext(name)[0]).upper() |
| 95 | |
| 96 | timeout = os.getenv("LLDB_%s_TIMEOUT" % timeout_name) or default_timeout |
| 97 | |
| 98 | exit_status = call_with_timeout(command, timeout) |
| 99 | |
| 100 | if ePassed == exit_status: |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 101 | passed.append(name) |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 102 | else: |
| 103 | if eTimedOut == exit_status: |
| 104 | timed_out.append(name) |
| 105 | failed.append(name) |
| 106 | return (timed_out, failed, passed) |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 107 | |
| 108 | in_q = None |
| 109 | out_q = None |
| 110 | |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 111 | def process_dir_worker(arg_tuple): |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 112 | """Worker thread main loop when in multithreaded mode. |
| 113 | Takes one directory specification at a time and works on it.""" |
Vince Harron | 41657cc | 2015-05-21 18:15:09 +0000 | [diff] [blame] | 114 | (root, files, test_root, dotest_argv) = arg_tuple |
| 115 | return process_dir(root, files, test_root, dotest_argv) |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 116 | |
Vince Harron | 41657cc | 2015-05-21 18:15:09 +0000 | [diff] [blame] | 117 | def walk_and_invoke(test_directory, test_subdir, dotest_argv, num_threads): |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 118 | """Look for matched files and invoke test driver on each one. |
| 119 | In single-threaded mode, each test driver is invoked directly. |
| 120 | In multi-threaded mode, submit each test driver to a worker |
Vince Harron | e06a7a8 | 2015-05-12 23:12:19 +0000 | [diff] [blame] | 121 | queue, and then wait for all to complete. |
| 122 | |
| 123 | test_directory - lldb/test/ directory |
| 124 | test_subdir - lldb/test/ or a subfolder with the tests we're interested in running |
| 125 | """ |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 126 | |
| 127 | # Collect the test files that we'll run. |
| 128 | test_work_items = [] |
Vince Harron | e06a7a8 | 2015-05-12 23:12:19 +0000 | [diff] [blame] | 129 | for root, dirs, files in os.walk(test_subdir, topdown=False): |
Vince Harron | 41657cc | 2015-05-21 18:15:09 +0000 | [diff] [blame] | 130 | test_work_items.append((root, files, test_directory, dotest_argv)) |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 131 | |
| 132 | # Run the items, either in a pool (for multicore speedup) or |
| 133 | # calling each individually. |
| 134 | if num_threads > 1: |
| 135 | pool = multiprocessing.Pool(num_threads) |
| 136 | test_results = pool.map(process_dir_worker, test_work_items) |
| 137 | else: |
| 138 | test_results = [] |
| 139 | for work_item in test_work_items: |
| 140 | test_results.append(process_dir_worker(work_item)) |
| 141 | |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 142 | timed_out = [] |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 143 | failed = [] |
| 144 | passed = [] |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 145 | |
| 146 | for test_result in test_results: |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 147 | (dir_timed_out, dir_failed, dir_passed) = test_result |
| 148 | timed_out += dir_timed_out |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 149 | failed += dir_failed |
| 150 | passed += dir_passed |
| 151 | |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 152 | return (timed_out, failed, passed) |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 153 | |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 154 | def getExpectedTimeouts(platform_name): |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 155 | # returns a set of test filenames that might timeout |
| 156 | # are we running against a remote target? |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 157 | if platform_name is None: |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 158 | target = sys.platform |
| 159 | remote = False |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 160 | else: |
| 161 | m = re.search('remote-(\w+)', platform_name) |
| 162 | target = m.group(1) |
| 163 | remote = True |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 164 | |
| 165 | expected_timeout = set() |
| 166 | |
| 167 | if target.startswith("linux"): |
| 168 | expected_timeout |= { |
Vince Harron | de92b52 | 2015-05-13 23:59:03 +0000 | [diff] [blame] | 169 | "TestAttachDenied.py", |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 170 | "TestAttachResume.py", |
| 171 | "TestConnectRemote.py", |
| 172 | "TestCreateAfterAttach.py", |
Tamas Berghammer | 0d0ec9f | 2015-05-19 10:49:40 +0000 | [diff] [blame] | 173 | "TestEvents.py", |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 174 | "TestExitDuringStep.py", |
| 175 | "TestThreadStepOut.py", |
| 176 | } |
| 177 | elif target.startswith("android"): |
| 178 | expected_timeout |= { |
| 179 | "TestExitDuringStep.py", |
| 180 | "TestHelloWorld.py", |
| 181 | } |
Ed Maste | 4dd8fba | 2015-05-14 16:25:52 +0000 | [diff] [blame] | 182 | elif target.startswith("freebsd"): |
| 183 | expected_timeout |= { |
| 184 | "TestBreakpointConditions.py", |
| 185 | "TestWatchpointConditionAPI.py", |
| 186 | } |
Vince Harron | 0f173ac | 2015-05-18 19:36:33 +0000 | [diff] [blame] | 187 | elif target.startswith("darwin"): |
| 188 | expected_timeout |= { |
| 189 | "TestThreadSpecificBreakpoint.py", # times out on MBP Retina, Mid 2012 |
| 190 | } |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 191 | return expected_timeout |
| 192 | |
Vince Harron | 0b9dbb5 | 2015-05-21 18:18:52 +0000 | [diff] [blame^] | 193 | def touch(fname, times=None): |
| 194 | with open(fname, 'a'): |
| 195 | os.utime(fname, times) |
| 196 | |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 197 | def main(): |
Vince Harron | d5fa102 | 2015-05-10 15:24:12 +0000 | [diff] [blame] | 198 | # We can't use sys.path[0] to determine the script directory |
| 199 | # because it doesn't work under a debugger |
Vince Harron | e06a7a8 | 2015-05-12 23:12:19 +0000 | [diff] [blame] | 200 | test_directory = os.path.dirname(os.path.realpath(__file__)) |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 201 | parser = OptionParser(usage="""\ |
| 202 | Run lldb test suite using a separate process for each test file. |
Vince Harron | ede5965 | 2015-01-08 02:11:26 +0000 | [diff] [blame] | 203 | |
Siva Chandra | 2d7832e | 2015-05-08 23:08:53 +0000 | [diff] [blame] | 204 | 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] | 205 | |
Siva Chandra | 2d7832e | 2015-05-08 23:08:53 +0000 | [diff] [blame] | 206 | Override the default time limit of 10 minutes by setting |
Vince Harron | ede5965 | 2015-01-08 02:11:26 +0000 | [diff] [blame] | 207 | the environment variable LLDB_TEST_TIMEOUT. |
| 208 | |
| 209 | E.g., export LLDB_TEST_TIMEOUT=10m |
| 210 | |
| 211 | Override the time limit for individual tests by setting |
| 212 | the environment variable LLDB_[TEST NAME]_TIMEOUT. |
| 213 | |
| 214 | E.g., export LLDB_TESTCONCURRENTEVENTS_TIMEOUT=2m |
| 215 | |
| 216 | Set to "0" to run without time limit. |
| 217 | |
| 218 | E.g., export LLDB_TEST_TIMEOUT=0 |
| 219 | or export LLDB_TESTCONCURRENTEVENTS_TIMEOUT=0 |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 220 | """) |
| 221 | parser.add_option('-o', '--options', |
| 222 | type='string', action='store', |
| 223 | dest='dotest_options', |
| 224 | help="""The options passed to 'dotest.py' if specified.""") |
| 225 | |
Greg Clayton | 2256d0d | 2014-03-24 23:01:57 +0000 | [diff] [blame] | 226 | parser.add_option('-t', '--threads', |
| 227 | type='int', |
| 228 | dest='num_threads', |
Ed Maste | cec2a5b | 2014-11-21 02:41:25 +0000 | [diff] [blame] | 229 | help="""The number of threads to use when running tests separately.""") |
Greg Clayton | 2256d0d | 2014-03-24 23:01:57 +0000 | [diff] [blame] | 230 | |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 231 | opts, args = parser.parse_args() |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 232 | dotest_option_string = opts.dotest_options |
| 233 | |
Vince Harron | 41657cc | 2015-05-21 18:15:09 +0000 | [diff] [blame] | 234 | is_posix = (os.name == "posix") |
| 235 | dotest_argv = shlex.split(dotest_option_string, posix=is_posix) if dotest_option_string else [] |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 236 | dotest_options = dotest_args.getArguments(dotest_argv) |
Vince Harron | 41657cc | 2015-05-21 18:15:09 +0000 | [diff] [blame] | 237 | if not dotest_options.s: |
| 238 | # no session log directory, we need to add this to prevent |
| 239 | # every dotest invocation from creating its own directory |
| 240 | import datetime |
| 241 | # The windows platforms don't like ':' in the pathname. |
| 242 | timestamp_started = datetime.datetime.now().strftime("%Y-%m-%d-%H_%M_%S") |
| 243 | dotest_argv.append('-s') |
| 244 | dotest_argv.append(timestamp_started) |
Vince Harron | 0b9dbb5 | 2015-05-21 18:18:52 +0000 | [diff] [blame^] | 245 | dotest_options.s = timestamp_started |
| 246 | |
| 247 | session_dir = os.path.join(os.getcwd(), dotest_options.s) |
Ed Maste | cec2a5b | 2014-11-21 02:41:25 +0000 | [diff] [blame] | 248 | |
Vince Harron | e06a7a8 | 2015-05-12 23:12:19 +0000 | [diff] [blame] | 249 | # The root directory was specified on the command line |
| 250 | if len(args) == 0: |
| 251 | test_subdir = test_directory |
| 252 | else: |
| 253 | test_subdir = os.path.join(test_directory, args[0]) |
| 254 | |
Ed Maste | cec2a5b | 2014-11-21 02:41:25 +0000 | [diff] [blame] | 255 | if opts.num_threads: |
| 256 | num_threads = opts.num_threads |
| 257 | else: |
Greg Clayton | 2256d0d | 2014-03-24 23:01:57 +0000 | [diff] [blame] | 258 | num_threads_str = os.environ.get("LLDB_TEST_THREADS") |
| 259 | if num_threads_str: |
| 260 | num_threads = int(num_threads_str) |
Greg Clayton | 2256d0d | 2014-03-24 23:01:57 +0000 | [diff] [blame] | 261 | else: |
Ed Maste | cec2a5b | 2014-11-21 02:41:25 +0000 | [diff] [blame] | 262 | num_threads = multiprocessing.cpu_count() |
| 263 | if num_threads < 1: |
| 264 | num_threads = 1 |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 265 | |
Daniel Malea | b42556f | 2013-04-19 18:32:53 +0000 | [diff] [blame] | 266 | system_info = " ".join(platform.uname()) |
Vince Harron | 41657cc | 2015-05-21 18:15:09 +0000 | [diff] [blame] | 267 | (timed_out, failed, passed) = walk_and_invoke(test_directory, test_subdir, dotest_argv, |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 268 | num_threads) |
| 269 | timed_out = set(timed_out) |
Daniel Malea | cbaef26 | 2013-02-15 21:31:37 +0000 | [diff] [blame] | 270 | num_tests = len(failed) + len(passed) |
Daniel Malea | b42556f | 2013-04-19 18:32:53 +0000 | [diff] [blame] | 271 | |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 272 | # remove expected timeouts from failures |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 273 | expected_timeout = getExpectedTimeouts(dotest_options.lldb_platform_name) |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 274 | for xtime in expected_timeout: |
| 275 | if xtime in timed_out: |
| 276 | timed_out.remove(xtime) |
| 277 | failed.remove(xtime) |
Vince Harron | 0b9dbb5 | 2015-05-21 18:18:52 +0000 | [diff] [blame^] | 278 | result = "ExpectedTimeout" |
| 279 | elif xtime in passed: |
| 280 | result = "UnexpectedCompletion" |
| 281 | else: |
| 282 | result = None # failed |
| 283 | |
| 284 | if result: |
| 285 | test_name = os.path.splitext(xtime)[0] |
| 286 | touch(os.path.join(session_dir, "{}-{}".format(result, test_name))) |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 287 | |
Daniel Malea | cbaef26 | 2013-02-15 21:31:37 +0000 | [diff] [blame] | 288 | print "Ran %d tests." % num_tests |
| 289 | if len(failed) > 0: |
Shawn Best | 13491c4 | 2014-10-22 19:29:00 +0000 | [diff] [blame] | 290 | failed.sort() |
Daniel Malea | cbaef26 | 2013-02-15 21:31:37 +0000 | [diff] [blame] | 291 | print "Failing Tests (%d)" % len(failed) |
| 292 | for f in failed: |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 293 | print "%s: LLDB (suite) :: %s (%s)" % ( |
| 294 | "TIMEOUT" if f in timed_out else "FAIL", f, system_info |
| 295 | ) |
Daniel Malea | cbaef26 | 2013-02-15 21:31:37 +0000 | [diff] [blame] | 296 | sys.exit(1) |
| 297 | sys.exit(0) |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 298 | |
| 299 | if __name__ == '__main__': |
| 300 | main() |