Module Name:    src
Committed By:   jruoho
Date:           Mon Sep 19 05:25:50 UTC 2011

Modified Files:
        src/distrib/sets/lists/tests: mi
        src/etc/mtree: NetBSD.dist.tests
        src/tests/lib/libc/gen: Makefile
Added Files:
        src/tests/lib/libc/gen: t_fpclassify.c t_fpsetmask.c t_fpsetround.c
            t_isnan.c
Removed Files:
        src/tests/lib/libc/ieeefp: Makefile Makefile.inc t_except.c t_nan_inf.c
            t_round.c t_subnormal.c

Log Message:
Move the tests/libc/ieeefp to tests/libc/gen to match the structure of libc.
Also rename the test files to gain functional scope.


To generate a diff of this commit:
cvs rdiff -u -r1.389 -r1.390 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.52 -r1.53 src/etc/mtree/NetBSD.dist.tests
cvs rdiff -u -r1.28 -r1.29 src/tests/lib/libc/gen/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/gen/t_fpclassify.c \
    src/tests/lib/libc/gen/t_fpsetmask.c \
    src/tests/lib/libc/gen/t_fpsetround.c src/tests/lib/libc/gen/t_isnan.c
cvs rdiff -u -r1.3 -r0 src/tests/lib/libc/ieeefp/Makefile \
    src/tests/lib/libc/ieeefp/t_subnormal.c
cvs rdiff -u -r1.1 -r0 src/tests/lib/libc/ieeefp/Makefile.inc
cvs rdiff -u -r1.7 -r0 src/tests/lib/libc/ieeefp/t_except.c
cvs rdiff -u -r1.2 -r0 src/tests/lib/libc/ieeefp/t_nan_inf.c \
    src/tests/lib/libc/ieeefp/t_round.c

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

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.389 src/distrib/sets/lists/tests/mi:1.390
--- src/distrib/sets/lists/tests/mi:1.389	Sun Sep 18 05:19:18 2011
+++ src/distrib/sets/lists/tests/mi	Mon Sep 19 05:25:50 2011
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.389 2011/09/18 05:19:18 jruoho Exp $
+# $NetBSD: mi,v 1.390 2011/09/19 05:25:50 jruoho Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -387,11 +387,11 @@
 ./usr/libdata/debug/usr/tests/lib/libc/hash				tests-lib-debug
 ./usr/libdata/debug/usr/tests/lib/libc/hash/h_hash.debug		tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libc/hash/t_sha2.debug		tests-lib-debug		debug,atf
-./usr/libdata/debug/usr/tests/lib/libc/ieeefp				tests-lib-debug
-./usr/libdata/debug/usr/tests/lib/libc/ieeefp/t_except.debug		tests-lib-debug		debug,atf
-./usr/libdata/debug/usr/tests/lib/libc/ieeefp/t_nan_inf.debug		tests-lib-debug		debug,atf
-./usr/libdata/debug/usr/tests/lib/libc/ieeefp/t_round.debug		tests-lib-debug		debug,atf
-./usr/libdata/debug/usr/tests/lib/libc/ieeefp/t_subnormal.debug		tests-lib-debug		debug,atf
+./usr/libdata/debug/usr/tests/lib/libc/ieeefp				tests-obsolete		obsolete
+./usr/libdata/debug/usr/tests/lib/libc/ieeefp/t_except.debug		tests-obsolete		obsolete
+./usr/libdata/debug/usr/tests/lib/libc/ieeefp/t_nan_inf.debug		tests-obsolete		obsolete
+./usr/libdata/debug/usr/tests/lib/libc/ieeefp/t_round.debug		tests-obsolete		obsolete
+./usr/libdata/debug/usr/tests/lib/libc/ieeefp/t_subnormal.debug		tests-obsolete		obsolete
 ./usr/libdata/debug/usr/tests/lib/libc/locale				tests-lib-debug
 ./usr/libdata/debug/usr/tests/lib/libc/locale/t_ctype1.debug		tests-obsolete		obsolete
 ./usr/libdata/debug/usr/tests/lib/libc/locale/t_ctype2.debug		tests-obsolete		obsolete
@@ -1935,12 +1935,12 @@
 ./usr/tests/lib/libc/hash/h_hash		tests-lib-tests		atf
 ./usr/tests/lib/libc/hash/t_hash		tests-lib-tests		atf
 ./usr/tests/lib/libc/hash/t_sha2		tests-lib-tests		atf
-./usr/tests/lib/libc/ieeefp			tests-lib-tests
-./usr/tests/lib/libc/ieeefp/Atffile		tests-lib-tests		atf
-./usr/tests/lib/libc/ieeefp/t_except		tests-lib-tests		atf
-./usr/tests/lib/libc/ieeefp/t_nan_inf		tests-lib-tests		atf
-./usr/tests/lib/libc/ieeefp/t_round		tests-lib-tests		atf
-./usr/tests/lib/libc/ieeefp/t_subnormal		tests-lib-tests		atf
+./usr/tests/lib/libc/ieeefp			tests-obsolete
+./usr/tests/lib/libc/ieeefp/Atffile		tests-obsolete		obsolete
+./usr/tests/lib/libc/ieeefp/t_except		tests-obsolete		obsolete
+./usr/tests/lib/libc/ieeefp/t_nan_inf		tests-obsolete		obsolete
+./usr/tests/lib/libc/ieeefp/t_round		tests-obsolete		obsolete
+./usr/tests/lib/libc/ieeefp/t_subnormal		tests-obsolete		obsolete
 ./usr/tests/lib/libc/locale			tests-lib-tests
 ./usr/tests/lib/libc/locale/Atffile		tests-lib-tests		atf
 ./usr/tests/lib/libc/locale/t_ctype1		tests-obsolete		obsolete

Index: src/etc/mtree/NetBSD.dist.tests
diff -u src/etc/mtree/NetBSD.dist.tests:1.52 src/etc/mtree/NetBSD.dist.tests:1.53
--- src/etc/mtree/NetBSD.dist.tests:1.52	Sat Aug 27 19:02:29 2011
+++ src/etc/mtree/NetBSD.dist.tests	Mon Sep 19 05:25:50 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: NetBSD.dist.tests,v 1.52 2011/08/27 19:02:29 dyoung Exp $
+#	$NetBSD: NetBSD.dist.tests,v 1.53 2011/09/19 05:25:50 jruoho Exp $
 
 ./usr/libdata/debug/usr/tests
 ./usr/libdata/debug/usr/tests/atf
@@ -51,7 +51,6 @@
 ./usr/libdata/debug/usr/tests/lib/libc/db
 ./usr/libdata/debug/usr/tests/lib/libc/gen
 ./usr/libdata/debug/usr/tests/lib/libc/hash
-./usr/libdata/debug/usr/tests/lib/libc/ieeefp
 ./usr/libdata/debug/usr/tests/lib/libc/locale
 ./usr/libdata/debug/usr/tests/lib/libc/inet
 ./usr/libdata/debug/usr/tests/lib/libc/net
@@ -173,7 +172,6 @@
 ./usr/tests/lib/libc/gen
 ./usr/tests/lib/libc/hash
 ./usr/tests/lib/libc/hash/data
-./usr/tests/lib/libc/ieeefp
 ./usr/tests/lib/libc/locale
 ./usr/tests/lib/libc/inet
 ./usr/tests/lib/libc/net

Index: src/tests/lib/libc/gen/Makefile
diff -u src/tests/lib/libc/gen/Makefile:1.28 src/tests/lib/libc/gen/Makefile:1.29
--- src/tests/lib/libc/gen/Makefile:1.28	Thu Jul  7 15:53:27 2011
+++ src/tests/lib/libc/gen/Makefile	Mon Sep 19 05:25:50 2011
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.28 2011/07/07 15:53:27 jruoho Exp $
+# $NetBSD: Makefile,v 1.29 2011/09/19 05:25:50 jruoho Exp $
 
 .include <bsd.own.mk>
 
@@ -10,10 +10,14 @@
 TESTS_C+=	t_closefrom
 TESTS_C+=	t_dir
 TESTS_C+=	t_fmtcheck
+TESTS_C+=	t_fpclassify
+TESTS_C+=	t_fpsetmask
+TESTS_C+=	t_fpsetround
 TESTS_C+=	t_getcwd
 TESTS_C+=	t_getgrent
 TESTS_C+=	t_glob
 TESTS_C+=	t_humanize_number
+TESTS_C+=	t_isnan
 TESTS_C+=	t_ldexp
 TESTS_C+=	t_nice
 TESTS_C+=	t_pause
@@ -26,8 +30,14 @@
 TESTS_C+=	t_ttyname
 TESTS_C+=	t_vis
 
+LDADD.t_fpclassify+=	-lm
 LDADD.t_ldexp+=		-lm
+
 LDADD.t_nice+=		-lpthread
 LDADD.t_syslog+=	-lpthread
 
+.if ${MACHINE_ARCH} == "alpha"
+COPTS+=			-mieee
+.endif
+
 .include <bsd.test.mk>

Added files:

Index: src/tests/lib/libc/gen/t_fpclassify.c
diff -u /dev/null src/tests/lib/libc/gen/t_fpclassify.c:1.1
--- /dev/null	Mon Sep 19 05:25:51 2011
+++ src/tests/lib/libc/gen/t_fpclassify.c	Mon Sep 19 05:25:50 2011
@@ -0,0 +1,206 @@
+/* $NetBSD: t_fpclassify.c,v 1.1 2011/09/19 05:25:50 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2011 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 <float.h>
+#include <math.h>
+#include <stdio.h>
+#include <string.h>
+
+#if defined(__vax__)
+
+ATF_TC(no_test);
+ATF_TC_HEAD(no_test, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Dummy test");
+}
+
+ATF_TC_BODY(no_test,tc)
+{
+	atf_tc_skip("Test not available on this architecture");
+}
+
+#else /* defined(__vax__) */
+
+ATF_TC(fpclassify_float);
+ATF_TC_HEAD(fpclassify_float, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr", "Test float operations");
+}
+
+ATF_TC_BODY(fpclassify_float, tc)
+{
+	float d0, d1, d2, f, ip;
+	int e, i;
+
+	d0 = FLT_MIN;
+	ATF_REQUIRE_EQ(fpclassify(d0), FP_NORMAL);
+	f = frexpf(d0, &e);
+	ATF_REQUIRE_EQ(e, FLT_MIN_EXP);
+	ATF_REQUIRE_EQ(f, 0.5);
+	d1 = d0;
+
+	/* shift a "1" bit through the mantissa (skip the implicit bit) */
+	for (i = 1; i < FLT_MANT_DIG; i++) {
+		d1 /= 2;
+		ATF_REQUIRE_EQ(fpclassify(d1), FP_SUBNORMAL);
+		ATF_REQUIRE(d1 > 0 && d1 < d0);
+
+		d2 = ldexpf(d0, -i);
+		ATF_REQUIRE_EQ(d2, d1);
+
+		d2 = modff(d1, &ip);
+		ATF_REQUIRE_EQ(d2, d1);
+		ATF_REQUIRE_EQ(ip, 0);
+
+		f = frexpf(d1, &e);
+		ATF_REQUIRE_EQ(e, FLT_MIN_EXP - i);
+		ATF_REQUIRE_EQ(f, 0.5);
+	}
+
+	d1 /= 2;
+	ATF_REQUIRE_EQ(fpclassify(d1), FP_ZERO);
+	f = frexpf(d1, &e);
+	ATF_REQUIRE_EQ(e, 0);
+	ATF_REQUIRE_EQ(f, 0);
+}
+
+ATF_TC(fpclassify_double);
+ATF_TC_HEAD(fpclassify_double, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr", "Test double operations");
+}
+
+ATF_TC_BODY(fpclassify_double, tc)
+{
+	double d0, d1, d2, f, ip;
+	int e, i;
+
+	d0 = DBL_MIN;
+	ATF_REQUIRE_EQ(fpclassify(d0), FP_NORMAL);
+	f = frexp(d0, &e);
+	ATF_REQUIRE_EQ(e, DBL_MIN_EXP);
+	ATF_REQUIRE_EQ(f, 0.5);
+	d1 = d0;
+
+	/* shift a "1" bit through the mantissa (skip the implicit bit) */
+	for (i = 1; i < DBL_MANT_DIG; i++) {
+		d1 /= 2;
+		ATF_REQUIRE_EQ(fpclassify(d1), FP_SUBNORMAL);
+		ATF_REQUIRE(d1 > 0 && d1 < d0);
+
+		d2 = ldexp(d0, -i);
+		ATF_REQUIRE_EQ(d2, d1);
+
+		d2 = modf(d1, &ip);
+		ATF_REQUIRE_EQ(d2, d1);
+		ATF_REQUIRE_EQ(ip, 0);
+
+		f = frexp(d1, &e);
+		ATF_REQUIRE_EQ(e, DBL_MIN_EXP - i);
+		ATF_REQUIRE_EQ(f, 0.5);
+	}
+
+	d1 /= 2;
+	ATF_REQUIRE_EQ(fpclassify(d1), FP_ZERO);
+	f = frexp(d1, &e);
+	ATF_REQUIRE_EQ(e, 0);
+	ATF_REQUIRE_EQ(f, 0);
+}
+
+/*
+ * XXX NetBSD doesn't have long-double flavors of frexp, ldexp, and modf,
+ * XXX so this test is disabled.
+ */
+
+#ifdef TEST_LONG_DOUBLE
+
+ATF_TC(fpclassify_long_double);
+ATF_TC_HEAD(fpclassify_long_double, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr", "Test long double operations");
+}
+
+ATF_TC_BODY(fpclassify_long_double, tc)
+{
+	long double d0, d1, d2, f, ip;
+	int e, i;
+
+	d0 = LDBL_MIN;
+	ATF_REQUIRE_EQ(fpclassify(d0), FP_NORMAL);
+	f = frexpl(d0, &e);
+	ATF_REQUIRE_EQ(e, LDBL_MIN_EXP);
+	ATF_REQUIRE_EQ(f, 0.5);
+	d1 = d0;
+
+	/* shift a "1" bit through the mantissa (skip the implicit bit) */
+	for (i = 1; i < LDBL_MANT_DIG; i++) {
+		d1 /= 2;
+		ATF_REQUIRE_EQ(fpclassify(d1), FP_SUBNORMAL);
+		ATF_REQUIRE(d1 > 0 && d1 < d0);
+
+		d2 = ldexpl(d0, -i);
+		ATF_REQUIRE_EQ(d2, d1);
+
+		d2 = modfl(d1, &ip);
+		ATF_REQUIRE_EQ(d2, d1);
+		ATF_REQUIRE_EQ(ip, 0);
+
+		f = frexpl(d1, &e);
+		ATF_REQUIRE_EQ(e, LDBL_MIN_EXP - i);
+		ATF_REQUIRE_EQ(f, 0.5);
+	}
+
+	d1 /= 2;
+	ATF_REQUIRE_EQ(fpclassify(d1), FP_ZERO);
+	f = frexpl(d1, &e);
+	ATF_REQUIRE_EQ(e, 0);
+	ATF_REQUIRE_EQ(f, 0);
+}
+#endif /* TEST_LONG_DOUBLE */
+#endif /* defined(__vax__) */
+
+ATF_TP_ADD_TCS(tp)
+{
+
+#if defined(__vax__)
+	ATF_TP_ADD_TC(tp, no_test);
+#else
+	ATF_TP_ADD_TC(tp, fpclassify_float);
+	ATF_TP_ADD_TC(tp, fpclassify_double);
+#ifdef TEST_LONG_DOUBLE
+	ATF_TP_ADD_TC(tp, fpclassify_long_double);
+#endif /* TEST_LONG_DOUBLE */
+#endif
+
+	return atf_no_error();
+}
Index: src/tests/lib/libc/gen/t_fpsetmask.c
diff -u /dev/null src/tests/lib/libc/gen/t_fpsetmask.c:1.1
--- /dev/null	Mon Sep 19 05:25:51 2011
+++ src/tests/lib/libc/gen/t_fpsetmask.c	Mon Sep 19 05:25:50 2011
@@ -0,0 +1,330 @@
+/*	$NetBSD: t_fpsetmask.c,v 1.1 2011/09/19 05:25:50 jruoho 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 <stdio.h>
+#include <signal.h>
+#include <float.h>
+#include <setjmp.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if defined(__mc68000__) || defined(__vax__)
+
+ATF_TC(no_test);
+ATF_TC_HEAD(no_test, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr", "Dummy test case");
+}
+
+ATF_TC_BODY(no_test, tc)
+{
+
+	atf_tc_skip("Test not available on this architecture.");
+}
+
+#else /* defined(__mc68000__) || defined(__vax__) */
+
+#include <ieeefp.h>
+
+const char *skip_mesg;
+const char *skip_arch;
+
+void		sigfpe(int, siginfo_t *, void *);
+
+volatile sig_atomic_t signal_caught;
+volatile int sicode;
+
+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 const 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 const 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 const 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
+fpsetmask_masked(const struct ops *test_ops)
+{
+	struct sigaction sa;
+	fp_except ex1, ex2;
+	const struct ops *t;
+
+	/* 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
+	 */
+	for (t = test_ops; t->op != NULL; t++) {
+		(*t->op)();
+		ex1 = fpgetsticky();
+		ATF_CHECK_EQ(ex1 & t->mask, t->mask);
+		ATF_CHECK_EQ(signal_caught, 0);
+
+		/* check correct fpsetsticky() behaviour */
+		ex2 = fpsetsticky(0);
+		ATF_CHECK_EQ(fpgetsticky(), 0);
+		ATF_CHECK_EQ(ex1, ex2);
+	}
+}
+
+/* force delayed exceptions to be delivered */
+#define BARRIER() fpsetmask(0); f_x = f_one * f_one
+
+static void
+fpsetmask_unmasked(const struct ops *test_ops)
+{
+	struct sigaction sa;
+	int r;
+	const struct ops *volatile t;
+
+	/* 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
+	 */
+	for (t = test_ops; t->op != NULL; t++) {
+		fpsetmask(t->mask);
+		r = sigsetjmp(b, 1);
+		if (!r) {
+			(*t->op)();
+			BARRIER();
+		}
+		ATF_CHECK_EQ(signal_caught, 1);
+		ATF_CHECK_EQ(sicode, t->sicode);
+		signal_caught = 0;
+	}
+}
+
+void
+sigfpe(int s, siginfo_t *si, void *c)
+{
+	signal_caught = 1;
+	sicode = si->si_code;
+	siglongjmp(b, 1);
+}
+
+#define TEST(m, t)							\
+	ATF_TC(m##_##t);						\
+									\
+	ATF_TC_HEAD(m##_##t, tc)					\
+	{								\
+									\
+		atf_tc_set_md_var(tc, "descr",				\
+		    "Test " ___STRING(m) " exceptions for "		\
+		    ___STRING(t) "values");				\
+	}								\
+									\
+	ATF_TC_BODY(m##_##t, tc)					\
+	{								\
+									\
+		if (system("cpuctl identify 0 | grep -q QEMU") == 0)	\
+			atf_tc_skip("Test not applicable on QEMU");	\
+		if (system("cpuctl identify 0 | grep -q			\
+		  'cpu0: Intel Pentium II (Klamath) (686-class), id 0x633'")\
+		    == 0)						\
+			atf_tc_skip("Test not applicable on QEMU "	\
+			    "(heuristic match)");			\
+		m(t##_ops);						\
+	}
+
+TEST(fpsetmask_masked, float)
+TEST(fpsetmask_masked, double)
+TEST(fpsetmask_masked, long_double)
+TEST(fpsetmask_unmasked, float)
+TEST(fpsetmask_unmasked, double)
+TEST(fpsetmask_unmasked, long_double)
+
+#endif /* defined(__mc68000__) || defined(__vax__) */
+
+ATF_TP_ADD_TCS(tp)
+{
+
+#if defined(__mc68000__) || defined(__vax__)
+	ATF_TP_ADD_TC(tp, no_test);
+#else
+	ATF_TP_ADD_TC(tp, fpsetmask_masked_float);
+	ATF_TP_ADD_TC(tp, fpsetmask_masked_double);
+	ATF_TP_ADD_TC(tp, fpsetmask_masked_long_double);
+	ATF_TP_ADD_TC(tp, fpsetmask_unmasked_float);
+	ATF_TP_ADD_TC(tp, fpsetmask_unmasked_double);
+	ATF_TP_ADD_TC(tp, fpsetmask_unmasked_long_double);
+#endif
+
+	return atf_no_error();
+}
Index: src/tests/lib/libc/gen/t_fpsetround.c
diff -u /dev/null src/tests/lib/libc/gen/t_fpsetround.c:1.1
--- /dev/null	Mon Sep 19 05:25:51 2011
+++ src/tests/lib/libc/gen/t_fpsetround.c	Mon Sep 19 05:25:50 2011
@@ -0,0 +1,77 @@
+/* $NetBSD: t_fpsetround.c,v 1.1 2011/09/19 05:25:50 jruoho Exp $ */
+
+/*
+ * Written by J.T. Conklin, Apr 18, 1995
+ * Public domain.
+ */
+
+#include <atf-c.h>
+
+#include <float.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if !defined(__mc68000__) && !defined(__vax__)
+#include <ieeefp.h>
+#endif
+
+ATF_TC(fpsetround_basic);
+ATF_TC_HEAD(fpsetround_basic, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr",
+	    "Minimal testing of fpgetround(3) and fpsetround(3)");
+}
+
+ATF_TC_BODY(fpsetround_basic, tc)
+{
+
+#if defined(__mc68000__) || defined(__vax__)
+	atf_tc_skip("Test not applicable on this architecture.");
+#else
+	/*
+	 * This test would be better if it actually performed some
+	 * calculations to verify the selected rounding mode.  But
+	 * this is probably acceptable since the fp{get,set}round
+	 * functions usually just get or set the processors fpu
+	 * control word.
+	 */
+
+	ATF_CHECK_EQ(fpgetround(), FP_RN);
+	ATF_CHECK_EQ(FLT_ROUNDS, 1);
+
+	/*
+	 * At least on one port (amd64), fpsetround() doesn't have any visible
+	 * effect.  So disable checking for the non-default modes for now.
+	 * See PR port-amd64/44293
+	 */
+#ifdef NOTYET
+	ATF_CHECK_EQ(fpsetround(FP_RP), FP_RN);
+	ATF_CHECK_EQ(fpgetround(), FP_RP);
+	ATF_CHECK_EQ(FLT_ROUNDS, 2);
+
+	ATF_CHECK_EQ(fpsetround(FP_RM), FP_RP);
+	ATF_CHECK_EQ(fpgetround(), FP_RM);
+	ATF_CHECK_EQ(FLT_ROUNDS, 3);
+
+	ATF_CHECK_EQ(fpsetround(FP_RZ), FP_RM);
+	ATF_CHECK_EQ(fpgetround(), FP_RZ);
+	ATF_CHECK_EQ(FLT_ROUNDS, 0);
+
+	ATF_CHECK_EQ(fpsetround(FP_RN), FP_RZ);
+#else /* NOTYET */
+	ATF_CHECK_EQ(fpsetround(FP_RN), FP_RN);
+#endif /* NOTYET */
+
+	ATF_CHECK_EQ(fpgetround(), FP_RN);
+	ATF_CHECK_EQ(FLT_ROUNDS, 1);
+#endif /* defined(__mc68000__) || defined(__vax__) */
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+	ATF_TP_ADD_TC(tp, fpsetround_basic);
+
+	return atf_no_error();
+}
Index: src/tests/lib/libc/gen/t_isnan.c
diff -u /dev/null src/tests/lib/libc/gen/t_isnan.c:1.1
--- /dev/null	Mon Sep 19 05:25:51 2011
+++ src/tests/lib/libc/gen/t_isnan.c	Mon Sep 19 05:25:50 2011
@@ -0,0 +1,62 @@
+/* $NetBSD: t_isnan.c,v 1.1 2011/09/19 05:25:50 jruoho Exp $ */
+
+/*
+ * This file is in the Public Domain.
+ *
+ * The nan test is blatently copied by Simon Burge from the infinity
+ * test by Ben Harris.
+ */
+
+#include <atf-c.h>
+#include <atf-c/config.h>
+
+#include <math.h>
+#include <string.h>
+
+ATF_TC(isnan_basic);
+ATF_TC_HEAD(isnan_basic, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Verify that isnan(3) works");
+}
+
+ATF_TC_BODY(isnan_basic, tc)
+{
+	/* NAN is meant to be a (float)NaN. */
+	ATF_CHECK(isnan(NAN) != 0);
+	ATF_CHECK(isnan((double)NAN) != 0);
+}
+
+ATF_TC(isinf_basic);
+ATF_TC_HEAD(isinf_basic, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Verify that isinf(3) works");
+}
+
+ATF_TC_BODY(isinf_basic, tc)
+{
+
+	/* HUGE_VAL is meant to be an infinity. */
+	ATF_CHECK(isinf(HUGE_VAL) != 0);
+
+	/* HUGE_VALF is the float analog of HUGE_VAL. */
+	ATF_CHECK(isinf(HUGE_VALF) != 0);
+
+	/* HUGE_VALL is the long double analog of HUGE_VAL. */
+	ATF_CHECK(isinf(HUGE_VALL) != 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+	const char *arch;
+
+	arch = atf_config_get("atf_arch");
+
+	if (strcmp("vax", arch) == 0 || strcmp("m68000", arch) == 0)
+		atf_tc_skip("Test not applicable on %s", arch);
+	else {
+		ATF_TP_ADD_TC(tp, isnan_basic);
+		ATF_TP_ADD_TC(tp, isinf_basic);
+	}
+
+	return atf_no_error();
+}

Reply via email to