Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | import re |
| 3 | import unittest |
| 4 | import platform |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 5 | from asfframework import VppAsfTestCase |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 6 | |
| 7 | |
| 8 | def checkX86(): |
| 9 | return platform.machine() in ["x86_64", "AMD64"] |
| 10 | |
| 11 | |
| 12 | def skipVariant(variant): |
| 13 | with open("/proc/cpuinfo") as f: |
| 14 | cpuinfo = f.read() |
| 15 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 16 | exp = re.compile(r"(?:flags\s+:)(?:\s\w+)+(?:\s(" + variant + r"))(?:\s\w+)+") |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 17 | match = exp.search(cpuinfo, re.DOTALL | re.MULTILINE) |
| 18 | |
| 19 | return checkX86() and match is not None |
| 20 | |
| 21 | |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 22 | class TestNodeVariant(VppAsfTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 23 | """Test Node Variants""" |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 24 | |
| 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 32 | cls.vpp_cmdline[node_variants] = ( |
| 33 | "default { variant default } " |
| 34 | "ip4-rewrite { variant " + variant + " } " |
| 35 | ) |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 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 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 55 | match = re.search( |
| 56 | r"\s+(\S+)\s+(\d+)\s+(:?yes)", node_desc, re.DOTALL | re.MULTILINE |
| 57 | ) |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 58 | |
| 59 | return match.groups(0) |
| 60 | |
| 61 | def checkVariant(self, variant): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 62 | """Test node variants defaults""" |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 63 | |
| 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 Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 71 | class TestICLVariant(TestNodeVariant): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 72 | """Test icl Node Variants""" |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 73 | |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 74 | VARIANT = "icl" |
| 75 | LINUX_VARIANT = "avx512_bitalg" |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 76 | |
| 77 | @classmethod |
| 78 | def setUpConstants(cls): |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 79 | super(TestICLVariant, cls).setUpConstants(cls.VARIANT) |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 80 | |
| 81 | @classmethod |
| 82 | def setUpClass(cls): |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 83 | super(TestICLVariant, cls).setUpClass() |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 84 | |
| 85 | @classmethod |
| 86 | def tearDownClass(cls): |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 87 | super(TestICLVariant, cls).tearDownClass() |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 88 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 89 | @unittest.skipUnless( |
| 90 | skipVariant(LINUX_VARIANT), VARIANT + " not a supported variant, skip." |
| 91 | ) |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 92 | def test_icl(self): |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 93 | self.checkVariant(self.VARIANT) |
| 94 | |
| 95 | |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 96 | class TestSKXVariant(TestNodeVariant): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 97 | """Test skx Node Variants""" |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 98 | |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 99 | VARIANT = "skx" |
| 100 | LINUX_VARIANT = "avx512f" |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 101 | |
| 102 | @classmethod |
| 103 | def setUpConstants(cls): |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 104 | super(TestSKXVariant, cls).setUpConstants(cls.VARIANT) |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 105 | |
| 106 | @classmethod |
| 107 | def setUpClass(cls): |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 108 | super(TestSKXVariant, cls).setUpClass() |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 109 | |
| 110 | @classmethod |
| 111 | def tearDownClass(cls): |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 112 | super(TestSKXVariant, cls).tearDownClass() |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 113 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 114 | @unittest.skipUnless( |
| 115 | skipVariant(LINUX_VARIANT), VARIANT + " not a supported variant, skip." |
| 116 | ) |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 117 | def test_skx(self): |
| 118 | self.checkVariant(self.VARIANT) |
| 119 | |
| 120 | |
| 121 | class TestHSWVariant(TestNodeVariant): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 122 | """Test avx2 Node Variants""" |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 123 | |
| 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 139 | @unittest.skipUnless( |
| 140 | skipVariant(LINUX_VARIANT), VARIANT + " not a supported variant, skip." |
| 141 | ) |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 142 | def test_hsw(self): |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 143 | self.checkVariant(self.VARIANT) |