blob: 59c9d83d51243e22cfa81e3280039290315039a3 [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Damjan Marionf56b77a2016-10-03 19:44:57 +02002
Klement Sekera993e0ed2017-03-16 09:14:59 +01003import sys
Dave Wallacee2efd122017-09-30 22:04:21 -04004import shutil
Damjan Marionf56b77a2016-10-03 19:44:57 +02005import os
Andrew Yourtchenkod760f792018-10-03 11:38:31 +02006import fnmatch
Damjan Marionf56b77a2016-10-03 19:44:57 +02007import unittest
Klement Sekera993e0ed2017-03-16 09:14:59 +01008import argparse
Klement Sekera545be522018-02-16 19:25:06 +01009import time
juraj.linkes184870a2018-07-16 14:22:01 +020010import threading
11import signal
12import psutil
juraj.linkes40dd73b2018-09-21 13:55:16 +020013import re
Paul Vinciguerra025cd9c2019-07-08 14:14:22 -040014import multiprocessing
juraj.linkes184870a2018-07-16 14:22:01 +020015from multiprocessing import Process, Pipe, cpu_count
16from multiprocessing.queues import Queue
17from multiprocessing.managers import BaseManager
Paul Vinciguerra0cbc71d2019-07-03 08:38:38 -040018import framework
juraj.linkes184870a2018-07-16 14:22:01 +020019from framework import VppTestRunner, running_extended_tests, VppTestCase, \
Ole Trøan5ba91592018-11-22 10:01:09 +000020 get_testcase_doc_name, get_test_description, PASS, FAIL, ERROR, SKIP, \
juraj.linkescae64f82018-09-19 15:01:47 +020021 TEST_RUN
Klement Sekera909a6a12017-08-08 04:33:53 +020022from debug import spawn_gdb
juraj.linkes184870a2018-07-16 14:22:01 +020023from log import get_parallel_logger, double_line_delim, RED, YELLOW, GREEN, \
juraj.linkes40dd73b2018-09-21 13:55:16 +020024 colorize, single_line_delim
Klement Sekerafcbf4442017-08-17 07:38:42 +020025from discover_tests import discover_tests
Klement Sekera9b6ece72018-03-23 10:50:11 +010026from subprocess import check_output, CalledProcessError
juraj.linkes40dd73b2018-09-21 13:55:16 +020027from util import check_core_path, get_core_path, is_core_present
Klement Sekera993e0ed2017-03-16 09:14:59 +010028
Klement Sekera05742262018-03-14 18:14:49 +010029# timeout which controls how long the child has to finish after seeing
30# a core dump in test temporary directory. If this is exceeded, parent assumes
Klement Sekeraeb506be2021-03-16 12:52:29 +010031# that child process is stuck (e.g. waiting for event from vpp) and kill
32# the child
Klement Sekera05742262018-03-14 18:14:49 +010033core_timeout = 3
34
Klement Sekera909a6a12017-08-08 04:33:53 +020035
juraj.linkes184870a2018-07-16 14:22:01 +020036class StreamQueue(Queue):
37 def write(self, msg):
38 self.put(msg)
39
40 def flush(self):
41 sys.__stdout__.flush()
42 sys.__stderr__.flush()
43
44 def fileno(self):
45 return self._writer.fileno()
46
47
48class StreamQueueManager(BaseManager):
49 pass
50
51
juraj.linkescae64f82018-09-19 15:01:47 +020052StreamQueueManager.register('StreamQueue', StreamQueue)
juraj.linkes184870a2018-07-16 14:22:01 +020053
54
juraj.linkescae64f82018-09-19 15:01:47 +020055class TestResult(dict):
juraj.linkes40dd73b2018-09-21 13:55:16 +020056 def __init__(self, testcase_suite, testcases_by_id=None):
juraj.linkescae64f82018-09-19 15:01:47 +020057 super(TestResult, self).__init__()
58 self[PASS] = []
59 self[FAIL] = []
60 self[ERROR] = []
61 self[SKIP] = []
62 self[TEST_RUN] = []
juraj.linkes40dd73b2018-09-21 13:55:16 +020063 self.crashed = False
juraj.linkescae64f82018-09-19 15:01:47 +020064 self.testcase_suite = testcase_suite
65 self.testcases = [testcase for testcase in testcase_suite]
juraj.linkes40dd73b2018-09-21 13:55:16 +020066 self.testcases_by_id = testcases_by_id
juraj.linkescae64f82018-09-19 15:01:47 +020067
68 def was_successful(self):
juraj.linkes40dd73b2018-09-21 13:55:16 +020069 return 0 == len(self[FAIL]) == len(self[ERROR]) \
Klement Sekerab8c72a42018-11-08 11:21:39 +010070 and len(self[PASS] + self[SKIP]) \
71 == self.testcase_suite.countTestCases() == len(self[TEST_RUN])
juraj.linkescae64f82018-09-19 15:01:47 +020072
73 def no_tests_run(self):
74 return 0 == len(self[TEST_RUN])
75
76 def process_result(self, test_id, result):
77 self[result].append(test_id)
juraj.linkescae64f82018-09-19 15:01:47 +020078
79 def suite_from_failed(self):
80 rerun_ids = set([])
81 for testcase in self.testcase_suite:
82 tc_id = testcase.id()
83 if tc_id not in self[PASS] and tc_id not in self[SKIP]:
84 rerun_ids.add(tc_id)
Naveen Joy2cbf2fb2019-03-06 10:41:06 -080085 if rerun_ids:
juraj.linkescae64f82018-09-19 15:01:47 +020086 return suite_from_failed(self.testcase_suite, rerun_ids)
87
88 def get_testcase_names(self, test_id):
juraj.linkes2eca70d2018-12-13 11:10:47 +010089 # could be tearDownClass (test_ipsec_esp.TestIpsecEsp1)
90 setup_teardown_match = re.match(
91 r'((tearDownClass)|(setUpClass)) \((.+\..+)\)', test_id)
92 if setup_teardown_match:
93 test_name, _, _, testcase_name = setup_teardown_match.groups()
94 if len(testcase_name.split('.')) == 2:
95 for key in self.testcases_by_id.keys():
96 if key.startswith(testcase_name):
97 testcase_name = key
98 break
99 testcase_name = self._get_testcase_doc_name(testcase_name)
100 else:
Ole Trøan5ba91592018-11-22 10:01:09 +0000101 test_name = self._get_test_description(test_id)
juraj.linkes40dd73b2018-09-21 13:55:16 +0200102 testcase_name = self._get_testcase_doc_name(test_id)
juraj.linkes40dd73b2018-09-21 13:55:16 +0200103
104 return testcase_name, test_name
juraj.linkescae64f82018-09-19 15:01:47 +0200105
Ole Trøan5ba91592018-11-22 10:01:09 +0000106 def _get_test_description(self, test_id):
juraj.linkes2eca70d2018-12-13 11:10:47 +0100107 if test_id in self.testcases_by_id:
108 desc = get_test_description(descriptions,
109 self.testcases_by_id[test_id])
110 else:
111 desc = test_id
112 return desc
Ole Trøan5ba91592018-11-22 10:01:09 +0000113
juraj.linkes40dd73b2018-09-21 13:55:16 +0200114 def _get_testcase_doc_name(self, test_id):
juraj.linkes2eca70d2018-12-13 11:10:47 +0100115 if test_id in self.testcases_by_id:
116 doc_name = get_testcase_doc_name(self.testcases_by_id[test_id])
117 else:
118 doc_name = test_id
119 return doc_name
juraj.linkescae64f82018-09-19 15:01:47 +0200120
121
122def test_runner_wrapper(suite, keep_alive_pipe, stdouterr_queue,
123 finished_pipe, result_pipe, logger):
juraj.linkes184870a2018-07-16 14:22:01 +0200124 sys.stdout = stdouterr_queue
125 sys.stderr = stdouterr_queue
juraj.linkesdfb5f2a2018-11-09 11:58:54 +0100126 VppTestCase.parallel_handler = logger.handlers[0]
juraj.linkes184870a2018-07-16 14:22:01 +0200127 result = VppTestRunner(keep_alive_pipe=keep_alive_pipe,
128 descriptions=descriptions,
129 verbosity=verbose,
juraj.linkescae64f82018-09-19 15:01:47 +0200130 result_pipe=result_pipe,
juraj.linkesabec0122018-11-16 17:28:56 +0100131 failfast=failfast,
132 print_summary=False).run(suite)
juraj.linkescae64f82018-09-19 15:01:47 +0200133 finished_pipe.send(result.wasSuccessful())
134 finished_pipe.close()
Klement Sekera909a6a12017-08-08 04:33:53 +0200135 keep_alive_pipe.close()
136
137
juraj.linkes184870a2018-07-16 14:22:01 +0200138class TestCaseWrapper(object):
139 def __init__(self, testcase_suite, manager):
140 self.keep_alive_parent_end, self.keep_alive_child_end = Pipe(
141 duplex=False)
juraj.linkescae64f82018-09-19 15:01:47 +0200142 self.finished_parent_end, self.finished_child_end = Pipe(duplex=False)
juraj.linkes184870a2018-07-16 14:22:01 +0200143 self.result_parent_end, self.result_child_end = Pipe(duplex=False)
144 self.testcase_suite = testcase_suite
Ole Troan7f991832018-12-06 17:35:12 +0100145 if sys.version[0] == '2':
146 self.stdouterr_queue = manager.StreamQueue()
147 else:
148 from multiprocessing import get_context
149 self.stdouterr_queue = manager.StreamQueue(ctx=get_context())
juraj.linkes184870a2018-07-16 14:22:01 +0200150 self.logger = get_parallel_logger(self.stdouterr_queue)
151 self.child = Process(target=test_runner_wrapper,
juraj.linkescae64f82018-09-19 15:01:47 +0200152 args=(testcase_suite,
153 self.keep_alive_child_end,
154 self.stdouterr_queue,
155 self.finished_child_end,
156 self.result_child_end,
157 self.logger)
juraj.linkes184870a2018-07-16 14:22:01 +0200158 )
159 self.child.start()
juraj.linkes184870a2018-07-16 14:22:01 +0200160 self.last_test_temp_dir = None
161 self.last_test_vpp_binary = None
juraj.linkes40dd73b2018-09-21 13:55:16 +0200162 self._last_test = None
163 self.last_test_id = None
juraj.linkes721872e2018-09-05 18:13:45 +0200164 self.vpp_pid = None
juraj.linkes184870a2018-07-16 14:22:01 +0200165 self.last_heard = time.time()
166 self.core_detected_at = None
juraj.linkes40dd73b2018-09-21 13:55:16 +0200167 self.testcases_by_id = {}
168 self.testclasess_with_core = {}
169 for testcase in self.testcase_suite:
170 self.testcases_by_id[testcase.id()] = testcase
171 self.result = TestResult(testcase_suite, self.testcases_by_id)
172
173 @property
174 def last_test(self):
175 return self._last_test
176
177 @last_test.setter
178 def last_test(self, test_id):
179 self.last_test_id = test_id
180 if test_id in self.testcases_by_id:
181 testcase = self.testcases_by_id[test_id]
182 self._last_test = testcase.shortDescription()
183 if not self._last_test:
184 self._last_test = str(testcase)
185 else:
186 self._last_test = test_id
187
188 def add_testclass_with_core(self):
189 if self.last_test_id in self.testcases_by_id:
190 test = self.testcases_by_id[self.last_test_id]
191 class_name = unittest.util.strclass(test.__class__)
192 test_name = "'{}' ({})".format(get_test_description(descriptions,
193 test),
194 self.last_test_id)
195 else:
196 test_name = self.last_test_id
197 class_name = re.match(r'((tearDownClass)|(setUpClass)) '
198 r'\((.+\..+)\)', test_name).groups()[3]
199 if class_name not in self.testclasess_with_core:
200 self.testclasess_with_core[class_name] = (
201 test_name,
202 self.last_test_vpp_binary,
203 self.last_test_temp_dir)
juraj.linkes184870a2018-07-16 14:22:01 +0200204
205 def close_pipes(self):
206 self.keep_alive_child_end.close()
juraj.linkescae64f82018-09-19 15:01:47 +0200207 self.finished_child_end.close()
juraj.linkes184870a2018-07-16 14:22:01 +0200208 self.result_child_end.close()
209 self.keep_alive_parent_end.close()
juraj.linkescae64f82018-09-19 15:01:47 +0200210 self.finished_parent_end.close()
juraj.linkes184870a2018-07-16 14:22:01 +0200211 self.result_parent_end.close()
212
juraj.linkes40dd73b2018-09-21 13:55:16 +0200213 def was_successful(self):
214 return self.result.was_successful()
215
juraj.linkes184870a2018-07-16 14:22:01 +0200216
217def stdouterr_reader_wrapper(unread_testcases, finished_unread_testcases,
218 read_testcases):
219 read_testcase = None
Naveen Joy2cbf2fb2019-03-06 10:41:06 -0800220 while read_testcases.is_set() or unread_testcases:
221 if finished_unread_testcases:
juraj.linkese6b58cf2018-11-29 09:56:35 +0100222 read_testcase = finished_unread_testcases.pop()
223 unread_testcases.remove(read_testcase)
Naveen Joy2cbf2fb2019-03-06 10:41:06 -0800224 elif unread_testcases:
juraj.linkese6b58cf2018-11-29 09:56:35 +0100225 read_testcase = unread_testcases.pop()
juraj.linkes184870a2018-07-16 14:22:01 +0200226 if read_testcase:
227 data = ''
228 while data is not None:
229 sys.stdout.write(data)
230 data = read_testcase.stdouterr_queue.get()
231
232 read_testcase.stdouterr_queue.close()
233 finished_unread_testcases.discard(read_testcase)
234 read_testcase = None
235
236
juraj.linkes40dd73b2018-09-21 13:55:16 +0200237def handle_failed_suite(logger, last_test_temp_dir, vpp_pid):
238 if last_test_temp_dir:
239 # Need to create link in case of a timeout or core dump without failure
240 lttd = os.path.basename(last_test_temp_dir)
Klement Sekerab8c72a42018-11-08 11:21:39 +0100241 failed_dir = os.getenv('FAILED_DIR')
juraj.linkes40dd73b2018-09-21 13:55:16 +0200242 link_path = '%s%s-FAILED' % (failed_dir, lttd)
243 if not os.path.exists(link_path):
juraj.linkes40dd73b2018-09-21 13:55:16 +0200244 os.symlink(last_test_temp_dir, link_path)
juraj.linkesabec0122018-11-16 17:28:56 +0100245 logger.error("Symlink to failed testcase directory: %s -> %s"
246 % (link_path, lttd))
juraj.linkes40dd73b2018-09-21 13:55:16 +0200247
248 # Report core existence
249 core_path = get_core_path(last_test_temp_dir)
250 if os.path.exists(core_path):
251 logger.error(
252 "Core-file exists in test temporary directory: %s!" %
253 core_path)
254 check_core_path(logger, core_path)
Paul Vinciguerra38a4ec72018-11-28 11:34:21 -0800255 logger.debug("Running 'file %s':" % core_path)
juraj.linkes40dd73b2018-09-21 13:55:16 +0200256 try:
257 info = check_output(["file", core_path])
258 logger.debug(info)
259 except CalledProcessError as e:
Paul Vinciguerra38a4ec72018-11-28 11:34:21 -0800260 logger.error("Subprocess returned with return code "
261 "while running `file' utility on core-file "
262 "returned: "
263 "rc=%s", e.returncode)
264 except OSError as e:
265 logger.error("Subprocess returned with OS error while "
266 "running 'file' utility "
267 "on core-file: "
268 "(%s) %s", e.errno, e.strerror)
269 except Exception as e:
270 logger.exception("Unexpected error running `file' utility "
271 "on core-file")
Klement Sekera98d82ca2021-02-02 13:25:40 +0100272 logger.error("gdb %s %s" %
273 (os.getenv('VPP_BIN', 'vpp'), core_path))
juraj.linkes40dd73b2018-09-21 13:55:16 +0200274
275 if vpp_pid:
276 # Copy api post mortem
277 api_post_mortem_path = "/tmp/api_post_mortem.%d" % vpp_pid
278 if os.path.isfile(api_post_mortem_path):
279 logger.error("Copying api_post_mortem.%d to %s" %
280 (vpp_pid, last_test_temp_dir))
281 shutil.copy2(api_post_mortem_path, last_test_temp_dir)
282
283
284def check_and_handle_core(vpp_binary, tempdir, core_crash_test):
285 if is_core_present(tempdir):
Klement Sekeraf40ee3a2019-05-06 19:11:25 +0200286 if debug_core:
287 print('VPP core detected in %s. Last test running was %s' %
288 (tempdir, core_crash_test))
289 print(single_line_delim)
290 spawn_gdb(vpp_binary, get_core_path(tempdir))
291 print(single_line_delim)
292 elif compress_core:
293 print("Compressing core-file in test directory `%s'" % tempdir)
294 os.system("gzip %s" % get_core_path(tempdir))
juraj.linkes40dd73b2018-09-21 13:55:16 +0200295
296
297def handle_cores(failed_testcases):
Klement Sekeraf40ee3a2019-05-06 19:11:25 +0200298 for failed_testcase in failed_testcases:
299 tcs_with_core = failed_testcase.testclasess_with_core
300 if tcs_with_core:
301 for test, vpp_binary, tempdir in tcs_with_core.values():
302 check_and_handle_core(vpp_binary, tempdir, test)
juraj.linkes40dd73b2018-09-21 13:55:16 +0200303
304
305def process_finished_testsuite(wrapped_testcase_suite,
306 finished_testcase_suites,
307 failed_wrapped_testcases,
308 results):
309 results.append(wrapped_testcase_suite.result)
310 finished_testcase_suites.add(wrapped_testcase_suite)
311 stop_run = False
312 if failfast and not wrapped_testcase_suite.was_successful():
313 stop_run = True
314
315 if not wrapped_testcase_suite.was_successful():
316 failed_wrapped_testcases.add(wrapped_testcase_suite)
317 handle_failed_suite(wrapped_testcase_suite.logger,
318 wrapped_testcase_suite.last_test_temp_dir,
319 wrapped_testcase_suite.vpp_pid)
320
321 return stop_run
322
323
juraj.linkes721872e2018-09-05 18:13:45 +0200324def run_forked(testcase_suites):
juraj.linkes184870a2018-07-16 14:22:01 +0200325 wrapped_testcase_suites = set()
Andrew Yourtchenkoa3b7c552020-08-26 14:33:54 +0000326 solo_testcase_suites = []
327 total_test_runners = 0
juraj.linkes184870a2018-07-16 14:22:01 +0200328
329 # suites are unhashable, need to use list
330 results = []
juraj.linkes184870a2018-07-16 14:22:01 +0200331 unread_testcases = set()
332 finished_unread_testcases = set()
333 manager = StreamQueueManager()
334 manager.start()
Andrew Yourtchenkoa3b7c552020-08-26 14:33:54 +0000335 total_test_runners = 0
336 while total_test_runners < concurrent_tests:
Naveen Joy2cbf2fb2019-03-06 10:41:06 -0800337 if testcase_suites:
Andrew Yourtchenkoa3b7c552020-08-26 14:33:54 +0000338 a_suite = testcase_suites.pop(0)
Andrew Yourtchenko06f32812021-01-14 10:19:08 +0000339 if a_suite.is_tagged_run_solo:
Andrew Yourtchenkoa3b7c552020-08-26 14:33:54 +0000340 solo_testcase_suites.append(a_suite)
341 continue
342 wrapped_testcase_suite = TestCaseWrapper(a_suite,
juraj.linkes721872e2018-09-05 18:13:45 +0200343 manager)
juraj.linkes184870a2018-07-16 14:22:01 +0200344 wrapped_testcase_suites.add(wrapped_testcase_suite)
345 unread_testcases.add(wrapped_testcase_suite)
Andrew Yourtchenkoa3b7c552020-08-26 14:33:54 +0000346 total_test_runners = total_test_runners + 1
347 else:
348 break
349
350 while total_test_runners < 1 and solo_testcase_suites:
351 if solo_testcase_suites:
352 a_suite = solo_testcase_suites.pop(0)
353 wrapped_testcase_suite = TestCaseWrapper(a_suite,
354 manager)
355 wrapped_testcase_suites.add(wrapped_testcase_suite)
356 unread_testcases.add(wrapped_testcase_suite)
357 total_test_runners = total_test_runners + 1
juraj.linkes184870a2018-07-16 14:22:01 +0200358 else:
359 break
360
361 read_from_testcases = threading.Event()
362 read_from_testcases.set()
363 stdouterr_thread = threading.Thread(target=stdouterr_reader_wrapper,
364 args=(unread_testcases,
365 finished_unread_testcases,
366 read_from_testcases))
367 stdouterr_thread.start()
368
juraj.linkes40dd73b2018-09-21 13:55:16 +0200369 failed_wrapped_testcases = set()
370 stop_run = False
juraj.linkese6b58cf2018-11-29 09:56:35 +0100371
372 try:
Naveen Joy2cbf2fb2019-03-06 10:41:06 -0800373 while wrapped_testcase_suites:
juraj.linkese6b58cf2018-11-29 09:56:35 +0100374 finished_testcase_suites = set()
375 for wrapped_testcase_suite in wrapped_testcase_suites:
376 while wrapped_testcase_suite.result_parent_end.poll():
377 wrapped_testcase_suite.result.process_result(
378 *wrapped_testcase_suite.result_parent_end.recv())
379 wrapped_testcase_suite.last_heard = time.time()
380
381 while wrapped_testcase_suite.keep_alive_parent_end.poll():
382 wrapped_testcase_suite.last_test, \
383 wrapped_testcase_suite.last_test_vpp_binary, \
384 wrapped_testcase_suite.last_test_temp_dir, \
385 wrapped_testcase_suite.vpp_pid = \
386 wrapped_testcase_suite.keep_alive_parent_end.recv()
387 wrapped_testcase_suite.last_heard = time.time()
388
389 if wrapped_testcase_suite.finished_parent_end.poll():
390 wrapped_testcase_suite.finished_parent_end.recv()
391 wrapped_testcase_suite.last_heard = time.time()
392 stop_run = process_finished_testsuite(
393 wrapped_testcase_suite,
394 finished_testcase_suites,
395 failed_wrapped_testcases,
396 results) or stop_run
397 continue
398
399 fail = False
400 if wrapped_testcase_suite.last_heard + test_timeout < \
401 time.time():
402 fail = True
403 wrapped_testcase_suite.logger.critical(
404 "Child test runner process timed out "
405 "(last test running was `%s' in `%s')!" %
406 (wrapped_testcase_suite.last_test,
407 wrapped_testcase_suite.last_test_temp_dir))
408 elif not wrapped_testcase_suite.child.is_alive():
409 fail = True
410 wrapped_testcase_suite.logger.critical(
411 "Child test runner process unexpectedly died "
412 "(last test running was `%s' in `%s')!" %
413 (wrapped_testcase_suite.last_test,
414 wrapped_testcase_suite.last_test_temp_dir))
415 elif wrapped_testcase_suite.last_test_temp_dir and \
416 wrapped_testcase_suite.last_test_vpp_binary:
417 if is_core_present(
418 wrapped_testcase_suite.last_test_temp_dir):
419 wrapped_testcase_suite.add_testclass_with_core()
420 if wrapped_testcase_suite.core_detected_at is None:
421 wrapped_testcase_suite.core_detected_at = \
422 time.time()
423 elif wrapped_testcase_suite.core_detected_at + \
424 core_timeout < time.time():
425 wrapped_testcase_suite.logger.critical(
426 "Child test runner process unresponsive and "
427 "core-file exists in test temporary directory "
428 "(last test running was `%s' in `%s')!" %
429 (wrapped_testcase_suite.last_test,
430 wrapped_testcase_suite.last_test_temp_dir))
431 fail = True
432
433 if fail:
434 wrapped_testcase_suite.child.terminate()
435 try:
436 # terminating the child process tends to leave orphan
437 # VPP process around
438 if wrapped_testcase_suite.vpp_pid:
439 os.kill(wrapped_testcase_suite.vpp_pid,
440 signal.SIGTERM)
441 except OSError:
442 # already dead
443 pass
444 wrapped_testcase_suite.result.crashed = True
445 wrapped_testcase_suite.result.process_result(
446 wrapped_testcase_suite.last_test_id, ERROR)
447 stop_run = process_finished_testsuite(
448 wrapped_testcase_suite,
449 finished_testcase_suites,
450 failed_wrapped_testcases,
451 results) or stop_run
452
453 for finished_testcase in finished_testcase_suites:
Andrew Yourtchenko42693522019-11-05 01:08:26 +0100454 # Somewhat surprisingly, the join below may
455 # timeout, even if client signaled that
456 # it finished - so we note it just in case.
457 join_start = time.time()
458 finished_testcase.child.join(test_finished_join_timeout)
459 join_end = time.time()
460 if join_end - join_start >= test_finished_join_timeout:
461 finished_testcase.logger.error(
462 "Timeout joining finished test: %s (pid %d)" %
463 (finished_testcase.last_test,
464 finished_testcase.child.pid))
juraj.linkese6b58cf2018-11-29 09:56:35 +0100465 finished_testcase.close_pipes()
466 wrapped_testcase_suites.remove(finished_testcase)
467 finished_unread_testcases.add(finished_testcase)
468 finished_testcase.stdouterr_queue.put(None)
Andrew Yourtchenkoa3b7c552020-08-26 14:33:54 +0000469 total_test_runners = total_test_runners - 1
juraj.linkese6b58cf2018-11-29 09:56:35 +0100470 if stop_run:
Naveen Joy2cbf2fb2019-03-06 10:41:06 -0800471 while testcase_suites:
juraj.linkese6b58cf2018-11-29 09:56:35 +0100472 results.append(TestResult(testcase_suites.pop(0)))
Naveen Joy2cbf2fb2019-03-06 10:41:06 -0800473 elif testcase_suites:
Andrew Yourtchenkoa3b7c552020-08-26 14:33:54 +0000474 a_testcase = testcase_suites.pop(0)
Andrew Yourtchenko06f32812021-01-14 10:19:08 +0000475 while a_testcase and a_testcase.is_tagged_run_solo:
Andrew Yourtchenkoa3b7c552020-08-26 14:33:54 +0000476 solo_testcase_suites.append(a_testcase)
477 if testcase_suites:
478 a_testcase = testcase_suites.pop(0)
479 else:
480 a_testcase = None
481 if a_testcase:
482 new_testcase = TestCaseWrapper(a_testcase,
483 manager)
484 wrapped_testcase_suites.add(new_testcase)
485 total_test_runners = total_test_runners + 1
486 unread_testcases.add(new_testcase)
Andrew Yourtchenko4d084072021-01-20 14:53:55 +0000487 if solo_testcase_suites and total_test_runners == 0:
488 a_testcase = solo_testcase_suites.pop(0)
489 new_testcase = TestCaseWrapper(a_testcase,
490 manager)
491 wrapped_testcase_suites.add(new_testcase)
492 total_test_runners = total_test_runners + 1
493 unread_testcases.add(new_testcase)
Paul Vinciguerrac0692a42019-03-15 19:16:50 -0700494 time.sleep(0.1)
juraj.linkese6b58cf2018-11-29 09:56:35 +0100495 except Exception:
juraj.linkes184870a2018-07-16 14:22:01 +0200496 for wrapped_testcase_suite in wrapped_testcase_suites:
juraj.linkese6b58cf2018-11-29 09:56:35 +0100497 wrapped_testcase_suite.child.terminate()
498 wrapped_testcase_suite.stdouterr_queue.put(None)
499 raise
500 finally:
501 read_from_testcases.clear()
502 stdouterr_thread.join(test_timeout)
503 manager.shutdown()
juraj.linkescae64f82018-09-19 15:01:47 +0200504
juraj.linkes40dd73b2018-09-21 13:55:16 +0200505 handle_cores(failed_wrapped_testcases)
juraj.linkes184870a2018-07-16 14:22:01 +0200506 return results
507
508
509class SplitToSuitesCallback:
510 def __init__(self, filter_callback):
511 self.suites = {}
512 self.suite_name = 'default'
513 self.filter_callback = filter_callback
514 self.filtered = unittest.TestSuite()
Klement Sekerafcbf4442017-08-17 07:38:42 +0200515
516 def __call__(self, file_name, cls, method):
juraj.linkes184870a2018-07-16 14:22:01 +0200517 test_method = cls(method)
518 if self.filter_callback(file_name, cls.__name__, method):
519 self.suite_name = file_name + cls.__name__
520 if self.suite_name not in self.suites:
521 self.suites[self.suite_name] = unittest.TestSuite()
Andrew Yourtchenko06f32812021-01-14 10:19:08 +0000522 self.suites[self.suite_name].is_tagged_run_solo = False
juraj.linkes184870a2018-07-16 14:22:01 +0200523 self.suites[self.suite_name].addTest(test_method)
Andrew Yourtchenko06f32812021-01-14 10:19:08 +0000524 if test_method.is_tagged_run_solo():
525 self.suites[self.suite_name].is_tagged_run_solo = True
juraj.linkes184870a2018-07-16 14:22:01 +0200526
527 else:
528 self.filtered.addTest(test_method)
Klement Sekerafcbf4442017-08-17 07:38:42 +0200529
530
juraj.linkes184870a2018-07-16 14:22:01 +0200531test_option = "TEST"
532
533
534def parse_test_option():
535 f = os.getenv(test_option, None)
536 filter_file_name = None
537 filter_class_name = None
538 filter_func_name = None
539 if f:
540 if '.' in f:
541 parts = f.split('.')
542 if len(parts) > 3:
543 raise Exception("Unrecognized %s option: %s" %
544 (test_option, f))
545 if len(parts) > 2:
546 if parts[2] not in ('*', ''):
547 filter_func_name = parts[2]
548 if parts[1] not in ('*', ''):
549 filter_class_name = parts[1]
550 if parts[0] not in ('*', ''):
551 if parts[0].startswith('test_'):
552 filter_file_name = parts[0]
553 else:
554 filter_file_name = 'test_%s' % parts[0]
555 else:
556 if f.startswith('test_'):
557 filter_file_name = f
558 else:
559 filter_file_name = 'test_%s' % f
560 if filter_file_name:
561 filter_file_name = '%s.py' % filter_file_name
562 return filter_file_name, filter_class_name, filter_func_name
563
564
565def filter_tests(tests, filter_cb):
566 result = unittest.suite.TestSuite()
567 for t in tests:
568 if isinstance(t, unittest.suite.TestSuite):
569 # this is a bunch of tests, recursively filter...
570 x = filter_tests(t, filter_cb)
571 if x.countTestCases() > 0:
572 result.addTest(x)
573 elif isinstance(t, unittest.TestCase):
574 # this is a single test
575 parts = t.id().split('.')
576 # t.id() for common cases like this:
577 # test_classifier.TestClassifier.test_acl_ip
578 # apply filtering only if it is so
579 if len(parts) == 3:
580 if not filter_cb(parts[0], parts[1], parts[2]):
581 continue
582 result.addTest(t)
583 else:
584 # unexpected object, don't touch it
585 result.addTest(t)
586 return result
587
588
589class FilterByTestOption:
590 def __init__(self, filter_file_name, filter_class_name, filter_func_name):
591 self.filter_file_name = filter_file_name
592 self.filter_class_name = filter_class_name
593 self.filter_func_name = filter_func_name
594
595 def __call__(self, file_name, class_name, func_name):
Andrew Yourtchenkod760f792018-10-03 11:38:31 +0200596 if self.filter_file_name:
597 fn_match = fnmatch.fnmatch(file_name, self.filter_file_name)
598 if not fn_match:
599 return False
juraj.linkes184870a2018-07-16 14:22:01 +0200600 if self.filter_class_name and class_name != self.filter_class_name:
601 return False
602 if self.filter_func_name and func_name != self.filter_func_name:
603 return False
604 return True
605
606
607class FilterByClassList:
juraj.linkes721872e2018-09-05 18:13:45 +0200608 def __init__(self, classes_with_filenames):
609 self.classes_with_filenames = classes_with_filenames
Klement Sekeradf2b9802017-10-05 10:26:03 +0200610
611 def __call__(self, file_name, class_name, func_name):
juraj.linkes721872e2018-09-05 18:13:45 +0200612 return '.'.join([file_name, class_name]) in self.classes_with_filenames
Klement Sekeradf2b9802017-10-05 10:26:03 +0200613
614
615def suite_from_failed(suite, failed):
juraj.linkes721872e2018-09-05 18:13:45 +0200616 failed = {x.rsplit('.', 1)[0] for x in failed}
juraj.linkes184870a2018-07-16 14:22:01 +0200617 filter_cb = FilterByClassList(failed)
618 suite = filter_tests(suite, filter_cb)
Klement Sekera4c5422e2018-06-22 13:19:45 +0200619 return suite
Klement Sekeradf2b9802017-10-05 10:26:03 +0200620
621
juraj.linkescae64f82018-09-19 15:01:47 +0200622class AllResults(dict):
juraj.linkes184870a2018-07-16 14:22:01 +0200623 def __init__(self):
juraj.linkescae64f82018-09-19 15:01:47 +0200624 super(AllResults, self).__init__()
juraj.linkes184870a2018-07-16 14:22:01 +0200625 self.all_testcases = 0
juraj.linkescae64f82018-09-19 15:01:47 +0200626 self.results_per_suite = []
627 self[PASS] = 0
628 self[FAIL] = 0
629 self[ERROR] = 0
630 self[SKIP] = 0
631 self[TEST_RUN] = 0
juraj.linkes184870a2018-07-16 14:22:01 +0200632 self.rerun = []
juraj.linkescae64f82018-09-19 15:01:47 +0200633 self.testsuites_no_tests_run = []
Klement Sekera909a6a12017-08-08 04:33:53 +0200634
juraj.linkescae64f82018-09-19 15:01:47 +0200635 def add_results(self, result):
636 self.results_per_suite.append(result)
637 result_types = [PASS, FAIL, ERROR, SKIP, TEST_RUN]
638 for result_type in result_types:
639 self[result_type] += len(result[result_type])
Klement Sekera05742262018-03-14 18:14:49 +0100640
juraj.linkescae64f82018-09-19 15:01:47 +0200641 def add_result(self, result):
juraj.linkes184870a2018-07-16 14:22:01 +0200642 retval = 0
juraj.linkescae64f82018-09-19 15:01:47 +0200643 self.all_testcases += result.testcase_suite.countTestCases()
juraj.linkes40dd73b2018-09-21 13:55:16 +0200644 self.add_results(result)
juraj.linkes184870a2018-07-16 14:22:01 +0200645
juraj.linkes40dd73b2018-09-21 13:55:16 +0200646 if result.no_tests_run():
juraj.linkescae64f82018-09-19 15:01:47 +0200647 self.testsuites_no_tests_run.append(result.testcase_suite)
juraj.linkes40dd73b2018-09-21 13:55:16 +0200648 if result.crashed:
649 retval = -1
650 else:
651 retval = 1
652 elif not result.was_successful():
653 retval = 1
juraj.linkes184870a2018-07-16 14:22:01 +0200654
juraj.linkes184870a2018-07-16 14:22:01 +0200655 if retval != 0:
juraj.linkesabec0122018-11-16 17:28:56 +0100656 self.rerun.append(result.testcase_suite)
juraj.linkes184870a2018-07-16 14:22:01 +0200657
658 return retval
659
660 def print_results(self):
661 print('')
662 print(double_line_delim)
663 print('TEST RESULTS:')
juraj.linkescae64f82018-09-19 15:01:47 +0200664 print(' Scheduled tests: {}'.format(self.all_testcases))
665 print(' Executed tests: {}'.format(self[TEST_RUN]))
666 print(' Passed tests: {}'.format(
667 colorize(str(self[PASS]), GREEN)))
668 if self[SKIP] > 0:
669 print(' Skipped tests: {}'.format(
670 colorize(str(self[SKIP]), YELLOW)))
671 if self.not_executed > 0:
672 print(' Not Executed tests: {}'.format(
673 colorize(str(self.not_executed), RED)))
674 if self[FAIL] > 0:
675 print(' Failures: {}'.format(
676 colorize(str(self[FAIL]), RED)))
677 if self[ERROR] > 0:
678 print(' Errors: {}'.format(
679 colorize(str(self[ERROR]), RED)))
juraj.linkes184870a2018-07-16 14:22:01 +0200680
681 if self.all_failed > 0:
juraj.linkes40dd73b2018-09-21 13:55:16 +0200682 print('FAILURES AND ERRORS IN TESTS:')
juraj.linkescae64f82018-09-19 15:01:47 +0200683 for result in self.results_per_suite:
684 failed_testcase_ids = result[FAIL]
685 errored_testcase_ids = result[ERROR]
686 old_testcase_name = None
Paul Vinciguerra67a77492019-12-10 23:36:05 -0500687 if failed_testcase_ids:
juraj.linkescae64f82018-09-19 15:01:47 +0200688 for failed_test_id in failed_testcase_ids:
689 new_testcase_name, test_name = \
690 result.get_testcase_names(failed_test_id)
691 if new_testcase_name != old_testcase_name:
692 print(' Testcase name: {}'.format(
693 colorize(new_testcase_name, RED)))
694 old_testcase_name = new_testcase_name
Klement Sekera33177d62018-11-30 14:17:20 +0100695 print(' FAILURE: {} [{}]'.format(
696 colorize(test_name, RED), failed_test_id))
Paul Vinciguerra67a77492019-12-10 23:36:05 -0500697 if errored_testcase_ids:
698 for errored_test_id in errored_testcase_ids:
juraj.linkescae64f82018-09-19 15:01:47 +0200699 new_testcase_name, test_name = \
Paul Vinciguerra67a77492019-12-10 23:36:05 -0500700 result.get_testcase_names(errored_test_id)
juraj.linkescae64f82018-09-19 15:01:47 +0200701 if new_testcase_name != old_testcase_name:
702 print(' Testcase name: {}'.format(
703 colorize(new_testcase_name, RED)))
704 old_testcase_name = new_testcase_name
Klement Sekera33177d62018-11-30 14:17:20 +0100705 print(' ERROR: {} [{}]'.format(
Paul Vinciguerra67a77492019-12-10 23:36:05 -0500706 colorize(test_name, RED), errored_test_id))
Naveen Joy2cbf2fb2019-03-06 10:41:06 -0800707 if self.testsuites_no_tests_run:
juraj.linkescae64f82018-09-19 15:01:47 +0200708 print('TESTCASES WHERE NO TESTS WERE SUCCESSFULLY EXECUTED:')
juraj.linkes40dd73b2018-09-21 13:55:16 +0200709 tc_classes = set()
juraj.linkescae64f82018-09-19 15:01:47 +0200710 for testsuite in self.testsuites_no_tests_run:
711 for testcase in testsuite:
712 tc_classes.add(get_testcase_doc_name(testcase))
713 for tc_class in tc_classes:
714 print(' {}'.format(colorize(tc_class, RED)))
juraj.linkes184870a2018-07-16 14:22:01 +0200715
716 print(double_line_delim)
717 print('')
718
719 @property
juraj.linkescae64f82018-09-19 15:01:47 +0200720 def not_executed(self):
721 return self.all_testcases - self[TEST_RUN]
722
723 @property
juraj.linkes184870a2018-07-16 14:22:01 +0200724 def all_failed(self):
juraj.linkescae64f82018-09-19 15:01:47 +0200725 return self[FAIL] + self[ERROR]
juraj.linkes184870a2018-07-16 14:22:01 +0200726
727
728def parse_results(results):
729 """
juraj.linkescae64f82018-09-19 15:01:47 +0200730 Prints the number of scheduled, executed, not executed, passed, failed,
731 errored and skipped tests and details about failed and errored tests.
juraj.linkes184870a2018-07-16 14:22:01 +0200732
juraj.linkescae64f82018-09-19 15:01:47 +0200733 Also returns all suites where any test failed.
juraj.linkes184870a2018-07-16 14:22:01 +0200734
735 :param results:
736 :return:
737 """
738
juraj.linkescae64f82018-09-19 15:01:47 +0200739 results_per_suite = AllResults()
juraj.linkes184870a2018-07-16 14:22:01 +0200740 crashed = False
741 failed = False
juraj.linkescae64f82018-09-19 15:01:47 +0200742 for result in results:
743 result_code = results_per_suite.add_result(result)
juraj.linkes184870a2018-07-16 14:22:01 +0200744 if result_code == 1:
745 failed = True
746 elif result_code == -1:
747 crashed = True
748
749 results_per_suite.print_results()
750
751 if crashed:
752 return_code = -1
753 elif failed:
754 return_code = 1
755 else:
756 return_code = 0
757 return return_code, results_per_suite.rerun
758
759
760def parse_digit_env(env_var, default):
761 value = os.getenv(env_var, default)
762 if value != default:
763 if value.isdigit():
764 value = int(value)
765 else:
766 print('WARNING: unsupported value "%s" for env var "%s",'
767 'defaulting to %s' % (value, env_var, default))
768 value = default
769 return value
Klement Sekera3f6ff192017-08-11 06:56:05 +0200770
771
772if __name__ == '__main__':
773
juraj.linkes184870a2018-07-16 14:22:01 +0200774 verbose = parse_digit_env("V", 0)
Klement Sekera3f6ff192017-08-11 06:56:05 +0200775
juraj.linkes184870a2018-07-16 14:22:01 +0200776 test_timeout = parse_digit_env("TIMEOUT", 600) # default = 10 minutes
Klement Sekera3f6ff192017-08-11 06:56:05 +0200777
Andrew Yourtchenko42693522019-11-05 01:08:26 +0100778 test_finished_join_timeout = 15
779
juraj.linkes184870a2018-07-16 14:22:01 +0200780 retries = parse_digit_env("RETRIES", 0)
Klement Sekera3f6ff192017-08-11 06:56:05 +0200781
juraj.linkes184870a2018-07-16 14:22:01 +0200782 debug = os.getenv("DEBUG", "n").lower() in ["gdb", "gdbserver"]
783
juraj.linkes40dd73b2018-09-21 13:55:16 +0200784 debug_core = os.getenv("DEBUG", "").lower() == "core"
Paul Vinciguerra0cbc71d2019-07-03 08:38:38 -0400785 compress_core = framework.BoolEnvironmentVariable("CORE_COMPRESS")
juraj.linkes40dd73b2018-09-21 13:55:16 +0200786
Paul Vinciguerra0cbc71d2019-07-03 08:38:38 -0400787 step = framework.BoolEnvironmentVariable("STEP")
788 force_foreground = framework.BoolEnvironmentVariable("FORCE_FOREGROUND")
juraj.linkesb5ef26d2019-07-03 10:42:40 +0200789
790 run_interactive = debug or step or force_foreground
juraj.linkes184870a2018-07-16 14:22:01 +0200791
Paul Vinciguerra025cd9c2019-07-08 14:14:22 -0400792 try:
793 num_cpus = len(os.sched_getaffinity(0))
794 except AttributeError:
795 num_cpus = multiprocessing.cpu_count()
Paul Vinciguerra025cd9c2019-07-08 14:14:22 -0400796
Klement Sekeraeb506be2021-03-16 12:52:29 +0100797 print("OS reports %s available cpu(s)." % num_cpus)
Paul Vinciguerra025cd9c2019-07-08 14:14:22 -0400798
juraj.linkes184870a2018-07-16 14:22:01 +0200799 test_jobs = os.getenv("TEST_JOBS", "1").lower() # default = 1 process
800 if test_jobs == 'auto':
801 if run_interactive:
802 concurrent_tests = 1
803 print('Interactive mode required, running on one core')
804 else:
Klement Sekeraeb506be2021-03-16 12:52:29 +0100805 concurrent_tests = num_cpus
juraj.linkes184870a2018-07-16 14:22:01 +0200806 print('Found enough resources to run tests with %s cores'
807 % concurrent_tests)
808 elif test_jobs.isdigit():
809 concurrent_tests = int(test_jobs)
Paul Vinciguerra025cd9c2019-07-08 14:14:22 -0400810 print("Running on %s core(s) as set by 'TEST_JOBS'." %
811 concurrent_tests)
juraj.linkes184870a2018-07-16 14:22:01 +0200812 else:
813 concurrent_tests = 1
Paul Vinciguerra025cd9c2019-07-08 14:14:22 -0400814 print('Running on one core.')
juraj.linkes184870a2018-07-16 14:22:01 +0200815
816 if run_interactive and concurrent_tests > 1:
817 raise NotImplementedError(
juraj.linkes40dd73b2018-09-21 13:55:16 +0200818 'Running tests interactively (DEBUG is gdb or gdbserver or STEP '
819 'is set) in parallel (TEST_JOBS is more than 1) is not supported')
Klement Sekera13a83ef2018-03-21 12:35:51 +0100820
Klement Sekera3f6ff192017-08-11 06:56:05 +0200821 parser = argparse.ArgumentParser(description="VPP unit tests")
juraj.linkes184870a2018-07-16 14:22:01 +0200822 parser.add_argument("-f", "--failfast", action='store_true',
Klement Sekera3f6ff192017-08-11 06:56:05 +0200823 help="fast failure flag")
824 parser.add_argument("-d", "--dir", action='append', type=str,
825 help="directory containing test files "
826 "(may be specified multiple times)")
827 args = parser.parse_args()
juraj.linkes184870a2018-07-16 14:22:01 +0200828 failfast = args.failfast
829 descriptions = True
Klement Sekera3f6ff192017-08-11 06:56:05 +0200830
juraj.linkes184870a2018-07-16 14:22:01 +0200831 print("Running tests using custom test runner") # debug message
832 filter_file, filter_class, filter_func = parse_test_option()
833
834 print("Active filters: file=%s, class=%s, function=%s" % (
835 filter_file, filter_class, filter_func))
836
837 filter_cb = FilterByTestOption(filter_file, filter_class, filter_func)
838
Klement Sekerab8c72a42018-11-08 11:21:39 +0100839 ignore_path = os.getenv("VENV_PATH", None)
juraj.linkes184870a2018-07-16 14:22:01 +0200840 cb = SplitToSuitesCallback(filter_cb)
Klement Sekera3f6ff192017-08-11 06:56:05 +0200841 for d in args.dir:
Klement Sekeradf2b9802017-10-05 10:26:03 +0200842 print("Adding tests from directory tree %s" % d)
Klement Sekerab8c72a42018-11-08 11:21:39 +0100843 discover_tests(d, cb, ignore_path)
Klement Sekera3f6ff192017-08-11 06:56:05 +0200844
juraj.linkes184870a2018-07-16 14:22:01 +0200845 # suites are not hashable, need to use list
846 suites = []
847 tests_amount = 0
848 for testcase_suite in cb.suites.values():
849 tests_amount += testcase_suite.countTestCases()
850 suites.append(testcase_suite)
Klement Sekerabbfa5fd2018-06-27 13:54:32 +0200851
juraj.linkes184870a2018-07-16 14:22:01 +0200852 print("%s out of %s tests match specified filters" % (
853 tests_amount, tests_amount + cb.filtered.countTestCases()))
854
Paul Vinciguerradefde0f2018-12-06 07:46:13 -0800855 if not running_extended_tests:
juraj.linkes184870a2018-07-16 14:22:01 +0200856 print("Not running extended tests (some tests will be skipped)")
857
Klement Sekeradf2b9802017-10-05 10:26:03 +0200858 attempts = retries + 1
859 if attempts > 1:
860 print("Perform %s attempts to pass the suite..." % attempts)
juraj.linkes184870a2018-07-16 14:22:01 +0200861
Naveen Joy2cbf2fb2019-03-06 10:41:06 -0800862 if run_interactive and suites:
juraj.linkes184870a2018-07-16 14:22:01 +0200863 # don't fork if requiring interactive terminal
juraj.linkesb5ef26d2019-07-03 10:42:40 +0200864 print('Running tests in foreground in the current process')
juraj.linkes46e8e912019-01-10 12:13:07 +0100865 full_suite = unittest.TestSuite()
Klement Sekerad743dff2019-10-29 11:03:47 +0000866 full_suite.addTests(suites)
juraj.linkesabec0122018-11-16 17:28:56 +0100867 result = VppTestRunner(verbosity=verbose,
868 failfast=failfast,
juraj.linkes46e8e912019-01-10 12:13:07 +0100869 print_summary=True).run(full_suite)
juraj.linkes40dd73b2018-09-21 13:55:16 +0200870 was_successful = result.wasSuccessful()
871 if not was_successful:
872 for test_case_info in result.failed_test_cases_info:
873 handle_failed_suite(test_case_info.logger,
874 test_case_info.tempdir,
875 test_case_info.vpp_pid)
Klement Sekeraf40ee3a2019-05-06 19:11:25 +0200876 if test_case_info in result.core_crash_test_cases_info:
juraj.linkes40dd73b2018-09-21 13:55:16 +0200877 check_and_handle_core(test_case_info.vpp_bin_path,
878 test_case_info.tempdir,
879 test_case_info.core_crash_test)
880
881 sys.exit(not was_successful)
Klement Sekera13a83ef2018-03-21 12:35:51 +0100882 else:
juraj.linkesb5ef26d2019-07-03 10:42:40 +0200883 print('Running each VPPTestCase in a separate background process'
884 ' with {} parallel process(es)'.format(concurrent_tests))
juraj.linkes184870a2018-07-16 14:22:01 +0200885 exit_code = 0
Naveen Joy2cbf2fb2019-03-06 10:41:06 -0800886 while suites and attempts > 0:
juraj.linkes184870a2018-07-16 14:22:01 +0200887 results = run_forked(suites)
888 exit_code, suites = parse_results(results)
889 attempts -= 1
890 if exit_code == 0:
891 print('Test run was successful')
892 else:
893 print('%s attempt(s) left.' % attempts)
894 sys.exit(exit_code)