1 /* Copyright (C) 2008-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
25 #if defined _POSIX_CLOCK_SELECTION && _POSIX_CLOCK_SELECTION >= 0
27 check (pthread_condattr_t
*condattr
, int pshared
, clockid_t cl
)
30 if (pthread_condattr_getclock (condattr
, &cl2
) != 0)
32 puts ("condattr_getclock failed");
37 printf ("condattr_getclock returned wrong value: %d, expected %d\n",
43 if (pthread_condattr_getpshared (condattr
, &p
) != 0)
45 puts ("condattr_getpshared failed");
48 else if (p
!= pshared
)
50 printf ("condattr_getpshared returned wrong value: %d, expected %d\n",
59 run_test (clockid_t cl
)
61 pthread_condattr_t condattr
;
63 printf ("clock = %d\n", (int) cl
);
65 if (pthread_condattr_init (&condattr
) != 0)
67 puts ("condattr_init failed");
71 if (check (&condattr
, PTHREAD_PROCESS_PRIVATE
, CLOCK_REALTIME
))
74 if (pthread_condattr_setpshared (&condattr
, PTHREAD_PROCESS_SHARED
) != 0)
76 puts ("1st condattr_setpshared failed");
80 if (check (&condattr
, PTHREAD_PROCESS_SHARED
, CLOCK_REALTIME
))
83 if (pthread_condattr_setclock (&condattr
, cl
) != 0)
85 puts ("1st condattr_setclock failed");
89 if (check (&condattr
, PTHREAD_PROCESS_SHARED
, cl
))
92 if (pthread_condattr_setpshared (&condattr
, PTHREAD_PROCESS_PRIVATE
) != 0)
94 puts ("2nd condattr_setpshared failed");
98 if (check (&condattr
, PTHREAD_PROCESS_PRIVATE
, cl
))
101 if (pthread_condattr_setclock (&condattr
, CLOCK_REALTIME
) != 0)
103 puts ("2nd condattr_setclock failed");
107 if (check (&condattr
, PTHREAD_PROCESS_PRIVATE
, CLOCK_REALTIME
))
110 if (pthread_condattr_setclock (&condattr
, cl
) != 0)
112 puts ("3rd condattr_setclock failed");
116 if (check (&condattr
, PTHREAD_PROCESS_PRIVATE
, cl
))
119 if (pthread_condattr_setpshared (&condattr
, PTHREAD_PROCESS_SHARED
) != 0)
121 puts ("3rd condattr_setpshared failed");
125 if (check (&condattr
, PTHREAD_PROCESS_SHARED
, cl
))
128 if (pthread_condattr_setclock (&condattr
, CLOCK_REALTIME
) != 0)
130 puts ("4th condattr_setclock failed");
134 if (check (&condattr
, PTHREAD_PROCESS_SHARED
, CLOCK_REALTIME
))
137 if (pthread_condattr_destroy (&condattr
) != 0)
139 puts ("condattr_destroy failed");
151 #if !defined _POSIX_CLOCK_SELECTION || _POSIX_CLOCK_SELECTION == -1
153 puts ("_POSIX_CLOCK_SELECTION not supported, test skipped");
158 int res
= run_test (CLOCK_REALTIME
);
160 # if defined _POSIX_MONOTONIC_CLOCK && _POSIX_MONOTONIC_CLOCK >= 0
161 # if _POSIX_MONOTONIC_CLOCK == 0
162 int e
= sysconf (_SC_MONOTONIC_CLOCK
);
164 puts ("CLOCK_MONOTONIC not supported");
167 puts ("sysconf (_SC_MONOTONIC_CLOCK) must not return 0");
172 res
|= run_test (CLOCK_MONOTONIC
);
174 puts ("_POSIX_MONOTONIC_CLOCK not defined");
181 #define TEST_FUNCTION do_test ()
182 #include "../test-skeleton.c"