1 /* Copyright (C) 2014-2021 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/>. */
25 #include <sys/prctl.h>
27 #if __mips_fpr != 0 || _MIPS_SPFPSET != 16
28 # error This test requires -mfpxx -mno-odd-spreg
31 /* This test verifies that all threads in a process see a mode
32 change when any thread causes a mode change. */
38 PR_FP_MODE_FR | PR_FP_MODE_FRE,
41 PR_FP_MODE_FR | PR_FP_MODE_FRE
43 static volatile int current_mode;
44 static volatile int finished;
45 static pthread_barrier_t barr_ready;
46 static pthread_barrier_t barr_cont;
49 thread_function (void * arg __attribute__ ((unused)))
53 int res = pthread_barrier_wait (&barr_ready);
55 if (res != 0 && res != PTHREAD_BARRIER_SERIAL_THREAD)
57 printf ("barrier wait failed: %m\n");
61 int mode = prctl (PR_GET_FP_MODE);
63 if (mode != current_mode)
65 printf ("unexpected mode: %d != %d\n", mode, current_mode);
69 res = pthread_barrier_wait (&barr_cont);
71 if (res != 0 && res != PTHREAD_BARRIER_SERIAL_THREAD)
73 printf ("barrier wait failed: %m\n");
83 int count = sysconf (_SC_NPROCESSORS_ONLN);
92 if (pthread_barrier_init (&barr_ready, NULL, count + 1) != 0)
94 printf ("failed to initialize barrier: %m\n");
98 if (pthread_barrier_init (&barr_cont, NULL, count + 1) != 0)
100 printf ("failed to initialize barrier: %m\n");
104 for (i = 0; i < count; ++i)
105 if (pthread_create (&th[i], NULL, thread_function, 0) != 0)
107 printf ("creation of thread %d failed\n", i);
111 for (i = 0 ; i < 7 ; i++)
113 if (prctl (PR_SET_FP_MODE, mode[i % 6]) != 0)
115 if (errno != ENOTSUP)
117 printf ("prctl PR_SET_FP_MODE failed: %m");
122 current_mode = mode[i % 6];
125 int res = pthread_barrier_wait (&barr_ready);
127 if (res != 0 && res != PTHREAD_BARRIER_SERIAL_THREAD)
129 printf ("barrier wait failed: %m\n");
136 res = pthread_barrier_wait (&barr_cont);
138 if (res != 0 && res != PTHREAD_BARRIER_SERIAL_THREAD)
140 printf ("barrier wait failed: %m\n");
145 for (i = 0; i < count; ++i)
148 if (pthread_join (th[i], &v) != 0)
150 printf ("join of thread %d failed\n", i);
155 printf ("join %d successful, but child failed\n", i);
159 printf ("join %d successful\n", i);
165 #define TEST_FUNCTION do_test ()
166 #include "../../test-skeleton.c"