test: improve hwclock unit test
This commit is contained in:
parent
4534db84c4
commit
c2773dbc2f
1 changed files with 14 additions and 6 deletions
|
@ -26,14 +26,14 @@ test_unit(void)
|
||||||
{
|
{
|
||||||
struct timespec start_hw_ts, start_local_ts, hw_ts, local_ts, ts;
|
struct timespec start_hw_ts, start_local_ts, hw_ts, local_ts, ts;
|
||||||
HCL_Instance clock;
|
HCL_Instance clock;
|
||||||
double freq, jitter, interval, d;
|
double freq, jitter, interval, dj, sum;
|
||||||
int i, j;
|
int i, j, count;
|
||||||
|
|
||||||
LCL_Initialise();
|
LCL_Initialise();
|
||||||
|
|
||||||
clock = HCL_CreateInstance(1.0);
|
clock = HCL_CreateInstance(1.0);
|
||||||
|
|
||||||
for (i = 0; i < 2000; i++) {
|
for (i = 0, count = 0, sum = 0.0; i < 2000; i++) {
|
||||||
UTI_ZeroTimespec(&start_hw_ts);
|
UTI_ZeroTimespec(&start_hw_ts);
|
||||||
UTI_ZeroTimespec(&start_local_ts);
|
UTI_ZeroTimespec(&start_local_ts);
|
||||||
UTI_AddDoubleToTimespec(&start_hw_ts, TST_GetRandomDouble(0.0, 1e9), &start_hw_ts);
|
UTI_AddDoubleToTimespec(&start_hw_ts, TST_GetRandomDouble(0.0, 1e9), &start_hw_ts);
|
||||||
|
@ -49,13 +49,19 @@ test_unit(void)
|
||||||
clock->valid_coefs = 0;
|
clock->valid_coefs = 0;
|
||||||
|
|
||||||
for (j = 0; j < 100; j++) {
|
for (j = 0; j < 100; j++) {
|
||||||
UTI_AddDoubleToTimespec(&start_hw_ts, j * interval * freq + TST_GetRandomDouble(-jitter, jitter), &hw_ts);
|
UTI_AddDoubleToTimespec(&start_hw_ts, j * interval * freq, &hw_ts);
|
||||||
UTI_AddDoubleToTimespec(&start_local_ts, j * interval, &local_ts);
|
UTI_AddDoubleToTimespec(&start_local_ts, j * interval, &local_ts);
|
||||||
if (HCL_CookTime(clock, &hw_ts, &ts, NULL)) {
|
if (HCL_CookTime(clock, &hw_ts, &ts, NULL)) {
|
||||||
d = UTI_DiffTimespecsToDouble(&ts, &local_ts);
|
dj = fabs(UTI_DiffTimespecsToDouble(&ts, &local_ts) / jitter);
|
||||||
TEST_CHECK(fabs(d) <= 5.0 * jitter);
|
DEBUG_LOG("delta/jitter %f", dj);
|
||||||
|
if (clock->n_samples >= 8)
|
||||||
|
sum += dj, count++;
|
||||||
|
TEST_CHECK(clock->n_samples < 4 || dj <= 4.0);
|
||||||
|
TEST_CHECK(clock->n_samples < 8 || dj <= 3.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UTI_AddDoubleToTimespec(&start_hw_ts, j * interval * freq + TST_GetRandomDouble(-jitter, jitter), &hw_ts);
|
||||||
|
|
||||||
if (HCL_NeedsNewSample(clock, &local_ts))
|
if (HCL_NeedsNewSample(clock, &local_ts))
|
||||||
HCL_AccumulateSample(clock, &hw_ts, &local_ts, 2.0 * jitter);
|
HCL_AccumulateSample(clock, &hw_ts, &local_ts, 2.0 * jitter);
|
||||||
|
|
||||||
|
@ -68,6 +74,8 @@ test_unit(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CHECK(sum / count < 0.4);
|
||||||
|
|
||||||
HCL_DestroyInstance(clock);
|
HCL_DestroyInstance(clock);
|
||||||
|
|
||||||
LCL_Finalise();
|
LCL_Finalise();
|
||||||
|
|
Loading…
Reference in a new issue