blob: 8a02639e76b7cddafc8d2a33bcda6e1953da8e4b [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 """
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 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",
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 Barachd498c9e2020-03-10 16:59:39 -040072 @unittest.skipUnless(running_gcov_tests, "part of code coverage tests")
Dave Barachd9ca7c92019-11-12 17:51:18 -050073 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 Vinciguerra41a817a2019-11-22 22:12:31 -050087 " }\n"
Dave Barachd9ca7c92019-11-12 17:51:18 -050088 "}\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 Barach6b3f25c2019-12-09 10:45:47 -0500106 "show \t",
Dave Barachd9ca7c92019-11-12 17:51:18 -0500107 ]
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 Barachd498c9e2020-03-10 16:59:39 -0400117 @unittest.skipUnless(running_gcov_tests, "part of code coverage tests")
Dave Barachc17fc442019-11-18 17:16:49 -0500118 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 Vinciguerra41a817a2019-11-22 22:12:31 -0500132 " }\n"
Dave Barachc17fc442019-11-18 17:16:49 -0500133 "}\n",
Dave Barachaa676742020-11-25 07:23:42 -0500134 "event-logger trace",
135 "event-logger trace enable",
136 "event-logger trace api cli barrier",
Dave Barachc17fc442019-11-18 17:16:49 -0500137 "pa en",
Dave Barach6b3f25c2019-12-09 10:45:47 -0500138 "show interface bogus",
Dave Barachaa676742020-11-25 07:23:42 -0500139 "event-logger trace disable api cli barrier",
140 "event-logger trace circuit-node ethernet-input",
141 "event-logger trace circuit-node ethernet-input disable",
Dave Barache51a9bb2019-11-19 10:36:41 -0500142 "clear interfaces",
Dave Barachc17fc442019-11-18 17:16:49 -0500143 "test vlib",
Dave Barach6b3f25c2019-12-09 10:45:47 -0500144 "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 Barachc17fc442019-11-18 17:16:49 -0500159 "show buffers",
Dave Barach6b3f25c2019-12-09 10:45:47 -0500160 "show eve",
161 "show help",
162 "show ip ",
Dave Barachc17fc442019-11-18 17:16:49 -0500163 ]
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 Barachd498c9e2020-03-10 16:59:39 -0400173 @unittest.skipUnless(running_gcov_tests, "part of code coverage tests")
Dave Barache51a9bb2019-11-19 10:36:41 -0500174 def test_vlib_format_unittest(self):
175 """ Vlib format.c Code Coverage Test """
176
177 cmds = ["loopback create",
Dave Barach29c61322019-12-24 16:59:38 -0500178 "classify filter pcap mask l2 proto match l2 proto 0x86dd",
179 "classify filter pcap del",
Dave Barache51a9bb2019-11-19 10:36:41 -0500180 "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 Barach3a491302020-06-15 17:38:12 -0400191 @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 Barachd9ca7c92019-11-12 17:51:18 -0500207if __name__ == '__main__':
208 unittest.main(testRunner=VppTestRunner)