Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libc/sys Introduce check for the support of FPU ex...



details:   https://anonhg.NetBSD.org/src/rev/58d7002fc8ca
branches:  trunk
changeset: 450786:58d7002fc8ca
user:      kamil <kamil%NetBSD.org@localhost>
date:      Thu Apr 25 19:15:23 2019 +0000

description:
Introduce check for the support of FPU exceptions

If FPU exceptions are unsupported, skip the SIGFPE crash tests.

Reuse code from tests/kernel/h_segv.c

diffstat:

 tests/lib/libc/sys/Makefile        |  26 +++++++++++++-------------
 tests/lib/libc/sys/t_ptrace_wait.c |  30 ++++++++++++++++++++++++++++--
 tests/lib/libc/sys/t_ptrace_wait.h |  21 ++++++++++++++++++++-
 3 files changed, 61 insertions(+), 16 deletions(-)

diffs (188 lines):

diff -r 48c4fcf56597 -r 58d7002fc8ca tests/lib/libc/sys/Makefile
--- a/tests/lib/libc/sys/Makefile       Thu Apr 25 11:47:59 2019 +0000
+++ b/tests/lib/libc/sys/Makefile       Thu Apr 25 19:15:23 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.54 2019/02/10 02:13:45 kamil Exp $
+# $NetBSD: Makefile,v 1.55 2019/04/25 19:15:23 kamil Exp $
 
 MKMAN= no
 
@@ -88,12 +88,12 @@
 
 LDADD.t_getpid+=        -lpthread
 
-LDFLAGS.t_ptrace_wait+=                -pthread
-LDFLAGS.t_ptrace_wait3+=       -pthread
-LDFLAGS.t_ptrace_wait4+=       -pthread
-LDFLAGS.t_ptrace_wait6+=       -pthread
-LDFLAGS.t_ptrace_waitid+=      -pthread
-LDFLAGS.t_ptrace_waitpid+=     -pthread
+LDFLAGS.t_ptrace_wait+=                -pthread -lm
+LDFLAGS.t_ptrace_wait3+=       -pthread -lm
+LDFLAGS.t_ptrace_wait4+=       -pthread -lm
+LDFLAGS.t_ptrace_wait6+=       -pthread -lm
+LDFLAGS.t_ptrace_waitid+=      -pthread -lm
+LDFLAGS.t_ptrace_waitpid+=     -pthread -lm
 
 .if (${MKRUMP} != "no") && !defined(BSD_MK_COMPAT_FILE)
 CPPFLAGS.t_posix_fadvise.c += -D_KERNTYPES
@@ -102,12 +102,12 @@
 .endif
 
 CPPFLAGS.t_lwp_create.c                += -D_KERNTYPES
-CPPFLAGS.t_ptrace_wait.c       += -D_KERNTYPES
-CPPFLAGS.t_ptrace_wait3.c      += -D_KERNTYPES
-CPPFLAGS.t_ptrace_wait4.c      += -D_KERNTYPES
-CPPFLAGS.t_ptrace_wait6.c      += -D_KERNTYPES
-CPPFLAGS.t_ptrace_waitid.c     += -D_KERNTYPES
-CPPFLAGS.t_ptrace_waitpid.c    += -D_KERNTYPES
+CPPFLAGS.t_ptrace_wait.c       += -D_KERNTYPES -D__TEST_FENV
+CPPFLAGS.t_ptrace_wait3.c      += -D_KERNTYPES -D__TEST_FENV
+CPPFLAGS.t_ptrace_wait4.c      += -D_KERNTYPES -D__TEST_FENV
+CPPFLAGS.t_ptrace_wait6.c      += -D_KERNTYPES -D__TEST_FENV
+CPPFLAGS.t_ptrace_waitid.c     += -D_KERNTYPES -D__TEST_FENV
+CPPFLAGS.t_ptrace_waitpid.c    += -D_KERNTYPES -D__TEST_FENV
 CPPFLAGS.t_ucontext.c          += -D_KERNTYPES
 
 FILES=         truncate_test.root_owned
diff -r 48c4fcf56597 -r 58d7002fc8ca tests/lib/libc/sys/t_ptrace_wait.c
--- a/tests/lib/libc/sys/t_ptrace_wait.c        Thu Apr 25 11:47:59 2019 +0000
+++ b/tests/lib/libc/sys/t_ptrace_wait.c        Thu Apr 25 19:15:23 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_ptrace_wait.c,v 1.113 2019/04/25 11:47:59 kamil Exp $        */
+/*     $NetBSD: t_ptrace_wait.c,v 1.114 2019/04/25 19:15:23 kamil Exp $        */
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.113 2019/04/25 11:47:59 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.114 2019/04/25 19:15:23 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -53,6 +53,11 @@
 #include <time.h>
 #include <unistd.h>
 
+#include <fenv.h>
+#if (__arm__ && !__SOFTFP__) || __aarch64__
+#include <ieeefp.h> /* only need for ARM Cortex/Neon hack */
+#endif
+
 #include <atf-c.h>
 
 #include "h_macros.h"
@@ -413,6 +418,9 @@
                atf_tc_skip("PTRACE_ILLEGAL_ASM not defined");
 #endif
 
+       if (sig == SIGFPE && !are_fpu_exceptions_supported())
+               atf_tc_skip("FP exceptions are not supported");
+
        memset(&info, 0, sizeof(info));
 
        DPRINTF("Before forking process PID=%d\n", getpid());
@@ -537,6 +545,9 @@
                atf_tc_skip("PTRACE_ILLEGAL_ASM not defined");
 #endif
 
+       if (sig == SIGFPE && !are_fpu_exceptions_supported())
+               atf_tc_skip("FP exceptions are not supported");
+
        memset(&info, 0, sizeof(info));
 
        DPRINTF("Before forking process PID=%d\n", getpid());
@@ -715,6 +726,9 @@
                atf_tc_skip("PTRACE_ILLEGAL_ASM not defined");
 #endif
 
+       if (sig == SIGFPE && !are_fpu_exceptions_supported())
+               atf_tc_skip("FP exceptions are not supported");
+
        memset(&info, 0, sizeof(info));
 
        DPRINTF("Before forking process PID=%d\n", getpid());
@@ -1523,6 +1537,9 @@
                atf_tc_skip("PTRACE_ILLEGAL_ASM not defined");
 #endif
 
+       if (sig == SIGFPE && !are_fpu_exceptions_supported())
+               atf_tc_skip("FP exceptions are not supported");
+
        DPRINTF("Before forking process PID=%d\n", getpid());
        SYSCALL_REQUIRE((child = vfork()) != -1);
        if (child == 0) {
@@ -1602,6 +1619,9 @@
                atf_tc_skip("PTRACE_ILLEGAL_ASM not defined");
 #endif
 
+       if (sig == SIGFPE && !are_fpu_exceptions_supported())
+               atf_tc_skip("FP exceptions are not supported");
+
        DPRINTF("Before forking process PID=%d\n", getpid());
        SYSCALL_REQUIRE((child = vfork()) != -1);
        if (child == 0) {
@@ -1685,6 +1705,9 @@
                atf_tc_skip("PTRACE_ILLEGAL_ASM not defined");
 #endif
 
+       if (sig == SIGFPE && !are_fpu_exceptions_supported())
+               atf_tc_skip("FP exceptions are not supported");
+
        DPRINTF("Before forking process PID=%d\n", getpid());
        SYSCALL_REQUIRE((child = vfork()) != -1);
        if (child == 0) {
@@ -1936,6 +1959,9 @@
                atf_tc_skip("PTRACE_ILLEGAL_ASM not defined");
 #endif
 
+       if (sig == SIGFPE && !are_fpu_exceptions_supported())
+               atf_tc_skip("FP exceptions are not supported");
+
        memset(&info, 0, sizeof(info));
 
        DPRINTF("Spawn tracee\n");
diff -r 48c4fcf56597 -r 58d7002fc8ca tests/lib/libc/sys/t_ptrace_wait.h
--- a/tests/lib/libc/sys/t_ptrace_wait.h        Thu Apr 25 11:47:59 2019 +0000
+++ b/tests/lib/libc/sys/t_ptrace_wait.h        Thu Apr 25 19:15:23 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_ptrace_wait.h,v 1.15 2019/04/11 20:20:54 kamil Exp $ */
+/*     $NetBSD: t_ptrace_wait.h,v 1.16 2019/04/25 19:15:23 kamil Exp $ */
 
 /*-
  * Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -602,12 +602,31 @@
 #endif
 }
 
+static bool __used
+are_fpu_exceptions_supported(void)
+{
+#if (__arm__ && !__SOFTFP__) || __aarch64__
+       /*
+        * Some NEON fpus do not trap on IEEE 754 FP exceptions.
+        * Skip these tests if running on them and compiled for
+        * hard float.
+        */
+       if (0 == fpsetmask(fpsetmask(FP_X_INV)))
+               return false;
+#endif
+       return true;
+}
+
 static void __used
 trigger_fpe(void)
 {
        volatile int a = getpid();
        volatile int b = atoi("0");
 
+#ifdef __HAVE_FENV
+       feenableexcept(FE_ALL_EXCEPT);
+#endif
+
        /* Division by zero causes CPU trap, translated to SIGFPE */
        usleep(a / b);
 }



Home | Main Index | Thread Index | Old Index