Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | import unittest |
Dave Barach | 3a49130 | 2020-06-15 17:38:12 -0400 | [diff] [blame] | 4 | import pexpect |
| 5 | import time |
| 6 | import signal |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 7 | from config import config |
| 8 | from framework import VppTestCase, VppTestRunner |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 9 | from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath |
| 10 | |
| 11 | |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 12 | @unittest.skipUnless(config.gcov, "part of code coverage tests") |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 13 | class TestVlib(VppTestCase): |
| 14 | """ Vlib Unit Test Cases """ |
Klement Sekera | 8d81502 | 2021-03-15 16:58:10 +0100 | [diff] [blame] | 15 | vpp_worker_count = 1 |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 16 | |
| 17 | @classmethod |
| 18 | def setUpClass(cls): |
| 19 | super(TestVlib, cls).setUpClass() |
| 20 | |
| 21 | @classmethod |
| 22 | def tearDownClass(cls): |
| 23 | super(TestVlib, cls).tearDownClass() |
| 24 | |
| 25 | def setUp(self): |
| 26 | super(TestVlib, self).setUp() |
| 27 | |
| 28 | def tearDown(self): |
| 29 | super(TestVlib, self).tearDown() |
| 30 | |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 31 | def test_vlib_main_unittest(self): |
| 32 | """ Vlib main.c Code Coverage Test """ |
| 33 | |
| 34 | cmds = ["loopback create", |
| 35 | "packet-generator new {\n" |
| 36 | " name vlib\n" |
| 37 | " limit 15\n" |
| 38 | " size 128-128\n" |
| 39 | " interface loop0\n" |
| 40 | " node ethernet-input\n" |
| 41 | " data {\n" |
| 42 | " IP6: 00:d0:2d:5e:86:85 -> 00:0d:ea:d0:00:00\n" |
| 43 | " ICMP: db00::1 -> db00::2\n" |
| 44 | " incrementing 30\n" |
Paul Vinciguerra | 41a817a | 2019-11-22 22:12:31 -0500 | [diff] [blame] | 45 | " }\n" |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 46 | "}\n", |
Dave Barach | aa67674 | 2020-11-25 07:23:42 -0500 | [diff] [blame] | 47 | "event-logger trace dispatch", |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 48 | "event-logger stop", |
| 49 | "event-logger clear", |
| 50 | "event-logger resize 102400", |
| 51 | "event-logger restart", |
| 52 | "pcap dispatch trace on max 100 buffer-trace pg-input 15", |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 53 | "pa en", |
| 54 | "show event-log 100 all", |
| 55 | "event-log save", |
| 56 | "event-log save foo", |
| 57 | "pcap dispatch trace", |
| 58 | "pcap dispatch trace status", |
| 59 | "pcap dispatch trace off", |
| 60 | "show vlib frame-allocation", |
| 61 | ] |
| 62 | |
| 63 | for cmd in cmds: |
| 64 | r = self.vapi.cli_return_response(cmd) |
| 65 | if r.retval != 0: |
| 66 | if hasattr(r, 'reply'): |
| 67 | self.logger.info(cmd + " FAIL reply " + r.reply) |
| 68 | else: |
| 69 | self.logger.info(cmd + " FAIL retval " + str(r.retval)) |
| 70 | |
| 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 | c17fc44 | 2019-11-18 17:16:49 -0500 | [diff] [blame] | 115 | def test_vlib_buffer_c_unittest(self): |
| 116 | """ Vlib buffer.c Code Coverage Test """ |
| 117 | |
| 118 | cmds = ["loopback create", |
| 119 | "packet-generator new {\n" |
| 120 | " name vlib\n" |
| 121 | " limit 15\n" |
| 122 | " size 128-128\n" |
| 123 | " interface loop0\n" |
| 124 | " node ethernet-input\n" |
| 125 | " data {\n" |
| 126 | " IP6: 00:d0:2d:5e:86:85 -> 00:0d:ea:d0:00:00\n" |
| 127 | " ICMP: db00::1 -> db00::2\n" |
| 128 | " incrementing 30\n" |
Paul Vinciguerra | 41a817a | 2019-11-22 22:12:31 -0500 | [diff] [blame] | 129 | " }\n" |
Dave Barach | c17fc44 | 2019-11-18 17:16:49 -0500 | [diff] [blame] | 130 | "}\n", |
Dave Barach | aa67674 | 2020-11-25 07:23:42 -0500 | [diff] [blame] | 131 | "event-logger trace", |
| 132 | "event-logger trace enable", |
| 133 | "event-logger trace api cli barrier", |
Dave Barach | c17fc44 | 2019-11-18 17:16:49 -0500 | [diff] [blame] | 134 | "pa en", |
Dave Barach | 6b3f25c | 2019-12-09 10:45:47 -0500 | [diff] [blame] | 135 | "show interface bogus", |
Dave Barach | aa67674 | 2020-11-25 07:23:42 -0500 | [diff] [blame] | 136 | "event-logger trace disable api cli barrier", |
| 137 | "event-logger trace circuit-node ethernet-input", |
| 138 | "event-logger trace circuit-node ethernet-input disable", |
Dave Barach | e51a9bb | 2019-11-19 10:36:41 -0500 | [diff] [blame] | 139 | "clear interfaces", |
Dave Barach | c17fc44 | 2019-11-18 17:16:49 -0500 | [diff] [blame] | 140 | "test vlib", |
Dave Barach | 6b3f25c | 2019-12-09 10:45:47 -0500 | [diff] [blame] | 141 | "test vlib2", |
| 142 | "show memory api-segment stats-segment main-heap verbose", |
| 143 | "leak-check { show memory }", |
| 144 | "show cpu", |
| 145 | "memory-trace main-heap", |
| 146 | "memory-trace main-heap api-segment stats-segment", |
| 147 | "leak-check { show version }", |
| 148 | "show version ?", |
| 149 | "comment { show version }", |
| 150 | "uncomment { show version }", |
| 151 | "show memory main-heap", |
| 152 | "show memory bogus", |
| 153 | "choices", |
| 154 | "test heap-validate", |
| 155 | "memory-trace main-heap disable", |
Dave Barach | c17fc44 | 2019-11-18 17:16:49 -0500 | [diff] [blame] | 156 | "show buffers", |
Dave Barach | 6b3f25c | 2019-12-09 10:45:47 -0500 | [diff] [blame] | 157 | "show eve", |
| 158 | "show help", |
| 159 | "show ip ", |
Dave Barach | c17fc44 | 2019-11-18 17:16:49 -0500 | [diff] [blame] | 160 | ] |
| 161 | |
| 162 | for cmd in cmds: |
| 163 | r = self.vapi.cli_return_response(cmd) |
| 164 | if r.retval != 0: |
| 165 | if hasattr(r, 'reply'): |
| 166 | self.logger.info(cmd + " FAIL reply " + r.reply) |
| 167 | else: |
| 168 | self.logger.info(cmd + " FAIL retval " + str(r.retval)) |
| 169 | |
Dave Barach | e51a9bb | 2019-11-19 10:36:41 -0500 | [diff] [blame] | 170 | def test_vlib_format_unittest(self): |
| 171 | """ Vlib format.c Code Coverage Test """ |
| 172 | |
| 173 | cmds = ["loopback create", |
Dave Barach | 29c6132 | 2019-12-24 16:59:38 -0500 | [diff] [blame] | 174 | "classify filter pcap mask l2 proto match l2 proto 0x86dd", |
| 175 | "classify filter pcap del", |
Dave Barach | e51a9bb | 2019-11-19 10:36:41 -0500 | [diff] [blame] | 176 | "test format-vlib", |
| 177 | ] |
| 178 | |
| 179 | for cmd in cmds: |
| 180 | r = self.vapi.cli_return_response(cmd) |
| 181 | if r.retval != 0: |
| 182 | if hasattr(r, 'reply'): |
| 183 | self.logger.info(cmd + " FAIL reply " + r.reply) |
| 184 | else: |
| 185 | self.logger.info(cmd + " FAIL retval " + str(r.retval)) |
| 186 | |
Dave Barach | 3a49130 | 2020-06-15 17:38:12 -0400 | [diff] [blame] | 187 | def test_vlib_main_unittest(self): |
| 188 | """ Private Binary API Segment Test (takes 70 seconds) """ |
| 189 | |
| 190 | vat_path = self.vpp_bin + '_api_test' |
Klement Sekera | e263685 | 2021-03-16 12:52:12 +0100 | [diff] [blame] | 191 | vat = pexpect.spawn(vat_path, ['socket-name', |
| 192 | self.get_api_sock_path()]) |
Dave Barach | 3a49130 | 2020-06-15 17:38:12 -0400 | [diff] [blame] | 193 | vat.expect("vat# ", timeout=10) |
| 194 | vat.sendline('sock_init_shm') |
| 195 | vat.expect("vat# ", timeout=10) |
| 196 | vat.sendline('sh api cli') |
| 197 | vat.kill(signal.SIGKILL) |
| 198 | vat.wait() |
| 199 | self.logger.info("vat terminated, 70 second wait for the Reaper") |
| 200 | time.sleep(70) |
| 201 | self.logger.info("Reaper should be complete...") |
| 202 | |
Dave Barach | 4de5f9b | 2021-06-02 18:18:18 -0400 | [diff] [blame] | 203 | def test_pool(self): |
| 204 | """ Fixed-size Pool Test """ |
| 205 | |
| 206 | cmds = ["test pool", |
| 207 | ] |
| 208 | |
| 209 | for cmd in cmds: |
| 210 | r = self.vapi.cli_return_response(cmd) |
| 211 | if r.retval != 0: |
| 212 | if hasattr(r, 'reply'): |
| 213 | self.logger.info(cmd + " FAIL reply " + r.reply) |
| 214 | else: |
| 215 | self.logger.info(cmd + " FAIL retval " + str(r.retval)) |
Klement Sekera | e263685 | 2021-03-16 12:52:12 +0100 | [diff] [blame] | 216 | |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 217 | if __name__ == '__main__': |
| 218 | unittest.main(testRunner=VppTestRunner) |