Module Name:    src
Committed By:   kamil
Date:           Thu Apr 25 19:15:23 UTC 2019

Modified Files:
        src/tests/lib/libc/sys: Makefile t_ptrace_wait.c t_ptrace_wait.h

Log Message:
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


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/tests/lib/libc/sys/Makefile
cvs rdiff -u -r1.113 -r1.114 src/tests/lib/libc/sys/t_ptrace_wait.c
cvs rdiff -u -r1.15 -r1.16 src/tests/lib/libc/sys/t_ptrace_wait.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/sys/Makefile
diff -u src/tests/lib/libc/sys/Makefile:1.54 src/tests/lib/libc/sys/Makefile:1.55
--- src/tests/lib/libc/sys/Makefile:1.54	Sun Feb 10 02:13:45 2019
+++ src/tests/lib/libc/sys/Makefile	Thu Apr 25 19:15:23 2019
@@ -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 @@ SRCS.t_mprotect=	t_mprotect.c ${SRCS_EXE
 
 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 @@ LDADD.t_posix_fadvise+= -lrumpvfs -lrump
 .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

Index: src/tests/lib/libc/sys/t_ptrace_wait.c
diff -u src/tests/lib/libc/sys/t_ptrace_wait.c:1.113 src/tests/lib/libc/sys/t_ptrace_wait.c:1.114
--- src/tests/lib/libc/sys/t_ptrace_wait.c:1.113	Thu Apr 25 11:47:59 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.c	Thu Apr 25 19:15:23 2019
@@ -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 @@ __RCSID("$NetBSD: t_ptrace_wait.c,v 1.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 @@ traceme_crash(int sig)
 		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 @@ traceme_signalmasked_crash(int sig)
 		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 @@ traceme_signalignored_crash(int sig)
 		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 @@ traceme_vfork_crash(int sig)
 		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 @@ traceme_vfork_signalmasked_crash(int sig
 		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 @@ traceme_vfork_signalignored_crash(int si
 		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 @@ unrelated_tracer_sees_crash(int sig, boo
 		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");

Index: src/tests/lib/libc/sys/t_ptrace_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_wait.h:1.15 src/tests/lib/libc/sys/t_ptrace_wait.h:1.16
--- src/tests/lib/libc/sys/t_ptrace_wait.h:1.15	Thu Apr 11 20:20:54 2019
+++ src/tests/lib/libc/sys/t_ptrace_wait.h	Thu Apr 25 19:15:23 2019
@@ -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 @@ trigger_ill(void)
 #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);
 }

Reply via email to