Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | import unittest |
| 4 | |
| 5 | from framework import VppTestCase, VppTestRunner, running_extended_tests |
| 6 | from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath |
| 7 | |
| 8 | |
| 9 | class TestVlib(VppTestCase): |
| 10 | """ Vlib Unit Test Cases """ |
| 11 | worker_config = "workers 1" |
| 12 | |
| 13 | @classmethod |
| 14 | def setUpClass(cls): |
| 15 | super(TestVlib, cls).setUpClass() |
| 16 | |
| 17 | @classmethod |
| 18 | def tearDownClass(cls): |
| 19 | super(TestVlib, cls).tearDownClass() |
| 20 | |
| 21 | def setUp(self): |
| 22 | super(TestVlib, self).setUp() |
| 23 | |
| 24 | def tearDown(self): |
| 25 | super(TestVlib, self).tearDown() |
| 26 | |
| 27 | # @unittest.skipUnless(running_extended_tests, "part of extended tests") |
| 28 | |
| 29 | def test_vlib_main_unittest(self): |
| 30 | """ Vlib main.c Code Coverage Test """ |
| 31 | |
| 32 | cmds = ["loopback create", |
| 33 | "packet-generator new {\n" |
| 34 | " name vlib\n" |
| 35 | " limit 15\n" |
| 36 | " size 128-128\n" |
| 37 | " interface loop0\n" |
| 38 | " node ethernet-input\n" |
| 39 | " data {\n" |
| 40 | " IP6: 00:d0:2d:5e:86:85 -> 00:0d:ea:d0:00:00\n" |
| 41 | " ICMP: db00::1 -> db00::2\n" |
| 42 | " incrementing 30\n" |
Paul Vinciguerra | 41a817a | 2019-11-22 22:12:31 -0500 | [diff] [blame] | 43 | " }\n" |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 44 | "}\n", |
| 45 | "elog trace dispatch", |
| 46 | "event-logger stop", |
| 47 | "event-logger clear", |
| 48 | "event-logger resize 102400", |
| 49 | "event-logger restart", |
| 50 | "pcap dispatch trace on max 100 buffer-trace pg-input 15", |
| 51 | "set pmc instructions-per-clock", |
| 52 | "pa en", |
| 53 | "show event-log 100 all", |
| 54 | "event-log save", |
| 55 | "event-log save foo", |
| 56 | "pcap dispatch trace", |
| 57 | "pcap dispatch trace status", |
| 58 | "pcap dispatch trace off", |
| 59 | "show vlib frame-allocation", |
| 60 | ] |
| 61 | |
| 62 | for cmd in cmds: |
| 63 | r = self.vapi.cli_return_response(cmd) |
| 64 | if r.retval != 0: |
| 65 | if hasattr(r, 'reply'): |
| 66 | self.logger.info(cmd + " FAIL reply " + r.reply) |
| 67 | else: |
| 68 | self.logger.info(cmd + " FAIL retval " + str(r.retval)) |
| 69 | |
| 70 | def test_vlib_node_cli_unittest(self): |
| 71 | """ Vlib node_cli.c Code Coverage Test """ |
| 72 | |
| 73 | cmds = ["loopback create", |
| 74 | "packet-generator new {\n" |
| 75 | " name vlib\n" |
| 76 | " limit 15\n" |
| 77 | " size 128-128\n" |
| 78 | " interface loop0\n" |
| 79 | " node ethernet-input\n" |
| 80 | " data {\n" |
| 81 | " IP6: 00:d0:2d:5e:86:85 -> 00:0d:ea:d0:00:00\n" |
| 82 | " ICMP: db00::1 -> db00::2\n" |
| 83 | " incrementing 30\n" |
Paul Vinciguerra | 41a817a | 2019-11-22 22:12:31 -0500 | [diff] [blame] | 84 | " }\n" |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 85 | "}\n", |
| 86 | "show vlib graph", |
| 87 | "show vlib graph ethernet-input", |
| 88 | "show vlib graphviz", |
| 89 | "show vlib graphviz graphviz.dot", |
| 90 | "pa en", |
| 91 | "show runtime ethernet-input", |
| 92 | "show runtime brief verbose max summary", |
| 93 | "clear runtime", |
| 94 | "show node index 1", |
| 95 | "show node ethernet-input", |
| 96 | "show node pg-input", |
| 97 | "set node function", |
| 98 | "set node function no-such-node", |
| 99 | "set node function cdp-input default", |
| 100 | "set node function ethernet-input default", |
| 101 | "set node function ethernet-input bozo", |
| 102 | "set node function ethernet-input", |
| 103 | ] |
| 104 | |
| 105 | for cmd in cmds: |
| 106 | r = self.vapi.cli_return_response(cmd) |
| 107 | if r.retval != 0: |
| 108 | if hasattr(r, 'reply'): |
| 109 | self.logger.info(cmd + " FAIL reply " + r.reply) |
| 110 | else: |
| 111 | self.logger.info(cmd + " FAIL retval " + str(r.retval)) |
| 112 | |
Dave Barach | c17fc44 | 2019-11-18 17:16:49 -0500 | [diff] [blame] | 113 | def test_vlib_buffer_c_unittest(self): |
| 114 | """ Vlib buffer.c Code Coverage Test """ |
| 115 | |
| 116 | cmds = ["loopback create", |
| 117 | "packet-generator new {\n" |
| 118 | " name vlib\n" |
| 119 | " limit 15\n" |
| 120 | " size 128-128\n" |
| 121 | " interface loop0\n" |
| 122 | " node ethernet-input\n" |
| 123 | " data {\n" |
| 124 | " IP6: 00:d0:2d:5e:86:85 -> 00:0d:ea:d0:00:00\n" |
| 125 | " ICMP: db00::1 -> db00::2\n" |
| 126 | " incrementing 30\n" |
Paul Vinciguerra | 41a817a | 2019-11-22 22:12:31 -0500 | [diff] [blame] | 127 | " }\n" |
Dave Barach | c17fc44 | 2019-11-18 17:16:49 -0500 | [diff] [blame] | 128 | "}\n", |
| 129 | "pa en", |
Dave Barach | e51a9bb | 2019-11-19 10:36:41 -0500 | [diff] [blame] | 130 | "clear interfaces", |
Dave Barach | c17fc44 | 2019-11-18 17:16:49 -0500 | [diff] [blame] | 131 | "test vlib", |
| 132 | "show buffers", |
| 133 | ] |
| 134 | |
| 135 | for cmd in cmds: |
| 136 | r = self.vapi.cli_return_response(cmd) |
| 137 | if r.retval != 0: |
| 138 | if hasattr(r, 'reply'): |
| 139 | self.logger.info(cmd + " FAIL reply " + r.reply) |
| 140 | else: |
| 141 | self.logger.info(cmd + " FAIL retval " + str(r.retval)) |
| 142 | |
Dave Barach | e51a9bb | 2019-11-19 10:36:41 -0500 | [diff] [blame] | 143 | def test_vlib_format_unittest(self): |
| 144 | """ Vlib format.c Code Coverage Test """ |
| 145 | |
| 146 | cmds = ["loopback create", |
| 147 | "classify filter pcap mask l2 proto ipv6 match l2 proto 86dd", |
| 148 | "classify filter del", |
| 149 | "test format-vlib", |
| 150 | ] |
| 151 | |
| 152 | for cmd in cmds: |
| 153 | r = self.vapi.cli_return_response(cmd) |
| 154 | if r.retval != 0: |
| 155 | if hasattr(r, 'reply'): |
| 156 | self.logger.info(cmd + " FAIL reply " + r.reply) |
| 157 | else: |
| 158 | self.logger.info(cmd + " FAIL retval " + str(r.retval)) |
| 159 | |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 160 | if __name__ == '__main__': |
| 161 | unittest.main(testRunner=VppTestRunner) |