Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Ole Troan | 72d8758 | 2019-05-10 12:01:10 +0200 | [diff] [blame] | 2 | """CLI functional tests""" |
| 3 | |
Paul Vinciguerra | bfd7d29 | 2019-10-26 22:25:49 -0400 | [diff] [blame^] | 4 | import datetime |
| 5 | import time |
Ole Troan | 72d8758 | 2019-05-10 12:01:10 +0200 | [diff] [blame] | 6 | import unittest |
Paul Vinciguerra | bfd7d29 | 2019-10-26 22:25:49 -0400 | [diff] [blame^] | 7 | |
| 8 | from vpp_papi import vpp_transport_shmem |
| 9 | |
Ole Troan | 72d8758 | 2019-05-10 12:01:10 +0200 | [diff] [blame] | 10 | from framework import VppTestCase, VppTestRunner |
| 11 | |
| 12 | |
| 13 | class TestCLI(VppTestCase): |
| 14 | """ CLI Test Case """ |
| 15 | maxDiff = None |
| 16 | |
| 17 | @classmethod |
| 18 | def setUpClass(cls): |
Paul Vinciguerra | bfd7d29 | 2019-10-26 22:25:49 -0400 | [diff] [blame^] | 19 | # using the framework default |
| 20 | # cls.vapi_response_timeout = 5 |
Ole Troan | 72d8758 | 2019-05-10 12:01:10 +0200 | [diff] [blame] | 21 | super(TestCLI, cls).setUpClass() |
| 22 | |
| 23 | @classmethod |
| 24 | def tearDownClass(cls): |
| 25 | super(TestCLI, cls).tearDownClass() |
| 26 | |
| 27 | def setUp(self): |
| 28 | super(TestCLI, self).setUp() |
| 29 | |
| 30 | def tearDown(self): |
| 31 | super(TestCLI, self).tearDown() |
| 32 | |
| 33 | def test_cli_retval(self): |
| 34 | """ CLI inband retval """ |
| 35 | rv = self.vapi.papi.cli_inband(cmd='this command does not exist') |
| 36 | self.assertNotEqual(rv.retval, 0) |
| 37 | |
| 38 | rv = self.vapi.papi.cli_inband(cmd='show version') |
| 39 | self.assertEqual(rv.retval, 0) |
| 40 | |
Paul Vinciguerra | bfd7d29 | 2019-10-26 22:25:49 -0400 | [diff] [blame^] | 41 | def test_long_cli_delay(self): |
| 42 | """ Test that VppApiClient raises VppTransportShmemIOError if timeout.""" # noqa |
| 43 | with self.assertRaises( |
| 44 | vpp_transport_shmem.VppTransportShmemIOError) as ctx: |
| 45 | rv = self.vapi.papi.cli_inband(cmd='wait 10') |
| 46 | |
| 47 | |
| 48 | class TestCLIExtendedVapiTimeout(VppTestCase): |
| 49 | maxDiff = None |
| 50 | |
| 51 | @classmethod |
| 52 | def setUpClass(cls): |
| 53 | cls.vapi_response_timeout = 15 |
| 54 | cls.__doc__ = " CLI Test Case w/ Extended (%ssec) Vapi Timeout " \ |
| 55 | % cls.vapi_response_timeout |
| 56 | super(TestCLIExtendedVapiTimeout, cls).setUpClass() |
| 57 | |
| 58 | @classmethod |
| 59 | def tearDownClass(cls): |
| 60 | super(TestCLIExtendedVapiTimeout, cls).tearDownClass() |
| 61 | |
| 62 | def setUp(self): |
| 63 | super(TestCLIExtendedVapiTimeout, self).setUp() |
| 64 | |
| 65 | def tearDown(self): |
| 66 | super(TestCLIExtendedVapiTimeout, self).tearDown() |
| 67 | |
| 68 | def test_long_cli_delay(self): |
| 69 | """ Test that delayed result returns with extended timeout.""" |
| 70 | wait_secs = self.vapi_response_timeout - 1 |
| 71 | |
| 72 | # get vpp time as float |
| 73 | start = self.vapi.papi.show_vpe_system_time( |
| 74 | _no_type_conversion=True).vpe_system_time |
| 75 | rv = self.vapi.papi.cli_inband(cmd='wait %s' % wait_secs) |
| 76 | now = self.vapi.papi.show_vpe_system_time( |
| 77 | _no_type_conversion=True).vpe_system_time |
| 78 | |
| 79 | # assume that the overhead of the measurement is not more that .5 sec. |
| 80 | self.assertEqual(round(now - start), wait_secs) |
| 81 | |
Ole Troan | 72d8758 | 2019-05-10 12:01:10 +0200 | [diff] [blame] | 82 | |
| 83 | if __name__ == '__main__': |
| 84 | unittest.main(testRunner=VppTestRunner) |