2019-10-31 13:31:07 -05:00
|
|
|
#!/usr/bin/env python3
|
2016-10-03 19:44:57 +02:00
|
|
|
|
2017-03-16 09:14:59 +01:00
|
|
|
import sys
|
2017-09-30 22:04:21 -04:00
|
|
|
import shutil
|
2016-10-03 19:44:57 +02:00
|
|
|
import os
|
2018-10-03 11:38:31 +02:00
|
|
|
import fnmatch
|
2016-10-03 19:44:57 +02:00
|
|
|
import unittest
|
2018-02-16 19:25:06 +01:00
|
|
|
import time
|
2018-07-16 14:22:01 +02:00
|
|
|
import threading
|
2021-05-31 16:08:53 +02:00
|
|
|
import traceback
|
2018-07-16 14:22:01 +02:00
|
|
|
import signal
|
2018-09-21 13:55:16 +02:00
|
|
|
import re
|
2021-04-08 19:37:41 +02:00
|
|
|
from multiprocessing import Process, Pipe, get_context
|
2018-07-16 14:22:01 +02:00
|
|
|
from multiprocessing.queues import Queue
|
|
|
|
from multiprocessing.managers import BaseManager
|
2021-05-31 16:08:53 +02:00
|
|
|
from config import config, num_cpus, available_cpus, max_vpp_cpus
|
2023-11-14 15:26:41 +01:00
|
|
|
from vpp_papi import VPPApiJSONFiles
|
2023-08-31 00:47:44 -04:00
|
|
|
from asfframework import (
|
2022-04-26 19:02:15 +02:00
|
|
|
VppTestRunner,
|
|
|
|
get_testcase_doc_name,
|
|
|
|
get_test_description,
|
2023-08-31 00:47:44 -04:00
|
|
|
get_failed_testcase_linkname,
|
|
|
|
get_testcase_dirname,
|
2022-04-26 19:02:15 +02:00
|
|
|
)
|
2023-08-31 00:47:44 -04:00
|
|
|
from framework import VppTestCase
|
2023-03-29 16:04:58 +02:00
|
|
|
from test_result_code import TestResultCode
|
2022-05-13 18:01:36 +02:00
|
|
|
from debug import spawn_gdb
|
2022-04-26 19:02:15 +02:00
|
|
|
from log import (
|
|
|
|
get_parallel_logger,
|
|
|
|
double_line_delim,
|
|
|
|
RED,
|
|
|
|
YELLOW,
|
|
|
|
GREEN,
|
|
|
|
colorize,
|
|
|
|
single_line_delim,
|
|
|
|
)
|
2017-08-17 07:38:42 +02:00
|
|
|
from discover_tests import discover_tests
|
2021-05-31 16:08:53 +02:00
|
|
|
import sanity_run_vpp
|
2018-03-23 10:50:11 +01:00
|
|
|
from subprocess import check_output, CalledProcessError
|
2018-09-21 13:55:16 +02:00
|
|
|
from util import check_core_path, get_core_path, is_core_present
|
2017-03-16 09:14:59 +01:00
|
|
|
|
2018-03-14 18:14:49 +01:00
|
|
|
# timeout which controls how long the child has to finish after seeing
|
|
|
|
# a core dump in test temporary directory. If this is exceeded, parent assumes
|
2021-03-16 12:52:29 +01:00
|
|
|
# that child process is stuck (e.g. waiting for event from vpp) and kill
|
|
|
|
# the child
|
2018-03-14 18:14:49 +01:00
|
|
|
core_timeout = 3
|
|
|
|
|
2017-08-08 04:33:53 +02:00
|
|
|
|
2018-07-16 14:22:01 +02:00
|
|
|
class StreamQueue(Queue):
|
|
|
|
def write(self, msg):
|
|
|
|
self.put(msg)
|
|
|
|
|
|
|
|
def flush(self):
|
|
|
|
sys.__stdout__.flush()
|
|
|
|
sys.__stderr__.flush()
|
|
|
|
|
|
|
|
def fileno(self):
|
|
|
|
return self._writer.fileno()
|
|
|
|
|
|
|
|
|
|
|
|
class StreamQueueManager(BaseManager):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
StreamQueueManager.register("StreamQueue", StreamQueue)
|
2018-07-16 14:22:01 +02:00
|
|
|
|
|
|
|
|
2018-09-19 15:01:47 +02:00
|
|
|
class TestResult(dict):
|
2018-09-21 13:55:16 +02:00
|
|
|
def __init__(self, testcase_suite, testcases_by_id=None):
|
2018-09-19 15:01:47 +02:00
|
|
|
super(TestResult, self).__init__()
|
2023-03-29 16:04:58 +02:00
|
|
|
for trc in list(TestResultCode):
|
|
|
|
self[trc] = []
|
2018-09-21 13:55:16 +02:00
|
|
|
self.crashed = False
|
2018-09-19 15:01:47 +02:00
|
|
|
self.testcase_suite = testcase_suite
|
|
|
|
self.testcases = [testcase for testcase in testcase_suite]
|
2018-09-21 13:55:16 +02:00
|
|
|
self.testcases_by_id = testcases_by_id
|
2018-09-19 15:01:47 +02:00
|
|
|
|
|
|
|
def was_successful(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
return (
|
2023-03-29 16:04:58 +02:00
|
|
|
0
|
|
|
|
== len(self[TestResultCode.FAIL])
|
|
|
|
== len(self[TestResultCode.ERROR])
|
|
|
|
== len(self[TestResultCode.UNEXPECTED_PASS])
|
|
|
|
and len(self[TestResultCode.PASS])
|
|
|
|
+ len(self[TestResultCode.SKIP])
|
|
|
|
+ len(self[TestResultCode.SKIP_CPU_SHORTAGE])
|
|
|
|
+ len(self[TestResultCode.EXPECTED_FAIL])
|
2021-04-08 19:37:41 +02:00
|
|
|
== self.testcase_suite.countTestCases()
|
2022-04-26 19:02:15 +02:00
|
|
|
)
|
2018-09-19 15:01:47 +02:00
|
|
|
|
|
|
|
def no_tests_run(self):
|
2023-03-29 16:04:58 +02:00
|
|
|
return 0 == len(self[TestResultCode.TEST_RUN])
|
2018-09-19 15:01:47 +02:00
|
|
|
|
|
|
|
def process_result(self, test_id, result):
|
|
|
|
self[result].append(test_id)
|
|
|
|
|
|
|
|
def suite_from_failed(self):
|
|
|
|
rerun_ids = set([])
|
|
|
|
for testcase in self.testcase_suite:
|
|
|
|
tc_id = testcase.id()
|
2023-03-29 16:04:58 +02:00
|
|
|
if (
|
|
|
|
tc_id
|
|
|
|
not in self[TestResultCode.PASS]
|
|
|
|
+ self[TestResultCode.SKIP]
|
|
|
|
+ self[TestResultCode.SKIP_CPU_SHORTAGE]
|
|
|
|
+ self[TestResultCode.EXPECTED_FAIL]
|
|
|
|
):
|
2018-09-19 15:01:47 +02:00
|
|
|
rerun_ids.add(tc_id)
|
2019-03-06 10:41:06 -08:00
|
|
|
if rerun_ids:
|
2018-09-19 15:01:47 +02:00
|
|
|
return suite_from_failed(self.testcase_suite, rerun_ids)
|
|
|
|
|
|
|
|
def get_testcase_names(self, test_id):
|
2018-12-13 11:10:47 +01:00
|
|
|
# could be tearDownClass (test_ipsec_esp.TestIpsecEsp1)
|
|
|
|
setup_teardown_match = re.match(
|
2022-04-26 19:02:15 +02:00
|
|
|
r"((tearDownClass)|(setUpClass)) \((.+\..+)\)", test_id
|
|
|
|
)
|
2018-12-13 11:10:47 +01:00
|
|
|
if setup_teardown_match:
|
|
|
|
test_name, _, _, testcase_name = setup_teardown_match.groups()
|
2022-04-26 19:02:15 +02:00
|
|
|
if len(testcase_name.split(".")) == 2:
|
2018-12-13 11:10:47 +01:00
|
|
|
for key in self.testcases_by_id.keys():
|
|
|
|
if key.startswith(testcase_name):
|
|
|
|
testcase_name = key
|
|
|
|
break
|
|
|
|
testcase_name = self._get_testcase_doc_name(testcase_name)
|
|
|
|
else:
|
2018-11-22 10:01:09 +00:00
|
|
|
test_name = self._get_test_description(test_id)
|
2018-09-21 13:55:16 +02:00
|
|
|
testcase_name = self._get_testcase_doc_name(test_id)
|
|
|
|
|
|
|
|
return testcase_name, test_name
|
2018-09-19 15:01:47 +02:00
|
|
|
|
2018-11-22 10:01:09 +00:00
|
|
|
def _get_test_description(self, test_id):
|
2018-12-13 11:10:47 +01:00
|
|
|
if test_id in self.testcases_by_id:
|
2022-04-26 19:02:15 +02:00
|
|
|
desc = get_test_description(descriptions, self.testcases_by_id[test_id])
|
2018-12-13 11:10:47 +01:00
|
|
|
else:
|
|
|
|
desc = test_id
|
|
|
|
return desc
|
2018-11-22 10:01:09 +00:00
|
|
|
|
2018-09-21 13:55:16 +02:00
|
|
|
def _get_testcase_doc_name(self, test_id):
|
2018-12-13 11:10:47 +01:00
|
|
|
if test_id in self.testcases_by_id:
|
|
|
|
doc_name = get_testcase_doc_name(self.testcases_by_id[test_id])
|
|
|
|
else:
|
|
|
|
doc_name = test_id
|
|
|
|
return doc_name
|
2018-09-19 15:01:47 +02:00
|
|
|
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
def test_runner_wrapper(
|
|
|
|
suite, keep_alive_pipe, stdouterr_queue, finished_pipe, result_pipe, logger
|
|
|
|
):
|
2018-07-16 14:22:01 +02:00
|
|
|
sys.stdout = stdouterr_queue
|
|
|
|
sys.stderr = stdouterr_queue
|
2018-11-09 11:58:54 +01:00
|
|
|
VppTestCase.parallel_handler = logger.handlers[0]
|
2022-04-26 19:02:15 +02:00
|
|
|
result = VppTestRunner(
|
|
|
|
keep_alive_pipe=keep_alive_pipe,
|
|
|
|
descriptions=descriptions,
|
|
|
|
verbosity=config.verbose,
|
|
|
|
result_pipe=result_pipe,
|
|
|
|
failfast=config.failfast,
|
|
|
|
print_summary=False,
|
|
|
|
).run(suite)
|
2018-09-19 15:01:47 +02:00
|
|
|
finished_pipe.send(result.wasSuccessful())
|
|
|
|
finished_pipe.close()
|
2017-08-08 04:33:53 +02:00
|
|
|
keep_alive_pipe.close()
|
|
|
|
|
|
|
|
|
2018-07-16 14:22:01 +02:00
|
|
|
class TestCaseWrapper(object):
|
|
|
|
def __init__(self, testcase_suite, manager):
|
2022-04-26 19:02:15 +02:00
|
|
|
self.keep_alive_parent_end, self.keep_alive_child_end = Pipe(duplex=False)
|
2018-09-19 15:01:47 +02:00
|
|
|
self.finished_parent_end, self.finished_child_end = Pipe(duplex=False)
|
2018-07-16 14:22:01 +02:00
|
|
|
self.result_parent_end, self.result_child_end = Pipe(duplex=False)
|
|
|
|
self.testcase_suite = testcase_suite
|
2021-04-08 19:37:41 +02:00
|
|
|
self.stdouterr_queue = manager.StreamQueue(ctx=get_context())
|
2018-07-16 14:22:01 +02:00
|
|
|
self.logger = get_parallel_logger(self.stdouterr_queue)
|
2022-04-26 19:02:15 +02:00
|
|
|
self.child = Process(
|
|
|
|
target=test_runner_wrapper,
|
|
|
|
args=(
|
|
|
|
testcase_suite,
|
|
|
|
self.keep_alive_child_end,
|
|
|
|
self.stdouterr_queue,
|
|
|
|
self.finished_child_end,
|
|
|
|
self.result_child_end,
|
|
|
|
self.logger,
|
|
|
|
),
|
|
|
|
)
|
2018-07-16 14:22:01 +02:00
|
|
|
self.child.start()
|
|
|
|
self.last_test_temp_dir = None
|
|
|
|
self.last_test_vpp_binary = None
|
2018-09-21 13:55:16 +02:00
|
|
|
self._last_test = None
|
|
|
|
self.last_test_id = None
|
2018-09-05 18:13:45 +02:00
|
|
|
self.vpp_pid = None
|
2018-07-16 14:22:01 +02:00
|
|
|
self.last_heard = time.time()
|
|
|
|
self.core_detected_at = None
|
2018-09-21 13:55:16 +02:00
|
|
|
self.testcases_by_id = {}
|
|
|
|
self.testclasess_with_core = {}
|
|
|
|
for testcase in self.testcase_suite:
|
|
|
|
self.testcases_by_id[testcase.id()] = testcase
|
|
|
|
self.result = TestResult(testcase_suite, self.testcases_by_id)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def last_test(self):
|
|
|
|
return self._last_test
|
|
|
|
|
|
|
|
@last_test.setter
|
|
|
|
def last_test(self, test_id):
|
|
|
|
self.last_test_id = test_id
|
|
|
|
if test_id in self.testcases_by_id:
|
|
|
|
testcase = self.testcases_by_id[test_id]
|
|
|
|
self._last_test = testcase.shortDescription()
|
|
|
|
if not self._last_test:
|
|
|
|
self._last_test = str(testcase)
|
|
|
|
else:
|
|
|
|
self._last_test = test_id
|
|
|
|
|
|
|
|
def add_testclass_with_core(self):
|
|
|
|
if self.last_test_id in self.testcases_by_id:
|
|
|
|
test = self.testcases_by_id[self.last_test_id]
|
|
|
|
class_name = unittest.util.strclass(test.__class__)
|
2022-04-26 19:02:15 +02:00
|
|
|
test_name = "'{}' ({})".format(
|
|
|
|
get_test_description(descriptions, test), self.last_test_id
|
|
|
|
)
|
2018-09-21 13:55:16 +02:00
|
|
|
else:
|
|
|
|
test_name = self.last_test_id
|
2022-04-26 19:02:15 +02:00
|
|
|
class_name = re.match(
|
|
|
|
r"((tearDownClass)|(setUpClass)) " r"\((.+\..+)\)", test_name
|
|
|
|
).groups()[3]
|
2018-09-21 13:55:16 +02:00
|
|
|
if class_name not in self.testclasess_with_core:
|
|
|
|
self.testclasess_with_core[class_name] = (
|
|
|
|
test_name,
|
|
|
|
self.last_test_vpp_binary,
|
2022-04-26 19:02:15 +02:00
|
|
|
self.last_test_temp_dir,
|
|
|
|
)
|
2018-07-16 14:22:01 +02:00
|
|
|
|
|
|
|
def close_pipes(self):
|
|
|
|
self.keep_alive_child_end.close()
|
2018-09-19 15:01:47 +02:00
|
|
|
self.finished_child_end.close()
|
2018-07-16 14:22:01 +02:00
|
|
|
self.result_child_end.close()
|
|
|
|
self.keep_alive_parent_end.close()
|
2018-09-19 15:01:47 +02:00
|
|
|
self.finished_parent_end.close()
|
2018-07-16 14:22:01 +02:00
|
|
|
self.result_parent_end.close()
|
|
|
|
|
2018-09-21 13:55:16 +02:00
|
|
|
def was_successful(self):
|
|
|
|
return self.result.was_successful()
|
|
|
|
|
2021-04-08 19:37:41 +02:00
|
|
|
@property
|
|
|
|
def cpus_used(self):
|
|
|
|
return self.testcase_suite.cpus_used
|
|
|
|
|
|
|
|
def get_assigned_cpus(self):
|
|
|
|
return self.testcase_suite.get_assigned_cpus()
|
|
|
|
|
2018-07-16 14:22:01 +02:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
def stdouterr_reader_wrapper(
|
|
|
|
unread_testcases, finished_unread_testcases, read_testcases
|
|
|
|
):
|
2018-07-16 14:22:01 +02:00
|
|
|
read_testcase = None
|
2019-03-06 10:41:06 -08:00
|
|
|
while read_testcases.is_set() or unread_testcases:
|
|
|
|
if finished_unread_testcases:
|
2018-11-29 09:56:35 +01:00
|
|
|
read_testcase = finished_unread_testcases.pop()
|
|
|
|
unread_testcases.remove(read_testcase)
|
2019-03-06 10:41:06 -08:00
|
|
|
elif unread_testcases:
|
2018-11-29 09:56:35 +01:00
|
|
|
read_testcase = unread_testcases.pop()
|
2018-07-16 14:22:01 +02:00
|
|
|
if read_testcase:
|
2022-04-26 19:02:15 +02:00
|
|
|
data = ""
|
2018-07-16 14:22:01 +02:00
|
|
|
while data is not None:
|
|
|
|
sys.stdout.write(data)
|
|
|
|
data = read_testcase.stdouterr_queue.get()
|
|
|
|
|
|
|
|
read_testcase.stdouterr_queue.close()
|
|
|
|
finished_unread_testcases.discard(read_testcase)
|
|
|
|
read_testcase = None
|
|
|
|
|
|
|
|
|
2022-03-26 15:43:14 +00:00
|
|
|
def handle_failed_suite(logger, last_test_temp_dir, vpp_pid, vpp_binary):
|
2018-09-21 13:55:16 +02:00
|
|
|
if last_test_temp_dir:
|
|
|
|
# Need to create link in case of a timeout or core dump without failure
|
|
|
|
lttd = os.path.basename(last_test_temp_dir)
|
2022-05-13 18:01:36 +02:00
|
|
|
link_path = os.path.join(config.failed_dir, f"{lttd}-FAILED")
|
2018-09-21 13:55:16 +02:00
|
|
|
if not os.path.exists(link_path):
|
|
|
|
os.symlink(last_test_temp_dir, link_path)
|
2022-04-26 19:02:15 +02:00
|
|
|
logger.error(
|
|
|
|
"Symlink to failed testcase directory: %s -> %s" % (link_path, lttd)
|
|
|
|
)
|
2018-09-21 13:55:16 +02:00
|
|
|
|
|
|
|
# Report core existence
|
|
|
|
core_path = get_core_path(last_test_temp_dir)
|
|
|
|
if os.path.exists(core_path):
|
|
|
|
logger.error(
|
2022-04-26 19:02:15 +02:00
|
|
|
"Core-file exists in test temporary directory: %s!" % core_path
|
|
|
|
)
|
2018-09-21 13:55:16 +02:00
|
|
|
check_core_path(logger, core_path)
|
2018-11-28 11:34:21 -08:00
|
|
|
logger.debug("Running 'file %s':" % core_path)
|
2018-09-21 13:55:16 +02:00
|
|
|
try:
|
|
|
|
info = check_output(["file", core_path])
|
|
|
|
logger.debug(info)
|
|
|
|
except CalledProcessError as e:
|
2022-04-26 19:02:15 +02:00
|
|
|
logger.error(
|
|
|
|
"Subprocess returned with return code "
|
|
|
|
"while running `file' utility on core-file "
|
|
|
|
"returned: "
|
|
|
|
"rc=%s",
|
|
|
|
e.returncode,
|
|
|
|
)
|
2018-11-28 11:34:21 -08:00
|
|
|
except OSError as e:
|
2022-04-26 19:02:15 +02:00
|
|
|
logger.error(
|
|
|
|
"Subprocess returned with OS error while "
|
|
|
|
"running 'file' utility "
|
|
|
|
"on core-file: "
|
|
|
|
"(%s) %s",
|
|
|
|
e.errno,
|
|
|
|
e.strerror,
|
|
|
|
)
|
2018-11-28 11:34:21 -08:00
|
|
|
except Exception as e:
|
2022-04-26 19:02:15 +02:00
|
|
|
logger.exception("Unexpected error running `file' utility on core-file")
|
2022-03-26 15:43:14 +00:00
|
|
|
logger.error(f"gdb {vpp_binary} {core_path}")
|
2018-09-21 13:55:16 +02:00
|
|
|
|
|
|
|
if vpp_pid:
|
|
|
|
# Copy api post mortem
|
|
|
|
api_post_mortem_path = "/tmp/api_post_mortem.%d" % vpp_pid
|
|
|
|
if os.path.isfile(api_post_mortem_path):
|
2022-04-26 19:02:15 +02:00
|
|
|
logger.error(
|
|
|
|
"Copying api_post_mortem.%d to %s" % (vpp_pid, last_test_temp_dir)
|
|
|
|
)
|
2018-09-21 13:55:16 +02:00
|
|
|
shutil.copy2(api_post_mortem_path, last_test_temp_dir)
|
|
|
|
|
|
|
|
|
|
|
|
def check_and_handle_core(vpp_binary, tempdir, core_crash_test):
|
|
|
|
if is_core_present(tempdir):
|
2019-05-06 19:11:25 +02:00
|
|
|
if debug_core:
|
2022-04-26 19:02:15 +02:00
|
|
|
print(
|
|
|
|
"VPP core detected in %s. Last test running was %s"
|
|
|
|
% (tempdir, core_crash_test)
|
|
|
|
)
|
2019-05-06 19:11:25 +02:00
|
|
|
print(single_line_delim)
|
|
|
|
spawn_gdb(vpp_binary, get_core_path(tempdir))
|
|
|
|
print(single_line_delim)
|
2021-05-31 16:08:53 +02:00
|
|
|
elif config.compress_core:
|
2019-05-06 19:11:25 +02:00
|
|
|
print("Compressing core-file in test directory `%s'" % tempdir)
|
|
|
|
os.system("gzip %s" % get_core_path(tempdir))
|
2018-09-21 13:55:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
def handle_cores(failed_testcases):
|
2019-05-06 19:11:25 +02:00
|
|
|
for failed_testcase in failed_testcases:
|
|
|
|
tcs_with_core = failed_testcase.testclasess_with_core
|
|
|
|
if tcs_with_core:
|
|
|
|
for test, vpp_binary, tempdir in tcs_with_core.values():
|
|
|
|
check_and_handle_core(vpp_binary, tempdir, test)
|
2018-09-21 13:55:16 +02:00
|
|
|
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
def process_finished_testsuite(
|
|
|
|
wrapped_testcase_suite, finished_testcase_suites, failed_wrapped_testcases, results
|
|
|
|
):
|
2018-09-21 13:55:16 +02:00
|
|
|
results.append(wrapped_testcase_suite.result)
|
|
|
|
finished_testcase_suites.add(wrapped_testcase_suite)
|
|
|
|
stop_run = False
|
2021-05-31 16:08:53 +02:00
|
|
|
if config.failfast and not wrapped_testcase_suite.was_successful():
|
2018-09-21 13:55:16 +02:00
|
|
|
stop_run = True
|
|
|
|
|
|
|
|
if not wrapped_testcase_suite.was_successful():
|
|
|
|
failed_wrapped_testcases.add(wrapped_testcase_suite)
|
2022-04-26 19:02:15 +02:00
|
|
|
handle_failed_suite(
|
|
|
|
wrapped_testcase_suite.logger,
|
|
|
|
wrapped_testcase_suite.last_test_temp_dir,
|
|
|
|
wrapped_testcase_suite.vpp_pid,
|
|
|
|
wrapped_testcase_suite.last_test_vpp_binary,
|
|
|
|
)
|
2018-09-21 13:55:16 +02:00
|
|
|
|
|
|
|
return stop_run
|
|
|
|
|
|
|
|
|
2018-09-05 18:13:45 +02:00
|
|
|
def run_forked(testcase_suites):
|
2018-07-16 14:22:01 +02:00
|
|
|
wrapped_testcase_suites = set()
|
2020-08-26 14:33:54 +00:00
|
|
|
solo_testcase_suites = []
|
2018-07-16 14:22:01 +02:00
|
|
|
|
|
|
|
# suites are unhashable, need to use list
|
|
|
|
results = []
|
|
|
|
unread_testcases = set()
|
|
|
|
finished_unread_testcases = set()
|
|
|
|
manager = StreamQueueManager()
|
|
|
|
manager.start()
|
2021-04-08 19:37:41 +02:00
|
|
|
tests_running = 0
|
|
|
|
free_cpus = list(available_cpus)
|
|
|
|
|
|
|
|
def on_suite_start(tc):
|
|
|
|
nonlocal tests_running
|
|
|
|
nonlocal free_cpus
|
|
|
|
tests_running = tests_running + 1
|
|
|
|
|
|
|
|
def on_suite_finish(tc):
|
|
|
|
nonlocal tests_running
|
|
|
|
nonlocal free_cpus
|
|
|
|
tests_running = tests_running - 1
|
|
|
|
assert tests_running >= 0
|
|
|
|
free_cpus.extend(tc.get_assigned_cpus())
|
|
|
|
|
|
|
|
def run_suite(suite):
|
|
|
|
nonlocal manager
|
|
|
|
nonlocal wrapped_testcase_suites
|
|
|
|
nonlocal unread_testcases
|
|
|
|
nonlocal free_cpus
|
2022-04-26 19:02:15 +02:00
|
|
|
suite.assign_cpus(free_cpus[: suite.cpus_used])
|
|
|
|
free_cpus = free_cpus[suite.cpus_used :]
|
2021-04-08 19:37:41 +02:00
|
|
|
wrapper = TestCaseWrapper(suite, manager)
|
|
|
|
wrapped_testcase_suites.add(wrapper)
|
|
|
|
unread_testcases.add(wrapper)
|
|
|
|
on_suite_start(suite)
|
|
|
|
|
|
|
|
def can_run_suite(suite):
|
2022-04-26 19:02:15 +02:00
|
|
|
return tests_running < max_concurrent_tests and (
|
|
|
|
suite.cpus_used <= len(free_cpus) or suite.cpus_used > max_vpp_cpus
|
|
|
|
)
|
2021-04-08 19:37:41 +02:00
|
|
|
|
|
|
|
while free_cpus and testcase_suites:
|
|
|
|
a_suite = testcase_suites[0]
|
|
|
|
if a_suite.is_tagged_run_solo:
|
|
|
|
a_suite = testcase_suites.pop(0)
|
|
|
|
solo_testcase_suites.append(a_suite)
|
|
|
|
continue
|
|
|
|
if can_run_suite(a_suite):
|
2020-08-26 14:33:54 +00:00
|
|
|
a_suite = testcase_suites.pop(0)
|
2021-04-08 19:37:41 +02:00
|
|
|
run_suite(a_suite)
|
2020-08-26 14:33:54 +00:00
|
|
|
else:
|
|
|
|
break
|
|
|
|
|
2021-04-08 19:37:41 +02:00
|
|
|
if tests_running == 0 and solo_testcase_suites:
|
|
|
|
a_suite = solo_testcase_suites.pop(0)
|
|
|
|
run_suite(a_suite)
|
2018-07-16 14:22:01 +02:00
|
|
|
|
|
|
|
read_from_testcases = threading.Event()
|
|
|
|
read_from_testcases.set()
|
2022-04-26 19:02:15 +02:00
|
|
|
stdouterr_thread = threading.Thread(
|
|
|
|
target=stdouterr_reader_wrapper,
|
|
|
|
args=(unread_testcases, finished_unread_testcases, read_from_testcases),
|
|
|
|
)
|
2018-07-16 14:22:01 +02:00
|
|
|
stdouterr_thread.start()
|
|
|
|
|
2018-09-21 13:55:16 +02:00
|
|
|
failed_wrapped_testcases = set()
|
|
|
|
stop_run = False
|
2018-11-29 09:56:35 +01:00
|
|
|
|
|
|
|
try:
|
2023-04-14 17:43:35 +02:00
|
|
|
while wrapped_testcase_suites or testcase_suites:
|
2018-11-29 09:56:35 +01:00
|
|
|
finished_testcase_suites = set()
|
|
|
|
for wrapped_testcase_suite in wrapped_testcase_suites:
|
|
|
|
while wrapped_testcase_suite.result_parent_end.poll():
|
|
|
|
wrapped_testcase_suite.result.process_result(
|
2022-04-26 19:02:15 +02:00
|
|
|
*wrapped_testcase_suite.result_parent_end.recv()
|
|
|
|
)
|
2018-11-29 09:56:35 +01:00
|
|
|
wrapped_testcase_suite.last_heard = time.time()
|
|
|
|
|
|
|
|
while wrapped_testcase_suite.keep_alive_parent_end.poll():
|
2022-04-26 19:02:15 +02:00
|
|
|
(
|
|
|
|
wrapped_testcase_suite.last_test,
|
|
|
|
wrapped_testcase_suite.last_test_vpp_binary,
|
|
|
|
wrapped_testcase_suite.last_test_temp_dir,
|
|
|
|
wrapped_testcase_suite.vpp_pid,
|
|
|
|
) = wrapped_testcase_suite.keep_alive_parent_end.recv()
|
2018-11-29 09:56:35 +01:00
|
|
|
wrapped_testcase_suite.last_heard = time.time()
|
|
|
|
|
|
|
|
if wrapped_testcase_suite.finished_parent_end.poll():
|
|
|
|
wrapped_testcase_suite.finished_parent_end.recv()
|
|
|
|
wrapped_testcase_suite.last_heard = time.time()
|
2022-04-26 19:02:15 +02:00
|
|
|
stop_run = (
|
|
|
|
process_finished_testsuite(
|
|
|
|
wrapped_testcase_suite,
|
|
|
|
finished_testcase_suites,
|
|
|
|
failed_wrapped_testcases,
|
|
|
|
results,
|
|
|
|
)
|
|
|
|
or stop_run
|
|
|
|
)
|
2018-11-29 09:56:35 +01:00
|
|
|
continue
|
|
|
|
|
|
|
|
fail = False
|
2022-04-26 19:02:15 +02:00
|
|
|
if wrapped_testcase_suite.last_heard + config.timeout < time.time():
|
2018-11-29 09:56:35 +01:00
|
|
|
fail = True
|
|
|
|
wrapped_testcase_suite.logger.critical(
|
|
|
|
"Child test runner process timed out "
|
2022-04-26 19:02:15 +02:00
|
|
|
"(last test running was `%s' in `%s')!"
|
|
|
|
% (
|
|
|
|
wrapped_testcase_suite.last_test,
|
|
|
|
wrapped_testcase_suite.last_test_temp_dir,
|
|
|
|
)
|
|
|
|
)
|
2018-11-29 09:56:35 +01:00
|
|
|
elif not wrapped_testcase_suite.child.is_alive():
|
|
|
|
fail = True
|
|
|
|
wrapped_testcase_suite.logger.critical(
|
|
|
|
"Child test runner process unexpectedly died "
|
2022-04-26 19:02:15 +02:00
|
|
|
"(last test running was `%s' in `%s')!"
|
|
|
|
% (
|
|
|
|
wrapped_testcase_suite.last_test,
|
|
|
|
wrapped_testcase_suite.last_test_temp_dir,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
elif (
|
|
|
|
wrapped_testcase_suite.last_test_temp_dir
|
|
|
|
and wrapped_testcase_suite.last_test_vpp_binary
|
|
|
|
):
|
|
|
|
if is_core_present(wrapped_testcase_suite.last_test_temp_dir):
|
2018-11-29 09:56:35 +01:00
|
|
|
wrapped_testcase_suite.add_testclass_with_core()
|
|
|
|
if wrapped_testcase_suite.core_detected_at is None:
|
2022-04-26 19:02:15 +02:00
|
|
|
wrapped_testcase_suite.core_detected_at = time.time()
|
|
|
|
elif (
|
|
|
|
wrapped_testcase_suite.core_detected_at + core_timeout
|
|
|
|
< time.time()
|
|
|
|
):
|
2018-11-29 09:56:35 +01:00
|
|
|
wrapped_testcase_suite.logger.critical(
|
|
|
|
"Child test runner process unresponsive and "
|
|
|
|
"core-file exists in test temporary directory "
|
2022-04-26 19:02:15 +02:00
|
|
|
"(last test running was `%s' in `%s')!"
|
|
|
|
% (
|
|
|
|
wrapped_testcase_suite.last_test,
|
|
|
|
wrapped_testcase_suite.last_test_temp_dir,
|
|
|
|
)
|
|
|
|
)
|
2018-11-29 09:56:35 +01:00
|
|
|
fail = True
|
|
|
|
|
|
|
|
if fail:
|
|
|
|
wrapped_testcase_suite.child.terminate()
|
|
|
|
try:
|
|
|
|
# terminating the child process tends to leave orphan
|
|
|
|
# VPP process around
|
|
|
|
if wrapped_testcase_suite.vpp_pid:
|
2022-04-26 19:02:15 +02:00
|
|
|
os.kill(wrapped_testcase_suite.vpp_pid, signal.SIGTERM)
|
2018-11-29 09:56:35 +01:00
|
|
|
except OSError:
|
|
|
|
# already dead
|
|
|
|
pass
|
|
|
|
wrapped_testcase_suite.result.crashed = True
|
|
|
|
wrapped_testcase_suite.result.process_result(
|
2023-03-29 16:04:58 +02:00
|
|
|
wrapped_testcase_suite.last_test_id, TestResultCode.ERROR
|
2022-04-26 19:02:15 +02:00
|
|
|
)
|
|
|
|
stop_run = (
|
|
|
|
process_finished_testsuite(
|
|
|
|
wrapped_testcase_suite,
|
|
|
|
finished_testcase_suites,
|
|
|
|
failed_wrapped_testcases,
|
|
|
|
results,
|
|
|
|
)
|
|
|
|
or stop_run
|
|
|
|
)
|
2018-11-29 09:56:35 +01:00
|
|
|
|
|
|
|
for finished_testcase in finished_testcase_suites:
|
2019-11-05 01:08:26 +01:00
|
|
|
# Somewhat surprisingly, the join below may
|
|
|
|
# timeout, even if client signaled that
|
|
|
|
# it finished - so we note it just in case.
|
|
|
|
join_start = time.time()
|
|
|
|
finished_testcase.child.join(test_finished_join_timeout)
|
|
|
|
join_end = time.time()
|
|
|
|
if join_end - join_start >= test_finished_join_timeout:
|
|
|
|
finished_testcase.logger.error(
|
2022-04-26 19:02:15 +02:00
|
|
|
"Timeout joining finished test: %s (pid %d)"
|
|
|
|
% (finished_testcase.last_test, finished_testcase.child.pid)
|
|
|
|
)
|
2018-11-29 09:56:35 +01:00
|
|
|
finished_testcase.close_pipes()
|
|
|
|
wrapped_testcase_suites.remove(finished_testcase)
|
|
|
|
finished_unread_testcases.add(finished_testcase)
|
|
|
|
finished_testcase.stdouterr_queue.put(None)
|
2021-04-08 19:37:41 +02:00
|
|
|
on_suite_finish(finished_testcase)
|
2018-11-29 09:56:35 +01:00
|
|
|
if stop_run:
|
2019-03-06 10:41:06 -08:00
|
|
|
while testcase_suites:
|
2018-11-29 09:56:35 +01:00
|
|
|
results.append(TestResult(testcase_suites.pop(0)))
|
2019-03-06 10:41:06 -08:00
|
|
|
elif testcase_suites:
|
2023-04-14 17:43:35 +02:00
|
|
|
a_suite = testcase_suites[0]
|
2021-04-08 19:37:41 +02:00
|
|
|
while a_suite and a_suite.is_tagged_run_solo:
|
2023-04-14 17:43:35 +02:00
|
|
|
testcase_suites.pop(0)
|
2021-04-08 19:37:41 +02:00
|
|
|
solo_testcase_suites.append(a_suite)
|
2020-08-26 14:33:54 +00:00
|
|
|
if testcase_suites:
|
2023-04-14 17:43:35 +02:00
|
|
|
a_suite = testcase_suites[0]
|
2020-08-26 14:33:54 +00:00
|
|
|
else:
|
2021-04-08 19:37:41 +02:00
|
|
|
a_suite = None
|
|
|
|
if a_suite and can_run_suite(a_suite):
|
2023-04-14 17:43:35 +02:00
|
|
|
testcase_suites.pop(0)
|
2021-04-08 19:37:41 +02:00
|
|
|
run_suite(a_suite)
|
|
|
|
if solo_testcase_suites and tests_running == 0:
|
|
|
|
a_suite = solo_testcase_suites.pop(0)
|
|
|
|
run_suite(a_suite)
|
2019-03-15 19:16:50 -07:00
|
|
|
time.sleep(0.1)
|
2018-11-29 09:56:35 +01:00
|
|
|
except Exception:
|
2018-07-16 14:22:01 +02:00
|
|
|
for wrapped_testcase_suite in wrapped_testcase_suites:
|
2018-11-29 09:56:35 +01:00
|
|
|
wrapped_testcase_suite.child.terminate()
|
|
|
|
wrapped_testcase_suite.stdouterr_queue.put(None)
|
|
|
|
raise
|
|
|
|
finally:
|
|
|
|
read_from_testcases.clear()
|
2021-05-31 16:08:53 +02:00
|
|
|
stdouterr_thread.join(config.timeout)
|
2018-11-29 09:56:35 +01:00
|
|
|
manager.shutdown()
|
|
|
|
|
2018-09-21 13:55:16 +02:00
|
|
|
handle_cores(failed_wrapped_testcases)
|
2018-07-16 14:22:01 +02:00
|
|
|
return results
|
|
|
|
|
|
|
|
|
2021-04-08 19:37:41 +02:00
|
|
|
class TestSuiteWrapper(unittest.TestSuite):
|
|
|
|
cpus_used = 0
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
return super().__init__()
|
|
|
|
|
|
|
|
def addTest(self, test):
|
|
|
|
self.cpus_used = max(self.cpus_used, test.get_cpus_required())
|
|
|
|
super().addTest(test)
|
|
|
|
|
|
|
|
def assign_cpus(self, cpus):
|
|
|
|
self.cpus = cpus
|
|
|
|
|
|
|
|
def _handleClassSetUp(self, test, result):
|
|
|
|
if not test.__class__.skipped_due_to_cpu_lack:
|
|
|
|
test.assign_cpus(self.cpus)
|
|
|
|
super()._handleClassSetUp(test, result)
|
|
|
|
|
|
|
|
def get_assigned_cpus(self):
|
|
|
|
return self.cpus
|
|
|
|
|
|
|
|
|
2018-07-16 14:22:01 +02:00
|
|
|
class SplitToSuitesCallback:
|
|
|
|
def __init__(self, filter_callback):
|
|
|
|
self.suites = {}
|
2022-04-26 19:02:15 +02:00
|
|
|
self.suite_name = "default"
|
2018-07-16 14:22:01 +02:00
|
|
|
self.filter_callback = filter_callback
|
2021-04-08 19:37:41 +02:00
|
|
|
self.filtered = TestSuiteWrapper()
|
2017-08-17 07:38:42 +02:00
|
|
|
|
|
|
|
def __call__(self, file_name, cls, method):
|
2018-07-16 14:22:01 +02:00
|
|
|
test_method = cls(method)
|
|
|
|
if self.filter_callback(file_name, cls.__name__, method):
|
|
|
|
self.suite_name = file_name + cls.__name__
|
|
|
|
if self.suite_name not in self.suites:
|
2021-04-08 19:37:41 +02:00
|
|
|
self.suites[self.suite_name] = TestSuiteWrapper()
|
2021-01-14 10:19:08 +00:00
|
|
|
self.suites[self.suite_name].is_tagged_run_solo = False
|
2018-07-16 14:22:01 +02:00
|
|
|
self.suites[self.suite_name].addTest(test_method)
|
2021-01-14 10:19:08 +00:00
|
|
|
if test_method.is_tagged_run_solo():
|
|
|
|
self.suites[self.suite_name].is_tagged_run_solo = True
|
2018-07-16 14:22:01 +02:00
|
|
|
|
|
|
|
else:
|
|
|
|
self.filtered.addTest(test_method)
|
|
|
|
|
2017-08-17 07:38:42 +02:00
|
|
|
|
2021-05-31 16:08:53 +02:00
|
|
|
def parse_test_filter(test_filter):
|
|
|
|
f = test_filter
|
2018-07-16 14:22:01 +02:00
|
|
|
filter_file_name = None
|
|
|
|
filter_class_name = None
|
|
|
|
filter_func_name = None
|
|
|
|
if f:
|
2022-04-26 19:02:15 +02:00
|
|
|
if "." in f:
|
|
|
|
parts = f.split(".")
|
2018-07-16 14:22:01 +02:00
|
|
|
if len(parts) > 3:
|
2023-04-14 17:44:04 +02:00
|
|
|
raise Exception(f"Invalid test filter: {test_filter}")
|
2018-07-16 14:22:01 +02:00
|
|
|
if len(parts) > 2:
|
2022-04-26 19:02:15 +02:00
|
|
|
if parts[2] not in ("*", ""):
|
2018-07-16 14:22:01 +02:00
|
|
|
filter_func_name = parts[2]
|
2022-04-26 19:02:15 +02:00
|
|
|
if parts[1] not in ("*", ""):
|
2018-07-16 14:22:01 +02:00
|
|
|
filter_class_name = parts[1]
|
2022-04-26 19:02:15 +02:00
|
|
|
if parts[0] not in ("*", ""):
|
|
|
|
if parts[0].startswith("test_"):
|
2018-07-16 14:22:01 +02:00
|
|
|
filter_file_name = parts[0]
|
|
|
|
else:
|
2022-04-26 19:02:15 +02:00
|
|
|
filter_file_name = "test_%s" % parts[0]
|
2018-07-16 14:22:01 +02:00
|
|
|
else:
|
2022-04-26 19:02:15 +02:00
|
|
|
if f.startswith("test_"):
|
2018-07-16 14:22:01 +02:00
|
|
|
filter_file_name = f
|
|
|
|
else:
|
2022-04-26 19:02:15 +02:00
|
|
|
filter_file_name = "test_%s" % f
|
2018-07-16 14:22:01 +02:00
|
|
|
if filter_file_name:
|
2022-04-26 19:02:15 +02:00
|
|
|
filter_file_name = "%s.py" % filter_file_name
|
2018-07-16 14:22:01 +02:00
|
|
|
return filter_file_name, filter_class_name, filter_func_name
|
|
|
|
|
|
|
|
|
|
|
|
def filter_tests(tests, filter_cb):
|
2021-04-08 19:37:41 +02:00
|
|
|
result = TestSuiteWrapper()
|
2018-07-16 14:22:01 +02:00
|
|
|
for t in tests:
|
|
|
|
if isinstance(t, unittest.suite.TestSuite):
|
|
|
|
# this is a bunch of tests, recursively filter...
|
|
|
|
x = filter_tests(t, filter_cb)
|
|
|
|
if x.countTestCases() > 0:
|
|
|
|
result.addTest(x)
|
|
|
|
elif isinstance(t, unittest.TestCase):
|
|
|
|
# this is a single test
|
2022-04-26 19:02:15 +02:00
|
|
|
parts = t.id().split(".")
|
2018-07-16 14:22:01 +02:00
|
|
|
# t.id() for common cases like this:
|
|
|
|
# test_classifier.TestClassifier.test_acl_ip
|
|
|
|
# apply filtering only if it is so
|
|
|
|
if len(parts) == 3:
|
|
|
|
if not filter_cb(parts[0], parts[1], parts[2]):
|
|
|
|
continue
|
|
|
|
result.addTest(t)
|
|
|
|
else:
|
|
|
|
# unexpected object, don't touch it
|
|
|
|
result.addTest(t)
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
class FilterByTestOption:
|
2023-04-14 17:44:04 +02:00
|
|
|
def __init__(self, filters):
|
|
|
|
self.filters = filters
|
2018-07-16 14:22:01 +02:00
|
|
|
|
|
|
|
def __call__(self, file_name, class_name, func_name):
|
2023-04-14 17:44:04 +02:00
|
|
|
def test_one(
|
|
|
|
filter_file_name,
|
|
|
|
filter_class_name,
|
|
|
|
filter_func_name,
|
|
|
|
file_name,
|
|
|
|
class_name,
|
|
|
|
func_name,
|
|
|
|
):
|
|
|
|
if filter_file_name:
|
|
|
|
fn_match = fnmatch.fnmatch(file_name, filter_file_name)
|
|
|
|
if not fn_match:
|
|
|
|
return False
|
|
|
|
if filter_class_name and class_name != filter_class_name:
|
2018-10-03 11:38:31 +02:00
|
|
|
return False
|
2023-04-14 17:44:04 +02:00
|
|
|
if filter_func_name and func_name != filter_func_name:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
for filter_file_name, filter_class_name, filter_func_name in self.filters:
|
|
|
|
if test_one(
|
|
|
|
filter_file_name,
|
|
|
|
filter_class_name,
|
|
|
|
filter_func_name,
|
|
|
|
file_name,
|
|
|
|
class_name,
|
|
|
|
func_name,
|
|
|
|
):
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
2018-07-16 14:22:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
class FilterByClassList:
|
2018-09-05 18:13:45 +02:00
|
|
|
def __init__(self, classes_with_filenames):
|
|
|
|
self.classes_with_filenames = classes_with_filenames
|
2017-10-05 10:26:03 +02:00
|
|
|
|
|
|
|
def __call__(self, file_name, class_name, func_name):
|
2022-04-26 19:02:15 +02:00
|
|
|
return ".".join([file_name, class_name]) in self.classes_with_filenames
|
2017-10-05 10:26:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
def suite_from_failed(suite, failed):
|
2022-04-26 19:02:15 +02:00
|
|
|
failed = {x.rsplit(".", 1)[0] for x in failed}
|
2018-07-16 14:22:01 +02:00
|
|
|
filter_cb = FilterByClassList(failed)
|
|
|
|
suite = filter_tests(suite, filter_cb)
|
2018-06-22 13:19:45 +02:00
|
|
|
return suite
|
2017-10-05 10:26:03 +02:00
|
|
|
|
|
|
|
|
2018-09-19 15:01:47 +02:00
|
|
|
class AllResults(dict):
|
2018-07-16 14:22:01 +02:00
|
|
|
def __init__(self):
|
2018-09-19 15:01:47 +02:00
|
|
|
super(AllResults, self).__init__()
|
2018-07-16 14:22:01 +02:00
|
|
|
self.all_testcases = 0
|
2018-09-19 15:01:47 +02:00
|
|
|
self.results_per_suite = []
|
2023-03-29 16:04:58 +02:00
|
|
|
for trc in list(TestResultCode):
|
|
|
|
self[trc] = 0
|
2018-07-16 14:22:01 +02:00
|
|
|
self.rerun = []
|
2018-09-19 15:01:47 +02:00
|
|
|
self.testsuites_no_tests_run = []
|
|
|
|
|
|
|
|
def add_results(self, result):
|
|
|
|
self.results_per_suite.append(result)
|
2023-03-29 16:04:58 +02:00
|
|
|
for trc in list(TestResultCode):
|
|
|
|
self[trc] += len(result[trc])
|
2018-09-19 15:01:47 +02:00
|
|
|
|
|
|
|
def add_result(self, result):
|
2018-07-16 14:22:01 +02:00
|
|
|
retval = 0
|
2018-09-19 15:01:47 +02:00
|
|
|
self.all_testcases += result.testcase_suite.countTestCases()
|
2018-09-21 13:55:16 +02:00
|
|
|
self.add_results(result)
|
2018-07-16 14:22:01 +02:00
|
|
|
|
2018-09-21 13:55:16 +02:00
|
|
|
if result.no_tests_run():
|
2018-09-19 15:01:47 +02:00
|
|
|
self.testsuites_no_tests_run.append(result.testcase_suite)
|
2018-09-21 13:55:16 +02:00
|
|
|
if result.crashed:
|
|
|
|
retval = -1
|
|
|
|
else:
|
|
|
|
retval = 1
|
|
|
|
elif not result.was_successful():
|
|
|
|
retval = 1
|
2018-07-16 14:22:01 +02:00
|
|
|
|
|
|
|
if retval != 0:
|
2018-11-16 17:28:56 +01:00
|
|
|
self.rerun.append(result.testcase_suite)
|
2018-07-16 14:22:01 +02:00
|
|
|
|
|
|
|
return retval
|
|
|
|
|
|
|
|
def print_results(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
print("")
|
2018-07-16 14:22:01 +02:00
|
|
|
print(double_line_delim)
|
2022-04-26 19:02:15 +02:00
|
|
|
print("TEST RESULTS:")
|
2021-04-08 19:37:41 +02:00
|
|
|
|
|
|
|
def indent_results(lines):
|
|
|
|
lines = list(filter(None, lines))
|
|
|
|
maximum = max(lines, key=lambda x: x.index(":"))
|
|
|
|
maximum = 4 + maximum.index(":")
|
|
|
|
for l in lines:
|
|
|
|
padding = " " * (maximum - l.index(":"))
|
|
|
|
print(f"{padding}{l}")
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
indent_results(
|
|
|
|
[
|
|
|
|
f"Scheduled tests: {self.all_testcases}",
|
2023-03-29 16:04:58 +02:00
|
|
|
f"Executed tests: {self[TestResultCode.TEST_RUN]}",
|
|
|
|
f"Passed tests: {colorize(self[TestResultCode.PASS], GREEN)}",
|
2024-04-03 12:31:42 -04:00
|
|
|
(
|
|
|
|
f"Expected failures: {colorize(self[TestResultCode.EXPECTED_FAIL], GREEN)}"
|
|
|
|
if self[TestResultCode.EXPECTED_FAIL]
|
|
|
|
else None
|
|
|
|
),
|
|
|
|
(
|
|
|
|
f"Skipped tests: {colorize(self[TestResultCode.SKIP], YELLOW)}"
|
|
|
|
if self[TestResultCode.SKIP]
|
|
|
|
else None
|
|
|
|
),
|
|
|
|
(
|
|
|
|
f"Not Executed tests: {colorize(self.not_executed, RED)}"
|
|
|
|
if self.not_executed
|
|
|
|
else None
|
|
|
|
),
|
|
|
|
(
|
|
|
|
f"Failures: {colorize(self[TestResultCode.FAIL], RED)}"
|
|
|
|
if self[TestResultCode.FAIL]
|
|
|
|
else None
|
|
|
|
),
|
|
|
|
(
|
|
|
|
f"Unexpected passes: {colorize(self[TestResultCode.UNEXPECTED_PASS], RED)}"
|
|
|
|
if self[TestResultCode.UNEXPECTED_PASS]
|
|
|
|
else None
|
|
|
|
),
|
|
|
|
(
|
|
|
|
f"Errors: {colorize(self[TestResultCode.ERROR], RED)}"
|
|
|
|
if self[TestResultCode.ERROR]
|
|
|
|
else None
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"Tests skipped due to lack of CPUS: "
|
|
|
|
f"{colorize(self[TestResultCode.SKIP_CPU_SHORTAGE], YELLOW)}"
|
|
|
|
if self[TestResultCode.SKIP_CPU_SHORTAGE]
|
|
|
|
else None
|
|
|
|
),
|
2022-04-26 19:02:15 +02:00
|
|
|
]
|
|
|
|
)
|
2018-07-16 14:22:01 +02:00
|
|
|
|
|
|
|
if self.all_failed > 0:
|
2022-04-26 19:02:15 +02:00
|
|
|
print("FAILURES AND ERRORS IN TESTS:")
|
2018-09-19 15:01:47 +02:00
|
|
|
for result in self.results_per_suite:
|
|
|
|
old_testcase_name = None
|
2023-03-29 16:04:58 +02:00
|
|
|
for tr_code, headline in (
|
|
|
|
(TestResultCode.FAIL, "FAILURE"),
|
|
|
|
(TestResultCode.ERROR, "ERROR"),
|
|
|
|
(TestResultCode.UNEXPECTED_PASS, "UNEXPECTED PASS"),
|
|
|
|
):
|
|
|
|
if not result[tr_code]:
|
|
|
|
continue
|
|
|
|
|
|
|
|
for failed_test_id in result[tr_code]:
|
2022-04-26 19:02:15 +02:00
|
|
|
new_testcase_name, test_name = result.get_testcase_names(
|
|
|
|
failed_test_id
|
|
|
|
)
|
2018-09-19 15:01:47 +02:00
|
|
|
if new_testcase_name != old_testcase_name:
|
2022-04-26 19:02:15 +02:00
|
|
|
print(
|
2023-03-29 16:04:58 +02:00
|
|
|
f" Testcase name: {colorize(new_testcase_name, RED)}"
|
2022-04-26 19:02:15 +02:00
|
|
|
)
|
2018-09-19 15:01:47 +02:00
|
|
|
old_testcase_name = new_testcase_name
|
2022-04-26 19:02:15 +02:00
|
|
|
print(
|
2023-03-29 16:04:58 +02:00
|
|
|
f" {headline}: {colorize(test_name, RED)} [{failed_test_id}]"
|
2022-04-26 19:02:15 +02:00
|
|
|
)
|
2023-03-29 16:04:58 +02:00
|
|
|
|
2019-03-06 10:41:06 -08:00
|
|
|
if self.testsuites_no_tests_run:
|
2022-04-26 19:02:15 +02:00
|
|
|
print("TESTCASES WHERE NO TESTS WERE SUCCESSFULLY EXECUTED:")
|
2018-09-21 13:55:16 +02:00
|
|
|
tc_classes = set()
|
2018-09-19 15:01:47 +02:00
|
|
|
for testsuite in self.testsuites_no_tests_run:
|
|
|
|
for testcase in testsuite:
|
|
|
|
tc_classes.add(get_testcase_doc_name(testcase))
|
|
|
|
for tc_class in tc_classes:
|
2022-04-26 19:02:15 +02:00
|
|
|
print(" {}".format(colorize(tc_class, RED)))
|
2018-07-16 14:22:01 +02:00
|
|
|
|
2023-03-29 16:04:58 +02:00
|
|
|
if self[TestResultCode.SKIP_CPU_SHORTAGE]:
|
2021-04-08 19:37:41 +02:00
|
|
|
print()
|
2022-04-26 19:02:15 +02:00
|
|
|
print(
|
|
|
|
colorize(
|
|
|
|
" SOME TESTS WERE SKIPPED BECAUSE THERE ARE NOT"
|
|
|
|
" ENOUGH CPUS AVAILABLE",
|
|
|
|
YELLOW,
|
|
|
|
)
|
|
|
|
)
|
2018-07-16 14:22:01 +02:00
|
|
|
print(double_line_delim)
|
2022-04-26 19:02:15 +02:00
|
|
|
print("")
|
2018-07-16 14:22:01 +02:00
|
|
|
|
2018-09-19 15:01:47 +02:00
|
|
|
@property
|
|
|
|
def not_executed(self):
|
2023-03-29 16:04:58 +02:00
|
|
|
return self.all_testcases - self[TestResultCode.TEST_RUN]
|
2018-09-19 15:01:47 +02:00
|
|
|
|
2018-07-16 14:22:01 +02:00
|
|
|
@property
|
|
|
|
def all_failed(self):
|
2023-03-29 16:04:58 +02:00
|
|
|
return (
|
|
|
|
self[TestResultCode.FAIL]
|
|
|
|
+ self[TestResultCode.ERROR]
|
|
|
|
+ self[TestResultCode.UNEXPECTED_PASS]
|
|
|
|
)
|
2018-07-16 14:22:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
def parse_results(results):
|
|
|
|
"""
|
2018-09-19 15:01:47 +02:00
|
|
|
Prints the number of scheduled, executed, not executed, passed, failed,
|
|
|
|
errored and skipped tests and details about failed and errored tests.
|
2018-07-16 14:22:01 +02:00
|
|
|
|
2018-09-19 15:01:47 +02:00
|
|
|
Also returns all suites where any test failed.
|
2018-07-16 14:22:01 +02:00
|
|
|
|
|
|
|
:param results:
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
|
2018-09-19 15:01:47 +02:00
|
|
|
results_per_suite = AllResults()
|
2018-07-16 14:22:01 +02:00
|
|
|
crashed = False
|
|
|
|
failed = False
|
2018-09-19 15:01:47 +02:00
|
|
|
for result in results:
|
|
|
|
result_code = results_per_suite.add_result(result)
|
2018-07-16 14:22:01 +02:00
|
|
|
if result_code == 1:
|
|
|
|
failed = True
|
|
|
|
elif result_code == -1:
|
|
|
|
crashed = True
|
|
|
|
|
|
|
|
results_per_suite.print_results()
|
|
|
|
|
|
|
|
if crashed:
|
|
|
|
return_code = -1
|
|
|
|
elif failed:
|
|
|
|
return_code = 1
|
|
|
|
else:
|
|
|
|
return_code = 0
|
|
|
|
return return_code, results_per_suite.rerun
|
|
|
|
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
if __name__ == "__main__":
|
2021-05-31 16:08:53 +02:00
|
|
|
print(f"Config is: {config}")
|
2018-07-16 14:22:01 +02:00
|
|
|
|
2023-11-14 15:26:41 +01:00
|
|
|
if config.api_preload:
|
|
|
|
VPPApiJSONFiles.load_api(apidir=config.extern_apidir + [config.vpp_install_dir])
|
|
|
|
|
2021-05-31 16:08:53 +02:00
|
|
|
if config.sanity:
|
|
|
|
print("Running sanity test case.")
|
|
|
|
try:
|
|
|
|
rc = sanity_run_vpp.main()
|
|
|
|
if rc != 0:
|
|
|
|
sys.exit(rc)
|
|
|
|
except Exception as e:
|
|
|
|
print(traceback.format_exc())
|
|
|
|
print("Couldn't run sanity test case.")
|
|
|
|
sys.exit(-1)
|
2018-07-16 14:22:01 +02:00
|
|
|
|
2019-11-05 01:08:26 +01:00
|
|
|
test_finished_join_timeout = 15
|
|
|
|
|
2021-05-31 16:08:53 +02:00
|
|
|
debug_gdb = config.debug in ["gdb", "gdbserver", "attach"]
|
|
|
|
debug_core = config.debug == "core"
|
2018-07-16 14:22:01 +02:00
|
|
|
|
2021-05-31 16:08:53 +02:00
|
|
|
run_interactive = debug_gdb or config.step or config.force_foreground
|
2017-08-11 06:56:05 +02:00
|
|
|
|
2021-04-08 19:37:41 +02:00
|
|
|
max_concurrent_tests = 0
|
|
|
|
print(f"OS reports {num_cpus} available cpu(s).")
|
2019-07-08 14:14:22 -04:00
|
|
|
|
2021-05-31 16:08:53 +02:00
|
|
|
test_jobs = config.jobs
|
2022-04-26 19:02:15 +02:00
|
|
|
if test_jobs == "auto":
|
2018-07-16 14:22:01 +02:00
|
|
|
if run_interactive:
|
2021-04-08 19:37:41 +02:00
|
|
|
max_concurrent_tests = 1
|
2022-04-26 19:02:15 +02:00
|
|
|
print("Interactive mode required, running tests consecutively.")
|
2018-07-16 14:22:01 +02:00
|
|
|
else:
|
2021-04-08 19:37:41 +02:00
|
|
|
max_concurrent_tests = num_cpus
|
2022-04-26 19:02:15 +02:00
|
|
|
print(
|
|
|
|
f"Running at most {max_concurrent_tests} python test "
|
|
|
|
"processes concurrently."
|
|
|
|
)
|
2018-07-16 14:22:01 +02:00
|
|
|
else:
|
2021-05-31 16:08:53 +02:00
|
|
|
max_concurrent_tests = test_jobs
|
2022-04-26 19:02:15 +02:00
|
|
|
print(
|
|
|
|
f"Running at most {max_concurrent_tests} python test processes "
|
|
|
|
"concurrently as set by 'TEST_JOBS'."
|
|
|
|
)
|
2021-04-08 19:37:41 +02:00
|
|
|
|
|
|
|
print(f"Using at most {max_vpp_cpus} cpus for VPP threads.")
|
|
|
|
|
|
|
|
if run_interactive and max_concurrent_tests > 1:
|
2018-07-16 14:22:01 +02:00
|
|
|
raise NotImplementedError(
|
2022-04-26 19:02:15 +02:00
|
|
|
"Running tests interactively (DEBUG is gdb[server] or ATTACH or "
|
|
|
|
"STEP is set) in parallel (TEST_JOBS is more than 1) is not "
|
|
|
|
"supported"
|
|
|
|
)
|
2018-03-21 12:35:51 +01:00
|
|
|
|
2018-07-16 14:22:01 +02:00
|
|
|
descriptions = True
|
|
|
|
|
2021-04-08 19:37:41 +02:00
|
|
|
print("Running tests using custom test runner.")
|
2023-04-14 17:44:04 +02:00
|
|
|
filters = [(parse_test_filter(f)) for f in config.filter.split(",")]
|
2018-07-16 14:22:01 +02:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
print(
|
2023-04-14 17:44:04 +02:00
|
|
|
"Selected filters: ",
|
|
|
|
"|".join(
|
|
|
|
f"file={filter_file}, class={filter_class}, function={filter_func}"
|
|
|
|
for filter_file, filter_class, filter_func in filters
|
|
|
|
),
|
2022-04-26 19:02:15 +02:00
|
|
|
)
|
2017-08-11 06:56:05 +02:00
|
|
|
|
2023-04-14 17:44:04 +02:00
|
|
|
filter_cb = FilterByTestOption(filters)
|
2018-07-16 14:22:01 +02:00
|
|
|
|
|
|
|
cb = SplitToSuitesCallback(filter_cb)
|
2021-05-31 16:08:53 +02:00
|
|
|
for d in config.test_src_dir:
|
2017-10-05 10:26:03 +02:00
|
|
|
print("Adding tests from directory tree %s" % d)
|
2022-08-10 03:25:31 -04:00
|
|
|
discover_tests(d, cb)
|
2017-08-11 06:56:05 +02:00
|
|
|
|
2018-07-16 14:22:01 +02:00
|
|
|
# suites are not hashable, need to use list
|
|
|
|
suites = []
|
|
|
|
tests_amount = 0
|
|
|
|
for testcase_suite in cb.suites.values():
|
|
|
|
tests_amount += testcase_suite.countTestCases()
|
2021-04-08 19:37:41 +02:00
|
|
|
if testcase_suite.cpus_used > max_vpp_cpus:
|
|
|
|
# here we replace test functions with lambdas to just skip them
|
|
|
|
# but we also replace setUp/tearDown functions to do nothing
|
|
|
|
# so that the test can be "started" and "stopped", so that we can
|
|
|
|
# still keep those prints (test description - SKIP), which are done
|
|
|
|
# in stopTest() (for that to trigger, test function must run)
|
|
|
|
for t in testcase_suite:
|
|
|
|
for m in dir(t):
|
2022-04-26 19:02:15 +02:00
|
|
|
if m.startswith("test_"):
|
2021-04-08 19:37:41 +02:00
|
|
|
setattr(t, m, lambda: t.skipTest("not enough cpus"))
|
2022-04-26 19:02:15 +02:00
|
|
|
setattr(t.__class__, "setUpClass", lambda: None)
|
|
|
|
setattr(t.__class__, "tearDownClass", lambda: None)
|
|
|
|
setattr(t, "setUp", lambda: None)
|
|
|
|
setattr(t, "tearDown", lambda: None)
|
2021-04-08 19:37:41 +02:00
|
|
|
t.__class__.skipped_due_to_cpu_lack = True
|
2018-07-16 14:22:01 +02:00
|
|
|
suites.append(testcase_suite)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
print(
|
|
|
|
"%s out of %s tests match specified filters"
|
|
|
|
% (tests_amount, tests_amount + cb.filtered.countTestCases())
|
|
|
|
)
|
2018-07-16 14:22:01 +02:00
|
|
|
|
2021-05-31 16:08:53 +02:00
|
|
|
if not config.extended:
|
2018-07-16 14:22:01 +02:00
|
|
|
print("Not running extended tests (some tests will be skipped)")
|
2018-06-27 13:54:32 +02:00
|
|
|
|
2021-05-31 16:08:53 +02:00
|
|
|
attempts = config.retries + 1
|
2017-10-05 10:26:03 +02:00
|
|
|
if attempts > 1:
|
|
|
|
print("Perform %s attempts to pass the suite..." % attempts)
|
2018-07-16 14:22:01 +02:00
|
|
|
|
2019-03-06 10:41:06 -08:00
|
|
|
if run_interactive and suites:
|
2018-07-16 14:22:01 +02:00
|
|
|
# don't fork if requiring interactive terminal
|
2022-04-26 19:02:15 +02:00
|
|
|
print("Running tests in foreground in the current process")
|
2019-01-10 12:13:07 +01:00
|
|
|
full_suite = unittest.TestSuite()
|
2021-04-08 19:37:41 +02:00
|
|
|
free_cpus = list(available_cpus)
|
|
|
|
cpu_shortage = False
|
|
|
|
for suite in suites:
|
|
|
|
if suite.cpus_used <= max_vpp_cpus:
|
2022-04-26 19:02:15 +02:00
|
|
|
suite.assign_cpus(free_cpus[: suite.cpus_used])
|
2021-04-08 19:37:41 +02:00
|
|
|
else:
|
|
|
|
suite.assign_cpus([])
|
|
|
|
cpu_shortage = True
|
2019-10-29 11:03:47 +00:00
|
|
|
full_suite.addTests(suites)
|
2022-04-26 19:02:15 +02:00
|
|
|
result = VppTestRunner(
|
|
|
|
verbosity=config.verbose, failfast=config.failfast, print_summary=True
|
|
|
|
).run(full_suite)
|
2018-09-21 13:55:16 +02:00
|
|
|
was_successful = result.wasSuccessful()
|
|
|
|
if not was_successful:
|
|
|
|
for test_case_info in result.failed_test_cases_info:
|
2022-04-26 19:02:15 +02:00
|
|
|
handle_failed_suite(
|
|
|
|
test_case_info.logger,
|
|
|
|
test_case_info.tempdir,
|
|
|
|
test_case_info.vpp_pid,
|
|
|
|
config.vpp,
|
|
|
|
)
|
2019-05-06 19:11:25 +02:00
|
|
|
if test_case_info in result.core_crash_test_cases_info:
|
2022-04-26 19:02:15 +02:00
|
|
|
check_and_handle_core(
|
|
|
|
test_case_info.vpp_bin_path,
|
|
|
|
test_case_info.tempdir,
|
|
|
|
test_case_info.core_crash_test,
|
|
|
|
)
|
2018-09-21 13:55:16 +02:00
|
|
|
|
2021-04-08 19:37:41 +02:00
|
|
|
if cpu_shortage:
|
|
|
|
print()
|
2022-04-26 19:02:15 +02:00
|
|
|
print(
|
|
|
|
colorize(
|
|
|
|
"SOME TESTS WERE SKIPPED BECAUSE THERE ARE NOT"
|
|
|
|
" ENOUGH CPUS AVAILABLE",
|
|
|
|
YELLOW,
|
|
|
|
)
|
|
|
|
)
|
2021-04-08 19:37:41 +02:00
|
|
|
print()
|
2018-09-21 13:55:16 +02:00
|
|
|
sys.exit(not was_successful)
|
2018-03-21 12:35:51 +01:00
|
|
|
else:
|
2022-04-26 19:02:15 +02:00
|
|
|
print(
|
|
|
|
"Running each VPPTestCase in a separate background process"
|
|
|
|
f" with at most {max_concurrent_tests} parallel python test "
|
|
|
|
"process(es)"
|
|
|
|
)
|
2018-07-16 14:22:01 +02:00
|
|
|
exit_code = 0
|
2019-03-06 10:41:06 -08:00
|
|
|
while suites and attempts > 0:
|
2023-08-31 00:47:44 -04:00
|
|
|
for suite in suites:
|
|
|
|
failed_link = get_failed_testcase_linkname(
|
|
|
|
config.failed_dir,
|
|
|
|
f"{get_testcase_dirname(suite._tests[0].__class__.__name__)}",
|
|
|
|
)
|
|
|
|
if os.path.islink(failed_link):
|
|
|
|
os.unlink(failed_link)
|
2018-07-16 14:22:01 +02:00
|
|
|
results = run_forked(suites)
|
|
|
|
exit_code, suites = parse_results(results)
|
|
|
|
attempts -= 1
|
|
|
|
if exit_code == 0:
|
2022-04-26 19:02:15 +02:00
|
|
|
print("Test run was successful")
|
2018-07-16 14:22:01 +02:00
|
|
|
else:
|
2022-04-26 19:02:15 +02:00
|
|
|
print("%s attempt(s) left." % attempts)
|
2018-07-16 14:22:01 +02:00
|
|
|
sys.exit(exit_code)
|