From: Cyril Hrubis <chrubis@suse.cz>
To: linuxtestproject.agent@gmail.com
Cc: Wake Liu <wakel@google.com>, ltp@lists.linux.it
Subject: Re: [LTP] sys_rtc01: Report TCONF on system time mismatch when STA_UNSYNC is set
Date: Wed, 18 Nov 2026 11:12:18 +0100 [thread overview]
Message-ID: <av16AqIo5sj10FEv@yuki.lan> (raw)
In-Reply-To: <20261118044914.3815-1-linuxtestproject.agent@gmail.com>
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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-11-18 10:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 23:58 [LTP] [PATCH] sys_rtc01: Report TCONF on system time mismatch when STA_UNSYNC is set Wake Liu via ltp
2026-11-18 4:49 ` [LTP] " linuxtestproject.agent
2026-11-18 10:12 ` Cyril Hrubis [this message]
2026-11-18 9:23 ` [LTP] [PATCH] " Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=av16AqIo5sj10FEv@yuki.lan \
--to=chrubis@suse.cz \
--cc=linuxtestproject.agent@gmail.com \
--cc=ltp@lists.linux.it \
--cc=wakel@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox