]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
test: fix util unit test for NTP era split
authorMiroslav Lichvar <mlichvar@redhat.com>
Fri, 3 Jan 2020 10:25:55 +0000 (11:25 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 3 Jan 2020 11:01:55 +0000 (12:01 +0100)
The current default NTP era split passed the Unix epoch (~50 years ago),
which means the epoch converted to an NTP timestamp and back ends up in
the next NTP era (year 2106).

Fix the test to take into account the era split.

test/unit/util.c

index f4d9f3309b62e94aba8a999526b00ef4d9d269dd..af9e90c6e7ed5e74c25941e84101b04430c5b0bf 100644 (file)
@@ -100,11 +100,19 @@ void test_unit(void) {
   ntp_ts.hi = htonl(JAN_1970);
   ntp_ts.lo = 0xffffffff;
   UTI_Ntp64ToTimespec(&ntp_ts, &ts);
+#if defined(HAVE_LONG_TIME_T) && NTP_ERA_SPLIT > 0
+  TEST_CHECK(ts.tv_sec == 0x100000000LL * (1 + (NTP_ERA_SPLIT - 1) / 0x100000000LL));
+#else
   TEST_CHECK(ts.tv_sec == 0);
+#endif
   TEST_CHECK(ts.tv_nsec == 999999999);
 
   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));
+#else
   TEST_CHECK(ts.tv_sec == 1);
+#endif
   TEST_CHECK(ts.tv_nsec == 0);
 
   ntp_fuzz.hi = 0;