[LTP] [PATCH] nanosleep: use POSIX runtime detection for CLOCK_MONOTONIC
Petr Vorel
pvorel@suse.cz
Thu Apr 16 14:08:21 CEST 2026
Hi Andrea,
...
> --- /dev/null
> +++ b/testcases/open_posix_testsuite/conformance/interfaces/nanosleep/helpers.h
> @@ -0,0 +1,28 @@
> +/*
> + * Copyright (c) 2026, Linux Test Project
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#ifndef NANOSLEEP_HELPERS_H
> +#define NANOSLEEP_HELPERS_H
> +
> +#include <stdio.h>
> +#include <unistd.h>
> +#include <time.h>
> +
> +static inline clockid_t get_supported_clock(void)
> +{
> +#ifdef _POSIX_MONOTONIC_CLOCK
> + if (_POSIX_MONOTONIC_CLOCK > 0)
> + return CLOCK_MONOTONIC;
> +
> + if (!_POSIX_MONOTONIC_CLOCK && sysconf(_SC_MONOTONIC_CLOCK) > 0)
> + return CLOCK_MONOTONIC;
> +#endif
> +
> + printf("CLOCK_MONOTONIC unavailable, test may fail due to "
> + "external clock adjustments\n");
> + return CLOCK_REALTIME;
> +}
> +
> +#endif /* NANOSLEEP_HELPERS_H */
Could you please also fix
testcases/open_posix_testsuite/conformance/interfaces/clock_settime/helpers.h?
The rest LGTM.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
More information about the ltp
mailing list