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(): |
Tom Jones | e49e75a | 2024-02-07 13:27:44 +0000 | [diff] [blame^] | 9 | return platform.machine() in ["x86_64", "AMD64", "amd64"] |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 10 | |
| 11 | |
| 12 | def skipVariant(variant): |
Tom Jones | e49e75a | 2024-02-07 13:27:44 +0000 | [diff] [blame^] | 13 | # 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 Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 18 | with open("/proc/cpuinfo") as f: |
| 19 | cpuinfo = f.read() |
| 20 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 21 | 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] | 22 | match = exp.search(cpuinfo, re.DOTALL | re.MULTILINE) |
| 23 | |
| 24 | return checkX86() and match is not None |
| 25 | |
| 26 | |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 27 | class TestNodeVariant(VppAsfTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 28 | """Test Node Variants""" |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 29 | |
| 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 37 | cls.vpp_cmdline[node_variants] = ( |
| 38 | "default { variant default } " |
| 39 | "ip4-rewrite { variant " + variant + " } " |
| 40 | ) |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 41 | |
| 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 60 | match = re.search( |
| 61 | r"\s+(\S+)\s+(\d+)\s+(:?yes)", node_desc, re.DOTALL | re.MULTILINE |
| 62 | ) |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 63 | |
| 64 | return match.groups(0) |
| 65 | |
| 66 | def checkVariant(self, variant): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 67 | """Test node variants defaults""" |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 68 | |
| 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 Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 76 | class TestICLVariant(TestNodeVariant): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 77 | """Test icl Node Variants""" |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 78 | |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 79 | VARIANT = "icl" |
| 80 | LINUX_VARIANT = "avx512_bitalg" |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 81 | |
| 82 | @classmethod |
| 83 | def setUpConstants(cls): |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 84 | super(TestICLVariant, cls).setUpConstants(cls.VARIANT) |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 85 | |
| 86 | @classmethod |
| 87 | def setUpClass(cls): |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 88 | super(TestICLVariant, cls).setUpClass() |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 89 | |
| 90 | @classmethod |
| 91 | def tearDownClass(cls): |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 92 | super(TestICLVariant, cls).tearDownClass() |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 93 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 94 | @unittest.skipUnless( |
| 95 | skipVariant(LINUX_VARIANT), VARIANT + " not a supported variant, skip." |
| 96 | ) |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 97 | def test_icl(self): |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 98 | self.checkVariant(self.VARIANT) |
| 99 | |
| 100 | |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 101 | class TestSKXVariant(TestNodeVariant): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 102 | """Test skx Node Variants""" |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 103 | |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 104 | VARIANT = "skx" |
| 105 | LINUX_VARIANT = "avx512f" |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 106 | |
| 107 | @classmethod |
| 108 | def setUpConstants(cls): |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 109 | super(TestSKXVariant, cls).setUpConstants(cls.VARIANT) |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 110 | |
| 111 | @classmethod |
| 112 | def setUpClass(cls): |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 113 | super(TestSKXVariant, cls).setUpClass() |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 114 | |
| 115 | @classmethod |
| 116 | def tearDownClass(cls): |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 117 | super(TestSKXVariant, cls).tearDownClass() |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 118 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 119 | @unittest.skipUnless( |
| 120 | skipVariant(LINUX_VARIANT), VARIANT + " not a supported variant, skip." |
| 121 | ) |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 122 | def test_skx(self): |
| 123 | self.checkVariant(self.VARIANT) |
| 124 | |
| 125 | |
| 126 | class TestHSWVariant(TestNodeVariant): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 127 | """Test avx2 Node Variants""" |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 128 | |
| 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 144 | @unittest.skipUnless( |
| 145 | skipVariant(LINUX_VARIANT), VARIANT + " not a supported variant, skip." |
| 146 | ) |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 147 | def test_hsw(self): |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 148 | self.checkVariant(self.VARIANT) |