1 /* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
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 run_test (clockid_t cl
)
30 pthread_condattr_t condattr
;
32 pthread_mutexattr_t mutattr
;
35 printf ("clock = %d\n", (int) cl
);
37 if (pthread_condattr_init (&condattr
) != 0)
39 puts ("condattr_init failed");
43 if (pthread_condattr_setclock (&condattr
, cl
) != 0)
45 puts ("condattr_setclock failed");
50 if (pthread_condattr_getclock (&condattr
, &cl2
) != 0)
52 puts ("condattr_getclock failed");
57 printf ("condattr_getclock returned wrong value: %d, expected %d\n",
62 if (pthread_cond_init (&cond
, &condattr
) != 0)
64 puts ("cond_init failed");
68 if (pthread_condattr_destroy (&condattr
) != 0)
70 puts ("condattr_destroy failed");
74 if (pthread_mutexattr_init (&mutattr
) != 0)
76 puts ("mutexattr_init failed");
80 if (pthread_mutexattr_settype (&mutattr
, PTHREAD_MUTEX_ERRORCHECK
) != 0)
82 puts ("mutexattr_settype failed");
86 if (pthread_mutex_init (&mut
, &mutattr
) != 0)
88 puts ("mutex_init failed");
92 if (pthread_mutexattr_destroy (&mutattr
) != 0)
94 puts ("mutexattr_destroy failed");
98 if (pthread_mutex_lock (&mut
) != 0)
100 puts ("mutex_lock failed");
104 if (pthread_mutex_lock (&mut
) != EDEADLK
)
106 puts ("2nd mutex_lock did not return EDEADLK");
111 if (clock_gettime (cl
, &ts
) != 0)
113 puts ("clock_gettime failed");
117 /* Wait one second. */
120 int e
= pthread_cond_timedwait (&cond
, &mut
, &ts
);
123 puts ("cond_timedwait succeeded");
126 else if (e
!= ETIMEDOUT
)
128 puts ("cond_timedwait did not return ETIMEDOUT");
132 if (pthread_mutex_unlock (&mut
) != 0)
134 puts ("mutex_unlock failed");
138 if (pthread_mutex_destroy (&mut
) != 0)
140 puts ("mutex_destroy failed");
144 if (pthread_cond_destroy (&cond
) != 0)
146 puts ("cond_destroy failed");
158 #if !defined _POSIX_CLOCK_SELECTION || _POSIX_CLOCK_SELECTION == -1
160 puts ("_POSIX_CLOCK_SELECTION not supported, test skipped");
165 int res
= run_test (CLOCK_REALTIME
);
167 # if defined _POSIX_MONOTONIC_CLOCK && _POSIX_MONOTONIC_CLOCK >= 0
168 # if _POSIX_MONOTONIC_CLOCK == 0
169 int e
= sysconf (_SC_MONOTONIC_CLOCK
);
171 puts ("CLOCK_MONOTONIC not supported");
174 puts ("sysconf (_SC_MONOTONIC_CLOCK) must not return 0");
179 res
|= run_test (CLOCK_MONOTONIC
);
181 puts ("_POSIX_MONOTONIC_CLOCK not defined");
189 #define TEST_FUNCTION do_test ()
190 #include "../test-skeleton.c"