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

Andrea Cervesato andrea.cervesato@suse.com
Tue Mar 31 14:20:01 CEST 2026


Hi Cyril,

> 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

good point. If it was a non-posix project it was called non-openposix :-)

Do you think that check is enough in this case? Or we should just mark
this test (if we really want to keep it 100% posix) as XFAIL ? I really
didn't see any option but introducing CLOCK_MONOTONIC checks.

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com


More information about the ltp mailing list