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