tests: timeutil: test large linearity
Add tests to ensure that conversions remain linear for large time deltas when no skew is present. Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
This commit is contained in:
parent
2c1f184d02
commit
a9779bb2dc
1 changed files with 42 additions and 0 deletions
|
@ -357,6 +357,47 @@ static void test_local_from_ref(void)
|
||||||
tlocal_from_ref("ext", &cfg2);
|
tlocal_from_ref("ext", &cfg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_large_linearity(void)
|
||||||
|
{
|
||||||
|
uint64_t inputs[] = {
|
||||||
|
1000ULL,
|
||||||
|
3999999999ULL,
|
||||||
|
4000000000ULL,
|
||||||
|
4000000001ULL,
|
||||||
|
UINT64_MAX / 10000000
|
||||||
|
};
|
||||||
|
uint64_t ref_out;
|
||||||
|
int64_t loc_out;
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
const struct timeutil_sync_config unity = {
|
||||||
|
.ref_Hz = 1000,
|
||||||
|
.local_Hz = 1000,
|
||||||
|
};
|
||||||
|
struct timeutil_sync_instant inst = {
|
||||||
|
.ref = 200,
|
||||||
|
.local = 100
|
||||||
|
};
|
||||||
|
struct timeutil_sync_state ss = {
|
||||||
|
.cfg = &unity,
|
||||||
|
};
|
||||||
|
uint64_t offset = inst.ref - inst.local;
|
||||||
|
|
||||||
|
timeutil_sync_state_set_skew(&ss, 1.0f, &inst);
|
||||||
|
|
||||||
|
for (int i = 0; i < ARRAY_SIZE(inputs); i++) {
|
||||||
|
rv = timeutil_sync_ref_from_local(&ss, inputs[i], &ref_out);
|
||||||
|
zassert_equal(rv, 0, "Unexpected conversion fail");
|
||||||
|
zassert_equal(ref_out, inputs[i] + offset,
|
||||||
|
"Large unity local->ref conversion fail");
|
||||||
|
|
||||||
|
rv = timeutil_sync_local_from_ref(&ss, inputs[i], &loc_out);
|
||||||
|
zassert_equal(rv, 0, "Unexpected conversion fail");
|
||||||
|
zassert_equal(loc_out, inputs[i] - offset,
|
||||||
|
"Large unity ref->local conversion fail");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void test_skew_to_ppb(void)
|
static void test_skew_to_ppb(void)
|
||||||
{
|
{
|
||||||
float skew = 1.0;
|
float skew = 1.0;
|
||||||
|
@ -392,5 +433,6 @@ void test_sync(void)
|
||||||
test_estimate_skew();
|
test_estimate_skew();
|
||||||
test_ref_from_local();
|
test_ref_from_local();
|
||||||
test_local_from_ref();
|
test_local_from_ref();
|
||||||
|
test_large_linearity();
|
||||||
test_skew_to_ppb();
|
test_skew_to_ppb();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue