blob: d2f7644ed7e4757a2ce2f8ef970b3533dfe71656 [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
124 for result in output:
Chaoren Linb6325d02015-08-12 18:02:54 +0000125 pass_count = re.search("^RESULT:.*([0-9]+) passes",
126 result, re.MULTILINE)
127 fail_count = re.search("^RESULT:.*([0-9]+) failures",
128 result, re.MULTILINE)
129 error_count = re.search("^RESULT:.*([0-9]+) errors",
130 result, re.MULTILINE)
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000131 this_fail_count = 0
132 this_error_count = 0
Chaoren Linb6325d02015-08-12 18:02:54 +0000133 if pass_count is not None:
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000134 passes = passes + int(pass_count.group(1))
Chaoren Linb6325d02015-08-12 18:02:54 +0000135 if fail_count is not None:
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000136 failures = failures + int(fail_count.group(1))
Chaoren Linb6325d02015-08-12 18:02:54 +0000137 if error_count is not None:
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000138 failures = failures + int(error_count.group(1))
139 pass
140 return passes, failures
141
Chaoren Linb6325d02015-08-12 18:02:54 +0000142
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +0000143def call_with_timeout(command, timeout, name):
Vince Harronede59652015-01-08 02:11:26 +0000144 """Run command with a timeout if possible."""
Vince Harrondcc2b9f2015-05-27 04:40:36 +0000145 """-s QUIT will create a coredump if they are enabled on your system"""
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000146 process = None
147 if timeout_command and timeout != "0":
148 command = [timeout_command, '-s', 'QUIT', timeout] + command
Chaoren Linb6325d02015-08-12 18:02:54 +0000149 # Specifying a value for close_fds is unsupported on Windows when using
150 # subprocess.PIPE
Zachary Turnerdc494d52015-02-07 00:14:55 +0000151 if os.name != "nt":
Chaoren Linb6325d02015-08-12 18:02:54 +0000152 process = subprocess.Popen(command,
153 stdin=subprocess.PIPE,
154 stdout=subprocess.PIPE,
155 stderr=subprocess.PIPE,
156 close_fds=True)
Zachary Turnerdc494d52015-02-07 00:14:55 +0000157 else:
Chaoren Linb6325d02015-08-12 18:02:54 +0000158 process = subprocess.Popen(command,
159 stdin=subprocess.PIPE,
160 stdout=subprocess.PIPE,
161 stderr=subprocess.PIPE)
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000162 output = process.communicate()
163 exit_status = process.returncode
164 passes, failures = parse_test_results(output)
Zachary Turner38e64172015-08-10 17:46:11 +0000165 if exit_status == 0:
Chaoren Linb6325d02015-08-12 18:02:54 +0000166 # stdout does not have any useful information from 'dotest.py',
167 # only stderr does.
Zachary Turner38e64172015-08-10 17:46:11 +0000168 report_test_pass(name, output[1])
169 else:
170 report_test_failure(name, command, output[1])
Chaoren Line80372a2015-08-12 18:02:53 +0000171 return name, exit_status, passes, failures
Johnny Chene8d9dc62011-10-31 19:04:07 +0000172
Chaoren Linb6325d02015-08-12 18:02:54 +0000173
Vince Harron41657cc2015-05-21 18:15:09 +0000174def process_dir(root, files, test_root, dotest_argv):
Steve Puccibefe2b12014-03-07 00:01:11 +0000175 """Examine a directory for tests, and invoke any found within it."""
Chaoren Line80372a2015-08-12 18:02:53 +0000176 results = []
Steve Puccibefe2b12014-03-07 00:01:11 +0000177 for name in files:
Zachary Turnerf6896b02015-01-05 19:37:03 +0000178 script_file = os.path.join(test_root, "dotest.py")
Zachary Turnerf6896b02015-01-05 19:37:03 +0000179 command = ([sys.executable, script_file] +
Vince Harron41657cc2015-05-21 18:15:09 +0000180 dotest_argv +
Vince Harron17f429f2014-12-13 00:08:19 +0000181 ["-p", name, root])
182
183 timeout_name = os.path.basename(os.path.splitext(name)[0]).upper()
184
Chaoren Linb6325d02015-08-12 18:02:54 +0000185 timeout = (os.getenv("LLDB_%s_TIMEOUT" % timeout_name) or
186 getDefaultTimeout(dotest_options.lldb_platform_name))
Vince Harron17f429f2014-12-13 00:08:19 +0000187
Chaoren Line80372a2015-08-12 18:02:53 +0000188 results.append(call_with_timeout(command, timeout, name))
Vince Harron17f429f2014-12-13 00:08:19 +0000189
Chaoren Line80372a2015-08-12 18:02:53 +0000190 # result = (name, status, passes, failures)
191 timed_out = [name for name, status, _, _ in results
192 if status == eTimedOut]
193 passed = [name for name, status, _, _ in results
194 if status == ePassed]
195 failed = [name for name, status, _, _ in results
196 if status != ePassed]
197 pass_count = sum([result[2] for result in results])
198 fail_count = sum([result[3] for result in results])
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000199
Chaoren Line80372a2015-08-12 18:02:53 +0000200 return (timed_out, passed, failed, pass_count, fail_count)
Steve Puccibefe2b12014-03-07 00:01:11 +0000201
202in_q = None
203out_q = None
204
Chaoren Linb6325d02015-08-12 18:02:54 +0000205
Todd Fiala3f0a3602014-07-08 06:42:37 +0000206def process_dir_worker(arg_tuple):
Steve Puccibefe2b12014-03-07 00:01:11 +0000207 """Worker thread main loop when in multithreaded mode.
208 Takes one directory specification at a time and works on it."""
Chaoren Line80372a2015-08-12 18:02:53 +0000209 return process_dir(*arg_tuple)
Steve Puccibefe2b12014-03-07 00:01:11 +0000210
Chaoren Linb6325d02015-08-12 18:02:54 +0000211
Vince Harron41657cc2015-05-21 18:15:09 +0000212def walk_and_invoke(test_directory, test_subdir, dotest_argv, num_threads):
Steve Puccibefe2b12014-03-07 00:01:11 +0000213 """Look for matched files and invoke test driver on each one.
214 In single-threaded mode, each test driver is invoked directly.
215 In multi-threaded mode, submit each test driver to a worker
Vince Harrone06a7a82015-05-12 23:12:19 +0000216 queue, and then wait for all to complete.
217
218 test_directory - lldb/test/ directory
Chaoren Linb6325d02015-08-12 18:02:54 +0000219 test_subdir - lldb/test/ or a subfolder with the tests we're interested in
220 running
Vince Harrone06a7a82015-05-12 23:12:19 +0000221 """
Todd Fiala3f0a3602014-07-08 06:42:37 +0000222
223 # Collect the test files that we'll run.
224 test_work_items = []
Vince Harrone06a7a82015-05-12 23:12:19 +0000225 for root, dirs, files in os.walk(test_subdir, topdown=False):
Chaoren Linffc63b02015-08-12 18:02:49 +0000226 def is_test(name):
227 # Not interested in symbolically linked files.
228 if os.path.islink(os.path.join(root, name)):
229 return False
230 # Only interested in test files with the "Test*.py" naming pattern.
231 return name.startswith("Test") and name.endswith(".py")
Todd Fiala3f0a3602014-07-08 06:42:37 +0000232
Chaoren Linffc63b02015-08-12 18:02:49 +0000233 tests = filter(is_test, files)
234 test_work_items.append((root, tests, test_directory, dotest_argv))
235
236 global output_lock, test_counter, total_tests, test_name_len
Zachary Turner38e64172015-08-10 17:46:11 +0000237 output_lock = multiprocessing.RLock()
Chaoren Linffc63b02015-08-12 18:02:49 +0000238 # item = (root, tests, test_directory, dotest_argv)
239 total_tests = sum([len(item[1]) for item in test_work_items])
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +0000240 test_counter = multiprocessing.Value('i', 0)
Chaoren Linffc63b02015-08-12 18:02:49 +0000241 test_name_len = multiprocessing.Value('i', 0)
242 print >> sys.stderr, "Testing: %d test suites, %d thread%s" % (
243 total_tests, num_threads, (num_threads > 1) * "s")
244 update_progress()
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +0000245
Todd Fiala3f0a3602014-07-08 06:42:37 +0000246 # Run the items, either in a pool (for multicore speedup) or
247 # calling each individually.
248 if num_threads > 1:
Chaoren Linffc63b02015-08-12 18:02:49 +0000249 pool = multiprocessing.Pool(
250 num_threads,
251 initializer=setup_global_variables,
252 initargs=(output_lock, test_counter, total_tests, test_name_len,
253 dotest_options))
Todd Fiala3f0a3602014-07-08 06:42:37 +0000254 test_results = pool.map(process_dir_worker, test_work_items)
255 else:
Chaoren Line80372a2015-08-12 18:02:53 +0000256 test_results = map(process_dir_worker, test_work_items)
Todd Fiala3f0a3602014-07-08 06:42:37 +0000257
Chaoren Line80372a2015-08-12 18:02:53 +0000258 # result = (timed_out, failed, passed, fail_count, pass_count)
259 timed_out = sum([result[0] for result in test_results], [])
260 passed = sum([result[1] for result in test_results], [])
261 failed = sum([result[2] for result in test_results], [])
262 pass_count = sum([result[3] for result in test_results])
263 fail_count = sum([result[4] for result in test_results])
Todd Fiala3f0a3602014-07-08 06:42:37 +0000264
Chaoren Line80372a2015-08-12 18:02:53 +0000265 return (timed_out, passed, failed, pass_count, fail_count)
Johnny Chene8d9dc62011-10-31 19:04:07 +0000266
Chaoren Linb6325d02015-08-12 18:02:54 +0000267
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000268def getExpectedTimeouts(platform_name):
Vince Harron06381732015-05-12 23:10:36 +0000269 # returns a set of test filenames that might timeout
270 # are we running against a remote target?
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000271 if platform_name is None:
Vince Harron06381732015-05-12 23:10:36 +0000272 target = sys.platform
273 remote = False
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000274 else:
275 m = re.search('remote-(\w+)', platform_name)
276 target = m.group(1)
277 remote = True
Vince Harron06381732015-05-12 23:10:36 +0000278
279 expected_timeout = set()
280
281 if target.startswith("linux"):
282 expected_timeout |= {
Vince Harronde92b522015-05-13 23:59:03 +0000283 "TestAttachDenied.py",
Vince Harron06381732015-05-12 23:10:36 +0000284 "TestAttachResume.py",
Chaoren Lin0b8bb3d2015-07-22 20:52:17 +0000285 "TestProcessAttach.py",
Vince Harron06381732015-05-12 23:10:36 +0000286 "TestConnectRemote.py",
287 "TestCreateAfterAttach.py",
Tamas Berghammer0d0ec9f2015-05-19 10:49:40 +0000288 "TestEvents.py",
Vince Harron06381732015-05-12 23:10:36 +0000289 "TestExitDuringStep.py",
Chaoren Linb6325d02015-08-12 18:02:54 +0000290
291 # Times out in ~10% of the times on the build bot
292 "TestHelloWorld.py",
Oleksiy Vyalov18f4c9f2015-06-10 01:34:25 +0000293 "TestMultithreaded.py",
Chaoren Linb6325d02015-08-12 18:02:54 +0000294 "TestRegisters.py", # ~12/600 dosep runs (build 3120-3122)
Vince Harron06381732015-05-12 23:10:36 +0000295 "TestThreadStepOut.py",
296 }
297 elif target.startswith("android"):
298 expected_timeout |= {
299 "TestExitDuringStep.py",
300 "TestHelloWorld.py",
301 }
Ed Maste4dd8fba2015-05-14 16:25:52 +0000302 elif target.startswith("freebsd"):
303 expected_timeout |= {
304 "TestBreakpointConditions.py",
Ed Maste08948132015-05-28 18:45:30 +0000305 "TestChangeProcessGroup.py",
Ed Mastebfd05632015-05-27 19:11:29 +0000306 "TestValueObjectRecursion.py",
Ed Maste4dd8fba2015-05-14 16:25:52 +0000307 "TestWatchpointConditionAPI.py",
308 }
Vince Harron0f173ac2015-05-18 19:36:33 +0000309 elif target.startswith("darwin"):
310 expected_timeout |= {
Chaoren Linb6325d02015-08-12 18:02:54 +0000311 # times out on MBP Retina, Mid 2012
312 "TestThreadSpecificBreakpoint.py",
Vince Harron0f173ac2015-05-18 19:36:33 +0000313 }
Vince Harron06381732015-05-12 23:10:36 +0000314 return expected_timeout
315
Chaoren Linb6325d02015-08-12 18:02:54 +0000316
Pavel Labathfad30cf2015-06-29 14:16:51 +0000317def getDefaultTimeout(platform_name):
318 if os.getenv("LLDB_TEST_TIMEOUT"):
319 return os.getenv("LLDB_TEST_TIMEOUT")
320
321 if platform_name is None:
322 platform_name = sys.platform
323
324 if platform_name.startswith("remote-"):
325 return "10m"
326 else:
327 return "4m"
328
Chaoren Linb6325d02015-08-12 18:02:54 +0000329
Vince Harron0b9dbb52015-05-21 18:18:52 +0000330def touch(fname, times=None):
Greg Clayton8c3f9c92015-08-11 21:01:32 +0000331 if os.path.exists(fname):
Vince Harron0b9dbb52015-05-21 18:18:52 +0000332 os.utime(fname, times)
333
Chaoren Linb6325d02015-08-12 18:02:54 +0000334
Vince Harrondcc2b9f2015-05-27 04:40:36 +0000335def find(pattern, path):
336 result = []
337 for root, dirs, files in os.walk(path):
338 for name in files:
339 if fnmatch.fnmatch(name, pattern):
340 result.append(os.path.join(root, name))
341 return result
342
Chaoren Linb6325d02015-08-12 18:02:54 +0000343
Johnny Chene8d9dc62011-10-31 19:04:07 +0000344def main():
Vince Harrond5fa1022015-05-10 15:24:12 +0000345 # We can't use sys.path[0] to determine the script directory
346 # because it doesn't work under a debugger
Vince Harrone06a7a82015-05-12 23:12:19 +0000347 test_directory = os.path.dirname(os.path.realpath(__file__))
Johnny Chene8d9dc62011-10-31 19:04:07 +0000348 parser = OptionParser(usage="""\
349Run lldb test suite using a separate process for each test file.
Vince Harronede59652015-01-08 02:11:26 +0000350
Siva Chandra2d7832e2015-05-08 23:08:53 +0000351 Each test will run with a time limit of 10 minutes by default.
Vince Harronede59652015-01-08 02:11:26 +0000352
Siva Chandra2d7832e2015-05-08 23:08:53 +0000353 Override the default time limit of 10 minutes by setting
Vince Harronede59652015-01-08 02:11:26 +0000354 the environment variable LLDB_TEST_TIMEOUT.
355
356 E.g., export LLDB_TEST_TIMEOUT=10m
357
358 Override the time limit for individual tests by setting
359 the environment variable LLDB_[TEST NAME]_TIMEOUT.
360
361 E.g., export LLDB_TESTCONCURRENTEVENTS_TIMEOUT=2m
362
363 Set to "0" to run without time limit.
364
365 E.g., export LLDB_TEST_TIMEOUT=0
366 or export LLDB_TESTCONCURRENTEVENTS_TIMEOUT=0
Johnny Chene8d9dc62011-10-31 19:04:07 +0000367""")
Chaoren Linb6325d02015-08-12 18:02:54 +0000368 parser.add_option(
369 '-o', '--options',
370 type='string', action='store',
371 dest='dotest_options',
372 help="""The options passed to 'dotest.py' if specified.""")
Johnny Chene8d9dc62011-10-31 19:04:07 +0000373
Chaoren Linb6325d02015-08-12 18:02:54 +0000374 parser.add_option(
375 '-s', '--output-on-success',
376 action='store_true',
377 dest='output_on_success',
378 default=False,
379 help="""Print full output of 'dotest.py' even when it succeeds.""")
Zachary Turner38e64172015-08-10 17:46:11 +0000380
Chaoren Linb6325d02015-08-12 18:02:54 +0000381 parser.add_option(
382 '-t', '--threads',
383 type='int',
384 dest='num_threads',
385 help="""The number of threads to use when running tests separately.""")
Greg Clayton2256d0d2014-03-24 23:01:57 +0000386
Johnny Chene8d9dc62011-10-31 19:04:07 +0000387 opts, args = parser.parse_args()
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000388 dotest_option_string = opts.dotest_options
389
Vince Harron41657cc2015-05-21 18:15:09 +0000390 is_posix = (os.name == "posix")
Chaoren Linb6325d02015-08-12 18:02:54 +0000391 dotest_argv = (shlex.split(dotest_option_string, posix=is_posix)
392 if dotest_option_string
393 else [])
Vince Harron8994fed2015-05-22 19:49:23 +0000394
395 parser = dotest_args.create_parser()
Pavel Labath05ab2372015-07-06 15:57:52 +0000396 global dotest_options
Zachary Turner38e64172015-08-10 17:46:11 +0000397 global output_on_success
398 output_on_success = opts.output_on_success
Vince Harron8994fed2015-05-22 19:49:23 +0000399 dotest_options = dotest_args.parse_args(parser, dotest_argv)
400
Vince Harron41657cc2015-05-21 18:15:09 +0000401 if not dotest_options.s:
402 # no session log directory, we need to add this to prevent
403 # every dotest invocation from creating its own directory
404 import datetime
405 # The windows platforms don't like ':' in the pathname.
Chaoren Linb6325d02015-08-12 18:02:54 +0000406 timestamp_started = datetime.datetime.now().strftime("%F-%H_%M_%S")
Vince Harron41657cc2015-05-21 18:15:09 +0000407 dotest_argv.append('-s')
408 dotest_argv.append(timestamp_started)
Vince Harron0b9dbb52015-05-21 18:18:52 +0000409 dotest_options.s = timestamp_started
410
411 session_dir = os.path.join(os.getcwd(), dotest_options.s)
Ed Mastecec2a5b2014-11-21 02:41:25 +0000412
Vince Harrone06a7a82015-05-12 23:12:19 +0000413 # The root directory was specified on the command line
414 if len(args) == 0:
415 test_subdir = test_directory
416 else:
417 test_subdir = os.path.join(test_directory, args[0])
418
Vince Harrondcc2b9f2015-05-27 04:40:36 +0000419 # clean core files in test tree from previous runs (Linux)
420 cores = find('core.*', test_subdir)
421 for core in cores:
422 os.unlink(core)
423
Ed Mastecec2a5b2014-11-21 02:41:25 +0000424 if opts.num_threads:
425 num_threads = opts.num_threads
426 else:
Greg Clayton2256d0d2014-03-24 23:01:57 +0000427 num_threads_str = os.environ.get("LLDB_TEST_THREADS")
428 if num_threads_str:
429 num_threads = int(num_threads_str)
Greg Clayton2256d0d2014-03-24 23:01:57 +0000430 else:
Ed Mastecec2a5b2014-11-21 02:41:25 +0000431 num_threads = multiprocessing.cpu_count()
432 if num_threads < 1:
433 num_threads = 1
Johnny Chene8d9dc62011-10-31 19:04:07 +0000434
Daniel Maleab42556f2013-04-19 18:32:53 +0000435 system_info = " ".join(platform.uname())
Chaoren Line80372a2015-08-12 18:02:53 +0000436 (timed_out, passed, failed, pass_count, fail_count) = walk_and_invoke(
437 test_directory, test_subdir, dotest_argv, num_threads)
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000438
Vince Harron17f429f2014-12-13 00:08:19 +0000439 timed_out = set(timed_out)
Chaoren Line80372a2015-08-12 18:02:53 +0000440 num_test_files = len(passed) + len(failed)
441 num_test_cases = pass_count + fail_count
Daniel Maleab42556f2013-04-19 18:32:53 +0000442
Vince Harrondcc2b9f2015-05-27 04:40:36 +0000443 # move core files into session dir
444 cores = find('core.*', test_subdir)
445 for core in cores:
446 dst = core.replace(test_directory, "")[1:]
447 dst = dst.replace(os.path.sep, "-")
448 os.rename(core, os.path.join(session_dir, dst))
449
Vince Harron06381732015-05-12 23:10:36 +0000450 # remove expected timeouts from failures
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000451 expected_timeout = getExpectedTimeouts(dotest_options.lldb_platform_name)
Vince Harron06381732015-05-12 23:10:36 +0000452 for xtime in expected_timeout:
453 if xtime in timed_out:
454 timed_out.remove(xtime)
455 failed.remove(xtime)
Vince Harron0b9dbb52015-05-21 18:18:52 +0000456 result = "ExpectedTimeout"
457 elif xtime in passed:
458 result = "UnexpectedCompletion"
459 else:
460 result = None # failed
461
462 if result:
463 test_name = os.path.splitext(xtime)[0]
464 touch(os.path.join(session_dir, "{}-{}".format(result, test_name)))
Vince Harron06381732015-05-12 23:10:36 +0000465
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +0000466 print
Chaoren Lin5a59e462015-08-12 18:02:51 +0000467 sys.stdout.write("Ran %d test suites" % num_test_files)
468 if num_test_files > 0:
469 sys.stdout.write(" (%d failed) (%f%%)" % (
470 len(failed), 100.0 * len(failed) / num_test_files))
471 print
Chaoren Line80372a2015-08-12 18:02:53 +0000472 sys.stdout.write("Ran %d test cases" % num_test_cases)
473 if num_test_cases > 0:
Chaoren Lin5a59e462015-08-12 18:02:51 +0000474 sys.stdout.write(" (%d failed) (%f%%)" % (
Chaoren Line80372a2015-08-12 18:02:53 +0000475 fail_count, 100.0 * fail_count / num_test_cases))
Chaoren Lin5a59e462015-08-12 18:02:51 +0000476 print
Daniel Maleacbaef262013-02-15 21:31:37 +0000477 if len(failed) > 0:
Shawn Best13491c42014-10-22 19:29:00 +0000478 failed.sort()
Ying Chen10ed1a92015-05-28 23:51:49 +0000479 print "Failing Tests (%d)" % len(failed)
Daniel Maleacbaef262013-02-15 21:31:37 +0000480 for f in failed:
Vince Harron17f429f2014-12-13 00:08:19 +0000481 print "%s: LLDB (suite) :: %s (%s)" % (
482 "TIMEOUT" if f in timed_out else "FAIL", f, system_info
483 )
Daniel Maleacbaef262013-02-15 21:31:37 +0000484 sys.exit(1)
485 sys.exit(0)
Johnny Chene8d9dc62011-10-31 19:04:07 +0000486
487if __name__ == '__main__':
488 main()