From 9d88c8cfb0f57b965cc744048eca8911d2be35e3 Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Wed, 3 Dec 2025 10:40:56 +1000 Subject: [PATCH] tests: unit: timeutil: test `CONFIG_TIMEUTIL_APPLY_SKEW=n` Test the `timeutil` libraries compile and behave the same way (excluding the skew application) when `CONFIG_TIMEUTIL_APPLY_SKEW=n`. Signed-off-by: Jordan Yates --- tests/unit/timeutil/test_sync.c | 19 ++++++++++++++++--- tests/unit/timeutil/testcase.yaml | 4 ++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/tests/unit/timeutil/test_sync.c b/tests/unit/timeutil/test_sync.c index 25bc3a22a52..bafd1bd6da3 100644 --- a/tests/unit/timeutil/test_sync.c +++ b/tests/unit/timeutil/test_sync.c @@ -225,6 +225,7 @@ static void tref_from_local(const char *tag, }; uint64_t ref = 0; int rv = timeutil_sync_ref_from_local(&ss, 0, &ref); + int skew_factor; zassert_equal(rv, -EINVAL, "%s: unexpected uninit convert: %d", tag, rv); @@ -274,9 +275,15 @@ static void tref_from_local(const char *tag, zassert_equal(rv, 0, "%s: failed set skew", tag); + /* Whether the conversion takes skew into account is controlled + * by the Kconfig option. + */ + skew_factor = IS_ENABLED(CONFIG_TIMEUTIL_APPLY_SKEW) ? 2 : 1; + /* Local at double speed corresponds to half advance in ref */ rv = timeutil_sync_ref_from_local(&ss, ss.base.local - + scale_local(2, cfg), &ref); + + scale_local(skew_factor, cfg), + &ref); zassert_equal(rv, 1, "%s: unexpected skew adj fail", tag); zassert_equal(ref, ss.base.ref + cfg->ref_Hz, @@ -302,6 +309,7 @@ static void tlocal_from_ref(const char *tag, }; int64_t local = 0; int rv = timeutil_sync_local_from_ref(&ss, 0, &local); + int skew_factor; zassert_equal(rv, -EINVAL, "%s: unexpected uninit convert: %d", tag, rv); @@ -336,15 +344,20 @@ static void tlocal_from_ref(const char *tag, zassert_equal(local, scale_local_signed(-2, cfg), "%s: unexpected base-7s convert", tag); - /* Skew of 0.5 means local runs at double speed */ rv = timeutil_sync_state_set_skew(&ss, 0.5, NULL); zassert_equal(rv, 0, "%s: failed set skew", tag); + /* Whether the conversion takes skew into account is controlled + * by the Kconfig option. + */ + skew_factor = IS_ENABLED(CONFIG_TIMEUTIL_APPLY_SKEW) ? 2 : 1; + /* Local at double speed corresponds to half advance in ref */ rv = timeutil_sync_local_from_ref(&ss, ss.base.ref - + scale_ref(1, cfg) / 2, &local); + + scale_ref(1, cfg) / skew_factor, + &local); zassert_equal(rv, 1, "%s: unexpected skew adj fail", tag); zassert_equal(local, ss.base.local + scale_local(1, cfg), diff --git a/tests/unit/timeutil/testcase.yaml b/tests/unit/timeutil/testcase.yaml index eac190d82ad..d854dcc756f 100644 --- a/tests/unit/timeutil/testcase.yaml +++ b/tests/unit/timeutil/testcase.yaml @@ -8,3 +8,7 @@ tests: utilities.time.64bit: extra_args: M64_MODE=1 + + utilities.time.no_skew: + extra_configs: + - CONFIG_TIMEUTIL_APPLY_SKEW=n