blob: d123f2c7dc71689762f5837842617cee0c4f051f [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?
Chaoren Linfebef1b2015-08-19 17:22:12 +0000280 host = sys.platform
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000281 if platform_name is None:
Vince Harron06381732015-05-12 23:10:36 +0000282 target = sys.platform
283 remote = False
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000284 else:
285 m = re.search('remote-(\w+)', platform_name)
286 target = m.group(1)
287 remote = True
Vince Harron06381732015-05-12 23:10:36 +0000288
289 expected_timeout = set()
290
291 if target.startswith("linux"):
292 expected_timeout |= {
Vince Harronde92b522015-05-13 23:59:03 +0000293 "TestAttachDenied.py",
Vince Harron06381732015-05-12 23:10:36 +0000294 "TestAttachResume.py",
Chaoren Lin0b8bb3d2015-07-22 20:52:17 +0000295 "TestProcessAttach.py",
Vince Harron06381732015-05-12 23:10:36 +0000296 "TestConnectRemote.py",
297 "TestCreateAfterAttach.py",
Tamas Berghammer0d0ec9f2015-05-19 10:49:40 +0000298 "TestEvents.py",
Vince Harron06381732015-05-12 23:10:36 +0000299 "TestExitDuringStep.py",
Chaoren Linb6325d02015-08-12 18:02:54 +0000300
301 # Times out in ~10% of the times on the build bot
302 "TestHelloWorld.py",
Oleksiy Vyalov18f4c9f2015-06-10 01:34:25 +0000303 "TestMultithreaded.py",
Chaoren Linb6325d02015-08-12 18:02:54 +0000304 "TestRegisters.py", # ~12/600 dosep runs (build 3120-3122)
Vince Harron06381732015-05-12 23:10:36 +0000305 "TestThreadStepOut.py",
Chaoren Linb0138022015-08-19 18:39:25 +0000306 "TestChangeProcessGroup.py",
Vince Harron06381732015-05-12 23:10:36 +0000307 }
308 elif target.startswith("android"):
309 expected_timeout |= {
310 "TestExitDuringStep.py",
311 "TestHelloWorld.py",
312 }
Chaoren Linfebef1b2015-08-19 17:22:12 +0000313 if host.startswith("win32"):
314 expected_timeout |= {
315 "TestEvents.py",
316 "TestThreadStates.py",
317 }
Ed Maste4dd8fba2015-05-14 16:25:52 +0000318 elif target.startswith("freebsd"):
319 expected_timeout |= {
320 "TestBreakpointConditions.py",
Ed Maste08948132015-05-28 18:45:30 +0000321 "TestChangeProcessGroup.py",
Ed Mastebfd05632015-05-27 19:11:29 +0000322 "TestValueObjectRecursion.py",
Ed Maste4dd8fba2015-05-14 16:25:52 +0000323 "TestWatchpointConditionAPI.py",
324 }
Vince Harron0f173ac2015-05-18 19:36:33 +0000325 elif target.startswith("darwin"):
326 expected_timeout |= {
Chaoren Linb6325d02015-08-12 18:02:54 +0000327 # times out on MBP Retina, Mid 2012
328 "TestThreadSpecificBreakpoint.py",
Chaoren Lind9043712015-08-19 17:13:02 +0000329 "TestExitDuringStep.py",
Chaoren Lin99f25be2015-08-20 01:26:57 +0000330 "TestIntegerTypesExpr.py",
Vince Harron0f173ac2015-05-18 19:36:33 +0000331 }
Vince Harron06381732015-05-12 23:10:36 +0000332 return expected_timeout
333
Chaoren Linb6325d02015-08-12 18:02:54 +0000334
Pavel Labathfad30cf2015-06-29 14:16:51 +0000335def getDefaultTimeout(platform_name):
336 if os.getenv("LLDB_TEST_TIMEOUT"):
337 return os.getenv("LLDB_TEST_TIMEOUT")
338
339 if platform_name is None:
340 platform_name = sys.platform
341
342 if platform_name.startswith("remote-"):
343 return "10m"
344 else:
345 return "4m"
346
Chaoren Linb6325d02015-08-12 18:02:54 +0000347
Vince Harron0b9dbb52015-05-21 18:18:52 +0000348def touch(fname, times=None):
Greg Clayton8c3f9c92015-08-11 21:01:32 +0000349 if os.path.exists(fname):
Vince Harron0b9dbb52015-05-21 18:18:52 +0000350 os.utime(fname, times)
351
Chaoren Linb6325d02015-08-12 18:02:54 +0000352
Vince Harrondcc2b9f2015-05-27 04:40:36 +0000353def find(pattern, path):
354 result = []
355 for root, dirs, files in os.walk(path):
356 for name in files:
357 if fnmatch.fnmatch(name, pattern):
358 result.append(os.path.join(root, name))
359 return result
360
Chaoren Linb6325d02015-08-12 18:02:54 +0000361
Johnny Chene8d9dc62011-10-31 19:04:07 +0000362def main():
Vince Harrond5fa1022015-05-10 15:24:12 +0000363 # We can't use sys.path[0] to determine the script directory
364 # because it doesn't work under a debugger
Vince Harrone06a7a82015-05-12 23:12:19 +0000365 test_directory = os.path.dirname(os.path.realpath(__file__))
Johnny Chene8d9dc62011-10-31 19:04:07 +0000366 parser = OptionParser(usage="""\
367Run lldb test suite using a separate process for each test file.
Vince Harronede59652015-01-08 02:11:26 +0000368
Siva Chandra2d7832e2015-05-08 23:08:53 +0000369 Each test will run with a time limit of 10 minutes by default.
Vince Harronede59652015-01-08 02:11:26 +0000370
Siva Chandra2d7832e2015-05-08 23:08:53 +0000371 Override the default time limit of 10 minutes by setting
Vince Harronede59652015-01-08 02:11:26 +0000372 the environment variable LLDB_TEST_TIMEOUT.
373
374 E.g., export LLDB_TEST_TIMEOUT=10m
375
376 Override the time limit for individual tests by setting
377 the environment variable LLDB_[TEST NAME]_TIMEOUT.
378
379 E.g., export LLDB_TESTCONCURRENTEVENTS_TIMEOUT=2m
380
381 Set to "0" to run without time limit.
382
383 E.g., export LLDB_TEST_TIMEOUT=0
384 or export LLDB_TESTCONCURRENTEVENTS_TIMEOUT=0
Johnny Chene8d9dc62011-10-31 19:04:07 +0000385""")
Chaoren Linb6325d02015-08-12 18:02:54 +0000386 parser.add_option(
387 '-o', '--options',
388 type='string', action='store',
389 dest='dotest_options',
390 help="""The options passed to 'dotest.py' if specified.""")
Johnny Chene8d9dc62011-10-31 19:04:07 +0000391
Chaoren Linb6325d02015-08-12 18:02:54 +0000392 parser.add_option(
393 '-s', '--output-on-success',
394 action='store_true',
395 dest='output_on_success',
396 default=False,
397 help="""Print full output of 'dotest.py' even when it succeeds.""")
Zachary Turner38e64172015-08-10 17:46:11 +0000398
Chaoren Linb6325d02015-08-12 18:02:54 +0000399 parser.add_option(
400 '-t', '--threads',
401 type='int',
402 dest='num_threads',
403 help="""The number of threads to use when running tests separately.""")
Greg Clayton2256d0d2014-03-24 23:01:57 +0000404
Johnny Chene8d9dc62011-10-31 19:04:07 +0000405 opts, args = parser.parse_args()
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000406 dotest_option_string = opts.dotest_options
407
Vince Harron41657cc2015-05-21 18:15:09 +0000408 is_posix = (os.name == "posix")
Chaoren Linb6325d02015-08-12 18:02:54 +0000409 dotest_argv = (shlex.split(dotest_option_string, posix=is_posix)
410 if dotest_option_string
411 else [])
Vince Harron8994fed2015-05-22 19:49:23 +0000412
413 parser = dotest_args.create_parser()
Pavel Labath05ab2372015-07-06 15:57:52 +0000414 global dotest_options
Zachary Turner38e64172015-08-10 17:46:11 +0000415 global output_on_success
416 output_on_success = opts.output_on_success
Vince Harron8994fed2015-05-22 19:49:23 +0000417 dotest_options = dotest_args.parse_args(parser, dotest_argv)
418
Vince Harron41657cc2015-05-21 18:15:09 +0000419 if not dotest_options.s:
420 # no session log directory, we need to add this to prevent
421 # every dotest invocation from creating its own directory
422 import datetime
423 # The windows platforms don't like ':' in the pathname.
Chaoren Linb6325d02015-08-12 18:02:54 +0000424 timestamp_started = datetime.datetime.now().strftime("%F-%H_%M_%S")
Vince Harron41657cc2015-05-21 18:15:09 +0000425 dotest_argv.append('-s')
426 dotest_argv.append(timestamp_started)
Vince Harron0b9dbb52015-05-21 18:18:52 +0000427 dotest_options.s = timestamp_started
428
429 session_dir = os.path.join(os.getcwd(), dotest_options.s)
Ed Mastecec2a5b2014-11-21 02:41:25 +0000430
Vince Harrone06a7a82015-05-12 23:12:19 +0000431 # The root directory was specified on the command line
432 if len(args) == 0:
433 test_subdir = test_directory
434 else:
435 test_subdir = os.path.join(test_directory, args[0])
436
Vince Harrondcc2b9f2015-05-27 04:40:36 +0000437 # clean core files in test tree from previous runs (Linux)
438 cores = find('core.*', test_subdir)
439 for core in cores:
440 os.unlink(core)
441
Ed Mastecec2a5b2014-11-21 02:41:25 +0000442 if opts.num_threads:
443 num_threads = opts.num_threads
444 else:
Greg Clayton2256d0d2014-03-24 23:01:57 +0000445 num_threads_str = os.environ.get("LLDB_TEST_THREADS")
446 if num_threads_str:
447 num_threads = int(num_threads_str)
Greg Clayton2256d0d2014-03-24 23:01:57 +0000448 else:
Ed Mastecec2a5b2014-11-21 02:41:25 +0000449 num_threads = multiprocessing.cpu_count()
450 if num_threads < 1:
451 num_threads = 1
Johnny Chene8d9dc62011-10-31 19:04:07 +0000452
Daniel Maleab42556f2013-04-19 18:32:53 +0000453 system_info = " ".join(platform.uname())
Zachary Turner4cceca72015-08-14 16:45:32 +0000454 (timed_out, passed, failed, unexpected_successes, pass_count, fail_count) = walk_and_invoke(
Chaoren Line80372a2015-08-12 18:02:53 +0000455 test_directory, test_subdir, dotest_argv, num_threads)
Zachary Turnerc7a7c8a2015-05-28 19:56:26 +0000456
Vince Harron17f429f2014-12-13 00:08:19 +0000457 timed_out = set(timed_out)
Chaoren Line80372a2015-08-12 18:02:53 +0000458 num_test_files = len(passed) + len(failed)
459 num_test_cases = pass_count + fail_count
Daniel Maleab42556f2013-04-19 18:32:53 +0000460
Vince Harrondcc2b9f2015-05-27 04:40:36 +0000461 # move core files into session dir
462 cores = find('core.*', test_subdir)
463 for core in cores:
464 dst = core.replace(test_directory, "")[1:]
465 dst = dst.replace(os.path.sep, "-")
466 os.rename(core, os.path.join(session_dir, dst))
467
Vince Harron06381732015-05-12 23:10:36 +0000468 # remove expected timeouts from failures
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000469 expected_timeout = getExpectedTimeouts(dotest_options.lldb_platform_name)
Vince Harron06381732015-05-12 23:10:36 +0000470 for xtime in expected_timeout:
471 if xtime in timed_out:
472 timed_out.remove(xtime)
473 failed.remove(xtime)
Vince Harron0b9dbb52015-05-21 18:18:52 +0000474 result = "ExpectedTimeout"
475 elif xtime in passed:
476 result = "UnexpectedCompletion"
477 else:
478 result = None # failed
479
480 if result:
481 test_name = os.path.splitext(xtime)[0]
482 touch(os.path.join(session_dir, "{}-{}".format(result, test_name)))
Vince Harron06381732015-05-12 23:10:36 +0000483
Chaoren Lin5e3ab2b2015-06-01 17:49:25 +0000484 print
Chaoren Lin5a59e462015-08-12 18:02:51 +0000485 sys.stdout.write("Ran %d test suites" % num_test_files)
486 if num_test_files > 0:
487 sys.stdout.write(" (%d failed) (%f%%)" % (
488 len(failed), 100.0 * len(failed) / num_test_files))
489 print
Chaoren Line80372a2015-08-12 18:02:53 +0000490 sys.stdout.write("Ran %d test cases" % num_test_cases)
491 if num_test_cases > 0:
Chaoren Lin5a59e462015-08-12 18:02:51 +0000492 sys.stdout.write(" (%d failed) (%f%%)" % (
Chaoren Line80372a2015-08-12 18:02:53 +0000493 fail_count, 100.0 * fail_count / num_test_cases))
Chaoren Lin5a59e462015-08-12 18:02:51 +0000494 print
Zachary Turner4cceca72015-08-14 16:45:32 +0000495 exit_code = 0
496
Daniel Maleacbaef262013-02-15 21:31:37 +0000497 if len(failed) > 0:
Shawn Best13491c42014-10-22 19:29:00 +0000498 failed.sort()
Ying Chen10ed1a92015-05-28 23:51:49 +0000499 print "Failing Tests (%d)" % len(failed)
Daniel Maleacbaef262013-02-15 21:31:37 +0000500 for f in failed:
Vince Harron17f429f2014-12-13 00:08:19 +0000501 print "%s: LLDB (suite) :: %s (%s)" % (
502 "TIMEOUT" if f in timed_out else "FAIL", f, system_info
503 )
Zachary Turner4cceca72015-08-14 16:45:32 +0000504 exit_code = 1
505
506 if len(unexpected_successes) > 0:
507 unexpected_successes.sort()
508 print "\nUnexpected Successes (%d)" % len(unexpected_successes)
509 for u in unexpected_successes:
510 print "UNEXPECTED SUCCESS: LLDB (suite) :: %s (%s)" % (u, system_info)
511
512 sys.exit(exit_code)
Johnny Chene8d9dc62011-10-31 19:04:07 +0000513
514if __name__ == '__main__':
515 main()