blob: 3632910e3cbab4a9b2c144bcf9c9ed7ceb131777 [file] [log] [blame]
Ray Kinsella4830e4f2020-03-10 14:35:32 +00001#!/usr/bin/env python3
2import re
3import unittest
4import platform
5from framework import VppTestCase
6
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
16 exp = re.compile(
17 r'(?:flags\s+:)(?:\s\w+)+(?:\s(' + variant + r'))(?:\s\w+)+')
18 match = exp.search(cpuinfo, re.DOTALL | re.MULTILINE)
19
20 return checkX86() and match is not None
21
22
23class TestNodeVariant(VppTestCase):
24 """ Test Node Variants """
25
26 @classmethod
27 def setUpConstants(cls, variant):
28 super(TestNodeVariant, cls).setUpConstants()
29 # find the position of node_variants in the cmdline args.
30
31 if checkX86():
32 node_variants = cls.vpp_cmdline.index("node { ") + 1
33 cls.vpp_cmdline[node_variants] = ("default { variant default } "
34 "ip4-rewrite { variant " +
35 variant + " } ")
36
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
55 match = re.search(r'\s+(\S+)\s+(\d+)\s+(:?yes)',
56 node_desc, re.DOTALL | re.MULTILINE)
57
58 return match.groups(0)
59
60 def checkVariant(self, variant):
61 """ Test node variants defaults """
62
63 variant_info = self.getActiveVariant("ip4-lookup")
64 self.assertEqual(variant_info[0], "default")
65
66 variant_info = self.getActiveVariant("ip4-rewrite")
67 self.assertEqual(variant_info[0], variant)
68
69
Damjan Marion162330f2020-04-29 21:28:15 +020070class TestICLVariant(TestNodeVariant):
71 """ Test icl Node Variants """
Ray Kinsella4830e4f2020-03-10 14:35:32 +000072
Damjan Marion162330f2020-04-29 21:28:15 +020073 VARIANT = "icl"
74 LINUX_VARIANT = "avx512_bitalg"
Ray Kinsella4830e4f2020-03-10 14:35:32 +000075
76 @classmethod
77 def setUpConstants(cls):
Damjan Marion162330f2020-04-29 21:28:15 +020078 super(TestICLVariant, cls).setUpConstants(cls.VARIANT)
Ray Kinsella4830e4f2020-03-10 14:35:32 +000079
80 @classmethod
81 def setUpClass(cls):
Damjan Marion162330f2020-04-29 21:28:15 +020082 super(TestICLVariant, cls).setUpClass()
Ray Kinsella4830e4f2020-03-10 14:35:32 +000083
84 @classmethod
85 def tearDownClass(cls):
Damjan Marion162330f2020-04-29 21:28:15 +020086 super(TestICLVariant, cls).tearDownClass()
Ray Kinsella4830e4f2020-03-10 14:35:32 +000087
88 @unittest.skipUnless(skipVariant(LINUX_VARIANT),
89 VARIANT + " not a supported variant, skip.")
Damjan Marion162330f2020-04-29 21:28:15 +020090 def test_icl(self):
Ray Kinsella4830e4f2020-03-10 14:35:32 +000091 self.checkVariant(self.VARIANT)
92
93
Damjan Marion162330f2020-04-29 21:28:15 +020094class TestSKXVariant(TestNodeVariant):
95 """ Test skx Node Variants """
Ray Kinsella4830e4f2020-03-10 14:35:32 +000096
Damjan Marion162330f2020-04-29 21:28:15 +020097 VARIANT = "skx"
98 LINUX_VARIANT = "avx512f"
Ray Kinsella4830e4f2020-03-10 14:35:32 +000099
100 @classmethod
101 def setUpConstants(cls):
Damjan Marion162330f2020-04-29 21:28:15 +0200102 super(TestSKXVariant, cls).setUpConstants(cls.VARIANT)
Ray Kinsella4830e4f2020-03-10 14:35:32 +0000103
104 @classmethod
105 def setUpClass(cls):
Damjan Marion162330f2020-04-29 21:28:15 +0200106 super(TestSKXVariant, cls).setUpClass()
Ray Kinsella4830e4f2020-03-10 14:35:32 +0000107
108 @classmethod
109 def tearDownClass(cls):
Damjan Marion162330f2020-04-29 21:28:15 +0200110 super(TestSKXVariant, cls).tearDownClass()
Ray Kinsella4830e4f2020-03-10 14:35:32 +0000111
Damjan Marion162330f2020-04-29 21:28:15 +0200112 @unittest.skipUnless(skipVariant(LINUX_VARIANT),
Ray Kinsella4830e4f2020-03-10 14:35:32 +0000113 VARIANT + " not a supported variant, skip.")
Damjan Marion162330f2020-04-29 21:28:15 +0200114 def test_skx(self):
115 self.checkVariant(self.VARIANT)
116
117
118class TestHSWVariant(TestNodeVariant):
119 """ Test avx2 Node Variants """
120
121 VARIANT = "hsw"
122 LINUX_VARIANT = "avx2"
123
124 @classmethod
125 def setUpConstants(cls):
126 super(TestHSWVariant, cls).setUpConstants(cls.VARIANT)
127
128 @classmethod
129 def setUpClass(cls):
130 super(TestHSWVariant, cls).setUpClass()
131
132 @classmethod
133 def tearDownClass(cls):
134 super(TestHSWVariant, cls).tearDownClass()
135
136 @unittest.skipUnless(skipVariant(LINUX_VARIANT),
137 VARIANT + " not a supported variant, skip.")
138 def test_hsw(self):
Ray Kinsella4830e4f2020-03-10 14:35:32 +0000139 self.checkVariant(self.VARIANT)