blob: dac0df5a821884bb65d20419116fa5e4d6ead526 [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
23To collect core files for timed out tests, do the following before running dosep.py
24
25OSX
26ulimit -c unlimited
27sudo sysctl -w kern.corefile=core.%P
28
29Linux:
30ulimit -c unlimited
31echo core.%p | sudo tee /proc/sys/kernel/core_pattern
Johnny Chene8d9dc62011-10-31 19:04:07 +000032"""
33
Greg Clayton2256d0d2014-03-24 23:01:57 +000034import multiprocessing
Todd Fiala3f0a3602014-07-08 06:42:37 +000035import os
Vince Harrondcc2b9f2015-05-27 04:40:36 +000036import fnmatch
Todd Fiala3f0a3602014-07-08 06:42:37 +000037import platform
Vince Harron06381732015-05-12 23:10:36 +000038import re
Vince Harronf8b9a1d2015-05-18 19:40:54 +000039import dotest_args
Vince Harron17f429f2014-12-13 00:08:19 +000040import shlex
41import subprocess
Todd Fiala3f0a3602014-07-08 06:42:37 +000042import sys
Steve Puccibefe2b12014-03-07 00:01:11 +000043
Johnny Chene8d9dc62011-10-31 19:04:07 +000044from optparse import OptionParser
45
Vince Harron17f429f2014-12-13 00:08:19 +000046def get_timeout_command():
Vince Harronede59652015-01-08 02:11:26 +000047 """Search for a suitable timeout command."""
Ying Chen93190c42015-07-20 20:04:22 +000048 if not sys.platform.startswith("win32"):
49 try:
50 subprocess.call("timeout", stderr=subprocess.PIPE)
51 return "timeout"
52 except OSError:
53 pass
Vince Harron17f429f2014-12-13 00:08:19 +000054 try:
Chaoren Lin45c17ff2015-05-28 23:00:10 +000055 subprocess.call("gtimeout", stderr=subprocess.PIPE)
Vince Harron17f429f2014-12-13 00:08:19 +000056 return "gtimeout"
57 except OSError:
58 pass
59 return None
60
61timeout_command = get_timeout_command()
62
Vince Harron17f429f2014-12-13 00:08:19 +000063# Status codes for running command with timeout.
64eTimedOut, ePassed, eFailed = 124, 0, 1
65
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +000066output_lock = None
67test_counter = None
68total_tests = None
Chaoren Linffc63b02015-08-12 18:02:49 +000069test_name_len = None
Pavel Labath05ab2372015-07-06 15:57:52 +000070dotest_options = None
Zachary Turner38e64172015-08-10 17:46:11 +000071output_on_success = False
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +000072
Chaoren Linffc63b02015-08-12 18:02:49 +000073def setup_global_variables(lock, counter, total, name_len, options):
74 global output_lock, test_counter, total_tests, test_name_len
75 global dotest_options
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +000076 output_lock = lock
77 test_counter = counter
78 total_tests = total
Chaoren Linffc63b02015-08-12 18:02:49 +000079 test_name_len = name_len
Pavel Labath05ab2372015-07-06 15:57:52 +000080 dotest_options = options
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +000081
Zachary Turner38e64172015-08-10 17:46:11 +000082def report_test_failure(name, command, output):
83 global output_lock
84 with output_lock:
Chaoren Linffc63b02015-08-12 18:02:49 +000085 print >> sys.stderr
Zachary Turner38e64172015-08-10 17:46:11 +000086 print >> sys.stderr, output
Chaoren Linffc63b02015-08-12 18:02:49 +000087 print >> sys.stderr, "[%s FAILED]" % name
Zachary Turner38e64172015-08-10 17:46:11 +000088 print >> sys.stderr, "Command invoked: %s" % ' '.join(command)
Chaoren Linffc63b02015-08-12 18:02:49 +000089 update_progress(name)
Zachary Turner38e64172015-08-10 17:46:11 +000090
91def report_test_pass(name, output):
92 global output_lock, output_on_success
93 with output_lock:
94 if output_on_success:
Chaoren Linffc63b02015-08-12 18:02:49 +000095 print >> sys.stderr
Zachary Turner38e64172015-08-10 17:46:11 +000096 print >> sys.stderr, output
Chaoren Linffc63b02015-08-12 18:02:49 +000097 print >> sys.stderr, "[%s PASSED]" % name
98 update_progress(name)
Zachary Turner38e64172015-08-10 17:46:11 +000099
Chaoren Linffc63b02015-08-12 18:02:49 +0000100def update_progress(test_name=""):
101 global output_lock, test_counter, total_tests, test_name_len
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +0000102 with output_lock:
Chaoren Linffc63b02015-08-12 18:02:49 +0000103 counter_len = len(str(total_tests))
104 sys.stderr.write(
105 "\r%*d out of %d test suites processed - %-*s" %
106 (counter_len, test_counter.value, total_tests,
107 test_name_len.value, test_name))
108 if len(test_name) > test_name_len.value:
109 test_name_len.value = len(test_name)
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +0000110 test_counter.value += 1
Zachary Turner38e64172015-08-10 17:46:11 +0000111 sys.stdout.flush()
112 sys.stderr.flush()
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +0000113
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000114def parse_test_results(output):
115 passes = 0
116 failures = 0
117 for result in output:
118 pass_count = re.search("^RESULT:.*([0-9]+) passes", result, re.MULTILINE)
119 fail_count = re.search("^RESULT:.*([0-9]+) failures", result, re.MULTILINE)
120 error_count = re.search("^RESULT:.*([0-9]+) errors", result, re.MULTILINE)
121 this_fail_count = 0
122 this_error_count = 0
123 if pass_count != None:
124 passes = passes + int(pass_count.group(1))
125 if fail_count != None:
126 failures = failures + int(fail_count.group(1))
127 if error_count != None:
128 failures = failures + int(error_count.group(1))
129 pass
130 return passes, failures
131
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +0000132def call_with_timeout(command, timeout, name):
Vince Harronede59652015-01-08 02:11:26 +0000133 """Run command with a timeout if possible."""
Vince Harrondcc2b9f2015-05-27 04:40:36 +0000134 """-s QUIT will create a coredump if they are enabled on your system"""
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000135 process = None
136 if timeout_command and timeout != "0":
137 command = [timeout_command, '-s', 'QUIT', timeout] + command
138 # Specifying a value for close_fds is unsupported on Windows when using subprocess.PIPE
Zachary Turnerdc494d52015-02-07 00:14:55 +0000139 if os.name != "nt":
Chaoren Lin9d2b7f92015-05-29 18:43:46 +0000140 process = subprocess.Popen(command, stdin=subprocess.PIPE,
141 stdout=subprocess.PIPE,
142 stderr=subprocess.PIPE,
143 close_fds=True)
Zachary Turnerdc494d52015-02-07 00:14:55 +0000144 else:
Chaoren Lin9d2b7f92015-05-29 18:43:46 +0000145 process = subprocess.Popen(command, stdin=subprocess.PIPE,
146 stdout=subprocess.PIPE,
147 stderr=subprocess.PIPE)
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000148 output = process.communicate()
149 exit_status = process.returncode
150 passes, failures = parse_test_results(output)
Zachary Turner38e64172015-08-10 17:46:11 +0000151 if exit_status == 0:
152 # stdout does not have any useful information from 'dotest.py', only stderr does.
153 report_test_pass(name, output[1])
154 else:
155 report_test_failure(name, command, output[1])
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000156 return exit_status, passes, failures
Johnny Chene8d9dc62011-10-31 19:04:07 +0000157
Vince Harron41657cc2015-05-21 18:15:09 +0000158def process_dir(root, files, test_root, dotest_argv):
Steve Puccibefe2b12014-03-07 00:01:11 +0000159 """Examine a directory for tests, and invoke any found within it."""
Vince Harron17f429f2014-12-13 00:08:19 +0000160 timed_out = []
Daniel Maleacbaef262013-02-15 21:31:37 +0000161 failed = []
162 passed = []
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000163 pass_sub_count = 0
164 fail_sub_count = 0
Steve Puccibefe2b12014-03-07 00:01:11 +0000165 for name in files:
Zachary Turnerf6896b02015-01-05 19:37:03 +0000166 script_file = os.path.join(test_root, "dotest.py")
Zachary Turnerf6896b02015-01-05 19:37:03 +0000167 command = ([sys.executable, script_file] +
Vince Harron41657cc2015-05-21 18:15:09 +0000168 dotest_argv +
Vince Harron17f429f2014-12-13 00:08:19 +0000169 ["-p", name, root])
170
171 timeout_name = os.path.basename(os.path.splitext(name)[0]).upper()
172
Pavel Labath05ab2372015-07-06 15:57:52 +0000173 timeout = os.getenv("LLDB_%s_TIMEOUT" % timeout_name) or getDefaultTimeout(dotest_options.lldb_platform_name)
Vince Harron17f429f2014-12-13 00:08:19 +0000174
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +0000175 exit_status, pass_count, fail_count = call_with_timeout(command, timeout, name)
Vince Harron17f429f2014-12-13 00:08:19 +0000176
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000177 pass_sub_count = pass_sub_count + pass_count
178 fail_sub_count = fail_sub_count + fail_count
179
180 if exit_status == ePassed:
Steve Puccibefe2b12014-03-07 00:01:11 +0000181 passed.append(name)
Vince Harron17f429f2014-12-13 00:08:19 +0000182 else:
183 if eTimedOut == exit_status:
184 timed_out.append(name)
185 failed.append(name)
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000186 return (timed_out, failed, passed, fail_sub_count, pass_sub_count)
Steve Puccibefe2b12014-03-07 00:01:11 +0000187
188in_q = None
189out_q = None
190
Todd Fiala3f0a3602014-07-08 06:42:37 +0000191def process_dir_worker(arg_tuple):
Steve Puccibefe2b12014-03-07 00:01:11 +0000192 """Worker thread main loop when in multithreaded mode.
193 Takes one directory specification at a time and works on it."""
Vince Harron41657cc2015-05-21 18:15:09 +0000194 (root, files, test_root, dotest_argv) = arg_tuple
195 return process_dir(root, files, test_root, dotest_argv)
Steve Puccibefe2b12014-03-07 00:01:11 +0000196
Vince Harron41657cc2015-05-21 18:15:09 +0000197def walk_and_invoke(test_directory, test_subdir, dotest_argv, num_threads):
Steve Puccibefe2b12014-03-07 00:01:11 +0000198 """Look for matched files and invoke test driver on each one.
199 In single-threaded mode, each test driver is invoked directly.
200 In multi-threaded mode, submit each test driver to a worker
Vince Harrone06a7a82015-05-12 23:12:19 +0000201 queue, and then wait for all to complete.
202
203 test_directory - lldb/test/ directory
204 test_subdir - lldb/test/ or a subfolder with the tests we're interested in running
205 """
Todd Fiala3f0a3602014-07-08 06:42:37 +0000206
207 # Collect the test files that we'll run.
208 test_work_items = []
Vince Harrone06a7a82015-05-12 23:12:19 +0000209 for root, dirs, files in os.walk(test_subdir, topdown=False):
Chaoren Linffc63b02015-08-12 18:02:49 +0000210 def is_test(name):
211 # Not interested in symbolically linked files.
212 if os.path.islink(os.path.join(root, name)):
213 return False
214 # Only interested in test files with the "Test*.py" naming pattern.
215 return name.startswith("Test") and name.endswith(".py")
Todd Fiala3f0a3602014-07-08 06:42:37 +0000216
Chaoren Linffc63b02015-08-12 18:02:49 +0000217 tests = filter(is_test, files)
218 test_work_items.append((root, tests, test_directory, dotest_argv))
219
220 global output_lock, test_counter, total_tests, test_name_len
Zachary Turner38e64172015-08-10 17:46:11 +0000221 output_lock = multiprocessing.RLock()
Chaoren Linffc63b02015-08-12 18:02:49 +0000222 # item = (root, tests, test_directory, dotest_argv)
223 total_tests = sum([len(item[1]) for item in test_work_items])
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +0000224 test_counter = multiprocessing.Value('i', 0)
Chaoren Linffc63b02015-08-12 18:02:49 +0000225 test_name_len = multiprocessing.Value('i', 0)
226 print >> sys.stderr, "Testing: %d test suites, %d thread%s" % (
227 total_tests, num_threads, (num_threads > 1) * "s")
228 update_progress()
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +0000229
Todd Fiala3f0a3602014-07-08 06:42:37 +0000230 # Run the items, either in a pool (for multicore speedup) or
231 # calling each individually.
232 if num_threads > 1:
Chaoren Linffc63b02015-08-12 18:02:49 +0000233 pool = multiprocessing.Pool(
234 num_threads,
235 initializer=setup_global_variables,
236 initargs=(output_lock, test_counter, total_tests, test_name_len,
237 dotest_options))
Todd Fiala3f0a3602014-07-08 06:42:37 +0000238 test_results = pool.map(process_dir_worker, test_work_items)
239 else:
240 test_results = []
241 for work_item in test_work_items:
242 test_results.append(process_dir_worker(work_item))
243
Vince Harron17f429f2014-12-13 00:08:19 +0000244 timed_out = []
Steve Puccibefe2b12014-03-07 00:01:11 +0000245 failed = []
246 passed = []
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000247 fail_sub_count = 0
248 pass_sub_count = 0
Todd Fiala3f0a3602014-07-08 06:42:37 +0000249
250 for test_result in test_results:
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000251 (dir_timed_out, dir_failed, dir_passed, dir_fail_sub_count, dir_pass_sub_count) = test_result
Vince Harron17f429f2014-12-13 00:08:19 +0000252 timed_out += dir_timed_out
Todd Fiala3f0a3602014-07-08 06:42:37 +0000253 failed += dir_failed
254 passed += dir_passed
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000255 fail_sub_count = fail_sub_count + dir_fail_sub_count
256 pass_sub_count = pass_sub_count + dir_pass_sub_count
Todd Fiala3f0a3602014-07-08 06:42:37 +0000257
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000258 return (timed_out, failed, passed, fail_sub_count, pass_sub_count)
Johnny Chene8d9dc62011-10-31 19:04:07 +0000259
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000260def getExpectedTimeouts(platform_name):
Vince Harron06381732015-05-12 23:10:36 +0000261 # returns a set of test filenames that might timeout
262 # are we running against a remote target?
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000263 if platform_name is None:
Vince Harron06381732015-05-12 23:10:36 +0000264 target = sys.platform
265 remote = False
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000266 else:
267 m = re.search('remote-(\w+)', platform_name)
268 target = m.group(1)
269 remote = True
Vince Harron06381732015-05-12 23:10:36 +0000270
271 expected_timeout = set()
272
273 if target.startswith("linux"):
274 expected_timeout |= {
Vince Harronde92b522015-05-13 23:59:03 +0000275 "TestAttachDenied.py",
Vince Harron06381732015-05-12 23:10:36 +0000276 "TestAttachResume.py",
Chaoren Lin0b8bb3d2015-07-22 20:52:17 +0000277 "TestProcessAttach.py",
Vince Harron06381732015-05-12 23:10:36 +0000278 "TestConnectRemote.py",
279 "TestCreateAfterAttach.py",
Tamas Berghammer0d0ec9f2015-05-19 10:49:40 +0000280 "TestEvents.py",
Vince Harron06381732015-05-12 23:10:36 +0000281 "TestExitDuringStep.py",
Tamas Berghammer0b11db52015-06-02 14:45:25 +0000282 "TestHelloWorld.py", # Times out in ~10% of the times on the build bot
Oleksiy Vyalov18f4c9f2015-06-10 01:34:25 +0000283 "TestMultithreaded.py",
Vince Harrone8843892015-06-22 20:54:14 +0000284 "TestRegisters.py", # ~12/600 dosep runs (build 3120-3122)
Vince Harron06381732015-05-12 23:10:36 +0000285 "TestThreadStepOut.py",
286 }
287 elif target.startswith("android"):
288 expected_timeout |= {
289 "TestExitDuringStep.py",
290 "TestHelloWorld.py",
291 }
Ed Maste4dd8fba2015-05-14 16:25:52 +0000292 elif target.startswith("freebsd"):
293 expected_timeout |= {
294 "TestBreakpointConditions.py",
Ed Maste08948132015-05-28 18:45:30 +0000295 "TestChangeProcessGroup.py",
Ed Mastebfd05632015-05-27 19:11:29 +0000296 "TestValueObjectRecursion.py",
Ed Maste4dd8fba2015-05-14 16:25:52 +0000297 "TestWatchpointConditionAPI.py",
298 }
Vince Harron0f173ac2015-05-18 19:36:33 +0000299 elif target.startswith("darwin"):
300 expected_timeout |= {
301 "TestThreadSpecificBreakpoint.py", # times out on MBP Retina, Mid 2012
302 }
Vince Harron06381732015-05-12 23:10:36 +0000303 return expected_timeout
304
Pavel Labathfad30cf2015-06-29 14:16:51 +0000305def getDefaultTimeout(platform_name):
306 if os.getenv("LLDB_TEST_TIMEOUT"):
307 return os.getenv("LLDB_TEST_TIMEOUT")
308
309 if platform_name is None:
310 platform_name = sys.platform
311
312 if platform_name.startswith("remote-"):
313 return "10m"
314 else:
315 return "4m"
316
Vince Harron0b9dbb52015-05-21 18:18:52 +0000317def touch(fname, times=None):
Greg Clayton8c3f9c92015-08-11 21:01:32 +0000318 if os.path.exists(fname):
Vince Harron0b9dbb52015-05-21 18:18:52 +0000319 os.utime(fname, times)
320
Vince Harrondcc2b9f2015-05-27 04:40:36 +0000321def find(pattern, path):
322 result = []
323 for root, dirs, files in os.walk(path):
324 for name in files:
325 if fnmatch.fnmatch(name, pattern):
326 result.append(os.path.join(root, name))
327 return result
328
Johnny Chene8d9dc62011-10-31 19:04:07 +0000329def main():
Vince Harrond5fa1022015-05-10 15:24:12 +0000330 # We can't use sys.path[0] to determine the script directory
331 # because it doesn't work under a debugger
Vince Harrone06a7a82015-05-12 23:12:19 +0000332 test_directory = os.path.dirname(os.path.realpath(__file__))
Johnny Chene8d9dc62011-10-31 19:04:07 +0000333 parser = OptionParser(usage="""\
334Run lldb test suite using a separate process for each test file.
Vince Harronede59652015-01-08 02:11:26 +0000335
Siva Chandra2d7832e2015-05-08 23:08:53 +0000336 Each test will run with a time limit of 10 minutes by default.
Vince Harronede59652015-01-08 02:11:26 +0000337
Siva Chandra2d7832e2015-05-08 23:08:53 +0000338 Override the default time limit of 10 minutes by setting
Vince Harronede59652015-01-08 02:11:26 +0000339 the environment variable LLDB_TEST_TIMEOUT.
340
341 E.g., export LLDB_TEST_TIMEOUT=10m
342
343 Override the time limit for individual tests by setting
344 the environment variable LLDB_[TEST NAME]_TIMEOUT.
345
346 E.g., export LLDB_TESTCONCURRENTEVENTS_TIMEOUT=2m
347
348 Set to "0" to run without time limit.
349
350 E.g., export LLDB_TEST_TIMEOUT=0
351 or export LLDB_TESTCONCURRENTEVENTS_TIMEOUT=0
Johnny Chene8d9dc62011-10-31 19:04:07 +0000352""")
353 parser.add_option('-o', '--options',
354 type='string', action='store',
355 dest='dotest_options',
356 help="""The options passed to 'dotest.py' if specified.""")
357
Zachary Turner38e64172015-08-10 17:46:11 +0000358 parser.add_option('-s', '--output-on-success',
359 action='store_true',
360 dest='output_on_success',
361 default=False,
362 help="""Print full output of 'dotest.py' even when it succeeds.""")
363
Greg Clayton2256d0d2014-03-24 23:01:57 +0000364 parser.add_option('-t', '--threads',
365 type='int',
366 dest='num_threads',
Ed Mastecec2a5b2014-11-21 02:41:25 +0000367 help="""The number of threads to use when running tests separately.""")
Greg Clayton2256d0d2014-03-24 23:01:57 +0000368
Johnny Chene8d9dc62011-10-31 19:04:07 +0000369 opts, args = parser.parse_args()
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000370 dotest_option_string = opts.dotest_options
371
Vince Harron41657cc2015-05-21 18:15:09 +0000372 is_posix = (os.name == "posix")
373 dotest_argv = shlex.split(dotest_option_string, posix=is_posix) if dotest_option_string else []
Vince Harron8994fed2015-05-22 19:49:23 +0000374
375 parser = dotest_args.create_parser()
Pavel Labath05ab2372015-07-06 15:57:52 +0000376 global dotest_options
Zachary Turner38e64172015-08-10 17:46:11 +0000377 global output_on_success
378 output_on_success = opts.output_on_success
Vince Harron8994fed2015-05-22 19:49:23 +0000379 dotest_options = dotest_args.parse_args(parser, dotest_argv)
380
Vince Harron41657cc2015-05-21 18:15:09 +0000381 if not dotest_options.s:
382 # no session log directory, we need to add this to prevent
383 # every dotest invocation from creating its own directory
384 import datetime
385 # The windows platforms don't like ':' in the pathname.
386 timestamp_started = datetime.datetime.now().strftime("%Y-%m-%d-%H_%M_%S")
387 dotest_argv.append('-s')
388 dotest_argv.append(timestamp_started)
Vince Harron0b9dbb52015-05-21 18:18:52 +0000389 dotest_options.s = timestamp_started
390
391 session_dir = os.path.join(os.getcwd(), dotest_options.s)
Ed Mastecec2a5b2014-11-21 02:41:25 +0000392
Vince Harrone06a7a82015-05-12 23:12:19 +0000393 # The root directory was specified on the command line
394 if len(args) == 0:
395 test_subdir = test_directory
396 else:
397 test_subdir = os.path.join(test_directory, args[0])
398
Vince Harrondcc2b9f2015-05-27 04:40:36 +0000399 # clean core files in test tree from previous runs (Linux)
400 cores = find('core.*', test_subdir)
401 for core in cores:
402 os.unlink(core)
403
Ed Mastecec2a5b2014-11-21 02:41:25 +0000404 if opts.num_threads:
405 num_threads = opts.num_threads
406 else:
Greg Clayton2256d0d2014-03-24 23:01:57 +0000407 num_threads_str = os.environ.get("LLDB_TEST_THREADS")
408 if num_threads_str:
409 num_threads = int(num_threads_str)
Greg Clayton2256d0d2014-03-24 23:01:57 +0000410 else:
Ed Mastecec2a5b2014-11-21 02:41:25 +0000411 num_threads = multiprocessing.cpu_count()
412 if num_threads < 1:
413 num_threads = 1
Johnny Chene8d9dc62011-10-31 19:04:07 +0000414
Daniel Maleab42556f2013-04-19 18:32:53 +0000415 system_info = " ".join(platform.uname())
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000416 (timed_out, failed, passed, all_fails, all_passes) = walk_and_invoke(test_directory, test_subdir, dotest_argv, num_threads)
417
Vince Harron17f429f2014-12-13 00:08:19 +0000418 timed_out = set(timed_out)
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000419 num_test_files = len(failed) + len(passed)
420 num_tests = all_fails + all_passes
Daniel Maleab42556f2013-04-19 18:32:53 +0000421
Vince Harrondcc2b9f2015-05-27 04:40:36 +0000422 # move core files into session dir
423 cores = find('core.*', test_subdir)
424 for core in cores:
425 dst = core.replace(test_directory, "")[1:]
426 dst = dst.replace(os.path.sep, "-")
427 os.rename(core, os.path.join(session_dir, dst))
428
Vince Harron06381732015-05-12 23:10:36 +0000429 # remove expected timeouts from failures
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000430 expected_timeout = getExpectedTimeouts(dotest_options.lldb_platform_name)
Vince Harron06381732015-05-12 23:10:36 +0000431 for xtime in expected_timeout:
432 if xtime in timed_out:
433 timed_out.remove(xtime)
434 failed.remove(xtime)
Vince Harron0b9dbb52015-05-21 18:18:52 +0000435 result = "ExpectedTimeout"
436 elif xtime in passed:
437 result = "UnexpectedCompletion"
438 else:
439 result = None # failed
440
441 if result:
442 test_name = os.path.splitext(xtime)[0]
443 touch(os.path.join(session_dir, "{}-{}".format(result, test_name)))
Vince Harron06381732015-05-12 23:10:36 +0000444
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +0000445 print
Chaoren Lin5a59e462015-08-12 18:02:51 +0000446 sys.stdout.write("Ran %d test suites" % num_test_files)
447 if num_test_files > 0:
448 sys.stdout.write(" (%d failed) (%f%%)" % (
449 len(failed), 100.0 * len(failed) / num_test_files))
450 print
451 sys.stdout.write("Ran %d test cases" % num_tests)
452 if num_tests > 0:
453 sys.stdout.write(" (%d failed) (%f%%)" % (
454 all_fails, 100.0 * all_fails / num_tests))
455 print
Daniel Maleacbaef262013-02-15 21:31:37 +0000456 if len(failed) > 0:
Shawn Best13491c42014-10-22 19:29:00 +0000457 failed.sort()
Ying Chen10ed1a92015-05-28 23:51:49 +0000458 print "Failing Tests (%d)" % len(failed)
Daniel Maleacbaef262013-02-15 21:31:37 +0000459 for f in failed:
Vince Harron17f429f2014-12-13 00:08:19 +0000460 print "%s: LLDB (suite) :: %s (%s)" % (
461 "TIMEOUT" if f in timed_out else "FAIL", f, system_info
462 )
Daniel Maleacbaef262013-02-15 21:31:37 +0000463 sys.exit(1)
464 sys.exit(0)
Johnny Chene8d9dc62011-10-31 19:04:07 +0000465
466if __name__ == '__main__':
467 main()