blob: a9a5f6aeb891500b5152aea6afc6e1d3ed754736 [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
Dave Barachd9ca7c92019-11-12 17:51:18 -05007from framework import VppTestCase, VppTestRunner, running_extended_tests
Dave Barachd498c9e2020-03-10 16:59:39 -04008from framework import running_gcov_tests
Dave Barachd9ca7c92019-11-12 17:51:18 -05009from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
10
11
12class TestVlib(VppTestCase):
13 """ Vlib Unit Test Cases """
Klement Sekera8d815022021-03-15 16:58:10 +010014 vpp_worker_count = 1
Dave Barachd9ca7c92019-11-12 17:51:18 -050015
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 Barachd498c9e2020-03-10 16:59:39 -040030 @unittest.skipUnless(running_gcov_tests, "part of code coverage tests")
Dave Barachd9ca7c92019-11-12 17:51:18 -050031 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 Vinciguerra41a817a2019-11-22 22:12:31 -050045 " }\n"
Dave Barachd9ca7c92019-11-12 17:51:18 -050046 "}\n",
Dave Barachaa676742020-11-25 07:23:42 -050047 "event-logger trace dispatch",
Dave Barachd9ca7c92019-11-12 17:51:18 -050048 "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 Barachd9ca7c92019-11-12 17:51:18 -050053 "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 Barachd498c9e2020-03-10 16:59:39 -040071 @unittest.skipUnless(running_gcov_tests, "part of code coverage tests")
Dave Barachd9ca7c92019-11-12 17:51:18 -050072 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 Vinciguerra41a817a2019-11-22 22:12:31 -050086 " }\n"
Dave Barachd9ca7c92019-11-12 17:51:18 -050087 "}\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 Barach6b3f25c2019-12-09 10:45:47 -0500105 "show \t",
Dave Barachd9ca7c92019-11-12 17:51:18 -0500106 ]
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 Barachd498c9e2020-03-10 16:59:39 -0400116 @unittest.skipUnless(running_gcov_tests, "part of code coverage tests")
Dave Barachc17fc442019-11-18 17:16:49 -0500117 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 Vinciguerra41a817a2019-11-22 22:12:31 -0500131 " }\n"
Dave Barachc17fc442019-11-18 17:16:49 -0500132 "}\n",
Dave Barachaa676742020-11-25 07:23:42 -0500133 "event-logger trace",
134 "event-logger trace enable",
135 "event-logger trace api cli barrier",
Dave Barachc17fc442019-11-18 17:16:49 -0500136 "pa en",
Dave Barach6b3f25c2019-12-09 10:45:47 -0500137 "show interface bogus",
Dave Barachaa676742020-11-25 07:23:42 -0500138 "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 Barache51a9bb2019-11-19 10:36:41 -0500141 "clear interfaces",
Dave Barachc17fc442019-11-18 17:16:49 -0500142 "test vlib",
Dave Barach6b3f25c2019-12-09 10:45:47 -0500143 "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 Barachc17fc442019-11-18 17:16:49 -0500158 "show buffers",
Dave Barach6b3f25c2019-12-09 10:45:47 -0500159 "show eve",
160 "show help",
161 "show ip ",
Dave Barachc17fc442019-11-18 17:16:49 -0500162 ]
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 Barachd498c9e2020-03-10 16:59:39 -0400172 @unittest.skipUnless(running_gcov_tests, "part of code coverage tests")
Dave Barache51a9bb2019-11-19 10:36:41 -0500173 def test_vlib_format_unittest(self):
174 """ Vlib format.c Code Coverage Test """
175
176 cmds = ["loopback create",
Dave Barach29c61322019-12-24 16:59:38 -0500177 "classify filter pcap mask l2 proto match l2 proto 0x86dd",
178 "classify filter pcap del",
Dave Barache51a9bb2019-11-19 10:36:41 -0500179 "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 Barach3a491302020-06-15 17:38:12 -0400190 @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 Sekerae2636852021-03-16 12:52:12 +0100195 vat = pexpect.spawn(vat_path, ['socket-name',
196 self.get_api_sock_path()])
Dave Barach3a491302020-06-15 17:38:12 -0400197 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 Sekerae2636852021-03-16 12:52:12 +0100207
Dave Barachd9ca7c92019-11-12 17:51:18 -0500208if __name__ == '__main__':
209 unittest.main(testRunner=VppTestRunner)