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 | |
| 70 | class TestAVX512Variant(TestNodeVariant): |
| 71 | """ Test avx512 Node Variants """ |
| 72 | |
| 73 | VARIANT = "avx512" |
| 74 | LINUX_VARIANT = VARIANT + "f" |
| 75 | |
| 76 | @classmethod |
| 77 | def setUpConstants(cls): |
| 78 | super(TestAVX512Variant, cls).setUpConstants(cls.VARIANT) |
| 79 | |
| 80 | @classmethod |
| 81 | def setUpClass(cls): |
| 82 | super(TestAVX512Variant, cls).setUpClass() |
| 83 | |
| 84 | @classmethod |
| 85 | def tearDownClass(cls): |
| 86 | super(TestAVX512Variant, cls).tearDownClass() |
| 87 | |
| 88 | @unittest.skipUnless(skipVariant(LINUX_VARIANT), |
| 89 | VARIANT + " not a supported variant, skip.") |
| 90 | def test_avx512(self): |
| 91 | self.checkVariant(self.VARIANT) |
| 92 | |
| 93 | |
| 94 | class TestAVX2Variant(TestNodeVariant): |
| 95 | """ Test avx2 Node Variants """ |
| 96 | |
| 97 | VARIANT = "avx2" |
| 98 | |
| 99 | @classmethod |
| 100 | def setUpConstants(cls): |
| 101 | super(TestAVX2Variant, cls).setUpConstants(cls.VARIANT) |
| 102 | |
| 103 | @classmethod |
| 104 | def setUpClass(cls): |
| 105 | super(TestAVX2Variant, cls).setUpClass() |
| 106 | |
| 107 | @classmethod |
| 108 | def tearDownClass(cls): |
| 109 | super(TestAVX2Variant, cls).tearDownClass() |
| 110 | |
| 111 | @unittest.skipUnless(skipVariant(VARIANT), |
| 112 | VARIANT + " not a supported variant, skip.") |
| 113 | def test_avx2(self): |
| 114 | self.checkVariant(self.VARIANT) |