test: improve ntp_sources unit test
This commit is contained in:
parent
b6c634298d
commit
68c35a0072
1 changed files with 14 additions and 2 deletions
|
@ -28,6 +28,7 @@
|
||||||
#include <nameserv_async.h>
|
#include <nameserv_async.h>
|
||||||
#include <ntp_core.h>
|
#include <ntp_core.h>
|
||||||
#include <ntp_io.h>
|
#include <ntp_io.h>
|
||||||
|
#include <sched.h>
|
||||||
|
|
||||||
static char *requested_name = NULL;
|
static char *requested_name = NULL;
|
||||||
static DNS_NameResolveHandler resolve_handler = 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)
|
change_remote_address(inst, remote_addr, ntp_only)
|
||||||
#define NCR_ProcessRxKnown(remote_addr, local_addr, ts, msg, len) (random() % 2)
|
#define NCR_ProcessRxKnown(remote_addr, local_addr, ts, msg, len) (random() % 2)
|
||||||
#define NIO_IsServerConnectable(addr) (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,
|
static void change_remote_address(NCR_Instance inst, NTP_Remote_Address *remote_addr,
|
||||||
int ntp_only);
|
int ntp_only);
|
||||||
|
static double get_mono_time(void);
|
||||||
|
|
||||||
#include <ntp_sources.c>
|
#include <ntp_sources.c>
|
||||||
|
|
||||||
|
@ -96,17 +99,26 @@ change_remote_address(NCR_Instance inst, NTP_Remote_Address *remote_addr, int nt
|
||||||
TEST_CHECK(record_lock);
|
TEST_CHECK(record_lock);
|
||||||
|
|
||||||
if (update && update_pos == 0)
|
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);
|
NCR_ChangeRemoteAddress(inst, remote_addr, ntp_only);
|
||||||
|
|
||||||
if (update && update_pos == 1)
|
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)
|
if (r)
|
||||||
TEST_CHECK(UTI_IsIPReal(&saved_address_update.old_address.ip_addr));
|
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
|
void
|
||||||
test_unit(void)
|
test_unit(void)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue