From e5118e049ba258e3ba29a58c3520ba415d3dc555 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 13 Oct 2023 01:04:27 +0200 Subject: [PATCH] nan, snan tests: Avoid test failures. * tests/test-nan-1.c (main): Special handling of arm CPUs with software floating-point emulation. * tests/test-snan-1.c (main): Likewise. Disable tests that are known to fail. * tests/test-snan-2.c (main): Skip tests that are known to fail. * modules/snan-tests (Files): Add m4/math_h.m4. (configure.ac): Require gl_LONG_DOUBLE_VS_DOUBLE. * m4/math_h.m4 (gl_LONG_DOUBLE_VS_DOUBLE): Mention also NetBSD/sparc32. --- ChangeLog | 12 +++++++++ m4/math_h.m4 | 2 +- modules/snan-tests | 2 ++ tests/test-nan-1.c | 24 +++++++++++++++--- tests/test-snan-1.c | 51 +++++++++++++++++++++++++++++++++++--- tests/test-snan-2.c | 60 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 142 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2a2ed122e1..7112234f8f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2023-10-12 Bruno Haible + + nan, snan tests: Avoid test failures. + * tests/test-nan-1.c (main): Special handling of arm CPUs with software + floating-point emulation. + * tests/test-snan-1.c (main): Likewise. Disable tests that are known to + fail. + * tests/test-snan-2.c (main): Skip tests that are known to fail. + * modules/snan-tests (Files): Add m4/math_h.m4. + (configure.ac): Require gl_LONG_DOUBLE_VS_DOUBLE. + * m4/math_h.m4 (gl_LONG_DOUBLE_VS_DOUBLE): Mention also NetBSD/sparc32. + 2023-10-12 Bruno Haible snan: Add tests. diff --git a/m4/math_h.m4 b/m4/math_h.m4 index 008dd6fa3b..959006472a 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -375,7 +375,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], # Sets variable HAVE_SAME_LONG_DOUBLE_AS_DOUBLE to 0 or 1, and defines # HAVE_SAME_LONG_DOUBLE_AS_DOUBLE accordingly. # The currently known platforms where this is the case are: -# Linux/HPPA, Minix 3.1.8, AIX 5, AIX 6 and 7 with xlc, MSVC 9. +# Linux/HPPA, NetBSD/sparc32, Minix 3.1.8, AIX 5, AIX 6 and 7 with xlc, MSVC 9. AC_DEFUN([gl_LONG_DOUBLE_VS_DOUBLE], [ AC_CACHE_CHECK([whether long double and double are the same], diff --git a/modules/snan-tests b/modules/snan-tests index d3f2b8615e..91210d2ea5 100644 --- a/modules/snan-tests +++ b/modules/snan-tests @@ -3,12 +3,14 @@ tests/test-snan-1.c tests/test-snan-2.sh tests/test-snan-2.c tests/macros.h +m4/math_h.m4 Depends-on: fpe-tracking fpe-trapping configure.ac: +AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE]) Makefile.am: TESTS += test-snan-1 test-snan-2.sh diff --git a/tests/test-nan-1.c b/tests/test-nan-1.c index 9bce3225c1..4ebe013e3c 100644 --- a/tests/test-nan-1.c +++ b/tests/test-nan-1.c @@ -21,11 +21,27 @@ /* Specification. */ #include "nan.h" +#include + #if HAVE_FE_INVALID -# include +# if defined __GLIBC__ && defined __arm__ && defined __SOFTFP__ + +/* The arm software floating-point emulation (used e.g. on armv5) does not set + the floating-point exception bits. */ + +int +main () +{ + fputs ("Skipping test: software floating-point emulation\n", stderr); + return 77; +} + +# else + +# include -# include "macros.h" +# include "macros.h" float volatile resultf; double volatile resultd; @@ -64,14 +80,14 @@ main () return 0; } +# endif + #else /* No available. We could use the various alternative approaches from libgfortran/config/fpu-*.h, but that's not worth it. */ -#include - int main () { diff --git a/tests/test-snan-1.c b/tests/test-snan-1.c index de87372f17..fc8fc99e31 100644 --- a/tests/test-snan-1.c +++ b/tests/test-snan-1.c @@ -21,11 +21,27 @@ /* Specification. */ #include "snan.h" +#include + #if HAVE_FE_INVALID -# include +# if defined __GLIBC__ && defined __arm__ && defined __SOFTFP__ + +/* The arm software floating-point emulation (used e.g. on armv5) does not set + the floating-point exception bits. */ + +int +main () +{ + fputs ("Skipping test: software floating-point emulation\n", stderr); + return 77; +} + +# else + +# include -# include "macros.h" +# include "macros.h" float volatile resultf; double volatile resultd; @@ -45,33 +61,60 @@ main () long double volatile nanl = SNaNl (); /* Check that the values are really signalling. */ + /* These tests do not work on 32-bit x86 processors, although the + "Intel 64 and IA-32 Architectures Software Developer's Manual" and + "IA-32 Intel Architecture Software Developer's Manual", each in + sections + 4.8.3.4 NaNs + 4.8.3.5 Operating on SNaNs and QNaNs + 4.8.3.6 Using SNaNs and QNaNs in Applications + claim that it should work. */ + #if !(defined __i386 || defined _M_IX86) + /* This test does not work on AIX 7.1 with the xlc compiler, even with + the compiler options -qfloat=fenv -qfloat=nans -qfloat=spnans. */ + #if !(defined _AIX && defined __xlC__) { feclearexcept (FE_INVALID); resultf = nanf + 42.0f; ASSERT (fetestexcept (FE_INVALID)); } + #endif { feclearexcept (FE_INVALID); resultd = nand + 42.0; ASSERT (fetestexcept (FE_INVALID)); } + #endif + /* This test does not work on eglibc 2.13/mips64 + (bug in libc function __addtf3). + This test does not work on FreeBSD/arm64 + (bug in libc function __addtf3). + This test does not work on FreeBSD/sparc64 and NetBSD/sparc64 + (bug in libc function _Qp_add). + This test does not work on MSVC/i386, because of the general IA-32 + problem (see above) and 'long double' == 'double'. */ + #if !((((__GLIBC__ == 2 && __GLIBC_MINOR__ < 19 && defined __mips64) \ + || ((defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__) && (defined __aarch64__ || defined __sparc__))) \ + && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE) \ + || ((defined __i386 || defined _M_IX86) && HAVE_SAME_LONG_DOUBLE_AS_DOUBLE)) { feclearexcept (FE_INVALID); resultl = nanl + 42.0L; ASSERT (fetestexcept (FE_INVALID)); } + #endif return 0; } +# endif + #else /* No available. We could use the various alternative approaches from libgfortran/config/fpu-*.h, but that's not worth it. */ -#include - int main () { diff --git a/tests/test-snan-2.c b/tests/test-snan-2.c index e1ee7c8928..42927d6077 100644 --- a/tests/test-snan-2.c +++ b/tests/test-snan-2.c @@ -65,14 +65,74 @@ main (int argc, char *argv[]) switch (argv[1][0]) { case 'f': + /* This test does not work on 32-bit x86 processors, although the + "Intel 64 and IA-32 Architectures Software Developer's Manual" and + "IA-32 Intel Architecture Software Developer's Manual", each in + sections + 4.8.3.4 NaNs + 4.8.3.5 Operating on SNaNs and QNaNs + 4.8.3.6 Using SNaNs and QNaNs in Applications + claim that it should work. */ + #if !(defined __i386 || defined _M_IX86) + /* This test does not work on AIX 7.1 with the xlc compiler, even with + the compiler options -qfloat=fenv -qfloat=nans -qfloat=spnans. */ + #if !(defined _AIX && defined __xlC__) resultf = nanf + 42.0f; + #else + fputs ("Skipping test: known failure on this platform with this compiler\n", stderr); + return 77; + #endif + #else + fputs ("Skipping test: known failure on this platform\n", stderr); + return 77; + #endif break; + case 'd': + /* This test does not work on 32-bit x86 processors, although the + "Intel 64 and IA-32 Architectures Software Developer's Manual" and + "IA-32 Intel Architecture Software Developer's Manual", each in + sections + 4.8.3.4 NaNs + 4.8.3.5 Operating on SNaNs and QNaNs + 4.8.3.6 Using SNaNs and QNaNs in Applications + claim that it should work. */ + #if !(defined __i386 || defined _M_IX86) resultd = nand + 42.0; + #else + fputs ("Skipping test: known failure on this platform\n", stderr); + return 77; + #endif break; + case 'l': + /* This test does not work on Linux/alpha with glibc 2.7. But it + works with glibc 2.36. Cause unknown. + This test does not work on Linux/loongarch64 with glibc 2.37. + Cause unknown. + This test does not work on eglibc 2.13/mips64 + (bug in libc function __addtf3). + This test does not work on FreeBSD/arm64 + (bug in libc function __addtf3). + This test does not work on FreeBSD/sparc64 and NetBSD/sparc64 + (bug in libc function _Qp_add). + This test does not work on Cygwin 2.9.0/i386. Cause unknown. + This test does not work on MSVC/i386, because of the general IA-32 + problem (see above) and 'long double' == 'double'. */ + #if !((__GLIBC__ == 2 && __GLIBC_MINOR__ < 36 && defined __alpha__) \ + || (__GLIBC__ >= 2 && defined __loongarch__) \ + || (((__GLIBC__ == 2 && __GLIBC_MINOR__ < 19 && defined __mips64) \ + || ((defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__) && (defined __aarch64__ || defined __sparc__))) \ + && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE) \ + || (defined __CYGWIN__ && defined __i386) \ + || ((defined __i386 || defined _M_IX86) && HAVE_SAME_LONG_DOUBLE_AS_DOUBLE)) resultl = nanl + 42.0L; + #else + fputs ("Skipping test: known failure on this platform\n", stderr); + return 77; + #endif break; + default: break; } -- 2.39.5