m68k: Consolidate NPTL/non versions of vfork
[glibc.git] / setjmp / tst-setjmp-fp.c
blobd84c47ed5c4a4ce02053e119a784944dc3c1db06
1 /* Test that setjmp/longjmp do not save and restore floating-point
2 exceptions and rounding modes.
3 Copyright (C) 2013-2014 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #include <fenv.h>
21 #include <setjmp.h>
22 #include <stdio.h>
23 #include <stdlib.h>
25 static jmp_buf env;
26 static int result = 0;
28 #if defined FE_TONEAREST && defined FE_TOWARDZERO
29 static int expected_rounding_mode = FE_TONEAREST;
31 static void
32 change_rounding_mode (void)
34 if (fesetround (FE_TOWARDZERO) == 0)
35 expected_rounding_mode = FE_TOWARDZERO;
36 else
37 puts ("fesetround (FE_TOWARDZERO) failed, continuing test");
38 longjmp (env, 1);
40 #endif
42 #ifdef FE_INVALID
43 static int expected_exceptions = 0;
45 static void
46 raise_exception (void)
48 if (feraiseexcept (FE_INVALID) == 0)
49 expected_exceptions = FE_INVALID;
50 else
51 puts ("feraiseexcept (FE_INVALID) failed, continuing test");
52 longjmp (env, 1);
54 #endif
56 static int
57 do_test (void)
59 #if defined FE_TONEAREST && defined FE_TOWARDZERO
60 if (fesetround (FE_TONEAREST) == 0)
62 if (setjmp (env) == 0)
63 change_rounding_mode ();
64 else
66 if (fegetround () == expected_rounding_mode)
67 puts ("PASS: longjmp preserved rounding mode");
68 else
70 puts ("FAIL: longjmp changed rounding mode");
71 result = 1;
75 else
76 puts ("fesetround (FE_TONEAREST) failed, not testing rounding modes");
77 #else
78 puts ("rounding mode test not supported");
79 #endif
80 #ifdef FE_INVALID
81 if (feclearexcept (FE_ALL_EXCEPT) == 0)
83 if (setjmp (env) == 0)
84 raise_exception ();
85 else
87 if (fetestexcept (FE_INVALID) == expected_exceptions)
88 puts ("PASS: longjmp preserved exceptions");
89 else
91 puts ("FAIL: longjmp changed exceptions");
92 result = 1;
96 else
97 puts ("feclearexcept (FE_ALL_EXCEPT) failed, not testing exceptions");
98 #else
99 puts ("exception test not supported");
100 #endif
101 return result;
104 #define TEST_FUNCTION do_test ()
105 #include "../test-skeleton.c"