tests/kernel/h_segv: Disable SIGFPE test on RISC-V.

No floating-point exception traps on RISC-V.

Also don't pass the result of divide-by-zero converted to integer to
usleep.  Although the floating-point result of divide-by-zero is
well-defined by IEEE 754 (+/-infinity), the outcome of C conversion
to integer is not.  And while on some architectures this might return
zero, on RISC-V it looks like it'll return all bits set.  And as of
PR 58184, usleep now honours sleeps longer than 1sec, which means
this will be waiting at least two billion microseconds, or about half
an hour...

So instead, just write the result to a volatile variable.
This commit is contained in:
riastradh 2024-05-14 15:54:16 +00:00
parent e14c40965f
commit fd16ce12c7
1 changed files with 14 additions and 3 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: h_segv.c,v 1.14 2019/04/25 19:37:09 kamil Exp $ */
/* $NetBSD: h_segv.c,v 1.15 2024/05/14 15:54:16 riastradh Exp $ */
/*-
* Copyright (c) 2017 The NetBSD Foundation, Inc.
@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: h_segv.c,v 1.14 2019/04/25 19:37:09 kamil Exp $");
__RCSID("$NetBSD: h_segv.c,v 1.15 2024/05/14 15:54:16 riastradh Exp $");
#define __TEST_FENV
@ -121,10 +121,15 @@ check_fpe(void)
printf("FPU does not implement traps on FP exceptions\n");
exit(EXIT_FAILURE);
}
#elif defined __riscv__
printf("RISC-V does not support floating-point exception traps\n");
exit(EXIT_FAILURE);
#endif
exit(EXIT_SUCCESS);
}
volatile int ignore_result;
static void
trigger_fpe(void)
{
@ -135,7 +140,13 @@ trigger_fpe(void)
feenableexcept(FE_ALL_EXCEPT);
#endif
usleep((int)(a/b));
/*
* Try to trigger SIGFPE either by dividing by zero (which is
* defined to raise FE_DIVBYZERO, but may just return infinity
* without trapping the exception) or by converting infinity to
* integer.
*/
ignore_result = (int)(a/b);
}
static void