1 /* Copyright (C) 2008 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27 #if defined _POSIX_CLOCK_SELECTION && _POSIX_CLOCK_SELECTION >= 0
29 check (pthread_condattr_t
*condattr
, int pshared
, clockid_t cl
)
32 if (pthread_condattr_getclock (condattr
, &cl2
) != 0)
34 puts ("condattr_getclock failed");
39 printf ("condattr_getclock returned wrong value: %d, expected %d\n",
45 if (pthread_condattr_getpshared (condattr
, &p
) != 0)
47 puts ("condattr_getpshared failed");
50 else if (p
!= pshared
)
52 printf ("condattr_getpshared returned wrong value: %d, expected %d\n",
61 run_test (clockid_t cl
)
63 pthread_condattr_t condattr
;
65 printf ("clock = %d\n", (int) cl
);
67 if (pthread_condattr_init (&condattr
) != 0)
69 puts ("condattr_init failed");
73 if (check (&condattr
, PTHREAD_PROCESS_PRIVATE
, CLOCK_REALTIME
))
76 if (pthread_condattr_setpshared (&condattr
, PTHREAD_PROCESS_SHARED
) != 0)
78 puts ("1st condattr_setpshared failed");
82 if (check (&condattr
, PTHREAD_PROCESS_SHARED
, CLOCK_REALTIME
))
85 if (pthread_condattr_setclock (&condattr
, cl
) != 0)
87 puts ("1st condattr_setclock failed");
91 if (check (&condattr
, PTHREAD_PROCESS_SHARED
, cl
))
94 if (pthread_condattr_setpshared (&condattr
, PTHREAD_PROCESS_PRIVATE
) != 0)
96 puts ("2nd condattr_setpshared failed");
100 if (check (&condattr
, PTHREAD_PROCESS_PRIVATE
, cl
))
103 if (pthread_condattr_setclock (&condattr
, CLOCK_REALTIME
) != 0)
105 puts ("2nd condattr_setclock failed");
109 if (check (&condattr
, PTHREAD_PROCESS_PRIVATE
, CLOCK_REALTIME
))
112 if (pthread_condattr_setclock (&condattr
, cl
) != 0)
114 puts ("3rd condattr_setclock failed");
118 if (check (&condattr
, PTHREAD_PROCESS_PRIVATE
, cl
))
121 if (pthread_condattr_setpshared (&condattr
, PTHREAD_PROCESS_SHARED
) != 0)
123 puts ("3rd condattr_setpshared failed");
127 if (check (&condattr
, PTHREAD_PROCESS_SHARED
, cl
))
130 if (pthread_condattr_setclock (&condattr
, CLOCK_REALTIME
) != 0)
132 puts ("4th condattr_setclock failed");
136 if (check (&condattr
, PTHREAD_PROCESS_SHARED
, CLOCK_REALTIME
))
139 if (pthread_condattr_destroy (&condattr
) != 0)
141 puts ("condattr_destroy failed");
153 #if !defined _POSIX_CLOCK_SELECTION || _POSIX_CLOCK_SELECTION == -1
155 puts ("_POSIX_CLOCK_SELECTION not supported, test skipped");
160 int res
= run_test (CLOCK_REALTIME
);
162 # if defined _POSIX_MONOTONIC_CLOCK && _POSIX_MONOTONIC_CLOCK >= 0
163 # if _POSIX_MONOTONIC_CLOCK == 0
164 int e
= sysconf (_SC_MONOTONIC_CLOCK
);
166 puts ("CLOCK_MONOTONIC not supported");
169 puts ("sysconf (_SC_MONOTONIC_CLOCK) must not return 0");
174 res
|= run_test (CLOCK_MONOTONIC
);
176 puts ("_POSIX_MONOTONIC_CLOCK not defined");
183 #define TEST_FUNCTION do_test ()
184 #include "../test-skeleton.c"