blob: 4d866ec906a994df16355214c9eb13a541e703bb [file] [log] [blame]
Paul Vinciguerra03f1af22019-06-25 22:30:19 -04001# 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 Vinciguerraa47a5f22019-07-23 09:53:06 -040014import datetime
Paul Vinciguerra03f1af22019-06-25 22:30:19 -040015import time
Dave Wallace8800f732023-08-31 00:47:44 -040016from asfframework import VppAsfTestCase
Paul Vinciguerra03f1af22019-06-25 22:30:19 -040017
Paul Vinciguerraa47a5f22019-07-23 09:53:06 -040018enable_print = False
19
Paul Vinciguerra03f1af22019-06-25 22:30:19 -040020
Dave Wallace8800f732023-08-31 00:47:44 -040021class TestVpeApi(VppAsfTestCase):
Paul Vinciguerra03f1af22019-06-25 22:30:19 -040022 """TestVpeApi"""
23
24 def test_log_dump_default(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020025 rv = self.vapi.cli("test log notice fib entry this is a test")
Paul Vinciguerra03f1af22019-06-25 22:30:19 -040026 rv = self.vapi.log_dump()
Paul Vinciguerraa47a5f22019-07-23 09:53:06 -040027 if enable_print:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020028 print("\n".join([str(v) for v in rv]))
Paul Vinciguerra03f1af22019-06-25 22:30:19 -040029 self.assertTrue(rv)
30
31 def test_log_dump_timestamp_0(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020032 rv = self.vapi.cli("test log notice fib entry this is a test")
Paul Vinciguerra03f1af22019-06-25 22:30:19 -040033 rv = self.vapi.log_dump(start_timestamp=0.0)
Paul Vinciguerraa47a5f22019-07-23 09:53:06 -040034 if enable_print:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020035 print("\n".join([str(v) for v in rv]))
Paul Vinciguerra03f1af22019-06-25 22:30:19 -040036 self.assertTrue(rv)
37
Paul Vinciguerra03f1af22019-06-25 22:30:19 -040038 def test_log_dump_timestamp_future(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020039 rv = self.vapi.cli("test log debug fib entry test")
Paul Vinciguerra03f1af22019-06-25 22:30:19 -040040 rv = self.vapi.log_dump(start_timestamp=time.time() + 60.0)
Paul Vinciguerraa47a5f22019-07-23 09:53:06 -040041 if enable_print:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020042 print("\n".join([str(v) for v in rv]))
Paul Vinciguerra03f1af22019-06-25 22:30:19 -040043 self.assertFalse(rv)
44
Paul Vinciguerraa47a5f22019-07-23 09:53:06 -040045 def test_show_vpe_system_time(self):
46 local_start_time = datetime.datetime.now()
47 rv = self.vapi.show_vpe_system_time()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020048 self.assertTrue(
49 rv.vpe_system_time > local_start_time - datetime.timedelta(hours=1.0),
50 "system times differ by more than an hour.",
51 )
Paul Vinciguerraa47a5f22019-07-23 09:53:06 -040052 if enable_print:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020053 print("\n".join([str(v) for v in rv]))
54 print("%r %s" % (rv.vpe_system_time, rv.vpe_system_time))