blob: 3c6288c8eb162ed1f627c7f93050cdc637b01d6c [file] [log] [blame]
Dave Barachd9ca7c92019-11-12 17:51:18 -05001#!/usr/bin/env python3
2
3import unittest
4
5from framework import VppTestCase, VppTestRunner, running_extended_tests
Dave Barachd498c9e2020-03-10 16:59:39 -04006from framework import running_gcov_tests
Dave Barachd9ca7c92019-11-12 17:51:18 -05007from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
8
9
10class TestVlib(VppTestCase):
11 """ Vlib Unit Test Cases """
12 worker_config = "workers 1"
13
14 @classmethod
15 def setUpClass(cls):
16 super(TestVlib, cls).setUpClass()
17
18 @classmethod
19 def tearDownClass(cls):
20 super(TestVlib, cls).tearDownClass()
21
22 def setUp(self):
23 super(TestVlib, self).setUp()
24
25 def tearDown(self):
26 super(TestVlib, self).tearDown()
27
Dave Barachd498c9e2020-03-10 16:59:39 -040028 @unittest.skipUnless(running_gcov_tests, "part of code coverage tests")
Dave Barachd9ca7c92019-11-12 17:51:18 -050029 def test_vlib_main_unittest(self):
30 """ Vlib main.c Code Coverage Test """
31
32 cmds = ["loopback create",
33 "packet-generator new {\n"
34 " name vlib\n"
35 " limit 15\n"
36 " size 128-128\n"
37 " interface loop0\n"
38 " node ethernet-input\n"
39 " data {\n"
40 " IP6: 00:d0:2d:5e:86:85 -> 00:0d:ea:d0:00:00\n"
41 " ICMP: db00::1 -> db00::2\n"
42 " incrementing 30\n"
Paul Vinciguerra41a817a2019-11-22 22:12:31 -050043 " }\n"
Dave Barachd9ca7c92019-11-12 17:51:18 -050044 "}\n",
45 "elog trace dispatch",
46 "event-logger stop",
47 "event-logger clear",
48 "event-logger resize 102400",
49 "event-logger restart",
50 "pcap dispatch trace on max 100 buffer-trace pg-input 15",
51 "set pmc instructions-per-clock",
52 "pa en",
53 "show event-log 100 all",
54 "event-log save",
55 "event-log save foo",
56 "pcap dispatch trace",
57 "pcap dispatch trace status",
58 "pcap dispatch trace off",
59 "show vlib frame-allocation",
60 ]
61
62 for cmd in cmds:
63 r = self.vapi.cli_return_response(cmd)
64 if r.retval != 0:
65 if hasattr(r, 'reply'):
66 self.logger.info(cmd + " FAIL reply " + r.reply)
67 else:
68 self.logger.info(cmd + " FAIL retval " + str(r.retval))
69
Dave Barachd498c9e2020-03-10 16:59:39 -040070 @unittest.skipUnless(running_gcov_tests, "part of code coverage tests")
Dave Barachd9ca7c92019-11-12 17:51:18 -050071 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 Barachd498c9e2020-03-10 16:59:39 -0400115 @unittest.skipUnless(running_gcov_tests, "part of code coverage tests")
Dave Barachc17fc442019-11-18 17:16:49 -0500116 def test_vlib_buffer_c_unittest(self):
117 """ Vlib buffer.c Code Coverage Test """
118
119 cmds = ["loopback create",
120 "packet-generator new {\n"
121 " name vlib\n"
122 " limit 15\n"
123 " size 128-128\n"
124 " interface loop0\n"
125 " node ethernet-input\n"
126 " data {\n"
127 " IP6: 00:d0:2d:5e:86:85 -> 00:0d:ea:d0:00:00\n"
128 " ICMP: db00::1 -> db00::2\n"
129 " incrementing 30\n"
Paul Vinciguerra41a817a2019-11-22 22:12:31 -0500130 " }\n"
Dave Barachc17fc442019-11-18 17:16:49 -0500131 "}\n",
Dave Barach6b3f25c2019-12-09 10:45:47 -0500132 "elog trace",
133 "elog trace enable",
134 "elog trace api cli barrier",
Dave Barachc17fc442019-11-18 17:16:49 -0500135 "pa en",
Dave Barach6b3f25c2019-12-09 10:45:47 -0500136 "show interface bogus",
137 "elog trace disable api cli barrier",
138 "elog trace circuit-node ethernet-input",
139 "elog trace circuit-node ethernet-input disable",
Dave Barache51a9bb2019-11-19 10:36:41 -0500140 "clear interfaces",
Dave Barachc17fc442019-11-18 17:16:49 -0500141 "test vlib",
Dave Barach6b3f25c2019-12-09 10:45:47 -0500142 "test vlib2",
143 "show memory api-segment stats-segment main-heap verbose",
144 "leak-check { show memory }",
145 "show cpu",
146 "memory-trace main-heap",
147 "memory-trace main-heap api-segment stats-segment",
148 "leak-check { show version }",
149 "show version ?",
150 "comment { show version }",
151 "uncomment { show version }",
152 "show memory main-heap",
153 "show memory bogus",
154 "choices",
155 "test heap-validate",
156 "memory-trace main-heap disable",
Dave Barachc17fc442019-11-18 17:16:49 -0500157 "show buffers",
Dave Barach6b3f25c2019-12-09 10:45:47 -0500158 "show eve",
159 "show help",
160 "show ip ",
Dave Barachc17fc442019-11-18 17:16:49 -0500161 ]
162
163 for cmd in cmds:
164 r = self.vapi.cli_return_response(cmd)
165 if r.retval != 0:
166 if hasattr(r, 'reply'):
167 self.logger.info(cmd + " FAIL reply " + r.reply)
168 else:
169 self.logger.info(cmd + " FAIL retval " + str(r.retval))
170
Dave Barachd498c9e2020-03-10 16:59:39 -0400171 @unittest.skipUnless(running_gcov_tests, "part of code coverage tests")
Dave Barache51a9bb2019-11-19 10:36:41 -0500172 def test_vlib_format_unittest(self):
173 """ Vlib format.c Code Coverage Test """
174
175 cmds = ["loopback create",
Dave Barach29c61322019-12-24 16:59:38 -0500176 "classify filter pcap mask l2 proto match l2 proto 0x86dd",
177 "classify filter pcap del",
Dave Barache51a9bb2019-11-19 10:36:41 -0500178 "test format-vlib",
179 ]
180
181 for cmd in cmds:
182 r = self.vapi.cli_return_response(cmd)
183 if r.retval != 0:
184 if hasattr(r, 'reply'):
185 self.logger.info(cmd + " FAIL reply " + r.reply)
186 else:
187 self.logger.info(cmd + " FAIL retval " + str(r.retval))
188
Dave Barachd9ca7c92019-11-12 17:51:18 -0500189if __name__ == '__main__':
190 unittest.main(testRunner=VppTestRunner)