1 | /* Check pthread_clockjoin_np clock support. |
2 | Copyright (C) 2020-2024 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. |
4 | |
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. |
9 | |
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. |
14 | |
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/>. */ |
18 | |
19 | #include <pthread.h> |
20 | #include <sys/time.h> |
21 | #include <unistd.h> |
22 | #include <errno.h> |
23 | |
24 | #include <array_length.h> |
25 | #include <support/check.h> |
26 | #include <support/timespec.h> |
27 | #include <support/xthread.h> |
28 | |
29 | static void * |
30 | tf (void *arg) |
31 | { |
32 | pause (); |
33 | return NULL; |
34 | } |
35 | |
36 | |
37 | static int |
38 | do_test (void) |
39 | { |
40 | const clockid_t clocks[] = { |
41 | CLOCK_REALTIME, |
42 | CLOCK_MONOTONIC, |
43 | CLOCK_PROCESS_CPUTIME_ID, |
44 | CLOCK_THREAD_CPUTIME_ID, |
45 | CLOCK_THREAD_CPUTIME_ID, |
46 | CLOCK_MONOTONIC_RAW, |
47 | CLOCK_REALTIME_COARSE, |
48 | CLOCK_MONOTONIC_COARSE, |
49 | #ifdef CLOCK_BOOTTIME |
50 | CLOCK_BOOTTIME, |
51 | #endif |
52 | #ifdef CLOCK_REALTIME_ALARM |
53 | CLOCK_REALTIME_ALARM, |
54 | #endif |
55 | #ifdef CLOCK_BOOTTIME_ALARM |
56 | CLOCK_BOOTTIME_ALARM, |
57 | #endif |
58 | #ifdef CLOCK_TAI |
59 | CLOCK_TAI |
60 | #endif |
61 | }; |
62 | |
63 | pthread_t thr = xpthread_create (NULL, thread_func: tf, NULL); |
64 | |
65 | for (int t = 0; t < array_length (clocks); t++) |
66 | { |
67 | /* Create a valid timeout to check for ETIMEDOUT on valid clocks. */ |
68 | struct timespec tmo; |
69 | if (clock_gettime (clock_id: clocks[t], tp: &tmo) == -1) |
70 | /* For clocks not supported, create a large timeout (it should |
71 | fail early with EINVAL). */ |
72 | tmo = make_timespec (s: -1, ns: 0); |
73 | else |
74 | tmo = timespec_add (tmo, make_timespec (s: 0, ns: 100000000)); |
75 | |
76 | int ret = clocks[t] == CLOCK_REALTIME || clocks[t] == CLOCK_MONOTONIC |
77 | ? ETIMEDOUT : EINVAL; |
78 | |
79 | TEST_COMPARE (pthread_clockjoin_np (thr, NULL, clocks[t], &tmo), ret); |
80 | } |
81 | |
82 | return 0; |
83 | } |
84 | |
85 | #include <support/test-driver.c> |
86 | |