Source-Changes-HG archive

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

[src/trunk]: src/tests/lib/libm Try to generate infinite values in all availa...



details:   https://anonhg.NetBSD.org/src/rev/7bf614ea70ee
branches:  trunk
changeset: 764098:7bf614ea70ee
user:      martin <martin%NetBSD.org@localhost>
date:      Mon Apr 11 10:51:36 2011 +0000

description:
Try to generate infinite values in all available floating point formats
on the FPU and check isinf() and fpclassify() results. This is
different from the libc internal consistency checks testing PR
lib/33262.

diffstat:

 tests/lib/libm/Makefile     |    4 +-
 tests/lib/libm/t_infinity.c |  117 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 119 insertions(+), 2 deletions(-)

diffs (137 lines):

diff -r 69eef80201db -r 7bf614ea70ee tests/lib/libm/Makefile
--- a/tests/lib/libm/Makefile   Mon Apr 11 10:41:17 2011 +0000
+++ b/tests/lib/libm/Makefile   Mon Apr 11 10:51:36 2011 +0000
@@ -1,10 +1,10 @@
-# $NetBSD: Makefile,v 1.5 2011/04/10 06:11:47 jruoho Exp $
+# $NetBSD: Makefile,v 1.6 2011/04/11 10:51:36 martin Exp $
 
 .include <bsd.own.mk>
 
 TESTSDIR=      ${TESTSBASE}/lib/libm
 
-TESTS_C+=      t_ceil t_floor t_log t_round t_tanh
+TESTS_C+=      t_ceil t_floor t_log t_round t_tanh t_infinity
 
 LDADD+=                -lm
 COPTS+=                -Wfloat-equal
diff -r 69eef80201db -r 7bf614ea70ee tests/lib/libm/t_infinity.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libm/t_infinity.c       Mon Apr 11 10:51:36 2011 +0000
@@ -0,0 +1,117 @@
+/* $NetBSD: t_infinity.c,v 1.1 2011/04/11 10:51:36 martin Exp $ */
+
+/*-
+ * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Martin Husemann <martin%NetBSD.org@localhost>.
+ *
+ * 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 <sys/cdefs.h>
+__RCSID("$NetBSD: t_infinity.c,v 1.1 2011/04/11 10:51:36 martin Exp $");
+
+#include <atf-c.h>
+#include <math.h>
+#include <float.h>
+
+ATF_TC(infinity_float);
+ATF_TC_HEAD(infinity_float, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+            "check FPU generated infinite float values");
+}
+
+ATF_TC_BODY(infinity_float, tc)
+{
+       float v;
+
+       v = FLT_MAX;
+       v *= v;
+       ATF_REQUIRE(isinf(v));
+       ATF_REQUIRE(fpclassify(v) == FP_INFINITE);
+
+       v = -FLT_MAX;
+       v *= v;
+       ATF_REQUIRE(isinf(v));
+       ATF_REQUIRE(fpclassify(v) == FP_INFINITE);
+}
+
+ATF_TC(infinity_double);
+ATF_TC_HEAD(infinity_double, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+            "check FPU generated infinite double values");
+}
+
+ATF_TC_BODY(infinity_double, tc)
+{
+       double v;
+
+       v = DBL_MAX;
+       v *= v;
+       ATF_REQUIRE(isinf(v));
+       ATF_REQUIRE(fpclassify(v) == FP_INFINITE);
+
+       v = -DBL_MAX;
+       v *= v;
+       ATF_REQUIRE(isinf(v));
+       ATF_REQUIRE(fpclassify(v) == FP_INFINITE);
+}
+
+ATF_TC(infinity_long_double);
+ATF_TC_HEAD(infinity_long_double, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+            "check FPU generated infinite long double values");
+}
+
+ATF_TC_BODY(infinity_long_double, tc)
+{
+#ifndef LDBL_MAX
+       atf_tc_skip("no long double support on this architecture");
+       return;
+#else
+       long double v;
+
+       v = LDBL_MAX;
+       v *= v;
+       ATF_REQUIRE(isinf(v));
+       ATF_REQUIRE(fpclassify(v) == FP_INFINITE);
+
+       v = -LDBL_MAX;
+       v *= v;
+       ATF_REQUIRE(isinf(v));
+       ATF_REQUIRE(fpclassify(v) == FP_INFINITE);
+#endif
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+       ATF_TP_ADD_TC(tp, infinity_float);
+       ATF_TP_ADD_TC(tp, infinity_double);
+       ATF_TP_ADD_TC(tp, infinity_long_double);
+
+       return atf_no_error();
+}



Home | Main Index | Thread Index | Old Index