Module Name:    src
Committed By:   jmmv
Date:           Sun Jun  5 07:58:03 UTC 2011

Modified Files:
        src/tests/lib/libc/stdlib: t_strtod.c

Log Message:
Do not blindly skip test code.

Tests are not supposed to skip whole parts of code to later report a success.
Instead, they need to report a 'skipped' result so that it is clear to the
user that some part of the tests were not run.

To do this, add proper calls to atf_tc_skip where some pieces of code are
skipped.  Also, make the strtod/strtof/strtold inf and nan tests more granular
so that the *ld versions can be skipped altogether when there is no support
for them.  As a result of this, the atf_tc_expect_fail becomes accurate; it
could have hidden bugs in strtod and strtof before.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/tests/lib/libc/stdlib/t_strtod.c

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/stdlib/t_strtod.c
diff -u src/tests/lib/libc/stdlib/t_strtod.c:1.17 src/tests/lib/libc/stdlib/t_strtod.c:1.18
--- src/tests/lib/libc/stdlib/t_strtod.c:1.17	Sun Jun  5 00:02:05 2011
+++ src/tests/lib/libc/stdlib/t_strtod.c	Sun Jun  5 07:58:03 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_strtod.c,v 1.17 2011/06/05 00:02:05 christos Exp $ */
+/*	$NetBSD: t_strtod.c,v 1.18 2011/06/05 07:58:03 jmmv Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 /* Public domain, Otto Moerbeek <o...@drijf.net>, 2006. */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_strtod.c,v 1.17 2011/06/05 00:02:05 christos Exp $");
+__RCSID("$NetBSD: t_strtod.c,v 1.18 2011/06/05 07:58:03 jmmv Exp $");
 
 #include <errno.h>
 #include <math.h>
@@ -47,6 +47,13 @@
 #include <fenv.h>
 #endif
 
+#if !defined(__vax__)
+static const char * const inf_strings[] =
+    { "Inf", "INF", "-Inf", "-INF", "Infinity", "+Infinity",
+      "INFINITY", "-INFINITY", "InFiNiTy", "+InFiNiTy" };
+const char *nan_string = "NaN(x)y";
+#endif
+
 ATF_TC(strtod_basic);
 ATF_TC_HEAD(strtod_basic, tc)
 {
@@ -105,10 +112,6 @@
 ATF_TC_BODY(strtod_inf, tc)
 {
 #ifndef __vax__
-	static const char * const str[] =
-	    { "Inf", "INF", "-Inf", "-INF", "Infinity", "+Infinity",
-	      "INFINITY", "-INFINITY", "InFiNiTy", "+InFiNiTy" };
-
 	/*
 	 * See the closed PR lib/33262.
 	 *
@@ -117,19 +120,68 @@
 	if (system("cpuctl identify 0 | grep -q QEMU") == 0)
 		atf_tc_expect_fail("PR misc/44767");
 
-	for (size_t i = 0; i < __arraycount(str); i++) {
-
-		double d = strtod(str[i], NULL);
+	for (size_t i = 0; i < __arraycount(inf_strings); i++) {
+		double d = strtod(inf_strings[i], NULL);
 		ATF_REQUIRE(isinf(d) != 0);
+	}
+#else
+	atf_tc_skip("vax not supported");
+#endif
+}
+
+ATF_TC(strtof_inf);
+ATF_TC_HEAD(strtof_inf, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "A strtof(3) with INF");
+}
+
+ATF_TC_BODY(strtof_inf, tc)
+{
+#ifndef __vax__
+	/*
+	 * See the closed PR lib/33262.
+	 *
+	 * This may also fail under QEMU; cf. PR misc/44767.
+	 */
+	if (system("cpuctl identify 0 | grep -q QEMU") == 0)
+		atf_tc_expect_fail("PR misc/44767");
 
-		float f = strtof(str[i], NULL);
+	for (size_t i = 0; i < __arraycount(inf_strings); i++) {
+		float f = strtof(inf_strings[i], NULL);
 		ATF_REQUIRE(isinf(f) != 0);
+	}
+#else
+	atf_tc_skip("vax not supported");
+#endif
+}
+
+ATF_TC(strtold_inf);
+ATF_TC_HEAD(strtold_inf, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "A strtold(3) with INF");
+}
+
+ATF_TC_BODY(strtold_inf, tc)
+{
+#ifndef __vax__
+#   ifdef __HAVE_LONG_DOUBLE
+	/*
+	 * See the closed PR lib/33262.
+	 *
+	 * This may also fail under QEMU; cf. PR misc/44767.
+	 */
+	if (system("cpuctl identify 0 | grep -q QEMU") == 0)
+		atf_tc_expect_fail("PR misc/44767");
 
-#ifdef __HAVE_LONG_DOUBLE
-		long double ld = strtold(str[i], NULL);
+	for (size_t i = 0; i < __arraycount(inf_strings); i++) {
+		long double ld = strtold(inf_strings[i], NULL);
 		ATF_REQUIRE(isinf(ld) != 0);
-#endif
 	}
+#   else
+	atf_tc_skip("Requires long double support");
+#   endif
+#else
+	atf_tc_skip("vax not supported");
 #endif
 }
 
@@ -142,25 +194,58 @@
 ATF_TC_BODY(strtod_nan, tc)
 {
 #ifndef __vax__
-	const char *str = "NaN(x)y";
 	char *end;
 
-	atf_tc_expect_fail("PR lib/45020");
-
-	double d = strtod(str, &end);
+	double d = strtod(nan_string, &end);
 	ATF_REQUIRE(isnan(d) != 0);
 	ATF_REQUIRE(strcmp(end, "y") == 0);
+#else
+	atf_tc_skip("vax not supported");
+#endif
+}
+
+ATF_TC(strtof_nan);
+ATF_TC_HEAD(strtof_nan, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "A strtof(3) with NaN");
+}
+
+ATF_TC_BODY(strtof_nan, tc)
+{
+#ifndef __vax__
+	char *end;
 
-	float f = strtof(str, &end);
+	float f = strtof(nan_string, &end);
 	ATF_REQUIRE(isnanf(f) != 0);
 	ATF_REQUIRE(strcmp(end, "y") == 0);
+#else
+	atf_tc_skip("vax not supported");
+#endif
+}
+
+ATF_TC(strtold_nan);
+ATF_TC_HEAD(strtold_nan, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "A strtold(3) with NaN");
+}
 
-#ifdef __HAVE_LONG_DOUBLE
-	long double ld = strtold(str, &end);
+ATF_TC_BODY(strtold_nan, tc)
+{
+#ifndef __vax__
+#   ifdef __HAVE_LONG_DOUBLE
+	char *end;
+
+	atf_tc_expect_fail("PR lib/45020");
+
+	long double ld = strtold(nan_string, &end);
 	ATF_REQUIRE(isnan(ld) != 0);
 	ATF_REQUIRE(__isnanl(ld) != 0);
 	ATF_REQUIRE(strcmp(end, "y") == 0);
-#endif
+#   else
+	atf_tc_skip("Requires long double support");
+#   endif
+#else
+	atf_tc_skip("vax not supported");
 #endif
 }
 
@@ -194,6 +279,8 @@
 	double d2 = strtod(val, NULL);
 
 	ATF_REQUIRE(fabs(d1 - d2) > 0.0);
+#else
+	atf_tc_skip("Requires one of i386, amd64 or sparc");
 #endif
 }
 
@@ -229,7 +316,11 @@
 	ATF_TP_ADD_TC(tp, strtod_basic);
 	ATF_TP_ADD_TC(tp, strtod_hex);
 	ATF_TP_ADD_TC(tp, strtod_inf);
+	ATF_TP_ADD_TC(tp, strtof_inf);
+	ATF_TP_ADD_TC(tp, strtold_inf);
 	ATF_TP_ADD_TC(tp, strtod_nan);
+	ATF_TP_ADD_TC(tp, strtof_nan);
+	ATF_TP_ADD_TC(tp, strtold_nan);
 	ATF_TP_ADD_TC(tp, strtod_round);
 	ATF_TP_ADD_TC(tp, strtod_underflow);
 

Reply via email to