mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 19:45:07 -05:00
util: add function to subtract NTP timestamps
This will be needed to work with monotonic timestamps, which don't have a stable epoch and cannot be converted to timespec.
This commit is contained in:
@@ -34,7 +34,7 @@ test_unit(void)
|
||||
{
|
||||
struct timespec ts, ts2, ts3, ts4;
|
||||
char buf[16], *s, *s2, *words[3];
|
||||
NTP_int64 ntp_ts, ntp_fuzz;
|
||||
NTP_int64 ntp_ts, ntp_ts2, ntp_fuzz;
|
||||
NTP_int32 ntp32_ts;
|
||||
struct timeval tv;
|
||||
double x, y, nan, inf;
|
||||
@@ -114,6 +114,13 @@ test_unit(void)
|
||||
#endif
|
||||
TEST_CHECK(ts.tv_nsec == 999999999);
|
||||
|
||||
ntp_ts.hi = htonl(JAN_1970 - 1);
|
||||
ntp_ts.lo = htonl(0xffffffff);
|
||||
ntp_ts2.hi = htonl(JAN_1970 + 1);
|
||||
ntp_ts2.lo = htonl(0x80000000);
|
||||
TEST_CHECK(fabs(UTI_DiffNtp64ToDouble(&ntp_ts, &ntp_ts2) + 1.5) < 1e-9);
|
||||
TEST_CHECK(fabs(UTI_DiffNtp64ToDouble(&ntp_ts2, &ntp_ts) - 1.5) < 1e-9);
|
||||
|
||||
UTI_AddDoubleToTimespec(&ts, 1e-9, &ts);
|
||||
#if defined(HAVE_LONG_TIME_T) && NTP_ERA_SPLIT > 0
|
||||
TEST_CHECK(ts.tv_sec == 1 + 0x100000000LL * (1 + (NTP_ERA_SPLIT - 1) / 0x100000000LL));
|
||||
|
||||
Reference in New Issue
Block a user