[LTP] [PATCH] nanosleep: Use CLOCK_MONOTONIC for elapsed time measurement

Cyril Hrubis chrubis@suse.cz
Tue Mar 31 14:14:25 CEST 2026


Hi!
> All nanosleep POSIX conformance tests used CLOCK_REALTIME to measure
> elapsed sleep duration. CLOCK_REALTIME can jump due to NTP corrections,
> VM time sync, or other wall-clock adjustments, causing sporadic test
> failures where measured time far exceeds expected sleep duration.
> 
> Switch to CLOCK_MONOTONIC which is immune to wall-clock changes and is
> the correct clock for measuring elapsed durations.

Unfortunately CLOCK_MONOTONIC is optional in POSIX so we have to check
if it's present at least at compile time with something as:

#if _POSIX_MONOTONIC_CLOCK
# define TEST_CLOCK CLOCK_MONOTONIC
#else
# define TEST_CLOCK CLOCK_REALTIME
#endif

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list