[LTP] sys_rtc01: Report TCONF on system time mismatch when STA_UNSYNC is set

Cyril Hrubis chrubis@suse.cz
Wed Nov 18 11:12:18 CET 2026


Hi!
> > +	} else if (is_clock_unsynced()) {
> > +		tst_res(TCONF,
> > +			"%s: since_epoch (%lld), system time (%lld), diff %llds > slack %lds (STA_UNSYNC is set)",
> > +			name, (long long)since_epoch, (long long)sys_epoch,
> > +			diff, slack);
> 
> STA_UNSYNC is already set at boot by ntp_init() and rtc_hctosys() (via
> do_settimeofday64() -> ntp_clear()), and it is only ever cleared when a
> userspace NTP daemon calls adjtimex(2) with ADJ_STATUS. On any system without
> an active NTP daemon, is_clock_unsynced() always returns 1 even if the clock
> was never stepped after boot, making the TFAIL branch unreachable and masking
> real RTC vs system time mismatches. Conversely, when an NTP daemon is active
> and clears STA_UNSYNC after syncing a system booted with a wrong RTC, the RTC
> can still diverge if CONFIG_RTC_SYSTOHC is disabled or unsupported by the
> driver.

Hmm, I guess that the logic should be the other way, if STA_UNSYNC is
not set the clock was modified by NTP and the test should be skipped:

diff --git a/testcases/kernel/sysfs/class/rtc/sys_rtc01.c b/testcases/kernel/sysfs/class/rtc/sys_rtc01.c
index 0e1c69f95..a4ad37088 100644
--- a/testcases/kernel/sysfs/class/rtc/sys_rtc01.c
+++ b/testcases/kernel/sysfs/class/rtc/sys_rtc01.c
@@ -47,8 +47,11 @@
  * 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.
+ * the RTC while hctosys remains 1.
+ *
+ * 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 +115,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 +220,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 {


-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list