From fe2c2458ee6d0dcf752281e7230f254e339d0714 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 5 Nov 2023 14:50:08 +0100 Subject: [PATCH] fenv-exceptions-tracking-c99 tests: Enhance tests. * tests/test-fenv-except-tracking-3.sh: Test not only FE_INVALID, but also FE_DIVBYZERO, FE_OVERFLOW, FE_UNDERFLOW, FE_INEXACT. * tests/test-fenv-except-tracking-3.c: Include , . Don't include fpe-trapping.h. Assume HAVE_FPE_TRAPPING is 1. (main): Receive the exception to test as first argument. --- ChangeLog | 9 ++++++ tests/test-fenv-except-tracking-3.c | 42 +++++++++++++++++++--------- tests/test-fenv-except-tracking-3.sh | 20 +++++++------ 3 files changed, 49 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3e8c6cf2a7..7c2d58913d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2023-11-05 Bruno Haible + + fenv-exceptions-tracking-c99 tests: Enhance tests. + * tests/test-fenv-except-tracking-3.sh: Test not only FE_INVALID, but + also FE_DIVBYZERO, FE_OVERFLOW, FE_UNDERFLOW, FE_INEXACT. + * tests/test-fenv-except-tracking-3.c: Include , . + Don't include fpe-trapping.h. Assume HAVE_FPE_TRAPPING is 1. + (main): Receive the exception to test as first argument. + 2023-11-05 Bruno Haible fpe-trapping: Simplify. diff --git a/tests/test-fenv-except-tracking-3.c b/tests/test-fenv-except-tracking-3.c index 63fabad48f..e2f16efa65 100644 --- a/tests/test-fenv-except-tracking-3.c +++ b/tests/test-fenv-except-tracking-3.c @@ -22,33 +22,49 @@ #include #include +#include +#include -#include "fpe-trapping.h" #include "macros.h" /* musl libc does not support floating-point exception trapping, even where the hardware supports it. See */ -#if HAVE_FPE_TRAPPING && (!MUSL_LIBC || GNULIB_FEENABLEEXCEPT) +#if !MUSL_LIBC || GNULIB_FEENABLEEXCEPT /* Check that feraiseexcept() can trigger a trap. */ int -main () +main (int argc, char *argv[]) { - /* Clear FE_INVALID exceptions from past operations. */ - feclearexcept (FE_INVALID); - - /* An FE_INVALID exception shall trigger a SIGFPE signal, which by default - terminates the program. */ - if (sigfpe_on_invalid () < 0) + if (argc > 1) { - fputs ("Skipping test: trapping floating-point exceptions are not supported on this machine.\n", stderr); - return 77; + int exception; + + if (STREQ (argv[1], "FE_INVALID")) exception = FE_INVALID; else + if (STREQ (argv[1], "FE_DIVBYZERO")) exception = FE_DIVBYZERO; else + if (STREQ (argv[1], "FE_OVERFLOW")) exception = FE_OVERFLOW; else + if (STREQ (argv[1], "FE_UNDERFLOW")) exception = FE_UNDERFLOW; else + if (STREQ (argv[1], "FE_INEXACT")) exception = FE_INEXACT; else + { + printf ("Invalid argument: %s\n", argv[1]); + exit (1); + } + + /* Clear FE_XX exceptions from past operations. */ + feclearexcept (exception); + + /* An FE_XX exception shall trigger a SIGFPE signal, which by default + terminates the program. */ + if (feenableexcept (exception) == -1) + { + fputs ("Skipping test: trapping floating-point exceptions are not supported on this machine.\n", stderr); + return 77; + } + + feraiseexcept (exception); } - feraiseexcept (FE_INVALID); - return 0; } diff --git a/tests/test-fenv-except-tracking-3.sh b/tests/test-fenv-except-tracking-3.sh index f44e43a59b..263af596b3 100755 --- a/tests/test-fenv-except-tracking-3.sh +++ b/tests/test-fenv-except-tracking-3.sh @@ -4,15 +4,17 @@ final_rc=0 -${CHECKER} ./test-fenv-except-tracking-3${EXEEXT} -rc=$? -if test $rc = 77; then - final_rc=77 -else - if test $rc = 0; then - echo "Failed: ./test-fenv-except-tracking-3" 1>&2 - exit 1 +for arg in FE_INVALID FE_DIVBYZERO FE_OVERFLOW FE_UNDERFLOW FE_INEXACT; do + ${CHECKER} ./test-fenv-except-tracking-3${EXEEXT} $arg + rc=$? + if test $rc = 77; then + final_rc=77 + else + if test $rc = 0; then + echo "Failed: ./test-fenv-except-tracking-3 $arg" 1>&2 + exit 1 + fi fi -fi +done exit $final_rc -- 2.39.5