blob: d9147ed2fbf446695abec2eb9e1207a882a9f02c [file] [log] [blame]
Johnny Chene8d9dc62011-10-31 19:04:07 +00001#!/usr/bin/env python
2
3"""
4Run the test suite using a separate process for each test file.
Vince Harronede59652015-01-08 02:11:26 +00005
Siva Chandra2d7832e2015-05-08 23:08:53 +00006Each test will run with a time limit of 10 minutes by default.
Vince Harronede59652015-01-08 02:11:26 +00007
Siva Chandra2d7832e2015-05-08 23:08:53 +00008Override the default time limit of 10 minutes by setting
Vince Harronede59652015-01-08 02:11:26 +00009the environment variable LLDB_TEST_TIMEOUT.
10
11E.g., export LLDB_TEST_TIMEOUT=10m
12
13Override the time limit for individual tests by setting
14the environment variable LLDB_[TEST NAME]_TIMEOUT.
15
16E.g., export LLDB_TESTCONCURRENTEVENTS_TIMEOUT=2m
17
18Set to "0" to run without time limit.
19
20E.g., export LLDB_TEST_TIMEOUT=0
21or export LLDB_TESTCONCURRENTEVENTS_TIMEOUT=0
Vince Harrondcc2b9f2015-05-27 04:40:36 +000022
Chaoren Linb6325d02015-08-12 18:02:54 +000023To collect core files for timed out tests,
24do the following before running dosep.py
Vince Harrondcc2b9f2015-05-27 04:40:36 +000025
26OSX
27ulimit -c unlimited
28sudo sysctl -w kern.corefile=core.%P
29
30Linux:
31ulimit -c unlimited
32echo core.%p | sudo tee /proc/sys/kernel/core_pattern
Johnny Chene8d9dc62011-10-31 19:04:07 +000033"""
34
Greg Clayton2256d0d2014-03-24 23:01:57 +000035import multiprocessing
Todd Fiala3f0a3602014-07-08 06:42:37 +000036import os
Vince Harrondcc2b9f2015-05-27 04:40:36 +000037import fnmatch
Todd Fiala3f0a3602014-07-08 06:42:37 +000038import platform
Vince Harron06381732015-05-12 23:10:36 +000039import re
Vince Harronf8b9a1d2015-05-18 19:40:54 +000040import dotest_args
Vince Harron17f429f2014-12-13 00:08:19 +000041import shlex
42import subprocess
Todd Fiala3f0a3602014-07-08 06:42:37 +000043import sys
Steve Puccibefe2b12014-03-07 00:01:11 +000044
Johnny Chene8d9dc62011-10-31 19:04:07 +000045from optparse import OptionParser
46
Chaoren Linb6325d02015-08-12 18:02:54 +000047
Vince Harron17f429f2014-12-13 00:08:19 +000048def get_timeout_command():
Vince Harronede59652015-01-08 02:11:26 +000049 """Search for a suitable timeout command."""
Ying Chen93190c42015-07-20 20:04:22 +000050 if not sys.platform.startswith("win32"):
51 try:
52 subprocess.call("timeout", stderr=subprocess.PIPE)
53 return "timeout"
54 except OSError:
55 pass
Vince Harron17f429f2014-12-13 00:08:19 +000056 try:
Chaoren Lin45c17ff2015-05-28 23:00:10 +000057 subprocess.call("gtimeout", stderr=subprocess.PIPE)
Vince Harron17f429f2014-12-13 00:08:19 +000058 return "gtimeout"
59 except OSError:
60 pass
61 return None
62
63timeout_command = get_timeout_command()
64
Vince Harron17f429f2014-12-13 00:08:19 +000065# Status codes for running command with timeout.
66eTimedOut, ePassed, eFailed = 124, 0, 1
67
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +000068output_lock = None
69test_counter = None
70total_tests = None
Chaoren Linffc63b02015-08-12 18:02:49 +000071test_name_len = None
Pavel Labath05ab2372015-07-06 15:57:52 +000072dotest_options = None
Zachary Turner38e64172015-08-10 17:46:11 +000073output_on_success = False
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +000074
Chaoren Linb6325d02015-08-12 18:02:54 +000075
Chaoren Linffc63b02015-08-12 18:02:49 +000076def setup_global_variables(lock, counter, total, name_len, options):
77 global output_lock, test_counter, total_tests, test_name_len
78 global dotest_options
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +000079 output_lock = lock
80 test_counter = counter
81 total_tests = total
Chaoren Linffc63b02015-08-12 18:02:49 +000082 test_name_len = name_len
Pavel Labath05ab2372015-07-06 15:57:52 +000083 dotest_options = options
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +000084
Chaoren Linb6325d02015-08-12 18:02:54 +000085
Zachary Turner38e64172015-08-10 17:46:11 +000086def report_test_failure(name, command, output):
87 global output_lock
88 with output_lock:
Chaoren Linffc63b02015-08-12 18:02:49 +000089 print >> sys.stderr
Zachary Turner38e64172015-08-10 17:46:11 +000090 print >> sys.stderr, output
Chaoren Linffc63b02015-08-12 18:02:49 +000091 print >> sys.stderr, "[%s FAILED]" % name
Zachary Turner38e64172015-08-10 17:46:11 +000092 print >> sys.stderr, "Command invoked: %s" % ' '.join(command)
Chaoren Linffc63b02015-08-12 18:02:49 +000093 update_progress(name)
Zachary Turner38e64172015-08-10 17:46:11 +000094
Chaoren Linb6325d02015-08-12 18:02:54 +000095
Zachary Turner38e64172015-08-10 17:46:11 +000096def report_test_pass(name, output):
97 global output_lock, output_on_success
98 with output_lock:
99 if output_on_success:
Chaoren Linffc63b02015-08-12 18:02:49 +0000100 print >> sys.stderr
Zachary Turner38e64172015-08-10 17:46:11 +0000101 print >> sys.stderr, output
Chaoren Linffc63b02015-08-12 18:02:49 +0000102 print >> sys.stderr, "[%s PASSED]" % name
103 update_progress(name)
Zachary Turner38e64172015-08-10 17:46:11 +0000104
Chaoren Linb6325d02015-08-12 18:02:54 +0000105
Chaoren Linffc63b02015-08-12 18:02:49 +0000106def update_progress(test_name=""):
107 global output_lock, test_counter, total_tests, test_name_len
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +0000108 with output_lock:
Chaoren Linffc63b02015-08-12 18:02:49 +0000109 counter_len = len(str(total_tests))
110 sys.stderr.write(
111 "\r%*d out of %d test suites processed - %-*s" %
112 (counter_len, test_counter.value, total_tests,
113 test_name_len.value, test_name))
114 if len(test_name) > test_name_len.value:
115 test_name_len.value = len(test_name)
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +0000116 test_counter.value += 1
Zachary Turner38e64172015-08-10 17:46:11 +0000117 sys.stdout.flush()
118 sys.stderr.flush()
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +0000119
Chaoren Linb6325d02015-08-12 18:02:54 +0000120
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000121def parse_test_results(output):
122 passes = 0
123 failures = 0
Zachary Turner4cceca72015-08-14 16:45:32 +0000124 unexpected_successes = 0
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000125 for result in output:
Chaoren Linb6325d02015-08-12 18:02:54 +0000126 pass_count = re.search("^RESULT:.*([0-9]+) passes",
127 result, re.MULTILINE)
128 fail_count = re.search("^RESULT:.*([0-9]+) failures",
129 result, re.MULTILINE)
130 error_count = re.search("^RESULT:.*([0-9]+) errors",
131 result, re.MULTILINE)
Zachary Turner4cceca72015-08-14 16:45:32 +0000132 unexpected_success_count = re.search("^RESULT:.*([0-9]+) unexpected successes",
133 result, re.MULTILINE)
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000134 this_fail_count = 0
135 this_error_count = 0
Chaoren Linb6325d02015-08-12 18:02:54 +0000136 if pass_count is not None:
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000137 passes = passes + int(pass_count.group(1))
Chaoren Linb6325d02015-08-12 18:02:54 +0000138 if fail_count is not None:
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000139 failures = failures + int(fail_count.group(1))
Zachary Turner4cceca72015-08-14 16:45:32 +0000140 if unexpected_success_count is not None:
141 unexpected_successes = unexpected_successes + int(unexpected_success_count.group(1))
Chaoren Linb6325d02015-08-12 18:02:54 +0000142 if error_count is not None:
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000143 failures = failures + int(error_count.group(1))
144 pass
Zachary Turner4cceca72015-08-14 16:45:32 +0000145 return passes, failures, unexpected_successes
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000146
Chaoren Linb6325d02015-08-12 18:02:54 +0000147
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +0000148def call_with_timeout(command, timeout, name):
Vince Harronede59652015-01-08 02:11:26 +0000149 """Run command with a timeout if possible."""
Vince Harrondcc2b9f2015-05-27 04:40:36 +0000150 """-s QUIT will create a coredump if they are enabled on your system"""
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000151 process = None
152 if timeout_command and timeout != "0":
153 command = [timeout_command, '-s', 'QUIT', timeout] + command
Chaoren Linb6325d02015-08-12 18:02:54 +0000154 # Specifying a value for close_fds is unsupported on Windows when using
155 # subprocess.PIPE
Zachary Turnerdc494d52015-02-07 00:14:55 +0000156 if os.name != "nt":
Chaoren Linb6325d02015-08-12 18:02:54 +0000157 process = subprocess.Popen(command,
158 stdin=subprocess.PIPE,
159 stdout=subprocess.PIPE,
160 stderr=subprocess.PIPE,
161 close_fds=True)
Zachary Turnerdc494d52015-02-07 00:14:55 +0000162 else:
Chaoren Linb6325d02015-08-12 18:02:54 +0000163 process = subprocess.Popen(command,
164 stdin=subprocess.PIPE,
165 stdout=subprocess.PIPE,
166 stderr=subprocess.PIPE)
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000167 output = process.communicate()
168 exit_status = process.returncode
Zachary Turner4cceca72015-08-14 16:45:32 +0000169 passes, failures, unexpected_successes = parse_test_results(output)
Zachary Turner38e64172015-08-10 17:46:11 +0000170 if exit_status == 0:
Chaoren Linb6325d02015-08-12 18:02:54 +0000171 # stdout does not have any useful information from 'dotest.py',
172 # only stderr does.
Zachary Turner38e64172015-08-10 17:46:11 +0000173 report_test_pass(name, output[1])
174 else:
175 report_test_failure(name, command, output[1])
Zachary Turner4cceca72015-08-14 16:45:32 +0000176 return name, exit_status, passes, failures, unexpected_successes
Johnny Chene8d9dc62011-10-31 19:04:07 +0000177
Chaoren Linb6325d02015-08-12 18:02:54 +0000178
Vince Harron41657cc2015-05-21 18:15:09 +0000179def process_dir(root, files, test_root, dotest_argv):
Steve Puccibefe2b12014-03-07 00:01:11 +0000180 """Examine a directory for tests, and invoke any found within it."""
Chaoren Line80372a2015-08-12 18:02:53 +0000181 results = []
Steve Puccibefe2b12014-03-07 00:01:11 +0000182 for name in files:
Zachary Turnerf6896b02015-01-05 19:37:03 +0000183 script_file = os.path.join(test_root, "dotest.py")
Zachary Turnerf6896b02015-01-05 19:37:03 +0000184 command = ([sys.executable, script_file] +
Vince Harron41657cc2015-05-21 18:15:09 +0000185 dotest_argv +
Vince Harron17f429f2014-12-13 00:08:19 +0000186 ["-p", name, root])
187
188 timeout_name = os.path.basename(os.path.splitext(name)[0]).upper()
189
Chaoren Linb6325d02015-08-12 18:02:54 +0000190 timeout = (os.getenv("LLDB_%s_TIMEOUT" % timeout_name) or
191 getDefaultTimeout(dotest_options.lldb_platform_name))
Vince Harron17f429f2014-12-13 00:08:19 +0000192
Chaoren Line80372a2015-08-12 18:02:53 +0000193 results.append(call_with_timeout(command, timeout, name))
Vince Harron17f429f2014-12-13 00:08:19 +0000194
Zachary Turner4cceca72015-08-14 16:45:32 +0000195 # result = (name, status, passes, failures, unexpected_successes)
196 timed_out = [name for name, status, _, _, _ in results
Chaoren Line80372a2015-08-12 18:02:53 +0000197 if status == eTimedOut]
Zachary Turner4cceca72015-08-14 16:45:32 +0000198 passed = [name for name, status, _, _, _ in results
Chaoren Line80372a2015-08-12 18:02:53 +0000199 if status == ePassed]
Zachary Turner4cceca72015-08-14 16:45:32 +0000200 failed = [name for name, status, _, _, _ in results
Chaoren Line80372a2015-08-12 18:02:53 +0000201 if status != ePassed]
Zachary Turner4cceca72015-08-14 16:45:32 +0000202 unexpected_passes = [name for name, _, _, _, unexpected_successes in results
203 if unexpected_successes > 0]
204
Chaoren Line80372a2015-08-12 18:02:53 +0000205 pass_count = sum([result[2] for result in results])
206 fail_count = sum([result[3] for result in results])
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000207
Zachary Turner4cceca72015-08-14 16:45:32 +0000208 return (timed_out, passed, failed, unexpected_passes, pass_count, fail_count)
Steve Puccibefe2b12014-03-07 00:01:11 +0000209
210in_q = None
211out_q = None
212
Chaoren Linb6325d02015-08-12 18:02:54 +0000213
Todd Fiala3f0a3602014-07-08 06:42:37 +0000214def process_dir_worker(arg_tuple):
Steve Puccibefe2b12014-03-07 00:01:11 +0000215 """Worker thread main loop when in multithreaded mode.
216 Takes one directory specification at a time and works on it."""
Chaoren Line80372a2015-08-12 18:02:53 +0000217 return process_dir(*arg_tuple)
Steve Puccibefe2b12014-03-07 00:01:11 +0000218
Chaoren Linb6325d02015-08-12 18:02:54 +0000219
Vince Harron41657cc2015-05-21 18:15:09 +0000220def walk_and_invoke(test_directory, test_subdir, dotest_argv, num_threads):
Steve Puccibefe2b12014-03-07 00:01:11 +0000221 """Look for matched files and invoke test driver on each one.
222 In single-threaded mode, each test driver is invoked directly.
223 In multi-threaded mode, submit each test driver to a worker
Vince Harrone06a7a82015-05-12 23:12:19 +0000224 queue, and then wait for all to complete.
225
226 test_directory - lldb/test/ directory
Chaoren Linb6325d02015-08-12 18:02:54 +0000227 test_subdir - lldb/test/ or a subfolder with the tests we're interested in
228 running
Vince Harrone06a7a82015-05-12 23:12:19 +0000229 """
Todd Fiala3f0a3602014-07-08 06:42:37 +0000230
231 # Collect the test files that we'll run.
232 test_work_items = []
Vince Harrone06a7a82015-05-12 23:12:19 +0000233 for root, dirs, files in os.walk(test_subdir, topdown=False):
Chaoren Linffc63b02015-08-12 18:02:49 +0000234 def is_test(name):
235 # Not interested in symbolically linked files.
236 if os.path.islink(os.path.join(root, name)):
237 return False
238 # Only interested in test files with the "Test*.py" naming pattern.
239 return name.startswith("Test") and name.endswith(".py")
Todd Fiala3f0a3602014-07-08 06:42:37 +0000240
Chaoren Linffc63b02015-08-12 18:02:49 +0000241 tests = filter(is_test, files)
242 test_work_items.append((root, tests, test_directory, dotest_argv))
243
244 global output_lock, test_counter, total_tests, test_name_len
Zachary Turner38e64172015-08-10 17:46:11 +0000245 output_lock = multiprocessing.RLock()
Chaoren Linffc63b02015-08-12 18:02:49 +0000246 # item = (root, tests, test_directory, dotest_argv)
247 total_tests = sum([len(item[1]) for item in test_work_items])
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +0000248 test_counter = multiprocessing.Value('i', 0)
Chaoren Linffc63b02015-08-12 18:02:49 +0000249 test_name_len = multiprocessing.Value('i', 0)
250 print >> sys.stderr, "Testing: %d test suites, %d thread%s" % (
251 total_tests, num_threads, (num_threads > 1) * "s")
252 update_progress()
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +0000253
Todd Fiala3f0a3602014-07-08 06:42:37 +0000254 # Run the items, either in a pool (for multicore speedup) or
255 # calling each individually.
256 if num_threads > 1:
Chaoren Linffc63b02015-08-12 18:02:49 +0000257 pool = multiprocessing.Pool(
258 num_threads,
259 initializer=setup_global_variables,
260 initargs=(output_lock, test_counter, total_tests, test_name_len,
261 dotest_options))
Todd Fiala3f0a3602014-07-08 06:42:37 +0000262 test_results = pool.map(process_dir_worker, test_work_items)
263 else:
Chaoren Line80372a2015-08-12 18:02:53 +0000264 test_results = map(process_dir_worker, test_work_items)
Todd Fiala3f0a3602014-07-08 06:42:37 +0000265
Zachary Turner4cceca72015-08-14 16:45:32 +0000266 # result = (timed_out, failed, passed, unexpected_successes, fail_count, pass_count)
Chaoren Line80372a2015-08-12 18:02:53 +0000267 timed_out = sum([result[0] for result in test_results], [])
268 passed = sum([result[1] for result in test_results], [])
269 failed = sum([result[2] for result in test_results], [])
Zachary Turner4cceca72015-08-14 16:45:32 +0000270 unexpected_successes = sum([result[3] for result in test_results], [])
271 pass_count = sum([result[4] for result in test_results])
272 fail_count = sum([result[5] for result in test_results])
Todd Fiala3f0a3602014-07-08 06:42:37 +0000273
Zachary Turner4cceca72015-08-14 16:45:32 +0000274 return (timed_out, passed, failed, unexpected_successes, pass_count, fail_count)
Johnny Chene8d9dc62011-10-31 19:04:07 +0000275
Chaoren Linb6325d02015-08-12 18:02:54 +0000276
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000277def getExpectedTimeouts(platform_name):
Vince Harron06381732015-05-12 23:10:36 +0000278 # returns a set of test filenames that might timeout
279 # are we running against a remote target?
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000280 if platform_name is None:
Vince Harron06381732015-05-12 23:10:36 +0000281 target = sys.platform
282 remote = False
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000283 else:
284 m = re.search('remote-(\w+)', platform_name)
285 target = m.group(1)
286 remote = True
Vince Harron06381732015-05-12 23:10:36 +0000287
288 expected_timeout = set()
289
290 if target.startswith("linux"):
291 expected_timeout |= {
Vince Harronde92b522015-05-13 23:59:03 +0000292 "TestAttachDenied.py",
Vince Harron06381732015-05-12 23:10:36 +0000293 "TestAttachResume.py",
Chaoren Lin0b8bb3d2015-07-22 20:52:17 +0000294 "TestProcessAttach.py",
Vince Harron06381732015-05-12 23:10:36 +0000295 "TestConnectRemote.py",
296 "TestCreateAfterAttach.py",
Tamas Berghammer0d0ec9f2015-05-19 10:49:40 +0000297 "TestEvents.py",
Vince Harron06381732015-05-12 23:10:36 +0000298 "TestExitDuringStep.py",
Chaoren Linb6325d02015-08-12 18:02:54 +0000299
300 # Times out in ~10% of the times on the build bot
301 "TestHelloWorld.py",
Oleksiy Vyalov18f4c9f2015-06-10 01:34:25 +0000302 "TestMultithreaded.py",
Chaoren Linb6325d02015-08-12 18:02:54 +0000303 "TestRegisters.py", # ~12/600 dosep runs (build 3120-3122)
Vince Harron06381732015-05-12 23:10:36 +0000304 "TestThreadStepOut.py",
305 }
306 elif target.startswith("android"):
307 expected_timeout |= {
308 "TestExitDuringStep.py",
309 "TestHelloWorld.py",
310 }
Ed Maste4dd8fba2015-05-14 16:25:52 +0000311 elif target.startswith("freebsd"):
312 expected_timeout |= {
313 "TestBreakpointConditions.py",
Ed Maste08948132015-05-28 18:45:30 +0000314 "TestChangeProcessGroup.py",
Ed Mastebfd05632015-05-27 19:11:29 +0000315 "TestValueObjectRecursion.py",
Ed Maste4dd8fba2015-05-14 16:25:52 +0000316 "TestWatchpointConditionAPI.py",
317 }
Vince Harron0f173ac2015-05-18 19:36:33 +0000318 elif target.startswith("darwin"):
319 expected_timeout |= {
Chaoren Linb6325d02015-08-12 18:02:54 +0000320 # times out on MBP Retina, Mid 2012
321 "TestThreadSpecificBreakpoint.py",
Chaoren Lind9043712015-08-19 17:13:02 +0000322 "TestExitDuringStep.py",
Vince Harron0f173ac2015-05-18 19:36:33 +0000323 }
Vince Harron06381732015-05-12 23:10:36 +0000324 return expected_timeout
325
Chaoren Linb6325d02015-08-12 18:02:54 +0000326
Pavel Labathfad30cf2015-06-29 14:16:51 +0000327def getDefaultTimeout(platform_name):
328 if os.getenv("LLDB_TEST_TIMEOUT"):
329 return os.getenv("LLDB_TEST_TIMEOUT")
330
331 if platform_name is None:
332 platform_name = sys.platform
333
334 if platform_name.startswith("remote-"):
335 return "10m"
336 else:
337 return "4m"
338
Chaoren Linb6325d02015-08-12 18:02:54 +0000339
Vince Harron0b9dbb52015-05-21 18:18:52 +0000340def touch(fname, times=None):
Greg Clayton8c3f9c92015-08-11 21:01:32 +0000341 if os.path.exists(fname):
Vince Harron0b9dbb52015-05-21 18:18:52 +0000342 os.utime(fname, times)
343
Chaoren Linb6325d02015-08-12 18:02:54 +0000344
Vince Harrondcc2b9f2015-05-27 04:40:36 +0000345def find(pattern, path):
346 result = []
347 for root, dirs, files in os.walk(path):
348 for name in files:
349 if fnmatch.fnmatch(name, pattern):
350 result.append(os.path.join(root, name))
351 return result
352
Chaoren Linb6325d02015-08-12 18:02:54 +0000353
Johnny Chene8d9dc62011-10-31 19:04:07 +0000354def main():
Vince Harrond5fa1022015-05-10 15:24:12 +0000355 # We can't use sys.path[0] to determine the script directory
356 # because it doesn't work under a debugger
Vince Harrone06a7a82015-05-12 23:12:19 +0000357 test_directory = os.path.dirname(os.path.realpath(__file__))
Johnny Chene8d9dc62011-10-31 19:04:07 +0000358 parser = OptionParser(usage="""\
359Run lldb test suite using a separate process for each test file.
Vince Harronede59652015-01-08 02:11:26 +0000360
Siva Chandra2d7832e2015-05-08 23:08:53 +0000361 Each test will run with a time limit of 10 minutes by default.
Vince Harronede59652015-01-08 02:11:26 +0000362
Siva Chandra2d7832e2015-05-08 23:08:53 +0000363 Override the default time limit of 10 minutes by setting
Vince Harronede59652015-01-08 02:11:26 +0000364 the environment variable LLDB_TEST_TIMEOUT.
365
366 E.g., export LLDB_TEST_TIMEOUT=10m
367
368 Override the time limit for individual tests by setting
369 the environment variable LLDB_[TEST NAME]_TIMEOUT.
370
371 E.g., export LLDB_TESTCONCURRENTEVENTS_TIMEOUT=2m
372
373 Set to "0" to run without time limit.
374
375 E.g., export LLDB_TEST_TIMEOUT=0
376 or export LLDB_TESTCONCURRENTEVENTS_TIMEOUT=0
Johnny Chene8d9dc62011-10-31 19:04:07 +0000377""")
Chaoren Linb6325d02015-08-12 18:02:54 +0000378 parser.add_option(
379 '-o', '--options',
380 type='string', action='store',
381 dest='dotest_options',
382 help="""The options passed to 'dotest.py' if specified.""")
Johnny Chene8d9dc62011-10-31 19:04:07 +0000383
Chaoren Linb6325d02015-08-12 18:02:54 +0000384 parser.add_option(
385 '-s', '--output-on-success',
386 action='store_true',
387 dest='output_on_success',
388 default=False,
389 help="""Print full output of 'dotest.py' even when it succeeds.""")
Zachary Turner38e64172015-08-10 17:46:11 +0000390
Chaoren Linb6325d02015-08-12 18:02:54 +0000391 parser.add_option(
392 '-t', '--threads',
393 type='int',
394 dest='num_threads',
395 help="""The number of threads to use when running tests separately.""")
Greg Clayton2256d0d2014-03-24 23:01:57 +0000396
Johnny Chene8d9dc62011-10-31 19:04:07 +0000397 opts, args = parser.parse_args()
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000398 dotest_option_string = opts.dotest_options
399
Vince Harron41657cc2015-05-21 18:15:09 +0000400 is_posix = (os.name == "posix")
Chaoren Linb6325d02015-08-12 18:02:54 +0000401 dotest_argv = (shlex.split(dotest_option_string, posix=is_posix)
402 if dotest_option_string
403 else [])
Vince Harron8994fed2015-05-22 19:49:23 +0000404
405 parser = dotest_args.create_parser()
Pavel Labath05ab2372015-07-06 15:57:52 +0000406 global dotest_options
Zachary Turner38e64172015-08-10 17:46:11 +0000407 global output_on_success
408 output_on_success = opts.output_on_success
Vince Harron8994fed2015-05-22 19:49:23 +0000409 dotest_options = dotest_args.parse_args(parser, dotest_argv)
410
Vince Harron41657cc2015-05-21 18:15:09 +0000411 if not dotest_options.s:
412 # no session log directory, we need to add this to prevent
413 # every dotest invocation from creating its own directory
414 import datetime
415 # The windows platforms don't like ':' in the pathname.
Chaoren Linb6325d02015-08-12 18:02:54 +0000416 timestamp_started = datetime.datetime.now().strftime("%F-%H_%M_%S")
Vince Harron41657cc2015-05-21 18:15:09 +0000417 dotest_argv.append('-s')
418 dotest_argv.append(timestamp_started)
Vince Harron0b9dbb52015-05-21 18:18:52 +0000419 dotest_options.s = timestamp_started
420
421 session_dir = os.path.join(os.getcwd(), dotest_options.s)
Ed Mastecec2a5b2014-11-21 02:41:25 +0000422
Vince Harrone06a7a82015-05-12 23:12:19 +0000423 # The root directory was specified on the command line
424 if len(args) == 0:
425 test_subdir = test_directory
426 else:
427 test_subdir = os.path.join(test_directory, args[0])
428
Vince Harrondcc2b9f2015-05-27 04:40:36 +0000429 # clean core files in test tree from previous runs (Linux)
430 cores = find('core.*', test_subdir)
431 for core in cores:
432 os.unlink(core)
433
Ed Mastecec2a5b2014-11-21 02:41:25 +0000434 if opts.num_threads:
435 num_threads = opts.num_threads
436 else:
Greg Clayton2256d0d2014-03-24 23:01:57 +0000437 num_threads_str = os.environ.get("LLDB_TEST_THREADS")
438 if num_threads_str:
439 num_threads = int(num_threads_str)
Greg Clayton2256d0d2014-03-24 23:01:57 +0000440 else:
Ed Mastecec2a5b2014-11-21 02:41:25 +0000441 num_threads = multiprocessing.cpu_count()
442 if num_threads < 1:
443 num_threads = 1
Johnny Chene8d9dc62011-10-31 19:04:07 +0000444
Daniel Maleab42556f2013-04-19 18:32:53 +0000445 system_info = " ".join(platform.uname())
Zachary Turner4cceca72015-08-14 16:45:32 +0000446 (timed_out, passed, failed, unexpected_successes, pass_count, fail_count) = walk_and_invoke(
Chaoren Line80372a2015-08-12 18:02:53 +0000447 test_directory, test_subdir, dotest_argv, num_threads)
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000448
Vince Harron17f429f2014-12-13 00:08:19 +0000449 timed_out = set(timed_out)
Chaoren Line80372a2015-08-12 18:02:53 +0000450 num_test_files = len(passed) + len(failed)
451 num_test_cases = pass_count + fail_count
Daniel Maleab42556f2013-04-19 18:32:53 +0000452
Vince Harrondcc2b9f2015-05-27 04:40:36 +0000453 # move core files into session dir
454 cores = find('core.*', test_subdir)
455 for core in cores:
456 dst = core.replace(test_directory, "")[1:]
457 dst = dst.replace(os.path.sep, "-")
458 os.rename(core, os.path.join(session_dir, dst))
459
Vince Harron06381732015-05-12 23:10:36 +0000460 # remove expected timeouts from failures
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000461 expected_timeout = getExpectedTimeouts(dotest_options.lldb_platform_name)
Vince Harron06381732015-05-12 23:10:36 +0000462 for xtime in expected_timeout:
463 if xtime in timed_out:
464 timed_out.remove(xtime)
465 failed.remove(xtime)
Vince Harron0b9dbb52015-05-21 18:18:52 +0000466 result = "ExpectedTimeout"
467 elif xtime in passed:
468 result = "UnexpectedCompletion"
469 else:
470 result = None # failed
471
472 if result:
473 test_name = os.path.splitext(xtime)[0]
474 touch(os.path.join(session_dir, "{}-{}".format(result, test_name)))
Vince Harron06381732015-05-12 23:10:36 +0000475
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +0000476 print
Chaoren Lin5a59e462015-08-12 18:02:51 +0000477 sys.stdout.write("Ran %d test suites" % num_test_files)
478 if num_test_files > 0:
479 sys.stdout.write(" (%d failed) (%f%%)" % (
480 len(failed), 100.0 * len(failed) / num_test_files))
481 print
Chaoren Line80372a2015-08-12 18:02:53 +0000482 sys.stdout.write("Ran %d test cases" % num_test_cases)
483 if num_test_cases > 0:
Chaoren Lin5a59e462015-08-12 18:02:51 +0000484 sys.stdout.write(" (%d failed) (%f%%)" % (
Chaoren Line80372a2015-08-12 18:02:53 +0000485 fail_count, 100.0 * fail_count / num_test_cases))
Chaoren Lin5a59e462015-08-12 18:02:51 +0000486 print
Zachary Turner4cceca72015-08-14 16:45:32 +0000487 exit_code = 0
488
Daniel Maleacbaef262013-02-15 21:31:37 +0000489 if len(failed) > 0:
Shawn Best13491c42014-10-22 19:29:00 +0000490 failed.sort()
Ying Chen10ed1a92015-05-28 23:51:49 +0000491 print "Failing Tests (%d)" % len(failed)
Daniel Maleacbaef262013-02-15 21:31:37 +0000492 for f in failed:
Vince Harron17f429f2014-12-13 00:08:19 +0000493 print "%s: LLDB (suite) :: %s (%s)" % (
494 "TIMEOUT" if f in timed_out else "FAIL", f, system_info
495 )
Zachary Turner4cceca72015-08-14 16:45:32 +0000496 exit_code = 1
497
498 if len(unexpected_successes) > 0:
499 unexpected_successes.sort()
500 print "\nUnexpected Successes (%d)" % len(unexpected_successes)
501 for u in unexpected_successes:
502 print "UNEXPECTED SUCCESS: LLDB (suite) :: %s (%s)" % (u, system_info)
503
504 sys.exit(exit_code)
Johnny Chene8d9dc62011-10-31 19:04:07 +0000505
506if __name__ == '__main__':
507 main()