[LTP] [PATCH v2] nanosleep: use POSIX runtime detection for CLOCK_MONOTONIC

Petr Vorel pvorel@suse.cz
Fri Apr 17 14:58: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");
+1 for warning. But please don't split string just due few chars over 100.

> +	return CLOCK_REALTIME;
I've suggested [1] in clock_settime [2] to move this function to newly created
testcases/open_posix_testsuite/include/clock.h, so that clock_settime/helpers.h
can also use it.

Kind regards,
Petr

[1] https://lore.kernel.org/ltp/20260417125322.GA419619@pevik/
[2] https://patchwork.ozlabs.org/project/ltp/patch/20260416-fix_clock_settime_helper-v1-1-2874202291bf@suse.com/


More information about the ltp mailing list