tests: add support for worker awareness 49/31649/13
authorKlement Sekera <ksekera@cisco.com>
Mon, 15 Mar 2021 15:58:10 +0000 (16:58 +0100)
committerAndrew Yourtchenko <ayourtch@gmail.com>
Sat, 20 Mar 2021 01:14:20 +0000 (01:14 +0000)
VppTestCase now has vpp_worker_count property set to number of workers.
This can be overriden by child classes. Also overriden by
VPP_WORKER_CONFIG variable for legacy reasons.

Type: improvement
Change-Id: Ic328bacb9003ddf9e92815767653bd362aa7f086
Signed-off-by: Klement Sekera <ksekera@cisco.com>
13 files changed:
src/plugins/nat/test/test_nat44_ed.py
src/plugins/nat/test/test_nat44_ei.py
src/plugins/quic/test/test_quic.py
src/plugins/wireguard/test/test_wireguard.py
src/vnet/policer/test/test_policer_input.py
test/framework.py
test/template_ipsec.py
test/test_ip4.py
test/test_ip6.py
test/test_ipsec_esp.py
test/test_reassembly.py
test/test_vlib.py
test/test_vppinfra.py

index 5eb56a1..ba068b4 100644 (file)
@@ -1957,7 +1957,7 @@ class TestNAT44ED(NAT44EDTestCase):
 
 class TestNAT44EDMW(TestNAT44ED):
     """ NAT44ED MW Test Case """
-    worker_config = "workers 1"
+    vpp_worker_count = 1
 
     def get_stats_counter(self, path, worker=1):
         return super(TestNAT44EDMW, self).get_stats_counter(path, worker)
index dcd7f46..f5c5abe 100644 (file)
@@ -3896,7 +3896,7 @@ class TestNAT44Out2InDPO(MethodHolder):
 class TestNAT44EIMW(MethodHolder):
     """ NAT44EI Test Cases (multiple workers) """
 
-    worker_config = "workers %d" % 2
+    vpp_worker_count = 2
 
     max_translations = 10240
     max_users = 10240
index d984b99..0e4cb2d 100644 (file)
@@ -177,7 +177,7 @@ class QUICEchoExtTestCase(QUICTestCase):
     post_test_sleep = 1
     app = "vpp_echo"
     evt_q_len = 16384
-    worker_config = "workers 1"
+    vpp_worker_count = 1
     server_fifo_size = "1M"
     client_fifo_size = "4M"
     extra_vpp_punt_config = ["session", "{",
index 82ba262..edc305b 100755 (executable)
@@ -663,7 +663,7 @@ class TestWg(VppTestCase):
 
 class WireguardHandoffTests(TestWg):
     """ Wireguard Tests in multi worker setup """
-    worker_config = "workers 2"
+    vpp_worker_count = 2
 
     def test_wg_peer_init(self):
         """ Handoff """
index 29ae58a..c95f664 100644 (file)
@@ -15,7 +15,7 @@ NUM_PKTS = 67
 
 class TestPolicerInput(VppTestCase):
     """ Policer on an input interface """
-    worker_config = "workers 2"
+    vpp_worker_count = 2
 
     def setUp(self):
         super(TestPolicerInput, self).setUp()
index 4e0949b..22a9509 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)
@@ -774,7 +783,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")
index f7becf0..62271d3 100644 (file)
@@ -1217,7 +1217,7 @@ class IpsecTun6Tests(IpsecTun6):
 
 class IpsecTun6HandoffTests(IpsecTun6):
     """ UT test methods for Tunnel v6 with multiple workers """
-    worker_config = "workers 2"
+    vpp_worker_count = 2
 
     def test_tun_handoff_66(self):
         """ ipsec 6o6 tunnel worker hand-off test """
@@ -1251,7 +1251,7 @@ class IpsecTun6HandoffTests(IpsecTun6):
 
 class IpsecTun4HandoffTests(IpsecTun4):
     """ UT test methods for Tunnel v4 with multiple workers """
-    worker_config = "workers 2"
+    vpp_worker_count = 2
 
     def test_tun_handooff_44(self):
         """ ipsec 4o4 tunnel worker hand-off test """
index f9fa33c..3f2894d 100644 (file)
@@ -1605,7 +1605,7 @@ class TestIPPunt(IPPuntSetup, VppTestCase):
 
 class TestIPPuntHandoff(IPPuntSetup, VppTestCase):
     """ IPv4 Punt Policer thread handoff """
-    worker_config = "workers 2"
+    vpp_worker_count = 2
 
     def setUp(self):
         super(TestIPPuntHandoff, self).setUp()
index db90b84..8abd8d6 100644 (file)
@@ -2320,7 +2320,7 @@ class TestIP6Punt(IP6PuntSetup, VppTestCase):
 
 class TestIP6PuntHandoff(IP6PuntSetup, VppTestCase):
     """ IPv6 Punt Police/Redirect """
-    worker_config = "workers 2"
+    vpp_worker_count = 2
 
     def setUp(self):
         super(TestIP6PuntHandoff, self).setUp()
index dcbbb82..acff595 100644 (file)
@@ -470,7 +470,7 @@ class TestIpsecEsp2(TemplateIpsecEsp, IpsecTcpTests):
 class TestIpsecEspAsync(TemplateIpsecEsp):
     """ Ipsec ESP - Aysnc tests """
 
-    worker_config = "workers 2"
+    vpp_worker_count = 2
 
     def setUp(self):
         super(TestIpsecEspAsync, self).setUp()
@@ -852,7 +852,7 @@ class RunTestIpsecEspAll(ConfigIpsecESP,
         test_args = str.split(cls.__doc__, " ")
         engine = test_args[0]
         if engine == "async":
-            cls.worker_config = "workers 2"
+            cls.vpp_worker_count = 2
         super(RunTestIpsecEspAll, cls).setUpConstants()
 
     def setUp(self):
index a8dc60a..124fec0 100644 (file)
@@ -21,9 +21,6 @@ from vpp_papi import VppEnum
 # 35 is enough to have >257 400-byte fragments
 test_packet_count = 35
 
-# number of workers used for multi-worker test cases
-worker_count = 3
-
 
 class TestIPv4Reassembly(VppTestCase):
     """ IPv4 Reassembly """
@@ -789,13 +786,13 @@ class TestIPv4SVReassembly(VppTestCase):
 
 class TestIPv4MWReassembly(VppTestCase):
     """ IPv4 Reassembly (multiple workers) """
-    worker_config = "workers %d" % worker_count
+    vpp_worker_count = 3
 
     @classmethod
     def setUpClass(cls):
         super(TestIPv4MWReassembly, cls).setUpClass()
 
-        cls.create_pg_interfaces(range(worker_count+1))
+        cls.create_pg_interfaces(range(cls.vpp_worker_count+1))
         cls.src_if = cls.pg0
         cls.send_ifs = cls.pg_interfaces[:-1]
         cls.dst_if = cls.pg_interfaces[-1]
@@ -908,7 +905,7 @@ class TestIPv4MWReassembly(VppTestCase):
                             "Packet with packet_index %d not received" % index)
 
     def send_packets(self, packets):
-        for counter in range(worker_count):
+        for counter in range(self.vpp_worker_count):
             if 0 == len(packets[counter]):
                 continue
             send_if = self.send_ifs[counter]
@@ -924,19 +921,19 @@ class TestIPv4MWReassembly(VppTestCase):
         # in first wave we send fragments which don't start at offset 0
         # then we send fragments with offset 0 on a different thread
         # then the rest of packets on a random thread
-        first_packets = [[] for n in range(worker_count)]
-        second_packets = [[] for n in range(worker_count)]
-        rest_of_packets = [[] for n in range(worker_count)]
+        first_packets = [[] for n in range(self.vpp_worker_count)]
+        second_packets = [[] for n in range(self.vpp_worker_count)]
+        rest_of_packets = [[] for n in range(self.vpp_worker_count)]
         for (_, p) in self.pkt_infos:
-            wi = randrange(worker_count)
+            wi = randrange(self.vpp_worker_count)
             second_packets[wi].append(p[0])
             if len(p) <= 1:
                 continue
             wi2 = wi
             while wi2 == wi:
-                wi2 = randrange(worker_count)
+                wi2 = randrange(self.vpp_worker_count)
             first_packets[wi2].append(p[1])
-            wi3 = randrange(worker_count)
+            wi3 = randrange(self.vpp_worker_count)
             rest_of_packets[wi3].extend(p[2:])
 
         self.pg_enable_capture()
@@ -1437,13 +1434,13 @@ class TestIPv6Reassembly(VppTestCase):
 
 class TestIPv6MWReassembly(VppTestCase):
     """ IPv6 Reassembly (multiple workers) """
-    worker_config = "workers %d" % worker_count
+    vpp_worker_count = 3
 
     @classmethod
     def setUpClass(cls):
         super(TestIPv6MWReassembly, cls).setUpClass()
 
-        cls.create_pg_interfaces(range(worker_count+1))
+        cls.create_pg_interfaces(range(cls.vpp_worker_count+1))
         cls.src_if = cls.pg0
         cls.send_ifs = cls.pg_interfaces[:-1]
         cls.dst_if = cls.pg_interfaces[-1]
@@ -1556,7 +1553,7 @@ class TestIPv6MWReassembly(VppTestCase):
                             "Packet with packet_index %d not received" % index)
 
     def send_packets(self, packets):
-        for counter in range(worker_count):
+        for counter in range(self.vpp_worker_count):
             if 0 == len(packets[counter]):
                 continue
             send_if = self.send_ifs[counter]
@@ -1572,19 +1569,19 @@ class TestIPv6MWReassembly(VppTestCase):
         # in first wave we send fragments which don't start at offset 0
         # then we send fragments with offset 0 on a different thread
         # then the rest of packets on a random thread
-        first_packets = [[] for n in range(worker_count)]
-        second_packets = [[] for n in range(worker_count)]
-        rest_of_packets = [[] for n in range(worker_count)]
+        first_packets = [[] for n in range(self.vpp_worker_count)]
+        second_packets = [[] for n in range(self.vpp_worker_count)]
+        rest_of_packets = [[] for n in range(self.vpp_worker_count)]
         for (_, p) in self.pkt_infos:
-            wi = randrange(worker_count)
+            wi = randrange(self.vpp_worker_count)
             second_packets[wi].append(p[0])
             if len(p) <= 1:
                 continue
             wi2 = wi
             while wi2 == wi:
-                wi2 = randrange(worker_count)
+                wi2 = randrange(self.vpp_worker_count)
             first_packets[wi2].append(p[1])
-            wi3 = randrange(worker_count)
+            wi3 = randrange(self.vpp_worker_count)
             rest_of_packets[wi3].extend(p[2:])
 
         self.pg_enable_capture()
index 89ccb39..64218ea 100644 (file)
@@ -11,7 +11,7 @@ from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
 
 class TestVlib(VppTestCase):
     """ Vlib Unit Test Cases """
-    worker_config = "workers 1"
+    vpp_worker_count = 1
 
     @classmethod
     def setUpClass(cls):
index 9cb782d..8b6ec96 100644 (file)
@@ -8,7 +8,7 @@ from framework import running_gcov_tests
 
 class TestVppinfra(VppTestCase):
     """ Vppinfra Unit Test Cases """
-    worker_config = "workers 1"
+    vpp_worker_count = 1
 
     @classmethod
     def setUpClass(cls):