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 """ |
| 14 | worker_config = "workers 1" |
| 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", |
| 47 | "elog trace dispatch", |
| 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", |
| 53 | "set pmc instructions-per-clock", |
| 54 | "pa en", |
| 55 | "show event-log 100 all", |
| 56 | "event-log save", |
| 57 | "event-log save foo", |
| 58 | "pcap dispatch trace", |
| 59 | "pcap dispatch trace status", |
| 60 | "pcap dispatch trace off", |
| 61 | "show vlib frame-allocation", |
| 62 | ] |
| 63 | |
| 64 | for cmd in cmds: |
| 65 | r = self.vapi.cli_return_response(cmd) |
| 66 | if r.retval != 0: |
| 67 | if hasattr(r, 'reply'): |
| 68 | self.logger.info(cmd + " FAIL reply " + r.reply) |
| 69 | else: |
| 70 | self.logger.info(cmd + " FAIL retval " + str(r.retval)) |
| 71 | |
Dave Barach | d498c9e | 2020-03-10 16:59:39 -0400 | [diff] [blame] | 72 | @unittest.skipUnless(running_gcov_tests, "part of code coverage tests") |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 73 | def test_vlib_node_cli_unittest(self): |
| 74 | """ Vlib node_cli.c Code Coverage Test """ |
| 75 | |
| 76 | cmds = ["loopback create", |
| 77 | "packet-generator new {\n" |
| 78 | " name vlib\n" |
| 79 | " limit 15\n" |
| 80 | " size 128-128\n" |
| 81 | " interface loop0\n" |
| 82 | " node ethernet-input\n" |
| 83 | " data {\n" |
| 84 | " IP6: 00:d0:2d:5e:86:85 -> 00:0d:ea:d0:00:00\n" |
| 85 | " ICMP: db00::1 -> db00::2\n" |
| 86 | " incrementing 30\n" |
Paul Vinciguerra | 41a817a | 2019-11-22 22:12:31 -0500 | [diff] [blame] | 87 | " }\n" |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 88 | "}\n", |
| 89 | "show vlib graph", |
| 90 | "show vlib graph ethernet-input", |
| 91 | "show vlib graphviz", |
| 92 | "show vlib graphviz graphviz.dot", |
| 93 | "pa en", |
| 94 | "show runtime ethernet-input", |
| 95 | "show runtime brief verbose max summary", |
| 96 | "clear runtime", |
| 97 | "show node index 1", |
| 98 | "show node ethernet-input", |
| 99 | "show node pg-input", |
| 100 | "set node function", |
| 101 | "set node function no-such-node", |
| 102 | "set node function cdp-input default", |
| 103 | "set node function ethernet-input default", |
| 104 | "set node function ethernet-input bozo", |
| 105 | "set node function ethernet-input", |
Dave Barach | 6b3f25c | 2019-12-09 10:45:47 -0500 | [diff] [blame] | 106 | "show \t", |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 107 | ] |
| 108 | |
| 109 | for cmd in cmds: |
| 110 | r = self.vapi.cli_return_response(cmd) |
| 111 | if r.retval != 0: |
| 112 | if hasattr(r, 'reply'): |
| 113 | self.logger.info(cmd + " FAIL reply " + r.reply) |
| 114 | else: |
| 115 | self.logger.info(cmd + " FAIL retval " + str(r.retval)) |
| 116 | |
Dave Barach | d498c9e | 2020-03-10 16:59:39 -0400 | [diff] [blame] | 117 | @unittest.skipUnless(running_gcov_tests, "part of code coverage tests") |
Dave Barach | c17fc44 | 2019-11-18 17:16:49 -0500 | [diff] [blame] | 118 | def test_vlib_buffer_c_unittest(self): |
| 119 | """ Vlib buffer.c Code Coverage Test """ |
| 120 | |
| 121 | cmds = ["loopback create", |
| 122 | "packet-generator new {\n" |
| 123 | " name vlib\n" |
| 124 | " limit 15\n" |
| 125 | " size 128-128\n" |
| 126 | " interface loop0\n" |
| 127 | " node ethernet-input\n" |
| 128 | " data {\n" |
| 129 | " IP6: 00:d0:2d:5e:86:85 -> 00:0d:ea:d0:00:00\n" |
| 130 | " ICMP: db00::1 -> db00::2\n" |
| 131 | " incrementing 30\n" |
Paul Vinciguerra | 41a817a | 2019-11-22 22:12:31 -0500 | [diff] [blame] | 132 | " }\n" |
Dave Barach | c17fc44 | 2019-11-18 17:16:49 -0500 | [diff] [blame] | 133 | "}\n", |
Dave Barach | 6b3f25c | 2019-12-09 10:45:47 -0500 | [diff] [blame] | 134 | "elog trace", |
| 135 | "elog trace enable", |
| 136 | "elog trace api cli barrier", |
Dave Barach | c17fc44 | 2019-11-18 17:16:49 -0500 | [diff] [blame] | 137 | "pa en", |
Dave Barach | 6b3f25c | 2019-12-09 10:45:47 -0500 | [diff] [blame] | 138 | "show interface bogus", |
| 139 | "elog trace disable api cli barrier", |
| 140 | "elog trace circuit-node ethernet-input", |
| 141 | "elog trace circuit-node ethernet-input disable", |
Dave Barach | e51a9bb | 2019-11-19 10:36:41 -0500 | [diff] [blame] | 142 | "clear interfaces", |
Dave Barach | c17fc44 | 2019-11-18 17:16:49 -0500 | [diff] [blame] | 143 | "test vlib", |
Dave Barach | 6b3f25c | 2019-12-09 10:45:47 -0500 | [diff] [blame] | 144 | "test vlib2", |
| 145 | "show memory api-segment stats-segment main-heap verbose", |
| 146 | "leak-check { show memory }", |
| 147 | "show cpu", |
| 148 | "memory-trace main-heap", |
| 149 | "memory-trace main-heap api-segment stats-segment", |
| 150 | "leak-check { show version }", |
| 151 | "show version ?", |
| 152 | "comment { show version }", |
| 153 | "uncomment { show version }", |
| 154 | "show memory main-heap", |
| 155 | "show memory bogus", |
| 156 | "choices", |
| 157 | "test heap-validate", |
| 158 | "memory-trace main-heap disable", |
Dave Barach | c17fc44 | 2019-11-18 17:16:49 -0500 | [diff] [blame] | 159 | "show buffers", |
Dave Barach | 6b3f25c | 2019-12-09 10:45:47 -0500 | [diff] [blame] | 160 | "show eve", |
| 161 | "show help", |
| 162 | "show ip ", |
Dave Barach | c17fc44 | 2019-11-18 17:16:49 -0500 | [diff] [blame] | 163 | ] |
| 164 | |
| 165 | for cmd in cmds: |
| 166 | r = self.vapi.cli_return_response(cmd) |
| 167 | if r.retval != 0: |
| 168 | if hasattr(r, 'reply'): |
| 169 | self.logger.info(cmd + " FAIL reply " + r.reply) |
| 170 | else: |
| 171 | self.logger.info(cmd + " FAIL retval " + str(r.retval)) |
| 172 | |
Dave Barach | d498c9e | 2020-03-10 16:59:39 -0400 | [diff] [blame] | 173 | @unittest.skipUnless(running_gcov_tests, "part of code coverage tests") |
Dave Barach | e51a9bb | 2019-11-19 10:36:41 -0500 | [diff] [blame] | 174 | def test_vlib_format_unittest(self): |
| 175 | """ Vlib format.c Code Coverage Test """ |
| 176 | |
| 177 | cmds = ["loopback create", |
Dave Barach | 29c6132 | 2019-12-24 16:59:38 -0500 | [diff] [blame] | 178 | "classify filter pcap mask l2 proto match l2 proto 0x86dd", |
| 179 | "classify filter pcap del", |
Dave Barach | e51a9bb | 2019-11-19 10:36:41 -0500 | [diff] [blame] | 180 | "test format-vlib", |
| 181 | ] |
| 182 | |
| 183 | for cmd in cmds: |
| 184 | r = self.vapi.cli_return_response(cmd) |
| 185 | if r.retval != 0: |
| 186 | if hasattr(r, 'reply'): |
| 187 | self.logger.info(cmd + " FAIL reply " + r.reply) |
| 188 | else: |
| 189 | self.logger.info(cmd + " FAIL retval " + str(r.retval)) |
| 190 | |
Dave Barach | 3a49130 | 2020-06-15 17:38:12 -0400 | [diff] [blame^] | 191 | @unittest.skipUnless(running_gcov_tests, "part of code coverage tests") |
| 192 | def test_vlib_main_unittest(self): |
| 193 | """ Private Binary API Segment Test (takes 70 seconds) """ |
| 194 | |
| 195 | vat_path = self.vpp_bin + '_api_test' |
| 196 | vat = pexpect.spawn(vat_path, ['socket-name', self.api_sock]) |
| 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 | |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 207 | if __name__ == '__main__': |
| 208 | unittest.main(testRunner=VppTestRunner) |