mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-04 04:25:06 -05:00
use common structure for NTP samples
Define a structure for NTP samples and use it to pass samples from the ntp_core and refclock code to sources and sourcestats.
This commit is contained in:
@@ -26,10 +26,9 @@ test_unit(void)
|
||||
{
|
||||
SRC_Instance srcs[16];
|
||||
RPT_SourceReport report;
|
||||
NTP_Sample sample;
|
||||
IPAddr addr;
|
||||
int i, j, k, l, samples, sel_options;
|
||||
double offset, delay, disp;
|
||||
struct timespec ts;
|
||||
|
||||
CNF_Initialise(0, 0);
|
||||
LCL_Initialise();
|
||||
@@ -59,21 +58,25 @@ test_unit(void)
|
||||
|
||||
samples = (i + j) % 5 + 3;
|
||||
|
||||
offset = TST_GetRandomDouble(-1.0, 1.0);
|
||||
sample.offset = TST_GetRandomDouble(-1.0, 1.0);
|
||||
|
||||
for (k = 0; k < samples; k++) {
|
||||
SCH_GetLastEventTime(&ts, NULL, NULL);
|
||||
UTI_AddDoubleToTimespec(&ts, TST_GetRandomDouble(k - samples, k - samples + 1), &ts);
|
||||
SCH_GetLastEventTime(&sample.time, NULL, NULL);
|
||||
UTI_AddDoubleToTimespec(&sample.time, TST_GetRandomDouble(k - samples, k - samples + 1),
|
||||
&sample.time);
|
||||
|
||||
offset += TST_GetRandomDouble(-1.0e-2, 1.0e-2);
|
||||
delay = TST_GetRandomDouble(1.0e-6, 1.0e-1);
|
||||
disp = TST_GetRandomDouble(1.0e-6, 1.0e-1);
|
||||
sample.offset += TST_GetRandomDouble(-1.0e-2, 1.0e-2);
|
||||
sample.peer_delay = TST_GetRandomDouble(1.0e-6, 1.0e-1);
|
||||
sample.peer_dispersion = TST_GetRandomDouble(1.0e-6, 1.0e-1);
|
||||
sample.root_delay = sample.peer_delay;
|
||||
sample.root_dispersion = sample.peer_dispersion;
|
||||
sample.stratum = 1;
|
||||
sample.leap = LEAP_Normal;
|
||||
|
||||
DEBUG_LOG("source %d sample %d offset %f delay %f disp %f", j, k,
|
||||
offset, delay, disp);
|
||||
sample.offset, sample.peer_delay, sample.peer_dispersion);
|
||||
|
||||
SRC_AccumulateSample(srcs[j], &ts, offset, delay, disp, delay, disp,
|
||||
1, LEAP_Normal);
|
||||
SRC_AccumulateSample(srcs[j], &sample);
|
||||
}
|
||||
|
||||
for (k = 0; k <= j; k++) {
|
||||
@@ -125,7 +128,7 @@ test_unit(void)
|
||||
}
|
||||
|
||||
for (j = 0; j < sizeof (srcs) / sizeof (srcs[0]); j++) {
|
||||
SRC_ReportSource(j, &report, &ts);
|
||||
SRC_ReportSource(j, &report, &sample.time);
|
||||
SRC_DestroyInstance(srcs[j]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user