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 |
Dave Barach | d498c9e | 2020-03-10 16:59:39 -0400 | [diff] [blame^] | 6 | from framework import running_gcov_tests |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 7 | from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath |
| 8 | |
| 9 | |
| 10 | class TestVlib(VppTestCase): |
| 11 | """ Vlib Unit Test Cases """ |
| 12 | worker_config = "workers 1" |
| 13 | |
| 14 | @classmethod |
| 15 | def setUpClass(cls): |
| 16 | super(TestVlib, cls).setUpClass() |
| 17 | |
| 18 | @classmethod |
| 19 | def tearDownClass(cls): |
| 20 | super(TestVlib, cls).tearDownClass() |
| 21 | |
| 22 | def setUp(self): |
| 23 | super(TestVlib, self).setUp() |
| 24 | |
| 25 | def tearDown(self): |
| 26 | super(TestVlib, self).tearDown() |
| 27 | |
Dave Barach | d498c9e | 2020-03-10 16:59:39 -0400 | [diff] [blame^] | 28 | @unittest.skipUnless(running_gcov_tests, "part of code coverage tests") |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 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 | |
Dave Barach | d498c9e | 2020-03-10 16:59:39 -0400 | [diff] [blame^] | 70 | @unittest.skipUnless(running_gcov_tests, "part of code coverage tests") |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 71 | def test_vlib_node_cli_unittest(self): |
| 72 | """ Vlib node_cli.c Code Coverage Test """ |
| 73 | |
| 74 | cmds = ["loopback create", |
| 75 | "packet-generator new {\n" |
| 76 | " name vlib\n" |
| 77 | " limit 15\n" |
| 78 | " size 128-128\n" |
| 79 | " interface loop0\n" |
| 80 | " node ethernet-input\n" |
| 81 | " data {\n" |
| 82 | " IP6: 00:d0:2d:5e:86:85 -> 00:0d:ea:d0:00:00\n" |
| 83 | " ICMP: db00::1 -> db00::2\n" |
| 84 | " incrementing 30\n" |
Paul Vinciguerra | 41a817a | 2019-11-22 22:12:31 -0500 | [diff] [blame] | 85 | " }\n" |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 86 | "}\n", |
| 87 | "show vlib graph", |
| 88 | "show vlib graph ethernet-input", |
| 89 | "show vlib graphviz", |
| 90 | "show vlib graphviz graphviz.dot", |
| 91 | "pa en", |
| 92 | "show runtime ethernet-input", |
| 93 | "show runtime brief verbose max summary", |
| 94 | "clear runtime", |
| 95 | "show node index 1", |
| 96 | "show node ethernet-input", |
| 97 | "show node pg-input", |
| 98 | "set node function", |
| 99 | "set node function no-such-node", |
| 100 | "set node function cdp-input default", |
| 101 | "set node function ethernet-input default", |
| 102 | "set node function ethernet-input bozo", |
| 103 | "set node function ethernet-input", |
Dave Barach | 6b3f25c | 2019-12-09 10:45:47 -0500 | [diff] [blame] | 104 | "show \t", |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 105 | ] |
| 106 | |
| 107 | for cmd in cmds: |
| 108 | r = self.vapi.cli_return_response(cmd) |
| 109 | if r.retval != 0: |
| 110 | if hasattr(r, 'reply'): |
| 111 | self.logger.info(cmd + " FAIL reply " + r.reply) |
| 112 | else: |
| 113 | self.logger.info(cmd + " FAIL retval " + str(r.retval)) |
| 114 | |
Dave Barach | d498c9e | 2020-03-10 16:59:39 -0400 | [diff] [blame^] | 115 | @unittest.skipUnless(running_gcov_tests, "part of code coverage tests") |
Dave Barach | c17fc44 | 2019-11-18 17:16:49 -0500 | [diff] [blame] | 116 | def test_vlib_buffer_c_unittest(self): |
| 117 | """ Vlib buffer.c Code Coverage Test """ |
| 118 | |
| 119 | cmds = ["loopback create", |
| 120 | "packet-generator new {\n" |
| 121 | " name vlib\n" |
| 122 | " limit 15\n" |
| 123 | " size 128-128\n" |
| 124 | " interface loop0\n" |
| 125 | " node ethernet-input\n" |
| 126 | " data {\n" |
| 127 | " IP6: 00:d0:2d:5e:86:85 -> 00:0d:ea:d0:00:00\n" |
| 128 | " ICMP: db00::1 -> db00::2\n" |
| 129 | " incrementing 30\n" |
Paul Vinciguerra | 41a817a | 2019-11-22 22:12:31 -0500 | [diff] [blame] | 130 | " }\n" |
Dave Barach | c17fc44 | 2019-11-18 17:16:49 -0500 | [diff] [blame] | 131 | "}\n", |
Dave Barach | 6b3f25c | 2019-12-09 10:45:47 -0500 | [diff] [blame] | 132 | "elog trace", |
| 133 | "elog trace enable", |
| 134 | "elog trace api cli barrier", |
Dave Barach | c17fc44 | 2019-11-18 17:16:49 -0500 | [diff] [blame] | 135 | "pa en", |
Dave Barach | 6b3f25c | 2019-12-09 10:45:47 -0500 | [diff] [blame] | 136 | "show interface bogus", |
| 137 | "elog trace disable api cli barrier", |
| 138 | "elog trace circuit-node ethernet-input", |
| 139 | "elog trace circuit-node ethernet-input disable", |
Dave Barach | e51a9bb | 2019-11-19 10:36:41 -0500 | [diff] [blame] | 140 | "clear interfaces", |
Dave Barach | c17fc44 | 2019-11-18 17:16:49 -0500 | [diff] [blame] | 141 | "test vlib", |
Dave Barach | 6b3f25c | 2019-12-09 10:45:47 -0500 | [diff] [blame] | 142 | "test vlib2", |
| 143 | "show memory api-segment stats-segment main-heap verbose", |
| 144 | "leak-check { show memory }", |
| 145 | "show cpu", |
| 146 | "memory-trace main-heap", |
| 147 | "memory-trace main-heap api-segment stats-segment", |
| 148 | "leak-check { show version }", |
| 149 | "show version ?", |
| 150 | "comment { show version }", |
| 151 | "uncomment { show version }", |
| 152 | "show memory main-heap", |
| 153 | "show memory bogus", |
| 154 | "choices", |
| 155 | "test heap-validate", |
| 156 | "memory-trace main-heap disable", |
Dave Barach | c17fc44 | 2019-11-18 17:16:49 -0500 | [diff] [blame] | 157 | "show buffers", |
Dave Barach | 6b3f25c | 2019-12-09 10:45:47 -0500 | [diff] [blame] | 158 | "show eve", |
| 159 | "show help", |
| 160 | "show ip ", |
Dave Barach | c17fc44 | 2019-11-18 17:16:49 -0500 | [diff] [blame] | 161 | ] |
| 162 | |
| 163 | for cmd in cmds: |
| 164 | r = self.vapi.cli_return_response(cmd) |
| 165 | if r.retval != 0: |
| 166 | if hasattr(r, 'reply'): |
| 167 | self.logger.info(cmd + " FAIL reply " + r.reply) |
| 168 | else: |
| 169 | self.logger.info(cmd + " FAIL retval " + str(r.retval)) |
| 170 | |
Dave Barach | d498c9e | 2020-03-10 16:59:39 -0400 | [diff] [blame^] | 171 | @unittest.skipUnless(running_gcov_tests, "part of code coverage tests") |
Dave Barach | e51a9bb | 2019-11-19 10:36:41 -0500 | [diff] [blame] | 172 | def test_vlib_format_unittest(self): |
| 173 | """ Vlib format.c Code Coverage Test """ |
| 174 | |
| 175 | cmds = ["loopback create", |
Dave Barach | 29c6132 | 2019-12-24 16:59:38 -0500 | [diff] [blame] | 176 | "classify filter pcap mask l2 proto match l2 proto 0x86dd", |
| 177 | "classify filter pcap del", |
Dave Barach | e51a9bb | 2019-11-19 10:36:41 -0500 | [diff] [blame] | 178 | "test format-vlib", |
| 179 | ] |
| 180 | |
| 181 | for cmd in cmds: |
| 182 | r = self.vapi.cli_return_response(cmd) |
| 183 | if r.retval != 0: |
| 184 | if hasattr(r, 'reply'): |
| 185 | self.logger.info(cmd + " FAIL reply " + r.reply) |
| 186 | else: |
| 187 | self.logger.info(cmd + " FAIL retval " + str(r.retval)) |
| 188 | |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 189 | if __name__ == '__main__': |
| 190 | unittest.main(testRunner=VppTestRunner) |