blob: c0c7cc356581c8b590de65a89e17b18a528622b8 [file] [log] [blame]
Ray Kinsella4830e4f2020-03-10 14:35:32 +00001#!/usr/bin/env python3
2import re
3import unittest
4import platform
Dave Wallace8800f732023-08-31 00:47:44 -04005from asfframework import VppAsfTestCase
Ray Kinsella4830e4f2020-03-10 14:35:32 +00006
7
8def checkX86():
9 return platform.machine() in ["x86_64", "AMD64"]
10
11
12def skipVariant(variant):
13 with open("/proc/cpuinfo") as f:
14 cpuinfo = f.read()
15
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020016 exp = re.compile(r"(?:flags\s+:)(?:\s\w+)+(?:\s(" + variant + r"))(?:\s\w+)+")
Ray Kinsella4830e4f2020-03-10 14:35:32 +000017 match = exp.search(cpuinfo, re.DOTALL | re.MULTILINE)
18
19 return checkX86() and match is not None
20
21
Dave Wallace8800f732023-08-31 00:47:44 -040022class TestNodeVariant(VppAsfTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020023 """Test Node Variants"""
Ray Kinsella4830e4f2020-03-10 14:35:32 +000024
25 @classmethod
26 def setUpConstants(cls, variant):
27 super(TestNodeVariant, cls).setUpConstants()
28 # find the position of node_variants in the cmdline args.
29
30 if checkX86():
31 node_variants = cls.vpp_cmdline.index("node { ") + 1
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020032 cls.vpp_cmdline[node_variants] = (
33 "default { variant default } "
34 "ip4-rewrite { variant " + variant + " } "
35 )
Ray Kinsella4830e4f2020-03-10 14:35:32 +000036
37 @classmethod
38 def setUpClass(cls):
39 super(TestNodeVariant, cls).setUpClass()
40
41 @classmethod
42 def tearDownClass(cls):
43 super(TestNodeVariant, cls).tearDownClass()
44
45 def setUp(self):
46 super(TestNodeVariant, self).setUp()
47
48 def tearDown(self):
49 super(TestNodeVariant, self).tearDown()
50
51 def getActiveVariant(self, node):
52 node_desc = self.vapi.cli("show node " + node)
53 self.logger.info(node_desc)
54
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020055 match = re.search(
56 r"\s+(\S+)\s+(\d+)\s+(:?yes)", node_desc, re.DOTALL | re.MULTILINE
57 )
Ray Kinsella4830e4f2020-03-10 14:35:32 +000058
59 return match.groups(0)
60
61 def checkVariant(self, variant):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020062 """Test node variants defaults"""
Ray Kinsella4830e4f2020-03-10 14:35:32 +000063
64 variant_info = self.getActiveVariant("ip4-lookup")
65 self.assertEqual(variant_info[0], "default")
66
67 variant_info = self.getActiveVariant("ip4-rewrite")
68 self.assertEqual(variant_info[0], variant)
69
70
Damjan Marion162330f2020-04-29 21:28:15 +020071class TestICLVariant(TestNodeVariant):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020072 """Test icl Node Variants"""
Ray Kinsella4830e4f2020-03-10 14:35:32 +000073
Damjan Marion162330f2020-04-29 21:28:15 +020074 VARIANT = "icl"
75 LINUX_VARIANT = "avx512_bitalg"
Ray Kinsella4830e4f2020-03-10 14:35:32 +000076
77 @classmethod
78 def setUpConstants(cls):
Damjan Marion162330f2020-04-29 21:28:15 +020079 super(TestICLVariant, cls).setUpConstants(cls.VARIANT)
Ray Kinsella4830e4f2020-03-10 14:35:32 +000080
81 @classmethod
82 def setUpClass(cls):
Damjan Marion162330f2020-04-29 21:28:15 +020083 super(TestICLVariant, cls).setUpClass()
Ray Kinsella4830e4f2020-03-10 14:35:32 +000084
85 @classmethod
86 def tearDownClass(cls):
Damjan Marion162330f2020-04-29 21:28:15 +020087 super(TestICLVariant, cls).tearDownClass()
Ray Kinsella4830e4f2020-03-10 14:35:32 +000088
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020089 @unittest.skipUnless(
90 skipVariant(LINUX_VARIANT), VARIANT + " not a supported variant, skip."
91 )
Damjan Marion162330f2020-04-29 21:28:15 +020092 def test_icl(self):
Ray Kinsella4830e4f2020-03-10 14:35:32 +000093 self.checkVariant(self.VARIANT)
94
95
Damjan Marion162330f2020-04-29 21:28:15 +020096class TestSKXVariant(TestNodeVariant):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020097 """Test skx Node Variants"""
Ray Kinsella4830e4f2020-03-10 14:35:32 +000098
Damjan Marion162330f2020-04-29 21:28:15 +020099 VARIANT = "skx"
100 LINUX_VARIANT = "avx512f"
Ray Kinsella4830e4f2020-03-10 14:35:32 +0000101
102 @classmethod
103 def setUpConstants(cls):
Damjan Marion162330f2020-04-29 21:28:15 +0200104 super(TestSKXVariant, cls).setUpConstants(cls.VARIANT)
Ray Kinsella4830e4f2020-03-10 14:35:32 +0000105
106 @classmethod
107 def setUpClass(cls):
Damjan Marion162330f2020-04-29 21:28:15 +0200108 super(TestSKXVariant, cls).setUpClass()
Ray Kinsella4830e4f2020-03-10 14:35:32 +0000109
110 @classmethod
111 def tearDownClass(cls):
Damjan Marion162330f2020-04-29 21:28:15 +0200112 super(TestSKXVariant, cls).tearDownClass()
Ray Kinsella4830e4f2020-03-10 14:35:32 +0000113
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200114 @unittest.skipUnless(
115 skipVariant(LINUX_VARIANT), VARIANT + " not a supported variant, skip."
116 )
Damjan Marion162330f2020-04-29 21:28:15 +0200117 def test_skx(self):
118 self.checkVariant(self.VARIANT)
119
120
121class TestHSWVariant(TestNodeVariant):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200122 """Test avx2 Node Variants"""
Damjan Marion162330f2020-04-29 21:28:15 +0200123
124 VARIANT = "hsw"
125 LINUX_VARIANT = "avx2"
126
127 @classmethod
128 def setUpConstants(cls):
129 super(TestHSWVariant, cls).setUpConstants(cls.VARIANT)
130
131 @classmethod
132 def setUpClass(cls):
133 super(TestHSWVariant, cls).setUpClass()
134
135 @classmethod
136 def tearDownClass(cls):
137 super(TestHSWVariant, cls).tearDownClass()
138
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200139 @unittest.skipUnless(
140 skipVariant(LINUX_VARIANT), VARIANT + " not a supported variant, skip."
141 )
Damjan Marion162330f2020-04-29 21:28:15 +0200142 def test_hsw(self):
Ray Kinsella4830e4f2020-03-10 14:35:32 +0000143 self.checkVariant(self.VARIANT)