LoongArch: Use "$fcsr0" instead of "$r0" in _FPU_{GET,SET}CW
[glibc.git] / sysdeps / pthread / tst-cond23.c
blob4a86effebe93bd6d9dcdf5c8b241dacb0c2625f4
1 /* Copyright (C) 2008-2024 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 #include <errno.h>
19 #include <pthread.h>
20 #include <stdio.h>
21 #include <time.h>
22 #include <unistd.h>
25 #if defined _POSIX_CLOCK_SELECTION && _POSIX_CLOCK_SELECTION >= 0
26 static int
27 check (pthread_condattr_t *condattr, int pshared, clockid_t cl)
29 clockid_t cl2;
30 if (pthread_condattr_getclock (condattr, &cl2) != 0)
32 puts ("condattr_getclock failed");
33 return 1;
35 if (cl != cl2)
37 printf ("condattr_getclock returned wrong value: %d, expected %d\n",
38 (int) cl2, (int) cl);
39 return 1;
42 int p;
43 if (pthread_condattr_getpshared (condattr, &p) != 0)
45 puts ("condattr_getpshared failed");
46 return 1;
48 else if (p != pshared)
50 printf ("condattr_getpshared returned wrong value: %d, expected %d\n",
51 p, pshared);
52 return 1;
55 return 0;
58 static int
59 run_test (clockid_t cl)
61 pthread_condattr_t condattr;
63 printf ("clock = %d\n", (int) cl);
65 if (pthread_condattr_init (&condattr) != 0)
67 puts ("condattr_init failed");
68 return 1;
71 if (check (&condattr, PTHREAD_PROCESS_PRIVATE, CLOCK_REALTIME))
72 return 1;
74 if (pthread_condattr_setpshared (&condattr, PTHREAD_PROCESS_SHARED) != 0)
76 puts ("1st condattr_setpshared failed");
77 return 1;
80 if (check (&condattr, PTHREAD_PROCESS_SHARED, CLOCK_REALTIME))
81 return 1;
83 if (pthread_condattr_setclock (&condattr, cl) != 0)
85 puts ("1st condattr_setclock failed");
86 return 1;
89 if (check (&condattr, PTHREAD_PROCESS_SHARED, cl))
90 return 1;
92 if (pthread_condattr_setpshared (&condattr, PTHREAD_PROCESS_PRIVATE) != 0)
94 puts ("2nd condattr_setpshared failed");
95 return 1;
98 if (check (&condattr, PTHREAD_PROCESS_PRIVATE, cl))
99 return 1;
101 if (pthread_condattr_setclock (&condattr, CLOCK_REALTIME) != 0)
103 puts ("2nd condattr_setclock failed");
104 return 1;
107 if (check (&condattr, PTHREAD_PROCESS_PRIVATE, CLOCK_REALTIME))
108 return 1;
110 if (pthread_condattr_setclock (&condattr, cl) != 0)
112 puts ("3rd condattr_setclock failed");
113 return 1;
116 if (check (&condattr, PTHREAD_PROCESS_PRIVATE, cl))
117 return 1;
119 if (pthread_condattr_setpshared (&condattr, PTHREAD_PROCESS_SHARED) != 0)
121 puts ("3rd condattr_setpshared failed");
122 return 1;
125 if (check (&condattr, PTHREAD_PROCESS_SHARED, cl))
126 return 1;
128 if (pthread_condattr_setclock (&condattr, CLOCK_REALTIME) != 0)
130 puts ("4th condattr_setclock failed");
131 return 1;
134 if (check (&condattr, PTHREAD_PROCESS_SHARED, CLOCK_REALTIME))
135 return 1;
137 if (pthread_condattr_destroy (&condattr) != 0)
139 puts ("condattr_destroy failed");
140 return 1;
143 return 0;
145 #endif
148 static int
149 do_test (void)
151 #if !defined _POSIX_CLOCK_SELECTION || _POSIX_CLOCK_SELECTION == -1
153 puts ("_POSIX_CLOCK_SELECTION not supported, test skipped");
154 return 0;
156 #else
158 int res = run_test (CLOCK_REALTIME);
160 # if defined _POSIX_MONOTONIC_CLOCK && _POSIX_MONOTONIC_CLOCK >= 0
161 # if _POSIX_MONOTONIC_CLOCK == 0
162 int e = sysconf (_SC_MONOTONIC_CLOCK);
163 if (e < 0)
164 puts ("CLOCK_MONOTONIC not supported");
165 else if (e == 0)
167 puts ("sysconf (_SC_MONOTONIC_CLOCK) must not return 0");
168 res = 1;
170 else
171 # endif
172 res |= run_test (CLOCK_MONOTONIC);
173 # else
174 puts ("_POSIX_MONOTONIC_CLOCK not defined");
175 # endif
177 return res;
178 #endif
181 #define TEST_FUNCTION do_test ()
182 #include "../test-skeleton.c"