]> Savannah Git Hosting - gnulib.git/commitdiff
fenv-exceptions-tracking-c99 tests: Enhance tests.
authorBruno Haible <bruno@clisp.org>
Sun, 5 Nov 2023 13:50:08 +0000 (14:50 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 5 Nov 2023 13:55:27 +0000 (14:55 +0100)
* 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 <stdlib.h>, <string.h>.
Don't include fpe-trapping.h. Assume HAVE_FPE_TRAPPING is 1.
(main): Receive the exception to test as first argument.

ChangeLog
tests/test-fenv-except-tracking-3.c
tests/test-fenv-except-tracking-3.sh

index 3e8c6cf2a76bc372fa48b2a7498a9ca3f6888b35..7c2d58913db15888b4041969570a05fae0f6b99e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2023-11-05  Bruno Haible  <bruno@clisp.org>
+
+       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 <stdlib.h>, <string.h>.
+       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  <bruno@clisp.org>
 
        fpe-trapping: Simplify.
index 63fabad48f43a320bc4aaae4859db844b885f938..e2f16efa65af323bc98674bc91c1cdf923d20d07 100644 (file)
 #include <fenv.h>
 
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
-#include "fpe-trapping.h"
 #include "macros.h"
 
 /* musl libc does not support floating-point exception trapping, even where
    the hardware supports it.  See
    <https://wiki.musl-libc.org/functional-differences-from-glibc.html>  */
-#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;
 }
 
index f44e43a59b2f6f773ace25f0a9afbf842330d662..263af596b3e2c64cbe8c3c03d5107307965e4cae 100755 (executable)
@@ -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