-def add_from_dir(suite, directory):
- do_insert = True
- for _f in os.listdir(directory):
- f = "%s/%s" % (directory, _f)
- if os.path.isdir(f):
- add_from_dir(suite, f)
- continue
- if not os.path.isfile(f):
- continue
- if do_insert:
- sys.path.insert(0, directory)
- do_insert = False
- if not _f.startswith("test_") or not _f.endswith(".py"):
- continue
- name = "".join(f.split("/")[-1].split(".")[:-1])
- if name in sys.modules:
- raise Exception("Duplicate test module `%s' found!" % name)
- module = importlib.import_module(name)
- for name, cls in module.__dict__.items():
- if not isinstance(cls, type):
- continue
- if not issubclass(cls, unittest.TestCase):
- continue
- if name == "VppTestCase":
- continue
- for method in dir(cls):
- if not callable(getattr(cls, method)):
- continue
- if method.startswith("test_"):
- suite.addTest(cls(method))
+def test_runner_wrapper(suite, keep_alive_pipe, result_pipe):
+ result = not VppTestRunner(
+ pipe=keep_alive_pipe,
+ verbosity=verbose,
+ failfast=failfast).run(suite).wasSuccessful()
+ result_pipe.send(result)
+ result_pipe.close()
+ keep_alive_pipe.close()
+
+
+class add_to_suite_callback:
+ def __init__(self, suite):
+ self.suite = suite
+
+ def __call__(self, file_name, cls, method):
+ suite.addTest(cls(method))
+
+
+def run_forked(suite):
+ keep_alive_parent_end, keep_alive_child_end = Pipe(duplex=False)
+ result_parent_end, result_child_end = Pipe(duplex=False)
+
+ child = Process(target=test_runner_wrapper,
+ args=(suite, keep_alive_child_end, result_child_end))
+ child.start()
+ last_test_temp_dir = None
+ last_test_vpp_binary = None
+ last_test = None
+ result = None
+ while result is None:
+ readable = select.select([keep_alive_parent_end.fileno(),
+ result_parent_end.fileno(),
+ ],
+ [], [], test_timeout)[0]
+ if result_parent_end.fileno() in readable:
+ result = result_parent_end.recv()
+ elif keep_alive_parent_end.fileno() in readable:
+ while keep_alive_parent_end.poll():
+ last_test, last_test_vpp_binary, last_test_temp_dir =\
+ keep_alive_parent_end.recv()
+ else:
+ global_logger.critical("Timeout while waiting for child test "
+ "runner process (last test running was "
+ "`%s' in `%s')!" %
+ (last_test, last_test_temp_dir))
+ 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)
+ if d and d.lower() == "core":
+ spawn_gdb(last_test_vpp_binary, core_path,
+ global_logger)
+ child.terminate()
+ result = -1
+ keep_alive_parent_end.close()
+ result_parent_end.close()
+ return result
+