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 |
| 5 | from framework import VppTestCase |
| 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 | |
| 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 | |
| 23 | class 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 Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame^] | 70 | class TestICLVariant(TestNodeVariant): |
| 71 | """ Test icl Node Variants """ |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 72 | |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame^] | 73 | VARIANT = "icl" |
| 74 | LINUX_VARIANT = "avx512_bitalg" |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 75 | |
| 76 | @classmethod |
| 77 | def setUpConstants(cls): |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame^] | 78 | super(TestICLVariant, cls).setUpConstants(cls.VARIANT) |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 79 | |
| 80 | @classmethod |
| 81 | def setUpClass(cls): |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame^] | 82 | super(TestICLVariant, cls).setUpClass() |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 83 | |
| 84 | @classmethod |
| 85 | def tearDownClass(cls): |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame^] | 86 | super(TestICLVariant, cls).tearDownClass() |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 87 | |
| 88 | @unittest.skipUnless(skipVariant(LINUX_VARIANT), |
| 89 | VARIANT + " not a supported variant, skip.") |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame^] | 90 | def test_icl(self): |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 91 | self.checkVariant(self.VARIANT) |
| 92 | |
| 93 | |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame^] | 94 | class TestSKXVariant(TestNodeVariant): |
| 95 | """ Test skx Node Variants """ |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 96 | |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame^] | 97 | VARIANT = "skx" |
| 98 | LINUX_VARIANT = "avx512f" |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 99 | |
| 100 | @classmethod |
| 101 | def setUpConstants(cls): |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame^] | 102 | super(TestSKXVariant, cls).setUpConstants(cls.VARIANT) |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 103 | |
| 104 | @classmethod |
| 105 | def setUpClass(cls): |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame^] | 106 | super(TestSKXVariant, cls).setUpClass() |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 107 | |
| 108 | @classmethod |
| 109 | def tearDownClass(cls): |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame^] | 110 | super(TestSKXVariant, cls).tearDownClass() |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 111 | |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame^] | 112 | @unittest.skipUnless(skipVariant(LINUX_VARIANT), |
Ray Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 113 | VARIANT + " not a supported variant, skip.") |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame^] | 114 | def test_skx(self): |
| 115 | self.checkVariant(self.VARIANT) |
| 116 | |
| 117 | |
| 118 | class 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 Kinsella | 4830e4f | 2020-03-10 14:35:32 +0000 | [diff] [blame] | 139 | self.checkVariant(self.VARIANT) |