tests: refactor asf framework code
[vpp.git] / test / asf / test_vpe_api.py
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.
14 import datetime
15 import time
16 from asfframework import VppAsfTestCase
17
18 enable_print = False
19
20
21 class TestVpeApi(VppAsfTestCase):
22     """TestVpeApi"""
23
24     def test_log_dump_default(self):
25         rv = self.vapi.cli("test log notice fib entry this is a test")
26         rv = self.vapi.log_dump()
27         if enable_print:
28             print("\n".join([str(v) for v in rv]))
29         self.assertTrue(rv)
30
31     def test_log_dump_timestamp_0(self):
32         rv = self.vapi.cli("test log notice fib entry this is a test")
33         rv = self.vapi.log_dump(start_timestamp=0.0)
34         if enable_print:
35             print("\n".join([str(v) for v in rv]))
36         self.assertTrue(rv)
37
38     def test_log_dump_timestamp_future(self):
39         rv = self.vapi.cli("test log debug fib entry test")
40         rv = self.vapi.log_dump(start_timestamp=time.time() + 60.0)
41         if enable_print:
42             print("\n".join([str(v) for v in rv]))
43         self.assertFalse(rv)
44
45     def test_show_vpe_system_time(self):
46         local_start_time = datetime.datetime.now()
47         rv = self.vapi.show_vpe_system_time()
48         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         )
52         if enable_print:
53             print("\n".join([str(v) for v in rv]))
54             print("%r %s" % (rv.vpe_system_time, rv.vpe_system_time))