vppinfra: refactor clib_timebase_t
Add a clib_time_t * argument to clib_timebase_init(...), to encourage
client code to share the vlib_main_t's clib_time_t object.
Display the current day / date in GMT via the "show time" debug CLI.
Fix the test framework so it processes the new "show time" output format.
Type: refactor
Signed-off-by: Dave Barach <dave@barachs.net>
Change-Id: I5e52d57eb164b7cdb6355362d520df6928491711
diff --git a/src/plugins/http_static/static_server.c b/src/plugins/http_static/static_server.c
index ddc8a9e..888cf41 100644
--- a/src/plugins/http_static/static_server.c
+++ b/src/plugins/http_static/static_server.c
@@ -1743,7 +1743,8 @@
hsm->first_index = hsm->last_index = ~0;
clib_timebase_init (&hsm->timebase, 0 /* GMT */ ,
- CLIB_TIMEBASE_DAYLIGHT_NONE);
+ CLIB_TIMEBASE_DAYLIGHT_NONE,
+ &vm->clib_time /* share the system clock */ );
return 0;
}
diff --git a/src/plugins/mactime/mactime.c b/src/plugins/mactime/mactime.c
index e7dcb03..bcd40b4 100644
--- a/src/plugins/mactime/mactime.c
+++ b/src/plugins/mactime/mactime.c
@@ -50,7 +50,8 @@
mm->lookup_table_num_buckets,
mm->lookup_table_memory_size);
clib_timebase_init (&mm->timebase, mm->timezone_offset,
- CLIB_TIMEBASE_DAYLIGHT_USA);
+ CLIB_TIMEBASE_DAYLIGHT_USA,
+ &(mm->vlib_main->clib_time));
mm->allow_counters.name = "allow";
mm->allow_counters.stat_segment_name = "/mactime/allow";
mm->drop_counters.name = "drop";
diff --git a/src/plugins/mactime/mactime_top.c b/src/plugins/mactime/mactime_top.c
index 48735a2..ee60535 100644
--- a/src/plugins/mactime/mactime_top.c
+++ b/src/plugins/mactime/mactime_top.c
@@ -480,7 +480,8 @@
clib_time_init (&mm->clib_time);
mm->timezone_offset = -5.0;
clib_timebase_init (&mm->timebase, mm->timezone_offset,
- CLIB_TIMEBASE_DAYLIGHT_USA);
+ CLIB_TIMEBASE_DAYLIGHT_USA,
+ 0 /* allocate a clib_time_t */ );
vec_add1 (mm->pattern1, (u8 *) "^/mactime/allow");
vec_add1 (mm->pattern2, (u8 *) "^/mactime/drop");
diff --git a/src/plugins/mactime/test/test_mactime.py b/src/plugins/mactime/test/test_mactime.py
index fa9516c..85ded33 100644
--- a/src/plugins/mactime/test/test_mactime.py
+++ b/src/plugins/mactime/test/test_mactime.py
@@ -2,7 +2,7 @@
import unittest
-from framework import VppTestCase, VppTestRunner, running_extended_tests
+from framework import VppTestCase, VppTestRunner, running_gcov_tests
from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
@@ -31,7 +31,7 @@
self.logger.critical(error)
self.assertNotIn('FAILED', error)
- @unittest.skipUnless(running_extended_tests, "part of extended tests")
+ @unittest.skipUnless(running_gcov_tests, "part of code coverage tests")
def test_mactime_unittest(self):
""" Mactime Plugin Code Coverage Test """
cmds = ["loopback create",
diff --git a/src/plugins/unittest/mactime_test.c b/src/plugins/unittest/mactime_test.c
index 907022f..46d6263 100644
--- a/src/plugins/unittest/mactime_test.c
+++ b/src/plugins/unittest/mactime_test.c
@@ -18,6 +18,7 @@
static int
test_time_range_main (unformat_input_t * input)
{
+ vlib_main_t *vm = vlib_get_main ();
clib_timebase_t _tb, *tb = &_tb;
clib_timebase_component_t _c, *cp = &_c;
clib_timebase_range_t *rp = 0;
@@ -30,7 +31,8 @@
f64 timezone_offset;
/* Init time base */
- clib_timebase_init (tb, -5 /* EST */ , CLIB_TIMEBASE_DAYLIGHT_USA);
+ clib_timebase_init (tb, -5 /* EST */ , CLIB_TIMEBASE_DAYLIGHT_USA,
+ &vm->clib_time);
/* Set up summer time cache */
now = clib_timebase_now (tb);
diff --git a/src/vlib/threads.c b/src/vlib/threads.c
index 3f09054..e9d9cb5 100644
--- a/src/vlib/threads.c
+++ b/src/vlib/threads.c
@@ -17,6 +17,7 @@
#include <signal.h>
#include <math.h>
#include <vppinfra/format.h>
+#include <vppinfra/time_range.h>
#include <vppinfra/linux/sysfs.h>
#include <vlib/vlib.h>
@@ -1890,10 +1891,16 @@
{
int i;
int verbose = 0;
+ clib_timebase_t _tb, *tb = &_tb;
(void) unformat (input, "verbose %=", &verbose, 1);
- vlib_cli_output (vm, "%U", format_clib_time, &vm->clib_time, verbose);
+ clib_timebase_init (tb, 0 /* GMT */ , CLIB_TIMEBASE_DAYLIGHT_NONE,
+ &vm->clib_time);
+
+ vlib_cli_output (vm, "%U, %U GMT", format_clib_time, &vm->clib_time,
+ verbose, format_clib_timebase_time,
+ clib_timebase_now (tb));
if (vec_len (vlib_mains) == 1)
return 0;
diff --git a/src/vppinfra/test_time_range.c b/src/vppinfra/test_time_range.c
index a22ef3a..a707109 100644
--- a/src/vppinfra/test_time_range.c
+++ b/src/vppinfra/test_time_range.c
@@ -30,7 +30,8 @@
f64 timezone_offset;
/* Init time base */
- clib_timebase_init (tb, -5 /* EST */ , CLIB_TIMEBASE_DAYLIGHT_USA);
+ clib_timebase_init (tb, -5 /* EST */ , CLIB_TIMEBASE_DAYLIGHT_USA,
+ 0 /* allocate a clib_time_t */ );
/* Set up summer time cache */
now = clib_timebase_now (tb);
@@ -142,6 +143,7 @@
}
unformat_free (input2);
+ clib_mem_free (tb->clib_time);
return 0;
}
diff --git a/src/vppinfra/time_range.c b/src/vppinfra/time_range.c
index ea95284..20048f8 100644
--- a/src/vppinfra/time_range.c
+++ b/src/vppinfra/time_range.c
@@ -17,12 +17,20 @@
void
clib_timebase_init (clib_timebase_t * tb, i32 timezone_offset_in_hours,
- clib_timebase_daylight_time_t daylight_type)
+ clib_timebase_daylight_time_t daylight_type,
+ clib_time_t * clib_time)
{
clib_memset (tb, 0, sizeof (*tb));
- clib_time_init (&tb->clib_time);
- tb->time_zero = unix_time_now ();
+ if (clib_time == 0)
+ {
+ tb->clib_time = clib_mem_alloc_aligned
+ (sizeof (*clib_time), CLIB_CACHE_LINE_BYTES);
+ memset (tb->clib_time, 0, sizeof (*clib_time));
+ clib_time_init (tb->clib_time);
+ }
+ else
+ tb->clib_time = clib_time;
tb->timezone_offset = ((f64) (timezone_offset_in_hours)) * 3600.0;
tb->daylight_time_type = daylight_type;
diff --git a/src/vppinfra/time_range.h b/src/vppinfra/time_range.h
index 6dcd82d..993bf9c 100644
--- a/src/vppinfra/time_range.h
+++ b/src/vppinfra/time_range.h
@@ -28,12 +28,7 @@
typedef struct
{
/* provides f64 seconds since clib_time_init was called */
- clib_time_t clib_time;
- /*
- * time in f64 seconds since Thursday 1 Jan 1970 00:00:00 UTC
- * when clib_time_init was called
- */
- f64 time_zero;
+ clib_time_t *clib_time;
f64 timezone_offset;
f64 summer_offset;
clib_timebase_daylight_time_t daylight_time_type;
@@ -57,7 +52,8 @@
} clib_timebase_range_t;
void clib_timebase_init (clib_timebase_t * tb, i32 timezone_offset_in_hours,
- clib_timebase_daylight_time_t daylight_type);
+ clib_timebase_daylight_time_t daylight_type,
+ clib_time_t * clib_time);
void clib_timebase_time_to_components (f64 now,
clib_timebase_component_t * cp);
@@ -93,7 +89,7 @@
{
f64 now;
- now = tb->time_zero + clib_time_now (&tb->clib_time);
+ now = tb->clib_time->init_reference_time + clib_time_now (tb->clib_time);
now += tb->timezone_offset;
now += clib_timebase_summer_offset_fastpath (tb, now);
diff --git a/test/framework.py b/test/framework.py
index 46f7542..c21d188 100644
--- a/test/framework.py
+++ b/test/framework.py
@@ -758,7 +758,12 @@
@classmethod
def get_vpp_time(cls):
- return float(cls.vapi.cli('show clock').replace("Time now ", ""))
+ # processes e.g. "Time now 2.190522, Wed, 11 Mar 2020 17:29:54 GMT"
+ # returns float("2.190522")
+ timestr = cls.vapi.cli('show clock')
+ head, sep, tail = timestr.partition(',')
+ head, sep, tail = head.partition('Time now')
+ return float(tail)
@classmethod
def sleep_on_vpp_time(cls, sec):