1 /* Copyright (C) 2008-2013 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Jakub Jelinek <jakub@redhat.com>, 2008.
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 <http://www.gnu.org/licenses/>. */
26 #if defined _POSIX_CLOCK_SELECTION && _POSIX_CLOCK_SELECTION >= 0
28 check (pthread_condattr_t
*condattr
, int pshared
, clockid_t cl
)
31 if (pthread_condattr_getclock (condattr
, &cl2
) != 0)
33 puts ("condattr_getclock failed");
38 printf ("condattr_getclock returned wrong value: %d, expected %d\n",
44 if (pthread_condattr_getpshared (condattr
, &p
) != 0)
46 puts ("condattr_getpshared failed");
49 else if (p
!= pshared
)
51 printf ("condattr_getpshared returned wrong value: %d, expected %d\n",
60 run_test (clockid_t cl
)
62 pthread_condattr_t condattr
;
64 printf ("clock = %d\n", (int) cl
);
66 if (pthread_condattr_init (&condattr
) != 0)
68 puts ("condattr_init failed");
72 if (check (&condattr
, PTHREAD_PROCESS_PRIVATE
, CLOCK_REALTIME
))
75 if (pthread_condattr_setpshared (&condattr
, PTHREAD_PROCESS_SHARED
) != 0)
77 puts ("1st condattr_setpshared failed");
81 if (check (&condattr
, PTHREAD_PROCESS_SHARED
, CLOCK_REALTIME
))
84 if (pthread_condattr_setclock (&condattr
, cl
) != 0)
86 puts ("1st condattr_setclock failed");
90 if (check (&condattr
, PTHREAD_PROCESS_SHARED
, cl
))
93 if (pthread_condattr_setpshared (&condattr
, PTHREAD_PROCESS_PRIVATE
) != 0)
95 puts ("2nd condattr_setpshared failed");
99 if (check (&condattr
, PTHREAD_PROCESS_PRIVATE
, cl
))
102 if (pthread_condattr_setclock (&condattr
, CLOCK_REALTIME
) != 0)
104 puts ("2nd condattr_setclock failed");
108 if (check (&condattr
, PTHREAD_PROCESS_PRIVATE
, CLOCK_REALTIME
))
111 if (pthread_condattr_setclock (&condattr
, cl
) != 0)
113 puts ("3rd condattr_setclock failed");
117 if (check (&condattr
, PTHREAD_PROCESS_PRIVATE
, cl
))
120 if (pthread_condattr_setpshared (&condattr
, PTHREAD_PROCESS_SHARED
) != 0)
122 puts ("3rd condattr_setpshared failed");
126 if (check (&condattr
, PTHREAD_PROCESS_SHARED
, cl
))
129 if (pthread_condattr_setclock (&condattr
, CLOCK_REALTIME
) != 0)
131 puts ("4th condattr_setclock failed");
135 if (check (&condattr
, PTHREAD_PROCESS_SHARED
, CLOCK_REALTIME
))
138 if (pthread_condattr_destroy (&condattr
) != 0)
140 puts ("condattr_destroy failed");
152 #if !defined _POSIX_CLOCK_SELECTION || _POSIX_CLOCK_SELECTION == -1
154 puts ("_POSIX_CLOCK_SELECTION not supported, test skipped");
159 int res
= run_test (CLOCK_REALTIME
);
161 # if defined _POSIX_MONOTONIC_CLOCK && _POSIX_MONOTONIC_CLOCK >= 0
162 # if _POSIX_MONOTONIC_CLOCK == 0
163 int e
= sysconf (_SC_MONOTONIC_CLOCK
);
165 puts ("CLOCK_MONOTONIC not supported");
168 puts ("sysconf (_SC_MONOTONIC_CLOCK) must not return 0");
173 res
|= run_test (CLOCK_MONOTONIC
);
175 puts ("_POSIX_MONOTONIC_CLOCK not defined");
182 #define TEST_FUNCTION do_test ()
183 #include "../test-skeleton.c"