tests: support injecting multiple worker pcaps on one PG
[vpp.git] / test / framework.py
index 4e0949b..5e39854 100644 (file)
@@ -406,11 +406,18 @@ class VppTestCase(unittest.TestCase):
             coredump_size = "coredump-size unlimited"
 
         cpu_core_number = cls.get_least_used_cpu()
-        if not hasattr(cls, "worker_config"):
-            cls.worker_config = os.getenv("VPP_WORKER_CONFIG", "")
-            if cls.worker_config != "":
-                if cls.has_tag(TestCaseTag.FIXME_VPP_WORKERS):
-                    cls.worker_config = ""
+        if not hasattr(cls, "vpp_worker_count"):
+            cls.vpp_worker_count = 0
+            worker_config = os.getenv("VPP_WORKER_CONFIG", "")
+            if worker_config:
+                elems = worker_config.split(" ")
+                if elems[0] != "workers" or len(elems) != 2:
+                    raise ValueError("Wrong VPP_WORKER_CONFIG == '%s' value." %
+                                     worker_config)
+                cls.vpp_worker_count = int(elems[1])
+                if cls.vpp_worker_count > 0 and\
+                        cls.has_tag(TestCaseTag.FIXME_VPP_WORKERS):
+                    cls.vpp_worker_count = 0
 
         default_variant = os.getenv("VARIANT")
         if default_variant is not None:
@@ -422,25 +429,27 @@ class VppTestCase(unittest.TestCase):
         if api_fuzzing is None:
             api_fuzzing = 'off'
 
-        cls.vpp_cmdline = [cls.vpp_bin, "unix",
-                           "{", "nodaemon", debug_cli, "full-coredump",
-                           coredump_size, "runtime-dir", cls.tempdir, "}",
-                           "api-trace", "{", "on", "}", "api-segment", "{",
-                           "prefix", cls.shm_prefix, "}", "cpu", "{",
-                           "main-core", str(cpu_core_number),
-                           cls.worker_config, "}",
-                           "physmem", "{", "max-size", "32m", "}",
-                           "statseg", "{", "socket-name", cls.stats_sock, "}",
-                           "socksvr", "{", "socket-name", cls.api_sock, "}",
-                           "node { ", default_variant, "}",
-                           "api-fuzz {", api_fuzzing, "}",
-                           "plugins",
-                           "{", "plugin", "dpdk_plugin.so", "{", "disable",
-                           "}", "plugin", "rdma_plugin.so", "{", "disable",
-                           "}", "plugin", "lisp_unittest_plugin.so", "{",
-                           "enable",
-                           "}", "plugin", "unittest_plugin.so", "{", "enable",
-                           "}"] + cls.extra_vpp_plugin_config + ["}", ]
+        cls.vpp_cmdline = [
+            cls.vpp_bin,
+            "unix", "{", "nodaemon", debug_cli, "full-coredump",
+            coredump_size, "runtime-dir", cls.tempdir, "}",
+            "api-trace", "{", "on", "}",
+            "api-segment", "{", "prefix", cls.shm_prefix, "}",
+            "cpu", "{", "main-core", str(cpu_core_number), ]
+        if cls.vpp_worker_count:
+            cls.vpp_cmdline.extend(["workers", str(cls.vpp_worker_count)])
+        cls.vpp_cmdline.extend([
+            "}",
+            "physmem", "{", "max-size", "32m", "}",
+            "statseg", "{", "socket-name", cls.stats_sock, "}",
+            "socksvr", "{", "socket-name", cls.api_sock, "}",
+            "node { ", default_variant, "}",
+            "api-fuzz {", api_fuzzing, "}",
+            "plugins", "{", "plugin", "dpdk_plugin.so", "{", "disable", "}",
+            "plugin", "rdma_plugin.so", "{", "disable", "}",
+            "plugin", "lisp_unittest_plugin.so", "{", "enable", "}",
+            "plugin", "unittest_plugin.so", "{", "enable", "}"
+        ] + cls.extra_vpp_plugin_config + ["}", ])
 
         if cls.extra_vpp_punt_config is not None:
             cls.vpp_cmdline.extend(cls.extra_vpp_punt_config)
@@ -572,6 +581,7 @@ class VppTestCase(unittest.TestCase):
         cls.setUpConstants()
         cls.reset_packet_infos()
         cls._captures = []
+        cls._old_captures = []
         cls.verbose = 0
         cls.vpp_dead = False
         cls.registry = VppObjectRegistry()
@@ -774,7 +784,6 @@ class VppTestCase(unittest.TestCase):
         super(VppTestCase, self).setUp()
         self.reporter.send_keep_alive(self)
         if self.vpp_dead:
-
             raise VppDiedError(rv=None, testcase=self.__class__.__name__,
                                method_name=self._testMethodName)
         self.sleep(.1, "during setUp")
@@ -806,10 +815,10 @@ class VppTestCase(unittest.TestCase):
             i.enable_capture()
 
     @classmethod
-    def register_capture(cls, cap_name):
+    def register_capture(cls, intf, worker):
         """ Register a capture in the testclass """
         # add to the list of captures with current timestamp
-        cls._captures.append((time.time(), cap_name))
+        cls._captures.append((intf, worker))
 
     @classmethod
     def get_vpp_time(cls):
@@ -833,6 +842,10 @@ class VppTestCase(unittest.TestCase):
     @classmethod
     def pg_start(cls, trace=True):
         """ Enable the PG, wait till it is done, then clean up """
+        for (intf, worker) in cls._old_captures:
+            intf.rename_previous_capture_file(intf.get_in_path(worker),
+                                              intf.in_history_counter)
+        cls._old_captures = []
         if trace:
             cls.vapi.cli("clear trace")
             cls.vapi.cli("trace add pg-input 1000")
@@ -847,8 +860,10 @@ class VppTestCase(unittest.TestCase):
             if time.time() > deadline:
                 cls.logger.error("Timeout waiting for pg to stop")
                 break
-        for stamp, cap_name in cls._captures:
-            cls.vapi.cli('packet-generator delete %s' % cap_name)
+        for intf, worker in cls._captures:
+            cls.vapi.cli('packet-generator delete %s' %
+                         intf.get_cap_name(worker))
+        cls._old_captures = cls._captures
         cls._captures = []
 
     @classmethod
@@ -1169,7 +1184,7 @@ class VppTestCase(unittest.TestCase):
                           "packet counter `%s'" % counter)
 
     def assert_error_counter_equal(self, counter, expected_value):
-        counter_value = self.statistics.get_err_counter(counter)
+        counter_value = self.statistics[counter].sum()
         self.assert_equal(counter_value, expected_value,
                           "error counter `%s'" % counter)