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 | |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 73 | def process_dir(root, files, test_root, dotest_options): |
| 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") |
| 90 | is_posix = (os.name == "posix") |
| 91 | split_args = shlex.split(dotest_options, posix=is_posix) if dotest_options else [] |
| 92 | command = ([sys.executable, script_file] + |
| 93 | split_args + |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 94 | ["-p", name, root]) |
| 95 | |
| 96 | timeout_name = os.path.basename(os.path.splitext(name)[0]).upper() |
| 97 | |
| 98 | timeout = os.getenv("LLDB_%s_TIMEOUT" % timeout_name) or default_timeout |
| 99 | |
| 100 | exit_status = call_with_timeout(command, timeout) |
| 101 | |
| 102 | if ePassed == exit_status: |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 103 | passed.append(name) |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 104 | else: |
| 105 | if eTimedOut == exit_status: |
| 106 | timed_out.append(name) |
| 107 | failed.append(name) |
| 108 | return (timed_out, failed, passed) |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 109 | |
| 110 | in_q = None |
| 111 | out_q = None |
| 112 | |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 113 | def process_dir_worker(arg_tuple): |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 114 | """Worker thread main loop when in multithreaded mode. |
| 115 | Takes one directory specification at a time and works on it.""" |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 116 | (root, files, test_root, dotest_options) = arg_tuple |
| 117 | return process_dir(root, files, test_root, dotest_options) |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 118 | |
Vince Harron | e06a7a8 | 2015-05-12 23:12:19 +0000 | [diff] [blame] | 119 | def walk_and_invoke(test_directory, test_subdir, dotest_options, num_threads): |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 120 | """Look for matched files and invoke test driver on each one. |
| 121 | In single-threaded mode, each test driver is invoked directly. |
| 122 | In multi-threaded mode, submit each test driver to a worker |
Vince Harron | e06a7a8 | 2015-05-12 23:12:19 +0000 | [diff] [blame] | 123 | queue, and then wait for all to complete. |
| 124 | |
| 125 | test_directory - lldb/test/ directory |
| 126 | test_subdir - lldb/test/ or a subfolder with the tests we're interested in running |
| 127 | """ |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 128 | |
| 129 | # Collect the test files that we'll run. |
| 130 | test_work_items = [] |
Vince Harron | e06a7a8 | 2015-05-12 23:12:19 +0000 | [diff] [blame] | 131 | for root, dirs, files in os.walk(test_subdir, topdown=False): |
| 132 | test_work_items.append((root, files, test_directory, dotest_options)) |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 133 | |
| 134 | # Run the items, either in a pool (for multicore speedup) or |
| 135 | # calling each individually. |
| 136 | if num_threads > 1: |
| 137 | pool = multiprocessing.Pool(num_threads) |
| 138 | test_results = pool.map(process_dir_worker, test_work_items) |
| 139 | else: |
| 140 | test_results = [] |
| 141 | for work_item in test_work_items: |
| 142 | test_results.append(process_dir_worker(work_item)) |
| 143 | |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 144 | timed_out = [] |
Steve Pucci | befe2b1 | 2014-03-07 00:01:11 +0000 | [diff] [blame] | 145 | failed = [] |
| 146 | passed = [] |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 147 | |
| 148 | for test_result in test_results: |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 149 | (dir_timed_out, dir_failed, dir_passed) = test_result |
| 150 | timed_out += dir_timed_out |
Todd Fiala | 3f0a360 | 2014-07-08 06:42:37 +0000 | [diff] [blame] | 151 | failed += dir_failed |
| 152 | passed += dir_passed |
| 153 | |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 154 | return (timed_out, failed, passed) |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 155 | |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 156 | def getExpectedTimeouts(platform_name): |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 157 | # returns a set of test filenames that might timeout |
| 158 | # are we running against a remote target? |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 159 | if platform_name is None: |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 160 | target = sys.platform |
| 161 | remote = False |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 162 | else: |
| 163 | m = re.search('remote-(\w+)', platform_name) |
| 164 | target = m.group(1) |
| 165 | remote = True |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 166 | |
| 167 | expected_timeout = set() |
| 168 | |
| 169 | if target.startswith("linux"): |
| 170 | expected_timeout |= { |
Vince Harron | de92b52 | 2015-05-13 23:59:03 +0000 | [diff] [blame] | 171 | "TestAttachDenied.py", |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 172 | "TestAttachResume.py", |
| 173 | "TestConnectRemote.py", |
| 174 | "TestCreateAfterAttach.py", |
Tamas Berghammer | 0d0ec9f | 2015-05-19 10:49:40 +0000 | [diff] [blame^] | 175 | "TestEvents.py", |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 176 | "TestExitDuringStep.py", |
| 177 | "TestThreadStepOut.py", |
| 178 | } |
| 179 | elif target.startswith("android"): |
| 180 | expected_timeout |= { |
| 181 | "TestExitDuringStep.py", |
| 182 | "TestHelloWorld.py", |
| 183 | } |
Ed Maste | 4dd8fba | 2015-05-14 16:25:52 +0000 | [diff] [blame] | 184 | elif target.startswith("freebsd"): |
| 185 | expected_timeout |= { |
| 186 | "TestBreakpointConditions.py", |
| 187 | "TestWatchpointConditionAPI.py", |
| 188 | } |
Vince Harron | 0f173ac | 2015-05-18 19:36:33 +0000 | [diff] [blame] | 189 | elif target.startswith("darwin"): |
| 190 | expected_timeout |= { |
| 191 | "TestThreadSpecificBreakpoint.py", # times out on MBP Retina, Mid 2012 |
| 192 | } |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 193 | return expected_timeout |
| 194 | |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 195 | def main(): |
Vince Harron | d5fa102 | 2015-05-10 15:24:12 +0000 | [diff] [blame] | 196 | # We can't use sys.path[0] to determine the script directory |
| 197 | # because it doesn't work under a debugger |
Vince Harron | e06a7a8 | 2015-05-12 23:12:19 +0000 | [diff] [blame] | 198 | test_directory = os.path.dirname(os.path.realpath(__file__)) |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 199 | parser = OptionParser(usage="""\ |
| 200 | Run lldb test suite using a separate process for each test file. |
Vince Harron | ede5965 | 2015-01-08 02:11:26 +0000 | [diff] [blame] | 201 | |
Siva Chandra | 2d7832e | 2015-05-08 23:08:53 +0000 | [diff] [blame] | 202 | 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] | 203 | |
Siva Chandra | 2d7832e | 2015-05-08 23:08:53 +0000 | [diff] [blame] | 204 | Override the default time limit of 10 minutes by setting |
Vince Harron | ede5965 | 2015-01-08 02:11:26 +0000 | [diff] [blame] | 205 | the environment variable LLDB_TEST_TIMEOUT. |
| 206 | |
| 207 | E.g., export LLDB_TEST_TIMEOUT=10m |
| 208 | |
| 209 | Override the time limit for individual tests by setting |
| 210 | the environment variable LLDB_[TEST NAME]_TIMEOUT. |
| 211 | |
| 212 | E.g., export LLDB_TESTCONCURRENTEVENTS_TIMEOUT=2m |
| 213 | |
| 214 | Set to "0" to run without time limit. |
| 215 | |
| 216 | E.g., export LLDB_TEST_TIMEOUT=0 |
| 217 | or export LLDB_TESTCONCURRENTEVENTS_TIMEOUT=0 |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 218 | """) |
| 219 | parser.add_option('-o', '--options', |
| 220 | type='string', action='store', |
| 221 | dest='dotest_options', |
| 222 | help="""The options passed to 'dotest.py' if specified.""") |
| 223 | |
Greg Clayton | 2256d0d | 2014-03-24 23:01:57 +0000 | [diff] [blame] | 224 | parser.add_option('-t', '--threads', |
| 225 | type='int', |
| 226 | dest='num_threads', |
Ed Maste | cec2a5b | 2014-11-21 02:41:25 +0000 | [diff] [blame] | 227 | help="""The number of threads to use when running tests separately.""") |
Greg Clayton | 2256d0d | 2014-03-24 23:01:57 +0000 | [diff] [blame] | 228 | |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 229 | opts, args = parser.parse_args() |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 230 | dotest_option_string = opts.dotest_options |
| 231 | |
| 232 | dotest_argv = shlex.split(dotest_option_string) |
| 233 | dotest_options = dotest_args.getArguments(dotest_argv) |
Ed Maste | cec2a5b | 2014-11-21 02:41:25 +0000 | [diff] [blame] | 234 | |
Vince Harron | e06a7a8 | 2015-05-12 23:12:19 +0000 | [diff] [blame] | 235 | # The root directory was specified on the command line |
| 236 | if len(args) == 0: |
| 237 | test_subdir = test_directory |
| 238 | else: |
| 239 | test_subdir = os.path.join(test_directory, args[0]) |
| 240 | |
Ed Maste | cec2a5b | 2014-11-21 02:41:25 +0000 | [diff] [blame] | 241 | if opts.num_threads: |
| 242 | num_threads = opts.num_threads |
| 243 | else: |
Greg Clayton | 2256d0d | 2014-03-24 23:01:57 +0000 | [diff] [blame] | 244 | num_threads_str = os.environ.get("LLDB_TEST_THREADS") |
| 245 | if num_threads_str: |
| 246 | num_threads = int(num_threads_str) |
Greg Clayton | 2256d0d | 2014-03-24 23:01:57 +0000 | [diff] [blame] | 247 | else: |
Ed Maste | cec2a5b | 2014-11-21 02:41:25 +0000 | [diff] [blame] | 248 | num_threads = multiprocessing.cpu_count() |
| 249 | if num_threads < 1: |
| 250 | num_threads = 1 |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 251 | |
Daniel Malea | b42556f | 2013-04-19 18:32:53 +0000 | [diff] [blame] | 252 | system_info = " ".join(platform.uname()) |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 253 | (timed_out, failed, passed) = walk_and_invoke(test_directory, test_subdir, dotest_option_string, |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 254 | num_threads) |
| 255 | timed_out = set(timed_out) |
Daniel Malea | cbaef26 | 2013-02-15 21:31:37 +0000 | [diff] [blame] | 256 | num_tests = len(failed) + len(passed) |
Daniel Malea | b42556f | 2013-04-19 18:32:53 +0000 | [diff] [blame] | 257 | |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 258 | # remove expected timeouts from failures |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 259 | expected_timeout = getExpectedTimeouts(dotest_options.lldb_platform_name) |
Vince Harron | 0638173 | 2015-05-12 23:10:36 +0000 | [diff] [blame] | 260 | for xtime in expected_timeout: |
| 261 | if xtime in timed_out: |
| 262 | timed_out.remove(xtime) |
| 263 | failed.remove(xtime) |
| 264 | |
Daniel Malea | cbaef26 | 2013-02-15 21:31:37 +0000 | [diff] [blame] | 265 | print "Ran %d tests." % num_tests |
| 266 | if len(failed) > 0: |
Shawn Best | 13491c4 | 2014-10-22 19:29:00 +0000 | [diff] [blame] | 267 | failed.sort() |
Daniel Malea | cbaef26 | 2013-02-15 21:31:37 +0000 | [diff] [blame] | 268 | print "Failing Tests (%d)" % len(failed) |
| 269 | for f in failed: |
Vince Harron | 17f429f | 2014-12-13 00:08:19 +0000 | [diff] [blame] | 270 | print "%s: LLDB (suite) :: %s (%s)" % ( |
| 271 | "TIMEOUT" if f in timed_out else "FAIL", f, system_info |
| 272 | ) |
Daniel Malea | cbaef26 | 2013-02-15 21:31:37 +0000 | [diff] [blame] | 273 | sys.exit(1) |
| 274 | sys.exit(0) |
Johnny Chen | e8d9dc6 | 2011-10-31 19:04:07 +0000 | [diff] [blame] | 275 | |
| 276 | if __name__ == '__main__': |
| 277 | main() |