1 /* Copyright (C) 2003, 2004, 2009 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, 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 run_test (clockid_t cl
)
31 pthread_condattr_t condattr
;
33 pthread_mutexattr_t mutattr
;
36 printf ("clock = %d\n", (int) cl
);
38 if (pthread_condattr_init (&condattr
) != 0)
40 puts ("condattr_init failed");
44 if (pthread_condattr_setclock (&condattr
, cl
) != 0)
46 puts ("condattr_setclock failed");
51 if (pthread_condattr_getclock (&condattr
, &cl2
) != 0)
53 puts ("condattr_getclock failed");
58 printf ("condattr_getclock returned wrong value: %d, expected %d\n",
63 if (pthread_cond_init (&cond
, &condattr
) != 0)
65 puts ("cond_init failed");
69 if (pthread_condattr_destroy (&condattr
) != 0)
71 puts ("condattr_destroy failed");
75 if (pthread_mutexattr_init (&mutattr
) != 0)
77 puts ("mutexattr_init failed");
81 if (pthread_mutexattr_settype (&mutattr
, PTHREAD_MUTEX_ERRORCHECK
) != 0)
83 puts ("mutexattr_settype failed");
87 if (pthread_mutex_init (&mut
, &mutattr
) != 0)
89 puts ("mutex_init failed");
93 if (pthread_mutexattr_destroy (&mutattr
) != 0)
95 puts ("mutexattr_destroy failed");
99 if (pthread_mutex_lock (&mut
) != 0)
101 puts ("mutex_lock failed");
105 if (pthread_mutex_lock (&mut
) != EDEADLK
)
107 puts ("2nd mutex_lock did not return EDEADLK");
112 if (clock_gettime (cl
, &ts
) != 0)
114 puts ("clock_gettime failed");
118 /* Wait one second. */
121 int e
= pthread_cond_timedwait (&cond
, &mut
, &ts
);
124 puts ("cond_timedwait succeeded");
127 else if (e
!= ETIMEDOUT
)
129 puts ("cond_timedwait did not return ETIMEDOUT");
134 if (clock_gettime (cl
, &ts2
) != 0)
136 puts ("second clock_gettime failed");
140 if (ts2
.tv_sec
< ts
.tv_sec
141 || (ts2
.tv_sec
== ts
.tv_sec
&& ts2
.tv_nsec
< ts
.tv_nsec
))
143 puts ("timeout too short");
147 if (pthread_mutex_unlock (&mut
) != 0)
149 puts ("mutex_unlock failed");
153 if (pthread_mutex_destroy (&mut
) != 0)
155 puts ("mutex_destroy failed");
159 if (pthread_cond_destroy (&cond
) != 0)
161 puts ("cond_destroy failed");
173 #if !defined _POSIX_CLOCK_SELECTION || _POSIX_CLOCK_SELECTION == -1
175 puts ("_POSIX_CLOCK_SELECTION not supported, test skipped");
180 int res
= run_test (CLOCK_REALTIME
);
182 # if defined _POSIX_MONOTONIC_CLOCK && _POSIX_MONOTONIC_CLOCK >= 0
183 # if _POSIX_MONOTONIC_CLOCK == 0
184 int e
= sysconf (_SC_MONOTONIC_CLOCK
);
186 puts ("CLOCK_MONOTONIC not supported");
189 puts ("sysconf (_SC_MONOTONIC_CLOCK) must not return 0");
194 res
|= run_test (CLOCK_MONOTONIC
);
196 puts ("_POSIX_MONOTONIC_CLOCK not defined");
204 #define TEST_FUNCTION do_test ()
205 #include "../test-skeleton.c"