usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-fenv-except-tracking-2.c
blob544a286e0fff33ec86ee9d339dfcdb772db1bbaa
1 /* Test of tracking of floating-point exceptions.
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 <stdio.h>
26 #include "fpe-trapping.h"
27 #include "macros.h"
29 #if HAVE_FPE_TRAPPING
31 /* Check that triggering a floating-point operation can trigger a trap. */
33 int
34 main (int argc, char *argv[])
36 /* Clear FE_INVALID exceptions from past operations. */
37 feclearexcept (FE_INVALID);
39 /* An FE_INVALID exception shall trigger a SIGFPE signal, which by default
40 terminates the program. */
41 if (sigfpe_on_invalid () < 0)
43 fputs ("Skipping test: trapping floating-point exceptions are not supported on this machine.\n", stderr);
44 return 77;
47 if (argc > 1)
48 switch (argv[1][0])
50 case 'f':
52 volatile float a, b;
53 _GL_UNUSED volatile float c;
54 a = 0; b = 0; c = a / b;
56 break;
58 case 'd':
60 volatile double a, b;
61 _GL_UNUSED volatile double c;
62 a = 0; b = 0; c = a / b;
64 break;
66 case 'l':
67 /* This test does not work on Linux/loongarch64 with glibc 2.37.
68 Likewise on Linux/alpha with glibc 2.7 on Linux 2.6.26.
69 Likewise on FreeBSD 12.2/sparc, NetBSD 8.0/sparc, OpenBSD 7.2/sparc64.
70 Likewise on OpenBSD 7.4/mips64.
71 Cause unknown. */
72 #if !((__GLIBC__ >= 2 && defined __loongarch__) \
73 || ((__GLIBC__ == 2 && __GLIBC_MINOR__ < 36) && defined __alpha) \
74 || ((defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__) && defined __sparc) \
75 || (defined __OpenBSD__ && defined __mips64))
77 volatile long double a, b;
78 _GL_UNUSED volatile long double c;
79 a = 0; b = 0; c = a / b;
81 #else
82 fputs ("Skipping test: known failure on this platform\n", stderr);
83 return 77;
84 #endif
85 break;
87 default:
88 break;
91 return test_exit_status;
94 #else
96 int
97 main ()
99 fputs ("Skipping test: feenableexcept not available\n", stderr);
100 return 77;
103 #endif