1 /* Test floating-point environment is thread-local.
2 Copyright (C) 2013 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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, see
17 <http://www.gnu.org/licenses/>. */
24 #define TEST_ONE_RM(RM) \
27 if (fesetround (RM) == 0) \
32 printf ("expected " #RM ", got %d\n", rm); \
40 test_round (void *arg
)
43 for (int i
= 0; i
< 10000; i
++)
47 TEST_ONE_RM (FE_DOWNWARD
);
50 TEST_ONE_RM (FE_TONEAREST
);
53 TEST_ONE_RM (FE_TOWARDZERO
);
56 TEST_ONE_RM (FE_UPWARD
);
62 #define TEST_ONE_RAISE(EX) \
65 if (feraiseexcept (EX) == 0) \
66 if (fetestexcept (EX) != EX) \
68 printf (#EX " not raised\n"); \
71 if (feclearexcept (FE_ALL_EXCEPT) == 0) \
72 if (fetestexcept (FE_ALL_EXCEPT) != 0) \
74 printf ("exceptions not all cleared\n"); \
81 test_raise (void *arg
)
84 for (int i
= 0; i
< 10000; i
++)
87 TEST_ONE_RAISE (FE_DIVBYZERO
);
90 TEST_ONE_RAISE (FE_INEXACT
);
93 TEST_ONE_RAISE (FE_INVALID
);
96 TEST_ONE_RAISE (FE_OVERFLOW
);
99 TEST_ONE_RAISE (FE_UNDERFLOW
);
105 #define TEST_ONE_ENABLE(EX) \
108 if (feenableexcept (EX) != -1) \
109 if (fegetexcept () != EX) \
111 printf (#EX " not enabled\n"); \
114 if (fedisableexcept (EX) != -1) \
115 if (fegetexcept () != 0) \
117 printf ("exceptions not all disabled\n"); \
124 test_enable (void *arg
)
127 for (int i
= 0; i
< 10000; i
++)
130 TEST_ONE_ENABLE (FE_DIVBYZERO
);
133 TEST_ONE_ENABLE (FE_INEXACT
);
136 TEST_ONE_ENABLE (FE_INVALID
);
139 TEST_ONE_ENABLE (FE_OVERFLOW
);
142 TEST_ONE_ENABLE (FE_UNDERFLOW
);
156 pret
= pthread_create (&thread_id
, NULL
, test_round
, NULL
);
159 printf ("pthread_create failed: %d\n", pret
);
162 vret
= test_round (NULL
);
163 ret
|= (intptr_t) vret
;
164 pret
= pthread_join (thread_id
, &vret
);
167 printf ("pthread_join failed: %d\n", pret
);
170 ret
|= (intptr_t) vret
;
172 pret
= pthread_create (&thread_id
, NULL
, test_raise
, NULL
);
175 printf ("pthread_create failed: %d\n", pret
);
178 vret
= test_raise (NULL
);
179 ret
|= (intptr_t) vret
;
180 pret
= pthread_join (thread_id
, &vret
);
183 printf ("pthread_join failed: %d\n", pret
);
186 ret
|= (intptr_t) vret
;
188 pret
= pthread_create (&thread_id
, NULL
, test_enable
, NULL
);
191 printf ("pthread_create failed: %d\n", pret
);
194 vret
= test_enable (NULL
);
195 ret
|= (intptr_t) vret
;
196 pret
= pthread_join (thread_id
, &vret
);
199 printf ("pthread_join failed: %d\n", pret
);
202 ret
|= (intptr_t) vret
;
207 #define TEST_FUNCTION do_test ()
208 #include "../test-skeleton.c"