1 /* Check pthread_clockjoin_np clock support.
2 Copyright (C) 2020-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
24 #include <array_length.h>
25 #include <support/check.h>
26 #include <support/timespec.h>
27 #include <support/xthread.h>
40 const clockid_t clocks
[] = {
43 CLOCK_PROCESS_CPUTIME_ID
,
44 CLOCK_THREAD_CPUTIME_ID
,
45 CLOCK_THREAD_CPUTIME_ID
,
47 CLOCK_REALTIME_COARSE
,
48 CLOCK_MONOTONIC_COARSE
,
52 #ifdef CLOCK_REALTIME_ALARM
55 #ifdef CLOCK_BOOTTIME_ALARM
63 pthread_t thr
= xpthread_create (NULL
, tf
, NULL
);
65 for (int t
= 0; t
< array_length (clocks
); t
++)
67 /* Create a valid timeout to check for ETIMEDOUT on valid clocks. */
69 if (clock_gettime (clocks
[t
], &tmo
) == -1)
70 /* For clocks not supported, create a large timeout (it should
71 fail early with EINVAL). */
72 tmo
= make_timespec (-1, 0);
74 tmo
= timespec_add (tmo
, make_timespec (0, 100000000));
76 int ret
= clocks
[t
] == CLOCK_REALTIME
|| clocks
[t
] == CLOCK_MONOTONIC
79 TEST_COMPARE (pthread_clockjoin_np (thr
, NULL
, clocks
[t
], &tmo
), ret
);
85 #include <support/test-driver.c>