X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=test%2Fframework.py;h=da34724befd60702037fa5e79124395e2e3cf917;hb=4a0559a804237f71b19d395b0fd25029cd03b248;hp=308842da6bcef97078358eea9f1f26ec90a5137d;hpb=0219b8dfbf25090214573394cf2c9e5e968cfa9a;p=vpp.git diff --git a/test/framework.py b/test/framework.py index 308842da6bc..da34724befd 100644 --- a/test/framework.py +++ b/test/framework.py @@ -23,6 +23,7 @@ from vpp_pg_interface import VppPGInterface from vpp_sub_interface import VppSubInterface from vpp_lo_interface import VppLoInterface from vpp_papi_provider import VppPapiProvider +from vpp_papi.vpp_stats import VPPStats from log import RED, GREEN, YELLOW, double_line_delim, single_line_delim, \ getLogger, colorize from vpp_object import VppObjectRegistry @@ -38,6 +39,13 @@ else: import subprocess +PASS = 0 +FAIL = 1 +ERROR = 2 +SKIP = 3 +TEST_RUN = 4 + + debug_framework = False if os.getenv('TEST_DEBUG', "0") == "1": debug_framework = True @@ -279,6 +287,7 @@ class VppTestCase(unittest.TestCase): coredump_size, "}", "api-trace", "{", "on", "}", "api-segment", "{", "prefix", cls.shm_prefix, "}", "cpu", "{", "main-core", str(cpu_core_number), "}", + "statseg", "{", "socket-name", cls.stats_sock, "}", "plugins", "{", "plugin", "dpdk_plugin.so", "{", "disable", "}", "plugin", "unittest_plugin.so", "{", "enable", "}", "}", ] @@ -336,6 +345,13 @@ class VppTestCase(unittest.TestCase): cls.wait_for_enter() + @classmethod + def wait_for_stats_socket(cls): + deadline = time.time() + 3 + while time.time() < deadline or cls.debug_gdb or cls.debug_gdbserver: + if os.path.exists(cls.stats_sock): + break + @classmethod def setUpClass(cls): """ @@ -350,6 +366,7 @@ class VppTestCase(unittest.TestCase): cls.logger.name = cls.__name__ cls.tempdir = tempfile.mkdtemp( prefix='vpp-unittest-%s-' % cls.__name__) + cls.stats_sock = "%s/stats.sock" % cls.tempdir cls.file_handler = FileHandler("%s/log.txt" % cls.tempdir) cls.file_handler.setFormatter( Formatter(fmt='%(asctime)s,%(msecs)03d %(message)s', @@ -381,13 +398,19 @@ class VppTestCase(unittest.TestCase): cls.pump_thread = Thread(target=pump_output, args=(cls,)) cls.pump_thread.daemon = True cls.pump_thread.start() - cls.vapi = VppPapiProvider(cls.shm_prefix, cls.shm_prefix, cls) + if cls.debug_gdb or cls.debug_gdbserver: + read_timeout = 0 + else: + read_timeout = 5 + cls.vapi = VppPapiProvider(cls.shm_prefix, cls.shm_prefix, cls, + read_timeout) if cls.step: hook = StepHook(cls) else: hook = PollHook(cls) cls.vapi.register_hook(hook) - cls.sleep(0.1, "after vpp startup, before initial poll") + cls.wait_for_stats_socket() + cls.statistics = VPPStats(socketname=cls.stats_sock) try: hook.poll_vpp() except VppDiedError: @@ -448,7 +471,7 @@ class VppTestCase(unittest.TestCase): cls.vpp.poll() if cls.vpp.returncode is None: cls.logger.debug("Sending TERM to vpp") - cls.vpp.terminate() + cls.vpp.kill() cls.logger.debug("Waiting for vpp to die") cls.vpp.communicate() del cls.vpp @@ -498,7 +521,7 @@ class VppTestCase(unittest.TestCase): self.logger.debug(self.vapi.cli("show trace")) self.logger.info(self.vapi.ppcli("show interface")) self.logger.info(self.vapi.ppcli("show hardware")) - self.logger.info(self.vapi.ppcli("show error")) + self.logger.info(self.statistics.set_errors_str()) self.logger.info(self.vapi.ppcli("show run")) self.logger.info(self.vapi.ppcli("show log")) self.registry.remove_vpp_config(self.logger) @@ -957,7 +980,6 @@ class VppTestResult(unittest.TestResult): self.verbosity = verbosity self.result_string = None self.printer = TestCasePrinter() - self.passed = 0 def addSuccess(self, test): """ @@ -971,10 +993,11 @@ class VppTestResult(unittest.TestResult): % (test.__class__.__name__, test._testMethodName, test._testMethodDoc)) - self.passed += 1 unittest.TestResult.addSuccess(self, test) self.result_string = colorize("OK", GREEN) + self.send_result_through_pipe(test, PASS) + def addSkip(self, test, reason): """ Record a test skipped. @@ -992,6 +1015,8 @@ class VppTestResult(unittest.TestResult): unittest.TestResult.addSkip(self, test, reason) self.result_string = colorize("SKIP", YELLOW) + self.send_result_through_pipe(test, SKIP) + def symlink_failed(self, test): logger = None if hasattr(test, 'logger'): @@ -1015,6 +1040,12 @@ class VppTestResult(unittest.TestResult): if logger: logger.error(e) + def send_result_through_pipe(self, test, result): + if hasattr(self, 'test_framework_result_pipe'): + pipe = self.test_framework_result_pipe + if pipe: + pipe.send((test.id(), result)) + def addFailure(self, test, err): """ Record a test failed result @@ -1038,6 +1069,8 @@ class VppTestResult(unittest.TestResult): else: self.result_string = colorize("FAIL", RED) + ' [no temp dir]' + self.send_result_through_pipe(test, FAIL) + def addError(self, test, err): """ Record a test error result @@ -1061,6 +1094,8 @@ class VppTestResult(unittest.TestResult): else: self.result_string = colorize("ERROR", RED) + ' [no temp dir]' + self.send_result_through_pipe(test, ERROR) + def getDescription(self, test): """ Get test description @@ -1087,7 +1122,7 @@ class VppTestResult(unittest.TestResult): def stopTest(self, test): """ - Stop a test + Called when the given test has been run :param test: @@ -1102,6 +1137,8 @@ class VppTestResult(unittest.TestResult): self.stream.writeln("%-73s%s" % (self.getDescription(test), self.result_string)) + self.send_result_through_pipe(test, TEST_RUN) + def printErrors(self): """ Print errors from running the test case @@ -1137,7 +1174,8 @@ class VppTestRunner(unittest.TextTestRunner): return VppTestResult def __init__(self, keep_alive_pipe=None, descriptions=True, verbosity=1, - failfast=False, buffer=False, resultclass=None): + result_pipe=None, failfast=False, buffer=False, + resultclass=None): # ignore stream setting here, use hard-coded stdout to be in sync # with prints from VppTestCase methods ... super(VppTestRunner, self).__init__(sys.stdout, descriptions, @@ -1146,6 +1184,8 @@ class VppTestRunner(unittest.TextTestRunner): reporter = KeepAliveReporter() reporter.pipe = keep_alive_pipe + VppTestResult.test_framework_result_pipe = result_pipe + def run(self, test): """ Run the tests