From 68c35a007212e7fe394d94f2eb0f476ba59317b3 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 18 Jul 2023 13:08:40 +0200 Subject: [PATCH] test: improve ntp_sources unit test --- test/unit/ntp_sources.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/test/unit/ntp_sources.c b/test/unit/ntp_sources.c index ea3910f..1626552 100644 --- a/test/unit/ntp_sources.c +++ b/test/unit/ntp_sources.c @@ -28,6 +28,7 @@ #include #include #include +#include static char *requested_name = NULL; static DNS_NameResolveHandler resolve_handler = NULL; @@ -41,9 +42,11 @@ static void *resolve_handler_arg = NULL; change_remote_address(inst, remote_addr, ntp_only) #define NCR_ProcessRxKnown(remote_addr, local_addr, ts, msg, len) (random() % 2) #define NIO_IsServerConnectable(addr) (random() % 2) +#define SCH_GetLastEventMonoTime() get_mono_time() static void change_remote_address(NCR_Instance inst, NTP_Remote_Address *remote_addr, int ntp_only); +static double get_mono_time(void); #include @@ -96,17 +99,26 @@ change_remote_address(NCR_Instance inst, NTP_Remote_Address *remote_addr, int nt TEST_CHECK(record_lock); if (update && update_pos == 0) - r = update_random_address(remote_addr, 4); + r = update_random_address(random() % 2 ? remote_addr : NCR_GetRemoteAddress(inst), 4); NCR_ChangeRemoteAddress(inst, remote_addr, ntp_only); if (update && update_pos == 1) - r = update_random_address(remote_addr, 4); + r = update_random_address(random() % 2 ? remote_addr : NCR_GetRemoteAddress(inst), 4); if (r) TEST_CHECK(UTI_IsIPReal(&saved_address_update.old_address.ip_addr)); } +static double get_mono_time(void) { + static double t = 0.0; + + if (random() % 2) + t += TST_GetRandomDouble(0.0, 100.0); + + return t; +} + void test_unit(void) {