blob: 1d5a3eb2594b94286bf4264c40c338d1052f2a17 [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):
14 """ Vlib Unit Test Cases """
Klement Sekera8d815022021-03-15 16:58:10 +010015 vpp_worker_count = 1
Dave Barachd9ca7c92019-11-12 17:51:18 -050016
17 @classmethod
18 def setUpClass(cls):
19 super(TestVlib, cls).setUpClass()
20
21 @classmethod
22 def tearDownClass(cls):
23 super(TestVlib, cls).tearDownClass()
24
25 def setUp(self):
26 super(TestVlib, self).setUp()
27
28 def tearDown(self):
29 super(TestVlib, self).tearDown()
30
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
71 def test_vlib_node_cli_unittest(self):
72 """ Vlib node_cli.c Code Coverage Test """
73
74 cmds = ["loopback create",
75 "packet-generator new {\n"
76 " name vlib\n"
77 " limit 15\n"
78 " size 128-128\n"
79 " interface loop0\n"
80 " node ethernet-input\n"
81 " data {\n"
82 " IP6: 00:d0:2d:5e:86:85 -> 00:0d:ea:d0:00:00\n"
83 " ICMP: db00::1 -> db00::2\n"
84 " incrementing 30\n"
Paul Vinciguerra41a817a2019-11-22 22:12:31 -050085 " }\n"
Dave Barachd9ca7c92019-11-12 17:51:18 -050086 "}\n",
87 "show vlib graph",
88 "show vlib graph ethernet-input",
89 "show vlib graphviz",
90 "show vlib graphviz graphviz.dot",
91 "pa en",
92 "show runtime ethernet-input",
93 "show runtime brief verbose max summary",
94 "clear runtime",
95 "show node index 1",
96 "show node ethernet-input",
97 "show node pg-input",
98 "set node function",
99 "set node function no-such-node",
100 "set node function cdp-input default",
101 "set node function ethernet-input default",
102 "set node function ethernet-input bozo",
103 "set node function ethernet-input",
Dave Barach6b3f25c2019-12-09 10:45:47 -0500104 "show \t",
Dave Barachd9ca7c92019-11-12 17:51:18 -0500105 ]
106
107 for cmd in cmds:
108 r = self.vapi.cli_return_response(cmd)
109 if r.retval != 0:
110 if hasattr(r, 'reply'):
111 self.logger.info(cmd + " FAIL reply " + r.reply)
112 else:
113 self.logger.info(cmd + " FAIL retval " + str(r.retval))
114
Dave Barachc17fc442019-11-18 17:16:49 -0500115 def test_vlib_buffer_c_unittest(self):
116 """ Vlib buffer.c Code Coverage Test """
117
118 cmds = ["loopback create",
119 "packet-generator new {\n"
120 " name vlib\n"
121 " limit 15\n"
122 " size 128-128\n"
123 " interface loop0\n"
124 " node ethernet-input\n"
125 " data {\n"
126 " IP6: 00:d0:2d:5e:86:85 -> 00:0d:ea:d0:00:00\n"
127 " ICMP: db00::1 -> db00::2\n"
128 " incrementing 30\n"
Paul Vinciguerra41a817a2019-11-22 22:12:31 -0500129 " }\n"
Dave Barachc17fc442019-11-18 17:16:49 -0500130 "}\n",
Dave Barachaa676742020-11-25 07:23:42 -0500131 "event-logger trace",
132 "event-logger trace enable",
133 "event-logger trace api cli barrier",
Dave Barachc17fc442019-11-18 17:16:49 -0500134 "pa en",
Dave Barach6b3f25c2019-12-09 10:45:47 -0500135 "show interface bogus",
Dave Barachaa676742020-11-25 07:23:42 -0500136 "event-logger trace disable api cli barrier",
137 "event-logger trace circuit-node ethernet-input",
138 "event-logger trace circuit-node ethernet-input disable",
Dave Barache51a9bb2019-11-19 10:36:41 -0500139 "clear interfaces",
Dave Barachc17fc442019-11-18 17:16:49 -0500140 "test vlib",
Dave Barach6b3f25c2019-12-09 10:45:47 -0500141 "test vlib2",
142 "show memory api-segment stats-segment main-heap verbose",
143 "leak-check { show memory }",
144 "show cpu",
145 "memory-trace main-heap",
146 "memory-trace main-heap api-segment stats-segment",
147 "leak-check { show version }",
148 "show version ?",
149 "comment { show version }",
150 "uncomment { show version }",
151 "show memory main-heap",
152 "show memory bogus",
153 "choices",
154 "test heap-validate",
155 "memory-trace main-heap disable",
Dave Barachc17fc442019-11-18 17:16:49 -0500156 "show buffers",
Dave Barach6b3f25c2019-12-09 10:45:47 -0500157 "show eve",
158 "show help",
159 "show ip ",
Dave Barachc17fc442019-11-18 17:16:49 -0500160 ]
161
162 for cmd in cmds:
163 r = self.vapi.cli_return_response(cmd)
164 if r.retval != 0:
165 if hasattr(r, 'reply'):
166 self.logger.info(cmd + " FAIL reply " + r.reply)
167 else:
168 self.logger.info(cmd + " FAIL retval " + str(r.retval))
169
Dave Barache51a9bb2019-11-19 10:36:41 -0500170 def test_vlib_format_unittest(self):
171 """ Vlib format.c Code Coverage Test """
172
173 cmds = ["loopback create",
Dave Barach29c61322019-12-24 16:59:38 -0500174 "classify filter pcap mask l2 proto match l2 proto 0x86dd",
175 "classify filter pcap del",
Dave Barache51a9bb2019-11-19 10:36:41 -0500176 "test format-vlib",
177 ]
178
179 for cmd in cmds:
180 r = self.vapi.cli_return_response(cmd)
181 if r.retval != 0:
182 if hasattr(r, 'reply'):
183 self.logger.info(cmd + " FAIL reply " + r.reply)
184 else:
185 self.logger.info(cmd + " FAIL retval " + str(r.retval))
186
Dave Barach3a491302020-06-15 17:38:12 -0400187 def test_vlib_main_unittest(self):
188 """ Private Binary API Segment Test (takes 70 seconds) """
189
190 vat_path = self.vpp_bin + '_api_test'
Klement Sekerae2636852021-03-16 12:52:12 +0100191 vat = pexpect.spawn(vat_path, ['socket-name',
192 self.get_api_sock_path()])
Dave Barach3a491302020-06-15 17:38:12 -0400193 vat.expect("vat# ", timeout=10)
194 vat.sendline('sock_init_shm')
195 vat.expect("vat# ", timeout=10)
196 vat.sendline('sh api cli')
197 vat.kill(signal.SIGKILL)
198 vat.wait()
199 self.logger.info("vat terminated, 70 second wait for the Reaper")
200 time.sleep(70)
201 self.logger.info("Reaper should be complete...")
202
Dave Barach4de5f9b2021-06-02 18:18:18 -0400203 def test_pool(self):
204 """ Fixed-size Pool Test """
205
206 cmds = ["test pool",
207 ]
208
209 for cmd in cmds:
210 r = self.vapi.cli_return_response(cmd)
211 if r.retval != 0:
212 if hasattr(r, 'reply'):
213 self.logger.info(cmd + " FAIL reply " + r.reply)
214 else:
215 self.logger.info(cmd + " FAIL retval " + str(r.retval))
Klement Sekerae2636852021-03-16 12:52:12 +0100216
Dave Barachd9ca7c92019-11-12 17:51:18 -0500217if __name__ == '__main__':
218 unittest.main(testRunner=VppTestRunner)