Source-Changes-HG archive

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

[src/trunk]: src/tests/lib/libc Atf-ify several of the ieeefp tests.



details:   https://anonhg.NetBSD.org/src/rev/0a6fbd7a2210
branches:  trunk
changeset: 760267:0a6fbd7a2210
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Sun Jan 02 03:51:20 2011 +0000

description:
Atf-ify several of the ieeefp tests.

Note that t_round is currently mostly disabled, due to PR/44293.  Also,
testfloat has not been converted.

diffstat:

 tests/lib/libc/Makefile             |    6 +-
 tests/lib/libc/ieeefp/Makefile      |   14 +
 tests/lib/libc/ieeefp/Makefile.inc  |    6 +
 tests/lib/libc/ieeefp/t_except.c    |  312 ++++++++++++++++++++++++++++++++++++
 tests/lib/libc/ieeefp/t_nan_inf.c   |   66 +++++++
 tests/lib/libc/ieeefp/t_round.c     |   78 +++++++++
 tests/lib/libc/ieeefp/t_subnormal.c |  200 +++++++++++++++++++++++
 7 files changed, 681 insertions(+), 1 deletions(-)

diffs (truncated from 719 to 300 lines):

diff -r a4f27f000b7e -r 0a6fbd7a2210 tests/lib/libc/Makefile
--- a/tests/lib/libc/Makefile   Sun Jan 02 02:58:52 2011 +0000
+++ b/tests/lib/libc/Makefile   Sun Jan 02 03:51:20 2011 +0000
@@ -1,10 +1,14 @@
-# $NetBSD: Makefile,v 1.15 2010/12/31 14:36:11 pgoyette Exp $
+# $NetBSD: Makefile,v 1.16 2011/01/02 03:51:20 pgoyette Exp $
 
 .include <bsd.own.mk>
 .include <bsd.sys.mk>
 
 TESTS_SUBDIRS+=        gen hash setjmp stdlib stdio string
 
+.if ${MACHINE_ARCH} != "vax" && ${MACHINE_ARCH} != "m68000"
+TESTS_SUBDIRS+=        ieeefp
+.endif
+
 .if ${HAS_SSP} == "yes"
 TESTS_SUBDIRS+=        ssp
 .endif
diff -r a4f27f000b7e -r 0a6fbd7a2210 tests/lib/libc/ieeefp/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/ieeefp/Makefile    Sun Jan 02 03:51:20 2011 +0000
@@ -0,0 +1,14 @@
+# $NetBSD: Makefile,v 1.1 2011/01/02 03:51:21 pgoyette Exp $
+
+.include <bsd.own.mk>
+
+TESTSDIR=      ${TESTSBASE}/lib/libc/ieeefp
+
+TESTS_C+=      t_except
+TESTS_C+=      t_nan_inf
+TESTS_C+=      t_round
+TESTS_C+=      t_subnormal
+
+LDADD.t_subnormal+=-lm
+
+.include <bsd.test.mk>
diff -r a4f27f000b7e -r 0a6fbd7a2210 tests/lib/libc/ieeefp/Makefile.inc
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/ieeefp/Makefile.inc        Sun Jan 02 03:51:20 2011 +0000
@@ -0,0 +1,6 @@
+#      $NetBSD: Makefile.inc,v 1.1 2011/01/02 03:51:21 pgoyette Exp $
+#
+
+.if ${MACHINE_ARCH} == "alpha"
+COPTS+=        -mieee
+.endif
diff -r a4f27f000b7e -r 0a6fbd7a2210 tests/lib/libc/ieeefp/t_except.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/ieeefp/t_except.c  Sun Jan 02 03:51:20 2011 +0000
@@ -0,0 +1,312 @@
+/*     $NetBSD: t_except.c,v 1.1 2011/01/02 03:51:21 pgoyette Exp $    */
+
+/*-
+ * Copyright (c) 1995 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <atf-c.h>
+#include <atf-c/config.h>
+
+#include <stdio.h>
+#include <signal.h>
+#include <assert.h>
+#include <ieeefp.h>
+#include <float.h>
+#include <setjmp.h>
+#include <stdlib.h>
+#include <string.h>
+
+void sigfpe(int, siginfo_t *, void *);
+volatile sig_atomic_t signal_caught;
+volatile int sicode;
+
+#ifdef USE_FLOAT
+#define FPTYPE float
+#else
+#ifdef USE_LONGDOUBLE
+#define FPTYPE long double
+#else
+#define FPTYPE double
+#endif
+#endif
+static volatile const float    f_one   = 1.0;
+static volatile const float    f_zero  = 0.0;
+static volatile const double   d_one   = 1.0;
+static volatile const double   d_zero  = 0.0;
+static volatile const long double ld_one  = 1.0;
+static volatile const long double ld_zero = 0.0;
+
+static volatile const float    f_huge = FLT_MAX;
+static volatile const float    f_tiny = FLT_MIN;
+static volatile const double   d_huge = DBL_MAX;
+static volatile const double   d_tiny = DBL_MIN;
+static volatile const long double ld_huge = LDBL_MAX;
+static volatile const long double ld_tiny = LDBL_MIN;
+
+static volatile float f_x;
+static volatile double d_x;
+static volatile long double ld_x;
+
+/* trip divide by zero */
+static void
+f_dz(void)
+{
+
+       f_x = f_one / f_zero;
+}
+
+static void
+d_dz(void)
+{
+
+       d_x = d_one / d_zero;
+}
+
+static void
+ld_dz(void)
+{
+
+       ld_x = ld_one / ld_zero;
+}
+
+/* trip invalid operation */
+static void
+d_inv(void)
+{
+
+       d_x = d_zero / d_zero;
+}
+
+static void
+ld_inv(void)
+{
+
+       ld_x = ld_zero / ld_zero;
+}
+
+static void
+f_inv(void)
+{
+
+       f_x = f_zero / f_zero;
+}
+
+/* trip overflow */
+static void
+f_ofl(void)
+{
+
+       f_x = f_huge * f_huge;
+}
+
+static void
+d_ofl(void)
+{
+
+       d_x = d_huge * d_huge;
+}
+
+static void
+ld_ofl(void)
+{
+
+       ld_x = ld_huge * ld_huge;
+}
+
+/* trip underflow */
+static void
+f_ufl(void)
+{
+
+       f_x = f_tiny * f_tiny;
+}
+
+static void
+d_ufl(void)
+{
+
+       d_x = d_tiny * d_tiny;
+}
+
+static void
+ld_ufl(void)
+{
+
+       ld_x = ld_tiny * ld_tiny;
+}
+
+struct ops {
+       void (*op)(void);
+       fp_except mask;
+       int sicode;
+};
+
+static struct ops float_ops[] = {
+       { f_dz, FP_X_DZ, FPE_FLTDIV },
+       { f_inv, FP_X_INV, FPE_FLTINV },
+       { f_ofl, FP_X_OFL, FPE_FLTOVF },
+       { f_ufl, FP_X_UFL, FPE_FLTUND },
+       { NULL, 0, 0 }
+};
+
+static struct ops double_ops[] = {
+       { d_dz, FP_X_DZ, FPE_FLTDIV },
+       { d_inv, FP_X_INV, FPE_FLTINV },
+       { d_ofl, FP_X_OFL, FPE_FLTOVF },
+       { d_ufl, FP_X_UFL, FPE_FLTUND },
+       { NULL, 0, 0 }
+};
+
+static struct ops long_double_ops[] = {
+       { ld_dz, FP_X_DZ, FPE_FLTDIV },
+       { ld_inv, FP_X_INV, FPE_FLTINV },
+       { ld_ofl, FP_X_OFL, FPE_FLTOVF },
+       { ld_ufl, FP_X_UFL, FPE_FLTUND },
+       { NULL, 0, 0 }
+};
+
+static sigjmp_buf b;
+
+static void
+masked(struct ops *test_ops)
+{
+       struct sigaction sa;
+       fp_except ex1, ex2;
+
+       /* mask all exceptions, clear history */
+       fpsetmask(0);
+       fpsetsticky(0);
+
+       /* set up signal handler */
+       sa.sa_sigaction = sigfpe;
+       sigemptyset(&sa.sa_mask);
+       sa.sa_flags = SA_SIGINFO;
+       sigaction(SIGFPE, &sa, 0);
+       signal_caught = 0;
+
+       /*
+        * exceptions masked, check whether "sticky" bits are set correctly
+        */
+       while (test_ops->op != NULL) {
+               (*test_ops->op)();
+               ex1 = fpgetsticky();
+               ATF_CHECK_EQ(ex1 & test_ops->mask, test_ops->mask);
+               ATF_CHECK_EQ(signal_caught, 0);
+
+               /* check correct fpsetsticky() behaviour */
+               ex2 = fpsetsticky(0);
+               ATF_CHECK_EQ(fpgetsticky(), 0);
+               ATF_CHECK_EQ(ex1, ex2);
+               test_ops++;
+       }
+}
+
+/* force delayed exceptions to be delivered */
+#define BARRIER() fpsetmask(0); f_x = f_one * f_one
+
+static void
+unmasked(struct ops *test_ops)
+{
+       struct sigaction sa;
+       int r;
+
+       /* mask all exceptions, clear history */
+       fpsetmask(0);
+       fpsetsticky(0);
+
+       /* set up signal handler */
+       sa.sa_sigaction = sigfpe;
+       sigemptyset(&sa.sa_mask);
+       sa.sa_flags = SA_SIGINFO;
+       sigaction(SIGFPE, &sa, 0);
+       signal_caught = 0;
+
+       /*
+        * exception unmasked, check SIGFPE delivery and correct siginfo
+        */
+       while (test_ops->op != NULL) {



Home | Main Index | Thread Index | Old Index