posix: Correctly enable/disable cancellation on Linux posix_spawn
[glibc.git] / math / test-fesetexcept.c
blob912a9a6baded995a74548640b117a272083a61f0
1 /* Test fesetexcept.
2 Copyright (C) 2016 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/>. */
19 #include <fenv.h>
20 #include <stdio.h>
21 #include <math-tests.h>
23 static int
24 test_fesetexcept (int exc, const char *exc_name)
26 int result = 0;
28 printf ("Testing %s\n", exc_name);
29 feclearexcept (FE_ALL_EXCEPT);
30 int ret = fesetexcept (exc);
31 if (ret == 0)
32 printf ("fesetexcept (%s) succeeded\n", exc_name);
33 else
35 printf ("fesetexcept (%s) failed\n", exc_name);
36 if (exc == 0 || EXCEPTION_TESTS (float))
38 puts ("failure of fesetexcept was unexpected");
39 result = 1;
41 else
42 puts ("failure of fesetexcept OK, skipping further tests");
43 return result;
45 ret = fetestexcept (FE_ALL_EXCEPT);
46 if (ret != exc)
48 printf ("raised exceptions %x, expected %x\n",
49 (unsigned int) ret, (unsigned int) exc);
50 result = 1;
53 ret = feraiseexcept (FE_ALL_EXCEPT);
54 if (ret != 0)
56 if (exc == 0 && !EXCEPTION_TESTS (float))
58 puts ("feraiseexcept (FE_ALL_EXCEPT) failed, skipping further tests");
59 return result;
61 puts ("feraiseexcept (FE_ALL_EXCEPT) unexpectedly failed");
62 result = 1;
64 ret = fesetexcept (exc);
65 if (ret != 0)
67 puts ("fesetexcept (second test) unexpectedly failed");
68 result = 1;
70 ret = fetestexcept (FE_ALL_EXCEPT);
71 if (ret != FE_ALL_EXCEPT)
73 printf ("raised exceptions (second test) %x, expected %x\n",
74 (unsigned int) ret, (unsigned int) FE_ALL_EXCEPT);
75 result = 1;
78 feclearexcept (FE_ALL_EXCEPT);
79 ret = feraiseexcept (FE_ALL_EXCEPT & ~exc);
80 if (ret != 0)
82 puts ("feraiseexcept (third test) unexpectedly failed");
83 result = 1;
85 ret = fesetexcept (exc);
86 if (ret != 0)
88 puts ("fesetexcept (third test) unexpectedly failed");
89 result = 1;
91 ret = fetestexcept (FE_ALL_EXCEPT);
92 if (ret != FE_ALL_EXCEPT)
94 printf ("raised exceptions (third test) %x, expected %x\n",
95 (unsigned int) ret, (unsigned int) FE_ALL_EXCEPT);
96 result = 1;
99 return result;
102 static int
103 do_test (void)
105 int result = 0;
107 result |= test_fesetexcept (0, "0");
108 result |= test_fesetexcept (FE_ALL_EXCEPT, "FE_ALL_EXCEPT");
109 #ifdef FE_DIVBYZERO
110 result |= test_fesetexcept (FE_DIVBYZERO, "FE_DIVBYZERO");
111 #endif
112 #ifdef FE_INEXACT
113 result |= test_fesetexcept (FE_INEXACT, "FE_INEXACT");
114 #endif
115 #ifdef FE_INVALID
116 result |= test_fesetexcept (FE_INVALID, "FE_INVALID");
117 #endif
118 #ifdef FE_OVERFLOW
119 result |= test_fesetexcept (FE_OVERFLOW, "FE_OVERFLOW");
120 #endif
121 #ifdef FE_UNDERFLOW
122 result |= test_fesetexcept (FE_UNDERFLOW, "FE_UNDERFLOW");
123 #endif
125 return result;
128 #define TEST_FUNCTION do_test ()
129 #include "../test-skeleton.c"