blob: 80a18eb055a673320b4f448ce9d5ac97a7486ed2 [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():
Tom Jonese49e75a2024-02-07 13:27:44 +00009 return platform.machine() in ["x86_64", "AMD64", "amd64"]
Ray Kinsella4830e4f2020-03-10 14:35:32 +000010
11
12def skipVariant(variant):
Tom Jonese49e75a2024-02-07 13:27:44 +000013 # TODO: We don't have cpu feature detection on FreeBSD yet, so always return
14 # that we don't have the requested variant.
15 if platform.uname().system == "FreeBSD":
16 return False
17
Ray Kinsella4830e4f2020-03-10 14:35:32 +000018 with open("/proc/cpuinfo") as f:
19 cpuinfo = f.read()
20
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020021 exp = re.compile(r"(?:flags\s+:)(?:\s\w+)+(?:\s(" + variant + r"))(?:\s\w+)+")
Ray Kinsella4830e4f2020-03-10 14:35:32 +000022 match = exp.search(cpuinfo, re.DOTALL | re.MULTILINE)
23
24 return checkX86() and match is not None
25
26
Dave Wallace8800f732023-08-31 00:47:44 -040027class TestNodeVariant(VppAsfTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020028 """Test Node Variants"""
Ray Kinsella4830e4f2020-03-10 14:35:32 +000029
30 @classmethod
31 def setUpConstants(cls, variant):
32 super(TestNodeVariant, cls).setUpConstants()
33 # find the position of node_variants in the cmdline args.
34
35 if checkX86():
36 node_variants = cls.vpp_cmdline.index("node { ") + 1
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020037 cls.vpp_cmdline[node_variants] = (
38 "default { variant default } "
39 "ip4-rewrite { variant " + variant + " } "
40 )
Ray Kinsella4830e4f2020-03-10 14:35:32 +000041
42 @classmethod
43 def setUpClass(cls):
44 super(TestNodeVariant, cls).setUpClass()
45
46 @classmethod
47 def tearDownClass(cls):
48 super(TestNodeVariant, cls).tearDownClass()
49
50 def setUp(self):
51 super(TestNodeVariant, self).setUp()
52
53 def tearDown(self):
54 super(TestNodeVariant, self).tearDown()
55
56 def getActiveVariant(self, node):
57 node_desc = self.vapi.cli("show node " + node)
58 self.logger.info(node_desc)
59
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020060 match = re.search(
61 r"\s+(\S+)\s+(\d+)\s+(:?yes)", node_desc, re.DOTALL | re.MULTILINE
62 )
Ray Kinsella4830e4f2020-03-10 14:35:32 +000063
64 return match.groups(0)
65
66 def checkVariant(self, variant):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020067 """Test node variants defaults"""
Ray Kinsella4830e4f2020-03-10 14:35:32 +000068
69 variant_info = self.getActiveVariant("ip4-lookup")
70 self.assertEqual(variant_info[0], "default")
71
72 variant_info = self.getActiveVariant("ip4-rewrite")
73 self.assertEqual(variant_info[0], variant)
74
75
Damjan Marion162330f2020-04-29 21:28:15 +020076class TestICLVariant(TestNodeVariant):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020077 """Test icl Node Variants"""
Ray Kinsella4830e4f2020-03-10 14:35:32 +000078
Damjan Marion162330f2020-04-29 21:28:15 +020079 VARIANT = "icl"
80 LINUX_VARIANT = "avx512_bitalg"
Ray Kinsella4830e4f2020-03-10 14:35:32 +000081
82 @classmethod
83 def setUpConstants(cls):
Damjan Marion162330f2020-04-29 21:28:15 +020084 super(TestICLVariant, cls).setUpConstants(cls.VARIANT)
Ray Kinsella4830e4f2020-03-10 14:35:32 +000085
86 @classmethod
87 def setUpClass(cls):
Damjan Marion162330f2020-04-29 21:28:15 +020088 super(TestICLVariant, cls).setUpClass()
Ray Kinsella4830e4f2020-03-10 14:35:32 +000089
90 @classmethod
91 def tearDownClass(cls):
Damjan Marion162330f2020-04-29 21:28:15 +020092 super(TestICLVariant, cls).tearDownClass()
Ray Kinsella4830e4f2020-03-10 14:35:32 +000093
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020094 @unittest.skipUnless(
95 skipVariant(LINUX_VARIANT), VARIANT + " not a supported variant, skip."
96 )
Damjan Marion162330f2020-04-29 21:28:15 +020097 def test_icl(self):
Ray Kinsella4830e4f2020-03-10 14:35:32 +000098 self.checkVariant(self.VARIANT)
99
100
Damjan Marion162330f2020-04-29 21:28:15 +0200101class TestSKXVariant(TestNodeVariant):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200102 """Test skx Node Variants"""
Ray Kinsella4830e4f2020-03-10 14:35:32 +0000103
Damjan Marion162330f2020-04-29 21:28:15 +0200104 VARIANT = "skx"
105 LINUX_VARIANT = "avx512f"
Ray Kinsella4830e4f2020-03-10 14:35:32 +0000106
107 @classmethod
108 def setUpConstants(cls):
Damjan Marion162330f2020-04-29 21:28:15 +0200109 super(TestSKXVariant, cls).setUpConstants(cls.VARIANT)
Ray Kinsella4830e4f2020-03-10 14:35:32 +0000110
111 @classmethod
112 def setUpClass(cls):
Damjan Marion162330f2020-04-29 21:28:15 +0200113 super(TestSKXVariant, cls).setUpClass()
Ray Kinsella4830e4f2020-03-10 14:35:32 +0000114
115 @classmethod
116 def tearDownClass(cls):
Damjan Marion162330f2020-04-29 21:28:15 +0200117 super(TestSKXVariant, cls).tearDownClass()
Ray Kinsella4830e4f2020-03-10 14:35:32 +0000118
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200119 @unittest.skipUnless(
120 skipVariant(LINUX_VARIANT), VARIANT + " not a supported variant, skip."
121 )
Damjan Marion162330f2020-04-29 21:28:15 +0200122 def test_skx(self):
123 self.checkVariant(self.VARIANT)
124
125
126class TestHSWVariant(TestNodeVariant):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200127 """Test avx2 Node Variants"""
Damjan Marion162330f2020-04-29 21:28:15 +0200128
129 VARIANT = "hsw"
130 LINUX_VARIANT = "avx2"
131
132 @classmethod
133 def setUpConstants(cls):
134 super(TestHSWVariant, cls).setUpConstants(cls.VARIANT)
135
136 @classmethod
137 def setUpClass(cls):
138 super(TestHSWVariant, cls).setUpClass()
139
140 @classmethod
141 def tearDownClass(cls):
142 super(TestHSWVariant, cls).tearDownClass()
143
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200144 @unittest.skipUnless(
145 skipVariant(LINUX_VARIANT), VARIANT + " not a supported variant, skip."
146 )
Damjan Marion162330f2020-04-29 21:28:15 +0200147 def test_hsw(self):
Ray Kinsella4830e4f2020-03-10 14:35:32 +0000148 self.checkVariant(self.VARIANT)