2016-10-03 19:44:57 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
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
|
2017-08-08 04:33:53 +02:00
|
|
|
import select
|
2016-10-03 19:44:57 +02:00
|
|
|
import unittest
|
2017-03-16 09:14:59 +01:00
|
|
|
import argparse
|
2018-02-16 19:25:06 +01:00
|
|
|
import time
|
2017-08-08 04:33:53 +02:00
|
|
|
from multiprocessing import Process, Pipe
|
2016-10-03 19:44:57 +02:00
|
|
|
from framework import VppTestRunner
|
2017-08-08 04:33:53 +02:00
|
|
|
from debug import spawn_gdb
|
|
|
|
from log import global_logger
|
2017-08-17 07:38:42 +02:00
|
|
|
from discover_tests import discover_tests
|
2017-03-16 09:14:59 +01:00
|
|
|
|
2017-08-08 04:33:53 +02:00
|
|
|
|
2017-10-05 10:26:03 +02:00
|
|
|
def test_runner_wrapper(suite, keep_alive_pipe, result_pipe, failed_pipe):
|
2017-08-08 04:33:53 +02:00
|
|
|
result = not VppTestRunner(
|
2017-10-05 10:26:03 +02:00
|
|
|
keep_alive_pipe=keep_alive_pipe,
|
|
|
|
failed_pipe=failed_pipe,
|
2017-08-08 04:33:53 +02:00
|
|
|
verbosity=verbose,
|
|
|
|
failfast=failfast).run(suite).wasSuccessful()
|
|
|
|
result_pipe.send(result)
|
|
|
|
result_pipe.close()
|
|
|
|
keep_alive_pipe.close()
|
2017-10-05 10:26:03 +02:00
|
|
|
failed_pipe.close()
|
2017-08-08 04:33:53 +02:00
|
|
|
|
|
|
|
|
2017-08-17 07:38:42 +02:00
|
|
|
class add_to_suite_callback:
|
|
|
|
def __init__(self, suite):
|
|
|
|
self.suite = suite
|
|
|
|
|
|
|
|
def __call__(self, file_name, cls, method):
|
|
|
|
suite.addTest(cls(method))
|
|
|
|
|
|
|
|
|
2017-10-05 10:26:03 +02:00
|
|
|
class Filter_by_class_list:
|
|
|
|
def __init__(self, class_list):
|
|
|
|
self.class_list = class_list
|
|
|
|
|
|
|
|
def __call__(self, file_name, class_name, func_name):
|
|
|
|
return class_name in self.class_list
|
|
|
|
|
|
|
|
|
|
|
|
def suite_from_failed(suite, failed):
|
|
|
|
filter_cb = Filter_by_class_list(failed)
|
|
|
|
return VppTestRunner.filter_tests(suite, filter_cb)
|
|
|
|
|
|
|
|
|
2017-08-11 06:56:05 +02:00
|
|
|
def run_forked(suite):
|
2017-08-08 04:33:53 +02:00
|
|
|
keep_alive_parent_end, keep_alive_child_end = Pipe(duplex=False)
|
|
|
|
result_parent_end, result_child_end = Pipe(duplex=False)
|
2017-10-05 10:26:03 +02:00
|
|
|
failed_parent_end, failed_child_end = Pipe(duplex=False)
|
2017-08-08 04:33:53 +02:00
|
|
|
|
2017-08-11 06:56:05 +02:00
|
|
|
child = Process(target=test_runner_wrapper,
|
2017-10-05 10:26:03 +02:00
|
|
|
args=(suite, keep_alive_child_end, result_child_end,
|
|
|
|
failed_child_end))
|
2017-08-11 06:56:05 +02:00
|
|
|
child.start()
|
2017-08-08 04:33:53 +02:00
|
|
|
last_test_temp_dir = None
|
|
|
|
last_test_vpp_binary = None
|
|
|
|
last_test = None
|
|
|
|
result = None
|
2017-10-05 10:26:03 +02:00
|
|
|
failed = set()
|
2018-02-16 19:25:06 +01:00
|
|
|
last_heard = time.time()
|
|
|
|
while True:
|
2017-08-08 04:33:53 +02:00
|
|
|
readable = select.select([keep_alive_parent_end.fileno(),
|
|
|
|
result_parent_end.fileno(),
|
2017-10-05 10:26:03 +02:00
|
|
|
failed_parent_end.fileno(),
|
2017-08-08 04:33:53 +02:00
|
|
|
],
|
2018-02-16 19:25:06 +01:00
|
|
|
[], [], 1)[0]
|
2017-08-08 04:33:53 +02:00
|
|
|
if result_parent_end.fileno() in readable:
|
|
|
|
result = result_parent_end.recv()
|
2018-02-16 19:25:06 +01:00
|
|
|
break
|
2017-10-05 10:26:03 +02:00
|
|
|
if keep_alive_parent_end.fileno() in readable:
|
2017-08-08 04:33:53 +02:00
|
|
|
while keep_alive_parent_end.poll():
|
2017-09-30 22:04:21 -04:00
|
|
|
last_test, last_test_vpp_binary,\
|
|
|
|
last_test_temp_dir, vpp_pid = keep_alive_parent_end.recv()
|
2018-02-16 19:25:06 +01:00
|
|
|
last_heard = time.time()
|
2017-10-05 10:26:03 +02:00
|
|
|
if failed_parent_end.fileno() in readable:
|
|
|
|
while failed_parent_end.poll():
|
|
|
|
failed_test = failed_parent_end.recv()
|
|
|
|
failed.add(failed_test.__name__)
|
2018-02-16 19:25:06 +01:00
|
|
|
last_heard = time.time()
|
|
|
|
fail = False
|
|
|
|
if last_heard + test_timeout < time.time():
|
|
|
|
fail = True
|
2017-08-08 04:33:53 +02:00
|
|
|
global_logger.critical("Timeout while waiting for child test "
|
|
|
|
"runner process (last test running was "
|
|
|
|
"`%s' in `%s')!" %
|
|
|
|
(last_test, last_test_temp_dir))
|
2018-02-16 19:25:06 +01:00
|
|
|
elif not child.is_alive():
|
|
|
|
fail = True
|
|
|
|
global_logger.critical("Child process unexpectedly died (last "
|
|
|
|
"test running was `%s' in `%s')!" %
|
|
|
|
(last_test, last_test_temp_dir))
|
|
|
|
if fail:
|
2017-09-30 15:12:19 -04:00
|
|
|
failed_dir = os.getenv('VPP_TEST_FAILED_DIR')
|
|
|
|
lttd = last_test_temp_dir.split("/")[-1]
|
|
|
|
link_path = '%s%s-FAILED' % (failed_dir, lttd)
|
|
|
|
global_logger.error("Creating a link to the failed " +
|
|
|
|
"test: %s -> %s" % (link_path, lttd))
|
2018-03-13 21:22:32 +01:00
|
|
|
try:
|
|
|
|
os.symlink(last_test_temp_dir, link_path)
|
|
|
|
except:
|
|
|
|
pass
|
2017-09-30 22:04:21 -04:00
|
|
|
api_post_mortem_path = "/tmp/api_post_mortem.%d" % vpp_pid
|
|
|
|
if os.path.isfile(api_post_mortem_path):
|
|
|
|
global_logger.error("Copying api_post_mortem.%d to %s" %
|
|
|
|
(vpp_pid, last_test_temp_dir))
|
|
|
|
shutil.copy2(api_post_mortem_path, last_test_temp_dir)
|
2017-08-08 04:33:53 +02:00
|
|
|
if last_test_temp_dir and last_test_vpp_binary:
|
|
|
|
core_path = "%s/core" % last_test_temp_dir
|
|
|
|
if os.path.isfile(core_path):
|
|
|
|
global_logger.error("Core-file exists in test temporary "
|
|
|
|
"directory: %s!" % core_path)
|
2017-08-11 06:56:05 +02:00
|
|
|
if d and d.lower() == "core":
|
|
|
|
spawn_gdb(last_test_vpp_binary, core_path,
|
|
|
|
global_logger)
|
|
|
|
child.terminate()
|
2017-08-08 04:33:53 +02:00
|
|
|
result = -1
|
2018-02-16 19:25:06 +01:00
|
|
|
break
|
2017-08-08 04:33:53 +02:00
|
|
|
keep_alive_parent_end.close()
|
|
|
|
result_parent_end.close()
|
2017-10-05 10:26:03 +02:00
|
|
|
failed_parent_end.close()
|
|
|
|
return result, failed
|
2017-08-11 06:56:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
try:
|
|
|
|
verbose = int(os.getenv("V", 0))
|
|
|
|
except:
|
|
|
|
verbose = 0
|
|
|
|
|
|
|
|
default_test_timeout = 600 # 10 minutes
|
|
|
|
try:
|
|
|
|
test_timeout = int(os.getenv("TIMEOUT", default_test_timeout))
|
|
|
|
except:
|
|
|
|
test_timeout = default_test_timeout
|
|
|
|
|
|
|
|
try:
|
|
|
|
debug = os.getenv("DEBUG")
|
|
|
|
except:
|
|
|
|
debug = None
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description="VPP unit tests")
|
|
|
|
parser.add_argument("-f", "--failfast", action='count',
|
|
|
|
help="fast failure flag")
|
|
|
|
parser.add_argument("-d", "--dir", action='append', type=str,
|
|
|
|
help="directory containing test files "
|
|
|
|
"(may be specified multiple times)")
|
|
|
|
args = parser.parse_args()
|
|
|
|
failfast = True if args.failfast == 1 else False
|
|
|
|
|
|
|
|
suite = unittest.TestSuite()
|
2017-08-17 07:38:42 +02:00
|
|
|
cb = add_to_suite_callback(suite)
|
2017-08-11 06:56:05 +02:00
|
|
|
for d in args.dir:
|
2017-10-05 10:26:03 +02:00
|
|
|
print("Adding tests from directory tree %s" % d)
|
2017-08-17 07:38:42 +02:00
|
|
|
discover_tests(d, cb)
|
2017-08-11 06:56:05 +02:00
|
|
|
|
2017-10-05 10:26:03 +02:00
|
|
|
try:
|
|
|
|
retries = int(os.getenv("RETRIES"))
|
|
|
|
except:
|
|
|
|
retries = 0
|
|
|
|
if retries is None:
|
|
|
|
retries = 0
|
|
|
|
attempts = retries + 1
|
|
|
|
if attempts > 1:
|
|
|
|
print("Perform %s attempts to pass the suite..." % attempts)
|
2017-08-11 06:56:05 +02:00
|
|
|
if debug is None or debug.lower() not in ["gdb", "gdbserver"]:
|
2017-10-05 10:26:03 +02:00
|
|
|
while True:
|
|
|
|
result, failed = run_forked(suite)
|
|
|
|
attempts = attempts - 1
|
|
|
|
print("%s test(s) failed, %s attempt(s) left" %
|
|
|
|
(len(failed), attempts))
|
|
|
|
if len(failed) > 0 and attempts > 0:
|
|
|
|
suite = suite_from_failed(suite, failed)
|
|
|
|
continue
|
|
|
|
sys.exit(result)
|
2017-08-11 06:56:05 +02:00
|
|
|
|
|
|
|
# don't fork if debugging..
|
|
|
|
sys.exit(not VppTestRunner(verbosity=verbose,
|
|
|
|
failfast=failfast).run(suite).wasSuccessful())
|