[LTP] [PATCH] sys_rtc01: Rewrite the RTC check

Wake Liu wakel@google.com
Thu Nov 19 16:06:19 CET 2026


Hi Cyril,

On Thu, Nov 19, 2026 at 11:37:11AM +0100, Cyril Hrubis wrote:
> Instead of comparing system time against RTC, which proved to be
> unreliable we now sample the RTC since_epoch and compare it with
> CLOCK_MONOTONIC_RAW timer.

Thanks for reworking this! Dropping the system time comparison and timing
since_epoch transitions against CLOCK_MONOTONIC_RAW is much cleaner and
avoids all the STA_UNSYNC / CONFIG_RTC_SYSTOHC corner cases on our
systems.

Two small things I noticed while reviewing and testing the patch:

> +static void poll_rtc(struct rtc_dev *rtc)
> +{
> +	struct timespec start, end;
> +	struct rtc_edge edge;
> +	long long val;
> +
> +	SAFE_CLOCK_GETTIME(CLOCK_MONOTONIC_RAW, &start);
> +	val = TST_SYSFS_READ_LI(PATH_CLASS_RTC "/%s/since_epoch", rtc->name);
> +	SAFE_CLOCK_GETTIME(CLOCK_MONOTONIC_RAW, &end);

The kernel exports since_epoch as time64_t ("%lld") and val is already
long long, so this should use TST_SYSFS_READ_LLI() (and likewise in
read_rtc_snapshot() with a long long since_epoch). Otherwise on 32-bit
userspace an uninitialized or secondary RTC set past 2038 clamps "%ld"
to LONG_MAX on every read, making poll_rtc() see 0 transitions (and
mismatching 64-bit timegm() when _TIME_BITS=64).

>  static struct tst_test test = {
> +	.setup = setup,
>  	.test_all = do_test,
> +	.runtime = 5,
>  };

Since the test requires at least 2 transitions, could we also set
.min_runtime = 3 (or 4)? Without it, running with e.g.
LTP_RUNTIME_MUL=0.2 clamps runtime to 1s and fails with:

  sys_rtc01.c:261: TFAIL: rtc0: since_epoch did not advance (1 transitions seen)

With those two fixed, feel free to add:
Reviewed-by: Wake Liu <wakel@google.com>

Best regards,
Wake


More information about the ltp mailing list