blob: 76a55e65a0345e41eade3684a4aa9279642020f8 [file] [log] [blame]
Dave Barachd9ca7c92019-11-12 17:51:18 -05001#!/usr/bin/env python3
2
3import unittest
Dave Barach3a491302020-06-15 17:38:12 -04004import pexpect
5import time
6import signal
Klement Sekerab23ffd72021-05-31 16:08:53 +02007from config import config
8from framework import VppTestCase, VppTestRunner
Dave Barachd9ca7c92019-11-12 17:51:18 -05009from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
10
11
Klement Sekerab23ffd72021-05-31 16:08:53 +020012@unittest.skipUnless(config.gcov, "part of code coverage tests")
Dave Barachd9ca7c92019-11-12 17:51:18 -050013class TestVlib(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020014 """Vlib Unit Test Cases"""
15
Klement Sekera8d815022021-03-15 16:58:10 +010016 vpp_worker_count = 1
Dave Barachd9ca7c92019-11-12 17:51:18 -050017
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 Barachd9ca7c92019-11-12 17:51:18 -050032 def test_vlib_main_unittest(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020033 """Vlib main.c Code Coverage Test"""
Dave Barachd9ca7c92019-11-12 17:51:18 -050034
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020035 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 Barachd9ca7c92019-11-12 17:51:18 -050064
65 for cmd in cmds:
66 r = self.vapi.cli_return_response(cmd)
67 if r.retval != 0:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020068 if hasattr(r, "reply"):
Dave Barachd9ca7c92019-11-12 17:51:18 -050069 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 Sekerad9b0c6f2022-04-26 19:02:15 +020074 """Vlib node_cli.c Code Coverage Test"""
Dave Barachd9ca7c92019-11-12 17:51:18 -050075
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020076 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 Barachd9ca7c92019-11-12 17:51:18 -0500109
110 for cmd in cmds:
111 r = self.vapi.cli_return_response(cmd)
112 if r.retval != 0:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200113 if hasattr(r, "reply"):
Dave Barachd9ca7c92019-11-12 17:51:18 -0500114 self.logger.info(cmd + " FAIL reply " + r.reply)
115 else:
116 self.logger.info(cmd + " FAIL retval " + str(r.retval))
117
Dave Barachc17fc442019-11-18 17:16:49 -0500118 def test_vlib_buffer_c_unittest(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200119 """Vlib buffer.c Code Coverage Test"""
Dave Barachc17fc442019-11-18 17:16:49 -0500120
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200121 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 Barachc17fc442019-11-18 17:16:49 -0500165
166 for cmd in cmds:
167 r = self.vapi.cli_return_response(cmd)
168 if r.retval != 0:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200169 if hasattr(r, "reply"):
Dave Barachc17fc442019-11-18 17:16:49 -0500170 self.logger.info(cmd + " FAIL reply " + r.reply)
171 else:
172 self.logger.info(cmd + " FAIL retval " + str(r.retval))
173
Dave Barache51a9bb2019-11-19 10:36:41 -0500174 def test_vlib_format_unittest(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200175 """Vlib format.c Code Coverage Test"""
Dave Barache51a9bb2019-11-19 10:36:41 -0500176
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200177 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 Barache51a9bb2019-11-19 10:36:41 -0500183
184 for cmd in cmds:
185 r = self.vapi.cli_return_response(cmd)
186 if r.retval != 0:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200187 if hasattr(r, "reply"):
Dave Barache51a9bb2019-11-19 10:36:41 -0500188 self.logger.info(cmd + " FAIL reply " + r.reply)
189 else:
190 self.logger.info(cmd + " FAIL retval " + str(r.retval))
191
Dave Barach3a491302020-06-15 17:38:12 -0400192 def test_vlib_main_unittest(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200193 """Private Binary API Segment Test (takes 70 seconds)"""
Dave Barach3a491302020-06-15 17:38:12 -0400194
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200195 vat_path = config.vpp + "_api_test"
196 vat = pexpect.spawn(vat_path, ["socket-name", self.get_api_sock_path()])
Dave Barach3a491302020-06-15 17:38:12 -0400197 vat.expect("vat# ", timeout=10)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200198 vat.sendline("sock_init_shm")
Dave Barach3a491302020-06-15 17:38:12 -0400199 vat.expect("vat# ", timeout=10)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200200 vat.sendline("sh api cli")
Dave Barach3a491302020-06-15 17:38:12 -0400201 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 Barach4de5f9b2021-06-02 18:18:18 -0400207 def test_pool(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200208 """Fixed-size Pool Test"""
Dave Barach4de5f9b2021-06-02 18:18:18 -0400209
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200210 cmds = [
211 "test pool",
212 ]
Dave Barach4de5f9b2021-06-02 18:18:18 -0400213
214 for cmd in cmds:
215 r = self.vapi.cli_return_response(cmd)
216 if r.retval != 0:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200217 if hasattr(r, "reply"):
Dave Barach4de5f9b2021-06-02 18:18:18 -0400218 self.logger.info(cmd + " FAIL reply " + r.reply)
219 else:
220 self.logger.info(cmd + " FAIL retval " + str(r.retval))
Klement Sekerae2636852021-03-16 12:52:12 +0100221
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200222
223if __name__ == "__main__":
Dave Barachd9ca7c92019-11-12 17:51:18 -0500224 unittest.main(testRunner=VppTestRunner)