Module Name: src
Committed By: christos
Date: Fri Sep 30 18:27:18 UTC 2011
Modified Files:
src/tests/lib/libc/gen: t_fpsetround.c
Log Message:
print stderr, when things go wrong.
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/gen/t_fpsetround.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/gen/t_fpsetround.c
diff -u src/tests/lib/libc/gen/t_fpsetround.c:1.2 src/tests/lib/libc/gen/t_fpsetround.c:1.3
--- src/tests/lib/libc/gen/t_fpsetround.c:1.2 Fri Sep 30 13:44:58 2011
+++ src/tests/lib/libc/gen/t_fpsetround.c Fri Sep 30 14:27:18 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: t_fpsetround.c,v 1.2 2011/09/30 17:44:58 christos Exp $ */
+/* $NetBSD: t_fpsetround.c,v 1.3 2011/09/30 18:27:18 christos Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -36,24 +36,18 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_fpsetround.c,v 1.2 2011/09/30 17:44:58 christos Exp $");
+__RCSID("$NetBSD: t_fpsetround.c,v 1.3 2011/09/30 18:27:18 christos Exp $");
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
+#include <stdio.h>
#if !defined(__mc68000__) && !defined(__vax__)
#include <ieeefp.h>
#endif
-#ifdef DEBUG
-#include <stdio.h>
-#define DPRINTF(a) printf a
-#else
-#define DPRINTF(a)
-#endif
-
#include <atf-c.h>
ATF_TC(fpsetround_basic);
@@ -66,6 +60,18 @@ ATF_TC_HEAD(fpsetround_basic, tc)
static const struct {
const char *n;
+ int rm;
+ int rf;
+} rnd[] = {
+ { "RN", FP_RN, 1 },
+ { "RP", FP_RP, 2 },
+ { "RM", FP_RM, 3 },
+ { "RZ", FP_RZ, 0 },
+
+};
+
+static const struct {
+ const char *n;
int v[4];
} tst[] = { /* RN RP RM RZ */
{ "1.1", { 1, 1, 2, 1 } },
@@ -79,23 +85,23 @@ static const struct {
static void
test(int r)
{
+ int did = 0;
for (size_t i = 0; i < __arraycount(tst); i++) {
double d = strtod(tst[i].n, NULL);
- ATF_CHECK_EQ((int)rint(d), tst[i].v[r]);
- DPRINTF(("%s %d %d\n", tst[i].n, (int)rint(d), tst[i].v[r]));
+ int g = (int)rint(d);
+ int e = tst[i].v[r];
+ ATF_CHECK_EQ(g, e);
+ if (g != e) {
+ if (!did) {
+ fprintf(stderr, "Mode Value Result Expected\n");
+ did = 1;
+ }
+ fprintf(stderr, "%4.4s %-5.5s %6d %8d\n", rnd[r].n,
+ tst[i].n, (int)rint(d), tst[i].v[r]);
+ }
}
}
-static const struct {
- int rm;
- int rf;
-} rnd[] = {
- { FP_RN, 1 },
- { FP_RP, 2 },
- { FP_RM, 3 },
- { FP_RZ, 0 },
-
-};
ATF_TC_BODY(fpsetround_basic, tc)
{
@@ -114,10 +120,15 @@ ATF_TC_BODY(fpsetround_basic, tc)
int n = rnd[j].rm;
ATF_CHECK_EQ(r = fpsetround(n), o);
- DPRINTF(("s o=%x r=%x\n", o, r));
+ if (o != r)
+ fprintf(stderr, "set expected=%x got=%x\n", o, r);
ATF_CHECK_EQ(r = fpgetround(), n);
- DPRINTF(("g n=%x r=%x\n", n, r));
- ATF_CHECK_EQ(FLT_ROUNDS, rnd[j].rf);
+ if (n != r)
+ fprintf(stderr, "get expected=%x got=%x\n", n, r);
+ ATF_CHECK_EQ(r= FLT_ROUNDS, rnd[j].rf);
+ if (r != rnd[j].rf)
+ fprintf(stderr, "rounds expected=%x got=%x\n",
+ rnd[j].rf, r);
test(rnd[j].rf);
}
#endif /* defined(__mc68000__) || defined(__vax__) */