Linux: Assume and consolidate getpeername wire-up syscall
[glibc.git] / math / test-femode-traps.c
blobc4ac963026821acba8de7be2f40c7da1b822babe
1 /* Test femode_t functions: test handling of exception traps.
2 Copyright (C) 2016-2023 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 <https://www.gnu.org/licenses/>. */
19 #include <fenv.h>
20 #include <stdio.h>
21 #include <math-tests.h>
23 static int
24 test_ee (int exc1, int exc2)
26 int result = 0;
27 printf ("testing %x %x\n", (unsigned int) exc1, (unsigned int) exc2);
29 fedisableexcept (FE_ALL_EXCEPT);
30 int ret = feenableexcept (exc1);
31 if (ret == -1)
33 if (EXCEPTION_ENABLE_SUPPORTED (exc1))
35 puts ("first feenableexcept failed unexpectedly");
36 result = 1;
38 else
39 puts ("first feenableexcept failed, cannot test");
40 return result;
42 femode_t saved;
43 ret = fegetmode (&saved);
44 if (ret != 0)
46 puts ("fegetmode failed");
47 result = 1;
48 return result;
50 fedisableexcept (FE_ALL_EXCEPT);
51 ret = feenableexcept (exc2);
52 if (ret == -1)
54 if (EXCEPTION_ENABLE_SUPPORTED (exc2))
56 puts ("second feenableexcept failed unexpectedly");
57 result = 1;
59 else
60 puts ("second feenableexcept failed, cannot test");
61 return result;
63 ret = fesetmode (&saved);
64 if (ret != 0)
66 puts ("fesetmode failed");
67 result = 1;
68 return result;
70 /* Verify that the set of enabled traps was restored. */
71 ret = fegetexcept ();
72 if (ret != exc1)
74 printf ("restored enabled traps %x not %x\n", (unsigned int) ret,
75 (unsigned int) exc1);
76 result = 1;
78 /* Likewise, with default modes. */
79 ret = fesetmode (FE_DFL_MODE);
80 if (ret != 0)
82 puts ("fesetmode (FE_DFL_MODE) failed");
83 result = 1;
84 return result;
86 ret = fegetexcept ();
87 if (ret != 0)
89 printf ("FE_DFL_MODE enabled traps %x not 0\n", (unsigned int) ret);
90 result = 1;
93 return result;
96 static int
97 test_e (int exc1)
99 int result = 0;
101 result |= test_ee (exc1, 0);
102 result |= test_ee (exc1, FE_ALL_EXCEPT);
103 #ifdef FE_DIVBYZERO
104 result |= test_ee (exc1, FE_DIVBYZERO);
105 #endif
106 #ifdef FE_INEXACT
107 result |= test_ee (exc1, FE_INEXACT);
108 #endif
109 #ifdef FE_INVALID
110 result |= test_ee (exc1, FE_INVALID);
111 #endif
112 #ifdef FE_OVERFLOW
113 result |= test_ee (exc1, FE_OVERFLOW);
114 #endif
115 #ifdef FE_UNDERFLOW
116 result |= test_ee (exc1, FE_UNDERFLOW);
117 #endif
119 return result;
122 static int
123 do_test (void)
125 int result = 0;
127 result |= test_e (0);
128 result |= test_e (FE_ALL_EXCEPT);
129 #ifdef FE_DIVBYZERO
130 result |= test_e (FE_DIVBYZERO);
131 #endif
132 #ifdef FE_INEXACT
133 result |= test_e (FE_INEXACT);
134 #endif
135 #ifdef FE_INVALID
136 result |= test_e (FE_INVALID);
137 #endif
138 #ifdef FE_OVERFLOW
139 result |= test_e (FE_OVERFLOW);
140 #endif
141 #ifdef FE_UNDERFLOW
142 result |= test_e (FE_UNDERFLOW);
143 #endif
145 return result;
148 #define TEST_FUNCTION do_test ()
149 #include "../test-skeleton.c"