[LTP] [PATCH] sys_rtc01: TCONF on system time mismatch when STA_UNSYNC is unset
Cyril Hrubis
chrubis@suse.cz
Wed Nov 18 11:17:20 CET 2026
It turns out that the STA_UNSYNC flag is set at boot and cleared by ntp,
so we should skip the TFAIL when the flag is cleared, since that means
that NTP have adjusted the system time and it's possibly out of sync
with RTC.
Fixes: 3d11e5dd622e "sys_rtc01: Report TCONF on system time mismatch when STA_UNSYNC is set"
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
testcases/kernel/sysfs/class/rtc/sys_rtc01.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/testcases/kernel/sysfs/class/rtc/sys_rtc01.c b/testcases/kernel/sysfs/class/rtc/sys_rtc01.c
index 0e1c69f95..4857d4a8b 100644
--- a/testcases/kernel/sysfs/class/rtc/sys_rtc01.c
+++ b/testcases/kernel/sysfs/class/rtc/sys_rtc01.c
@@ -43,12 +43,9 @@
* test performs, so on a long-running system a purely fixed slack would
* eventually produce false failures even on perfectly healthy hardware.
*
- * If the system was booted with an RTC that was off the current time and the
- * system clock was later stepped in userspace via :manpage:`clock_settime(2)`
- * or :manpage:`settimeofday(2)` without updating the RTC, the kernel sets
- * STA_UNSYNC and CONFIG_RTC_SYSTOHC does not write the system clock back to
- * the RTC while hctosys remains 1. Report TCONF instead of TFAIL when
- * since_epoch diverges from system time while STA_UNSYNC is set.
+ * If system time was corrected by NTP the kernel clears STA_UNSYNC flag.
+ * Report TCONF instead of TFAIL when since_epoch diverges from system time
+ * when STA_UNSYNC is not set.
*
* Under virtualization the slack is additionally multiplied, since a VM's
* clock (and thus its emulated RTC) commonly lags real time by tens of
@@ -112,14 +109,14 @@ static long read_hctosys(const char *name)
return TST_SYSFS_READ_LI(PATH_CLASS_RTC "/%s/hctosys", name);
}
-static int is_clock_unsynced(void)
+static int clock_is_synced(void)
{
struct timex tx = { .modes = 0 };
if (adjtimex(&tx) == -1)
tst_brk(TBROK | TERRNO, "adjtimex() failed");
- return !!(tx.status & STA_UNSYNC);
+ return !(tx.status & STA_UNSYNC);
}
static void read_rtc_snapshot(const char *name, char *date, size_t date_size,
@@ -217,9 +214,9 @@ static void check_rtc(const char *name, int any_hctosys)
"%s: since_epoch (%lld), system time (%lld), diff %llds <= slack %lds",
name, (long long)since_epoch, (long long)sys_epoch,
diff, slack);
- } else if (is_clock_unsynced()) {
+ } else if (clock_is_synced()) {
tst_res(TCONF,
- "%s: since_epoch (%lld), system time (%lld), diff %llds > slack %lds (STA_UNSYNC is set)",
+ "%s: since_epoch (%lld), system time (%lld), diff %llds > slack %lds (STA_UNSYNC is not set)",
name, (long long)since_epoch, (long long)sys_epoch,
diff, slack);
} else {
--
2.55.0
More information about the ltp
mailing list