Dave Barach | d9ca7c9 | 2019-11-12 17:51:18 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | import unittest |
| 4 | |
| 5 | from framework import VppTestCase, VppTestRunner, running_extended_tests |
| 6 | from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath |
| 7 | |
| 8 | |
| 9 | class TestVlib(VppTestCase): |
| 10 | """ Vlib Unit Test Cases """ |
| 11 | worker_config = "workers 1" |
| 12 | |
| 13 | @classmethod |
| 14 | def setUpClass(cls): |
| 15 | super(TestVlib, cls).setUpClass() |
| 16 | |
| 17 | @classmethod |
| 18 | def tearDownClass(cls): |
| 19 | super(TestVlib, cls).tearDownClass() |
| 20 | |
| 21 | def setUp(self): |
| 22 | super(TestVlib, self).setUp() |
| 23 | |
| 24 | def tearDown(self): |
| 25 | super(TestVlib, self).tearDown() |
| 26 | |
| 27 | # @unittest.skipUnless(running_extended_tests, "part of extended tests") |
| 28 | |
| 29 | 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" |
| 43 | " }\n", |
| 44 | "}\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 | |
| 70 | def test_vlib_node_cli_unittest(self): |
| 71 | """ Vlib node_cli.c Code Coverage Test """ |
| 72 | |
| 73 | cmds = ["loopback create", |
| 74 | "packet-generator new {\n" |
| 75 | " name vlib\n" |
| 76 | " limit 15\n" |
| 77 | " size 128-128\n" |
| 78 | " interface loop0\n" |
| 79 | " node ethernet-input\n" |
| 80 | " data {\n" |
| 81 | " IP6: 00:d0:2d:5e:86:85 -> 00:0d:ea:d0:00:00\n" |
| 82 | " ICMP: db00::1 -> db00::2\n" |
| 83 | " incrementing 30\n" |
| 84 | " }\n", |
| 85 | "}\n", |
| 86 | "show vlib graph", |
| 87 | "show vlib graph ethernet-input", |
| 88 | "show vlib graphviz", |
| 89 | "show vlib graphviz graphviz.dot", |
| 90 | "pa en", |
| 91 | "show runtime ethernet-input", |
| 92 | "show runtime brief verbose max summary", |
| 93 | "clear runtime", |
| 94 | "show node index 1", |
| 95 | "show node ethernet-input", |
| 96 | "show node pg-input", |
| 97 | "set node function", |
| 98 | "set node function no-such-node", |
| 99 | "set node function cdp-input default", |
| 100 | "set node function ethernet-input default", |
| 101 | "set node function ethernet-input bozo", |
| 102 | "set node function ethernet-input", |
| 103 | ] |
| 104 | |
| 105 | for cmd in cmds: |
| 106 | r = self.vapi.cli_return_response(cmd) |
| 107 | if r.retval != 0: |
| 108 | if hasattr(r, 'reply'): |
| 109 | self.logger.info(cmd + " FAIL reply " + r.reply) |
| 110 | else: |
| 111 | self.logger.info(cmd + " FAIL retval " + str(r.retval)) |
| 112 | |
| 113 | if __name__ == '__main__': |
| 114 | unittest.main(testRunner=VppTestRunner) |