Actually define and export pthread_mutexattr_[sg]etrobust.
[glibc.git] / nptl / tst-cond23.c
blob254d821cc93bb3ac15d9c51836c10e79fa879e39
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
18 02111-1307 USA. */
20 #include <errno.h>
21 #include <pthread.h>
22 #include <stdio.h>
23 #include <time.h>
24 #include <unistd.h>
27 #if defined _POSIX_CLOCK_SELECTION && _POSIX_CLOCK_SELECTION >= 0
28 static int
29 check (pthread_condattr_t *condattr, int pshared, clockid_t cl)
31 clockid_t cl2;
32 if (pthread_condattr_getclock (condattr, &cl2) != 0)
34 puts ("condattr_getclock failed");
35 return 1;
37 if (cl != cl2)
39 printf ("condattr_getclock returned wrong value: %d, expected %d\n",
40 (int) cl2, (int) cl);
41 return 1;
44 int p;
45 if (pthread_condattr_getpshared (condattr, &p) != 0)
47 puts ("condattr_getpshared failed");
48 return 1;
50 else if (p != pshared)
52 printf ("condattr_getpshared returned wrong value: %d, expected %d\n",
53 p, pshared);
54 return 1;
57 return 0;
60 static int
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");
70 return 1;
73 if (check (&condattr, PTHREAD_PROCESS_PRIVATE, CLOCK_REALTIME))
74 return 1;
76 if (pthread_condattr_setpshared (&condattr, PTHREAD_PROCESS_SHARED) != 0)
78 puts ("1st condattr_setpshared failed");
79 return 1;
82 if (check (&condattr, PTHREAD_PROCESS_SHARED, CLOCK_REALTIME))
83 return 1;
85 if (pthread_condattr_setclock (&condattr, cl) != 0)
87 puts ("1st condattr_setclock failed");
88 return 1;
91 if (check (&condattr, PTHREAD_PROCESS_SHARED, cl))
92 return 1;
94 if (pthread_condattr_setpshared (&condattr, PTHREAD_PROCESS_PRIVATE) != 0)
96 puts ("2nd condattr_setpshared failed");
97 return 1;
100 if (check (&condattr, PTHREAD_PROCESS_PRIVATE, cl))
101 return 1;
103 if (pthread_condattr_setclock (&condattr, CLOCK_REALTIME) != 0)
105 puts ("2nd condattr_setclock failed");
106 return 1;
109 if (check (&condattr, PTHREAD_PROCESS_PRIVATE, CLOCK_REALTIME))
110 return 1;
112 if (pthread_condattr_setclock (&condattr, cl) != 0)
114 puts ("3rd condattr_setclock failed");
115 return 1;
118 if (check (&condattr, PTHREAD_PROCESS_PRIVATE, cl))
119 return 1;
121 if (pthread_condattr_setpshared (&condattr, PTHREAD_PROCESS_SHARED) != 0)
123 puts ("3rd condattr_setpshared failed");
124 return 1;
127 if (check (&condattr, PTHREAD_PROCESS_SHARED, cl))
128 return 1;
130 if (pthread_condattr_setclock (&condattr, CLOCK_REALTIME) != 0)
132 puts ("4th condattr_setclock failed");
133 return 1;
136 if (check (&condattr, PTHREAD_PROCESS_SHARED, CLOCK_REALTIME))
137 return 1;
139 if (pthread_condattr_destroy (&condattr) != 0)
141 puts ("condattr_destroy failed");
142 return 1;
145 return 0;
147 #endif
150 static int
151 do_test (void)
153 #if !defined _POSIX_CLOCK_SELECTION || _POSIX_CLOCK_SELECTION == -1
155 puts ("_POSIX_CLOCK_SELECTION not supported, test skipped");
156 return 0;
158 #else
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);
165 if (e < 0)
166 puts ("CLOCK_MONOTONIC not supported");
167 else if (e == 0)
169 puts ("sysconf (_SC_MONOTONIC_CLOCK) must not return 0");
170 res = 1;
172 else
173 # endif
174 res |= run_test (CLOCK_MONOTONIC);
175 # else
176 puts ("_POSIX_MONOTONIC_CLOCK not defined");
177 # endif
179 return res;
180 #endif
183 #define TEST_FUNCTION do_test ()
184 #include "../test-skeleton.c"