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, 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");
133 if (pthread_mutex_unlock (&mut) != 0)
135 puts ("mutex_unlock failed");
139 if (pthread_mutex_destroy (&mut) != 0)
141 puts ("mutex_destroy failed");
145 if (pthread_cond_destroy (&cond) != 0)
147 puts ("cond_destroy failed");
159 #if !defined _POSIX_CLOCK_SELECTION || _POSIX_CLOCK_SELECTION == -1
161 puts ("_POSIX_CLOCK_SELECTION not supported, test skipped");
166 int res = run_test (CLOCK_REALTIME);
168 # if defined _POSIX_MONOTONIC_CLOCK && _POSIX_MONOTONIC_CLOCK >= 0
169 # if _POSIX_MONOTONIC_CLOCK == 0
170 int e = sysconf (_SC_MONOTONIC_CLOCK);
172 puts ("CLOCK_MONOTONIC not supported");
175 puts ("sysconf (_SC_MONOTONIC_CLOCK) must not return 0");
180 res |= run_test (CLOCK_MONOTONIC);
182 puts ("_POSIX_MONOTONIC_CLOCK not defined");
190 #define TEST_FUNCTION do_test ()
191 #include "../test-skeleton.c"