Paul Vinciguerra | 03f1af2 | 2019-06-25 22:30:19 -0400 | [diff] [blame] | 1 | # Copyright (c) 2019. Vinci Consulting Corp. All Rights Reserved. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
Paul Vinciguerra | a47a5f2 | 2019-07-23 09:53:06 -0400 | [diff] [blame] | 14 | import datetime |
Paul Vinciguerra | 03f1af2 | 2019-06-25 22:30:19 -0400 | [diff] [blame] | 15 | import time |
| 16 | import unittest |
| 17 | from framework import VppTestCase |
| 18 | |
Paul Vinciguerra | a47a5f2 | 2019-07-23 09:53:06 -0400 | [diff] [blame] | 19 | enable_print = False |
| 20 | |
Paul Vinciguerra | 03f1af2 | 2019-06-25 22:30:19 -0400 | [diff] [blame] | 21 | |
| 22 | class TestVpeApi(VppTestCase): |
| 23 | """TestVpeApi""" |
| 24 | |
| 25 | def test_log_dump_default(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 26 | rv = self.vapi.cli("test log notice fib entry this is a test") |
Paul Vinciguerra | 03f1af2 | 2019-06-25 22:30:19 -0400 | [diff] [blame] | 27 | rv = self.vapi.log_dump() |
Paul Vinciguerra | a47a5f2 | 2019-07-23 09:53:06 -0400 | [diff] [blame] | 28 | if enable_print: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 29 | print("\n".join([str(v) for v in rv])) |
Paul Vinciguerra | 03f1af2 | 2019-06-25 22:30:19 -0400 | [diff] [blame] | 30 | self.assertTrue(rv) |
| 31 | |
| 32 | def test_log_dump_timestamp_0(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 33 | rv = self.vapi.cli("test log notice fib entry this is a test") |
Paul Vinciguerra | 03f1af2 | 2019-06-25 22:30:19 -0400 | [diff] [blame] | 34 | rv = self.vapi.log_dump(start_timestamp=0.0) |
Paul Vinciguerra | a47a5f2 | 2019-07-23 09:53:06 -0400 | [diff] [blame] | 35 | if enable_print: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 36 | print("\n".join([str(v) for v in rv])) |
Paul Vinciguerra | 03f1af2 | 2019-06-25 22:30:19 -0400 | [diff] [blame] | 37 | self.assertTrue(rv) |
| 38 | |
Paul Vinciguerra | 03f1af2 | 2019-06-25 22:30:19 -0400 | [diff] [blame] | 39 | def test_log_dump_timestamp_future(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 40 | rv = self.vapi.cli("test log debug fib entry test") |
Paul Vinciguerra | 03f1af2 | 2019-06-25 22:30:19 -0400 | [diff] [blame] | 41 | rv = self.vapi.log_dump(start_timestamp=time.time() + 60.0) |
Paul Vinciguerra | a47a5f2 | 2019-07-23 09:53:06 -0400 | [diff] [blame] | 42 | if enable_print: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 43 | print("\n".join([str(v) for v in rv])) |
Paul Vinciguerra | 03f1af2 | 2019-06-25 22:30:19 -0400 | [diff] [blame] | 44 | self.assertFalse(rv) |
| 45 | |
Paul Vinciguerra | a47a5f2 | 2019-07-23 09:53:06 -0400 | [diff] [blame] | 46 | def test_show_vpe_system_time(self): |
| 47 | local_start_time = datetime.datetime.now() |
| 48 | rv = self.vapi.show_vpe_system_time() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 49 | self.assertTrue( |
| 50 | rv.vpe_system_time > local_start_time - datetime.timedelta(hours=1.0), |
| 51 | "system times differ by more than an hour.", |
| 52 | ) |
Paul Vinciguerra | a47a5f2 | 2019-07-23 09:53:06 -0400 | [diff] [blame] | 53 | if enable_print: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 54 | print("\n".join([str(v) for v in rv])) |
| 55 | print("%r %s" % (rv.vpe_system_time, rv.vpe_system_time)) |