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): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 14 | """Vlib Unit Test Cases""" |
| 15 | |
Klement Sekera | 8d81502 | 2021-03-15 16:58:10 +0100 | [diff] [blame] | 16 | vpp_worker_count = 1 |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 17 | |
| 18 | @classmethod |
| 19 | def setUpClass(cls): |
| 20 | super(TestVlib, cls).setUpClass() |
| 21 | |
| 22 | @classmethod |
| 23 | def tearDownClass(cls): |
| 24 | super(TestVlib, cls).tearDownClass() |
| 25 | |
| 26 | def setUp(self): |
| 27 | super(TestVlib, self).setUp() |
| 28 | |
| 29 | def tearDown(self): |
| 30 | super(TestVlib, self).tearDown() |
| 31 | |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 32 | def test_vlib_main_unittest(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 33 | """Vlib main.c Code Coverage Test""" |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 34 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 35 | cmds = [ |
| 36 | "loopback create", |
| 37 | "packet-generator new {\n" |
| 38 | " name vlib\n" |
| 39 | " limit 15\n" |
| 40 | " size 128-128\n" |
| 41 | " interface loop0\n" |
| 42 | " node ethernet-input\n" |
| 43 | " data {\n" |
| 44 | " IP6: 00:d0:2d:5e:86:85 -> 00:0d:ea:d0:00:00\n" |
| 45 | " ICMP: db00::1 -> db00::2\n" |
| 46 | " incrementing 30\n" |
| 47 | " }\n" |
| 48 | "}\n", |
| 49 | "event-logger trace dispatch", |
| 50 | "event-logger stop", |
| 51 | "event-logger clear", |
| 52 | "event-logger resize 102400", |
| 53 | "event-logger restart", |
| 54 | "pcap dispatch trace on max 100 buffer-trace pg-input 15", |
| 55 | "pa en", |
| 56 | "show event-log 100 all", |
| 57 | "event-log save", |
| 58 | "event-log save foo", |
| 59 | "pcap dispatch trace", |
| 60 | "pcap dispatch trace status", |
| 61 | "pcap dispatch trace off", |
| 62 | "show vlib frame-allocation", |
| 63 | ] |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 64 | |
| 65 | for cmd in cmds: |
| 66 | r = self.vapi.cli_return_response(cmd) |
| 67 | if r.retval != 0: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 68 | if hasattr(r, "reply"): |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 69 | self.logger.info(cmd + " FAIL reply " + r.reply) |
| 70 | else: |
| 71 | self.logger.info(cmd + " FAIL retval " + str(r.retval)) |
| 72 | |
| 73 | def test_vlib_node_cli_unittest(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 74 | """Vlib node_cli.c Code Coverage Test""" |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 75 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 76 | cmds = [ |
| 77 | "loopback create", |
| 78 | "packet-generator new {\n" |
| 79 | " name vlib\n" |
| 80 | " limit 15\n" |
| 81 | " size 128-128\n" |
| 82 | " interface loop0\n" |
| 83 | " node ethernet-input\n" |
| 84 | " data {\n" |
| 85 | " IP6: 00:d0:2d:5e:86:85 -> 00:0d:ea:d0:00:00\n" |
| 86 | " ICMP: db00::1 -> db00::2\n" |
| 87 | " incrementing 30\n" |
| 88 | " }\n" |
| 89 | "}\n", |
| 90 | "show vlib graph", |
| 91 | "show vlib graph ethernet-input", |
| 92 | "show vlib graphviz", |
| 93 | "show vlib graphviz graphviz.dot", |
| 94 | "pa en", |
| 95 | "show runtime ethernet-input", |
| 96 | "show runtime brief verbose max summary", |
| 97 | "clear runtime", |
| 98 | "show node index 1", |
| 99 | "show node ethernet-input", |
| 100 | "show node pg-input", |
| 101 | "set node function", |
| 102 | "set node function no-such-node", |
| 103 | "set node function cdp-input default", |
| 104 | "set node function ethernet-input default", |
| 105 | "set node function ethernet-input bozo", |
| 106 | "set node function ethernet-input", |
| 107 | "show \t", |
| 108 | ] |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 109 | |
| 110 | for cmd in cmds: |
| 111 | r = self.vapi.cli_return_response(cmd) |
| 112 | if r.retval != 0: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 113 | if hasattr(r, "reply"): |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 114 | self.logger.info(cmd + " FAIL reply " + r.reply) |
| 115 | else: |
| 116 | self.logger.info(cmd + " FAIL retval " + str(r.retval)) |
| 117 | |
Dave Barach | c17fc44 | 2019-11-18 17:16:49 -0500 | [diff] [blame] | 118 | def test_vlib_buffer_c_unittest(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 119 | """Vlib buffer.c Code Coverage Test""" |
Dave Barach | c17fc44 | 2019-11-18 17:16:49 -0500 | [diff] [blame] | 120 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 121 | cmds = [ |
| 122 | "loopback create", |
| 123 | "packet-generator new {\n" |
| 124 | " name vlib\n" |
| 125 | " limit 15\n" |
| 126 | " size 128-128\n" |
| 127 | " interface loop0\n" |
| 128 | " node ethernet-input\n" |
| 129 | " data {\n" |
| 130 | " IP6: 00:d0:2d:5e:86:85 -> 00:0d:ea:d0:00:00\n" |
| 131 | " ICMP: db00::1 -> db00::2\n" |
| 132 | " incrementing 30\n" |
| 133 | " }\n" |
| 134 | "}\n", |
| 135 | "event-logger trace", |
| 136 | "event-logger trace enable", |
| 137 | "event-logger trace api cli barrier", |
| 138 | "pa en", |
| 139 | "show interface bogus", |
| 140 | "event-logger trace disable api cli barrier", |
| 141 | "event-logger trace circuit-node ethernet-input", |
| 142 | "event-logger trace circuit-node ethernet-input disable", |
| 143 | "clear interfaces", |
| 144 | "test vlib", |
| 145 | "test vlib2", |
| 146 | "show memory api-segment stats-segment main-heap verbose", |
| 147 | "leak-check { show memory }", |
| 148 | "show cpu", |
| 149 | "memory-trace main-heap", |
| 150 | "memory-trace main-heap api-segment stats-segment", |
| 151 | "leak-check { show version }", |
| 152 | "show version ?", |
| 153 | "comment { show version }", |
| 154 | "uncomment { show version }", |
| 155 | "show memory main-heap", |
| 156 | "show memory bogus", |
| 157 | "choices", |
| 158 | "test heap-validate", |
| 159 | "memory-trace main-heap disable", |
| 160 | "show buffers", |
| 161 | "show eve", |
| 162 | "show help", |
| 163 | "show ip ", |
| 164 | ] |
Dave Barach | c17fc44 | 2019-11-18 17:16:49 -0500 | [diff] [blame] | 165 | |
| 166 | for cmd in cmds: |
| 167 | r = self.vapi.cli_return_response(cmd) |
| 168 | if r.retval != 0: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 169 | if hasattr(r, "reply"): |
Dave Barach | c17fc44 | 2019-11-18 17:16:49 -0500 | [diff] [blame] | 170 | self.logger.info(cmd + " FAIL reply " + r.reply) |
| 171 | else: |
| 172 | self.logger.info(cmd + " FAIL retval " + str(r.retval)) |
| 173 | |
Dave Barach | e51a9bb | 2019-11-19 10:36:41 -0500 | [diff] [blame] | 174 | def test_vlib_format_unittest(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 175 | """Vlib format.c Code Coverage Test""" |
Dave Barach | e51a9bb | 2019-11-19 10:36:41 -0500 | [diff] [blame] | 176 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 177 | cmds = [ |
| 178 | "loopback create", |
| 179 | "classify filter pcap mask l2 proto match l2 proto 0x86dd", |
| 180 | "classify filter pcap del", |
| 181 | "test format-vlib", |
| 182 | ] |
Dave Barach | e51a9bb | 2019-11-19 10:36:41 -0500 | [diff] [blame] | 183 | |
| 184 | for cmd in cmds: |
| 185 | r = self.vapi.cli_return_response(cmd) |
| 186 | if r.retval != 0: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 187 | if hasattr(r, "reply"): |
Dave Barach | e51a9bb | 2019-11-19 10:36:41 -0500 | [diff] [blame] | 188 | self.logger.info(cmd + " FAIL reply " + r.reply) |
| 189 | else: |
| 190 | self.logger.info(cmd + " FAIL retval " + str(r.retval)) |
| 191 | |
Dave Barach | 3a49130 | 2020-06-15 17:38:12 -0400 | [diff] [blame] | 192 | def test_vlib_main_unittest(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 193 | """Private Binary API Segment Test (takes 70 seconds)""" |
Dave Barach | 3a49130 | 2020-06-15 17:38:12 -0400 | [diff] [blame] | 194 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 195 | vat_path = config.vpp + "_api_test" |
| 196 | vat = pexpect.spawn(vat_path, ["socket-name", self.get_api_sock_path()]) |
Dave Barach | 3a49130 | 2020-06-15 17:38:12 -0400 | [diff] [blame] | 197 | vat.expect("vat# ", timeout=10) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 198 | vat.sendline("sock_init_shm") |
Dave Barach | 3a49130 | 2020-06-15 17:38:12 -0400 | [diff] [blame] | 199 | vat.expect("vat# ", timeout=10) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 200 | vat.sendline("sh api cli") |
Dave Barach | 3a49130 | 2020-06-15 17:38:12 -0400 | [diff] [blame] | 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 | 4de5f9b | 2021-06-02 18:18:18 -0400 | [diff] [blame] | 207 | def test_pool(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 208 | """Fixed-size Pool Test""" |
Dave Barach | 4de5f9b | 2021-06-02 18:18:18 -0400 | [diff] [blame] | 209 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 210 | cmds = [ |
| 211 | "test pool", |
| 212 | ] |
Dave Barach | 4de5f9b | 2021-06-02 18:18:18 -0400 | [diff] [blame] | 213 | |
| 214 | for cmd in cmds: |
| 215 | r = self.vapi.cli_return_response(cmd) |
| 216 | if r.retval != 0: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 217 | if hasattr(r, "reply"): |
Dave Barach | 4de5f9b | 2021-06-02 18:18:18 -0400 | [diff] [blame] | 218 | self.logger.info(cmd + " FAIL reply " + r.reply) |
| 219 | else: |
| 220 | self.logger.info(cmd + " FAIL retval " + str(r.retval)) |
Klement Sekera | e263685 | 2021-03-16 12:52:12 +0100 | [diff] [blame] | 221 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 222 | |
| 223 | if __name__ == "__main__": |
Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 224 | unittest.main(testRunner=VppTestRunner) |