usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-fenv-env-6.c
blob39b01f04441b13faedaed10d657fac5cc7cf1e54
1 /* Test of controlling the floating-point environment.
2 Copyright (C) 2023-2024 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program 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
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2023. */
19 #include <config.h>
21 /* Specification. */
22 #include <fenv.h>
24 #include "fpe-trapping.h"
25 #include "macros.h"
27 /* musl libc does not support floating-point exception trapping, even where
28 the hardware supports it. See
29 <https://wiki.musl-libc.org/functional-differences-from-glibc.html> */
30 #if HAVE_FPE_TRAPPING && (!MUSL_LIBC || GNULIB_FEENABLEEXCEPT)
32 /* Test that feupdateenv(), unlike fesetenv(), can trigger traps. */
34 int
35 main ()
37 fenv_t env1;
39 /* Get to a known initial state. */
40 ASSERT (feclearexcept (FE_ALL_EXCEPT) == 0);
42 /* Enable trapping on FE_INVALID. */
43 if (sigfpe_on_invalid () < 0)
45 fputs ("Skipping test: trapping floating-point exceptions are not supported on this machine.\n", stderr);
46 return 77;
49 /* Save the current environment in env1. */
50 ASSERT (fegetenv (&env1) == 0);
52 /* Go back to the default environment. */
53 ASSERT (fesetenv (FE_DFL_ENV) == 0);
55 /* Modify the current environment. */
56 ASSERT (feraiseexcept (FE_INVALID) == 0);
58 /* Go back to env1.
59 Since the exceptions flag FE_INVALID is currently set, and since
60 env1 has trapping on FE_INVALID enabled, this should trap. */
61 ASSERT (feupdateenv (&env1) == 0);
63 return test_exit_status;
66 #else
68 int
69 main ()
71 fputs ("Skipping test: feenableexcept not available\n", stderr);
72 return 77;
75 #endif