Source-Changes-HG archive

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

[src/trunk]: src/tests/include/sys t_bitops: Show the bad results on failure.



details:   https://anonhg.NetBSD.org/src/rev/5fb89842c59e
branches:  trunk
changeset: 377477:5fb89842c59e
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Thu Jul 13 20:39:24 2023 +0000

description:
t_bitops: Show the bad results on failure.

diffstat:

 tests/include/sys/t_bitops.c |  373 +++++++++++++++++++++++-------------------
 1 files changed, 208 insertions(+), 165 deletions(-)

diffs (truncated from 472 to 300 lines):

diff -r 29f8102843cc -r 5fb89842c59e tests/include/sys/t_bitops.c
--- a/tests/include/sys/t_bitops.c      Thu Jul 13 20:30:21 2023 +0000
+++ b/tests/include/sys/t_bitops.c      Thu Jul 13 20:39:24 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_bitops.c,v 1.20 2018/07/25 22:00:32 kamil Exp $ */
+/*     $NetBSD: t_bitops.c,v 1.21 2023/07/13 20:39:24 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2011, 2012 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_bitops.c,v 1.20 2018/07/25 22:00:32 kamil Exp $");
+__RCSID("$NetBSD: t_bitops.c,v 1.21 2023/07/13 20:39:24 riastradh Exp $");
 
 #include <atf-c.h>
 
@@ -72,31 +72,36 @@ ATF_TC_HEAD(bitmap_basic, tc)
 
 ATF_TC_BODY(bitmap_basic, tc)
 {
+       size_t n;
+
        __BITMAP_TYPE(, uint32_t, 65536) bm;
        __BITMAP_ZERO(&bm);
 
-       ATF_REQUIRE(__BITMAP_SIZE(uint32_t, 65536) == 2048);
+       ATF_CHECK_EQ_MSG((n = __BITMAP_SIZE(uint32_t, 65536)), 2048,
+           "n=%zu", n);
 
-       ATF_REQUIRE(__BITMAP_SHIFT(uint32_t) == 5);
+       ATF_CHECK_EQ_MSG((n = __BITMAP_SHIFT(uint32_t)), 5, "n=%zu", n);
 
-       ATF_REQUIRE(__BITMAP_MASK(uint32_t) == 31);
+       ATF_CHECK_EQ_MSG((n = __BITMAP_MASK(uint32_t)), 31, "n=%zu", n);
 
        for (size_t i = 0; i < 65536; i += 2)
                __BITMAP_SET(i, &bm);
 
-       for (size_t i = 0; i < 2048; i++)
-               ATF_REQUIRE(bm._b[i] == 0x55555555);
+       for (size_t i = 0; i < 2048; i++) {
+               ATF_CHECK_EQ_MSG(bm._b[i], 0x55555555, "bm._b[%zu]=0x%"PRIx32,
+                   i, bm._b[i]);
+       }
 
        for (size_t i = 0; i < 65536; i++)
                if (i & 1)
-                       ATF_REQUIRE(!__BITMAP_ISSET(i, &bm));
+                       ATF_CHECK_MSG(!__BITMAP_ISSET(i, &bm), "i=%zu", i);
                else {
-                       ATF_REQUIRE(__BITMAP_ISSET(i, &bm));
+                       ATF_CHECK_MSG(__BITMAP_ISSET(i, &bm), "i=%zu", i);
                        __BITMAP_CLR(i, &bm);
                }
 
        for (size_t i = 0; i < 65536; i += 2)
-               ATF_REQUIRE(!__BITMAP_ISSET(i, &bm));
+               ATF_CHECK_MSG(!__BITMAP_ISSET(i, &bm), "i=%zu", i);
 }
 
 ATF_TC(fast_divide32);
@@ -118,7 +123,14 @@ ATF_TC_BODY(fast_divide32, tc)
        q = fast_divide32(a, b, m, s1, s2);
        r = fast_remainder32(a, b, m, s1, s2);
 
-       ATF_REQUIRE(q == 0x1111 && r == 0);
+       ATF_CHECK_EQ_MSG(q, 0x1111,
+           "q=%"PRIu32"; a=%"PRIu32" b=%"PRIu32" a/b=%"PRIu32";"
+           " m=%"PRIu32" s1=%"PRIu8" s2=%"PRIu8,
+           q, a, b, a / b, m, s1, s2);
+       ATF_CHECK_EQ_MSG(r, 0,
+           "q=%"PRIu32", a=%"PRIu32", b=%"PRIu32", a%%b=%"PRIu32";"
+           " m=%"PRIu32" s1=%"PRIu8" s2=%"PRIu8,
+           q, a, b, a % b, m, s1, s2);
 
        for (i = 1; i < __arraycount(bits); i++) {
 
@@ -130,8 +142,14 @@ ATF_TC_BODY(fast_divide32, tc)
                q = fast_divide32(a, b, m, s1, s2);
                r = fast_remainder32(a, b, m, s1, s2);
 
-               ATF_REQUIRE(q == a / b);
-               ATF_REQUIRE(r == a % b);
+               ATF_CHECK_EQ_MSG(q, a / b,
+                   "q=%"PRIu32"; a=%"PRIu32" b=%"PRIu32" a/b=%"PRIu32";"
+                   " m=%"PRIu32" s1=%"PRIu8" s2=%"PRIu8,
+                   q, a, b, a / b, m, s1, s2);
+               ATF_CHECK_EQ_MSG(r, a % b,
+                   "q=%"PRIu32", a=%"PRIu32", b=%"PRIu32", a%%b=%"PRIu32";"
+                   " m=%"PRIu32" s1=%"PRIu8" s2=%"PRIu8,
+                   q, a, b, a % b, m, s1, s2);
        }
 }
 
@@ -144,33 +162,54 @@ ATF_TC_HEAD(ffsfls, tc)
 ATF_TC_BODY(ffsfls, tc)
 {
        uint8_t i;
+       int n, m;
 
-       ATF_REQUIRE(ffs32(0) == 0x00);
-       ATF_REQUIRE(fls32(0) == 0x00);
-       ATF_REQUIRE(ffs64(0) == 0x00);
-       ATF_REQUIRE(fls64(0) == 0x00);
+       ATF_CHECK_EQ_MSG((n = ffs32(0)), 0x00, "n=%d", n);
+       ATF_CHECK_EQ_MSG((n = fls32(0)), 0x00, "n=%d", n);
+       ATF_CHECK_EQ_MSG((n = ffs64(0)), 0x00, "n=%d", n);
+       ATF_CHECK_EQ_MSG((n = fls64(0)), 0x00, "n=%d", n);
 
-       ATF_REQUIRE(ffs32(UINT32_MAX) == 0x01);
-       ATF_REQUIRE(fls32(UINT32_MAX) == 0x20);
-       ATF_REQUIRE(ffs64(UINT64_MAX) == 0x01);
-       ATF_REQUIRE(fls64(UINT64_MAX) == 0x40);
+       ATF_CHECK_EQ_MSG((n = ffs32(UINT32_MAX)), 0x01, "n=%d", n);
+       ATF_CHECK_EQ_MSG((n = fls32(UINT32_MAX)), 0x20, "n=%d", n);
+       ATF_CHECK_EQ_MSG((n = ffs64(UINT64_MAX)), 0x01, "n=%d", n);
+       ATF_CHECK_EQ_MSG((n = fls64(UINT64_MAX)), 0x40, "n=%d", n);
 
        for (i = 1; i < __arraycount(bits); i++) {
 
-               ATF_REQUIRE(ffs32(bits[i].val) == bits[i].ffs);
-               ATF_REQUIRE(fls32(bits[i].val) == bits[i].fls);
-               ATF_REQUIRE(ffs64(bits[i].val) == bits[i].ffs);
-               ATF_REQUIRE(fls64(bits[i].val) == bits[i].fls);
+               ATF_CHECK_EQ_MSG((n = ffs32(bits[i].val)), (m = bits[i].ffs),
+                   "[i=%"PRIu8"] n=%d m=%d", i, n, m);
+               ATF_CHECK_EQ_MSG((n = fls32(bits[i].val)), (m = bits[i].fls),
+                   "[i=%"PRIu8"] n=%d m=%d", i, n, m);
+               ATF_CHECK_EQ_MSG((n = ffs64(bits[i].val)), (m = bits[i].ffs),
+                   "[i=%"PRIu8"] n=%d m=%d", i, n, m);
+               ATF_CHECK_EQ_MSG((n = fls64(bits[i].val)), (m = bits[i].fls),
+                   "[i=%"PRIu8"] n=%d m=%d", i, n, m);
 
-               ATF_REQUIRE(ffs32(bits[i].val << 1) == bits[i].ffs + 1);
-               ATF_REQUIRE(fls32(bits[i].val << 1) == bits[i].fls + 1);
-               ATF_REQUIRE(ffs64(bits[i].val << 1) == bits[i].ffs + 1);
-               ATF_REQUIRE(fls64(bits[i].val << 1) == bits[i].fls + 1);
+               ATF_CHECK_EQ_MSG((n = ffs32(bits[i].val << 1)),
+                   (m = bits[i].ffs + 1),
+                   "[i=%"PRIu8"] n=%d m=%d", i, n, m);
+               ATF_CHECK_EQ_MSG((n = fls32(bits[i].val << 1)),
+                   (m = bits[i].fls + 1),
+                   "[i=%"PRIu8"] n=%d m=%d", i, n, m);
+               ATF_CHECK_EQ_MSG((n = ffs64(bits[i].val << 1)),
+                   (m = bits[i].ffs + 1),
+                   "[i=%"PRIu8"] n=%d m=%d", i, n, m);
+               ATF_CHECK_EQ_MSG((n = fls64(bits[i].val << 1)),
+                   (m = bits[i].fls + 1),
+                   "[i=%"PRIu8"] n=%d m=%d", i, n, m);
 
-               ATF_REQUIRE(ffs32(bits[i].val << 9) == bits[i].ffs + 9);
-               ATF_REQUIRE(fls32(bits[i].val << 9) == bits[i].fls + 9);
-               ATF_REQUIRE(ffs64(bits[i].val << 9) == bits[i].ffs + 9);
-               ATF_REQUIRE(fls64(bits[i].val << 9) == bits[i].fls + 9);
+               ATF_CHECK_EQ_MSG((n = ffs32(bits[i].val << 9)),
+                   (m = bits[i].ffs + 9),
+                   "[i=%"PRIu8"] n=%d m=%d", i, n, m);
+               ATF_CHECK_EQ_MSG((n = fls32(bits[i].val << 9)),
+                   (m = bits[i].fls + 9),
+                   "[i=%"PRIu8"] n=%d m=%d", i, n, m);
+               ATF_CHECK_EQ_MSG((n = ffs64(bits[i].val << 9)),
+                   (m = bits[i].ffs + 9),
+                   "[i=%"PRIu8"] n=%d m=%d", i, n, m);
+               ATF_CHECK_EQ_MSG((n = fls64(bits[i].val << 9)),
+                   (m = bits[i].fls + 9),
+                   "[i=%"PRIu8"] n=%d m=%d", i, n, m);
        }
 }
 
@@ -182,12 +221,13 @@ ATF_TC_HEAD(ilog2_32bit, tc)
 
 ATF_TC_BODY(ilog2_32bit, tc)
 {
-       int i;
+       int i, L;
        uint32_t x;
 
        for (i = 0; i < 32; i++) {
                x = 1U << i;
-               ATF_REQUIRE(ilog2(x) == i);
+               ATF_CHECK_EQ_MSG((L = ilog2(x)), i, "i=%d x=0x%"PRIx32" L=%d",
+                   i, x, L);
        }
 }
 
@@ -199,12 +239,13 @@ ATF_TC_HEAD(ilog2_64bit, tc)
 
 ATF_TC_BODY(ilog2_64bit, tc)
 {
-       int i;
+       int i, L;
        uint64_t x;
 
        for (i = 0; i < 64; i++) {
-               x = ((uint64_t)1) << i;
-               ATF_REQUIRE(ilog2(x) == i);
+               x = (uint64_t)1 << i;
+               ATF_CHECK_EQ_MSG((L = ilog2(x)), i, "i=%d x=0x%"PRIx64" L=%d",
+                   i, x, L);
        }
 }
 
@@ -216,138 +257,140 @@ ATF_TC_HEAD(ilog2_const, tc)
 
 ATF_TC_BODY(ilog2_const, tc)
 {
+       int L;
+
        /*
         * These inlines test __builtin_constant_p() part of ilog2()
         * at compile time, so don't change it to loop.  PR lib/49745
         */
-       ATF_REQUIRE(ilog2(0x0000000000000001ULL) == 0);
-       ATF_REQUIRE(ilog2(0x0000000000000002ULL) == 1);
-       ATF_REQUIRE(ilog2(0x0000000000000004ULL) == 2);
-       ATF_REQUIRE(ilog2(0x0000000000000008ULL) == 3);
-       ATF_REQUIRE(ilog2(0x0000000000000010ULL) == 4);
-       ATF_REQUIRE(ilog2(0x0000000000000020ULL) == 5);
-       ATF_REQUIRE(ilog2(0x0000000000000040ULL) == 6);
-       ATF_REQUIRE(ilog2(0x0000000000000080ULL) == 7);
-       ATF_REQUIRE(ilog2(0x0000000000000100ULL) == 8);
-       ATF_REQUIRE(ilog2(0x0000000000000200ULL) == 9);
-       ATF_REQUIRE(ilog2(0x0000000000000400ULL) == 10);
-       ATF_REQUIRE(ilog2(0x0000000000000800ULL) == 11);
-       ATF_REQUIRE(ilog2(0x0000000000001000ULL) == 12);
-       ATF_REQUIRE(ilog2(0x0000000000002000ULL) == 13);
-       ATF_REQUIRE(ilog2(0x0000000000004000ULL) == 14);
-       ATF_REQUIRE(ilog2(0x0000000000008000ULL) == 15);
-       ATF_REQUIRE(ilog2(0x0000000000010000ULL) == 16);
-       ATF_REQUIRE(ilog2(0x0000000000020000ULL) == 17);
-       ATF_REQUIRE(ilog2(0x0000000000040000ULL) == 18);
-       ATF_REQUIRE(ilog2(0x0000000000080000ULL) == 19);
-       ATF_REQUIRE(ilog2(0x0000000000100000ULL) == 20);
-       ATF_REQUIRE(ilog2(0x0000000000200000ULL) == 21);
-       ATF_REQUIRE(ilog2(0x0000000000400000ULL) == 22);
-       ATF_REQUIRE(ilog2(0x0000000000800000ULL) == 23);
-       ATF_REQUIRE(ilog2(0x0000000001000000ULL) == 24);
-       ATF_REQUIRE(ilog2(0x0000000002000000ULL) == 25);
-       ATF_REQUIRE(ilog2(0x0000000004000000ULL) == 26);
-       ATF_REQUIRE(ilog2(0x0000000008000000ULL) == 27);
-       ATF_REQUIRE(ilog2(0x0000000010000000ULL) == 28);
-       ATF_REQUIRE(ilog2(0x0000000020000000ULL) == 29);
-       ATF_REQUIRE(ilog2(0x0000000040000000ULL) == 30);
-       ATF_REQUIRE(ilog2(0x0000000080000000ULL) == 31);
-       ATF_REQUIRE(ilog2(0x0000000100000000ULL) == 32);
-       ATF_REQUIRE(ilog2(0x0000000200000000ULL) == 33);
-       ATF_REQUIRE(ilog2(0x0000000400000000ULL) == 34);
-       ATF_REQUIRE(ilog2(0x0000000800000000ULL) == 35);
-       ATF_REQUIRE(ilog2(0x0000001000000000ULL) == 36);
-       ATF_REQUIRE(ilog2(0x0000002000000000ULL) == 37);
-       ATF_REQUIRE(ilog2(0x0000004000000000ULL) == 38);
-       ATF_REQUIRE(ilog2(0x0000008000000000ULL) == 39);
-       ATF_REQUIRE(ilog2(0x0000010000000000ULL) == 40);
-       ATF_REQUIRE(ilog2(0x0000020000000000ULL) == 41);
-       ATF_REQUIRE(ilog2(0x0000040000000000ULL) == 42);
-       ATF_REQUIRE(ilog2(0x0000080000000000ULL) == 43);
-       ATF_REQUIRE(ilog2(0x0000100000000000ULL) == 44);
-       ATF_REQUIRE(ilog2(0x0000200000000000ULL) == 45);
-       ATF_REQUIRE(ilog2(0x0000400000000000ULL) == 46);
-       ATF_REQUIRE(ilog2(0x0000800000000000ULL) == 47);
-       ATF_REQUIRE(ilog2(0x0001000000000000ULL) == 48);
-       ATF_REQUIRE(ilog2(0x0002000000000000ULL) == 49);
-       ATF_REQUIRE(ilog2(0x0004000000000000ULL) == 50);
-       ATF_REQUIRE(ilog2(0x0008000000000000ULL) == 51);
-       ATF_REQUIRE(ilog2(0x0010000000000000ULL) == 52);
-       ATF_REQUIRE(ilog2(0x0020000000000000ULL) == 53);
-       ATF_REQUIRE(ilog2(0x0040000000000000ULL) == 54);
-       ATF_REQUIRE(ilog2(0x0080000000000000ULL) == 55);
-       ATF_REQUIRE(ilog2(0x0100000000000000ULL) == 56);
-       ATF_REQUIRE(ilog2(0x0200000000000000ULL) == 57);
-       ATF_REQUIRE(ilog2(0x0400000000000000ULL) == 58);
-       ATF_REQUIRE(ilog2(0x0800000000000000ULL) == 59);
-       ATF_REQUIRE(ilog2(0x1000000000000000ULL) == 60);
-       ATF_REQUIRE(ilog2(0x2000000000000000ULL) == 61);
-       ATF_REQUIRE(ilog2(0x4000000000000000ULL) == 62);
-       ATF_REQUIRE(ilog2(0x8000000000000000ULL) == 63);
+       ATF_CHECK_EQ_MSG((L = ilog2(0x0000000000000001ULL)), 0, "L=%d", L);
+       ATF_CHECK_EQ_MSG((L = ilog2(0x0000000000000002ULL)), 1, "L=%d", L);
+       ATF_CHECK_EQ_MSG((L = ilog2(0x0000000000000004ULL)), 2, "L=%d", L);
+       ATF_CHECK_EQ_MSG((L = ilog2(0x0000000000000008ULL)), 3, "L=%d", L);
+       ATF_CHECK_EQ_MSG((L = ilog2(0x0000000000000010ULL)), 4, "L=%d", L);
+       ATF_CHECK_EQ_MSG((L = ilog2(0x0000000000000020ULL)), 5, "L=%d", L);
+       ATF_CHECK_EQ_MSG((L = ilog2(0x0000000000000040ULL)), 6, "L=%d", L);
+       ATF_CHECK_EQ_MSG((L = ilog2(0x0000000000000080ULL)), 7, "L=%d", L);
+       ATF_CHECK_EQ_MSG((L = ilog2(0x0000000000000100ULL)), 8, "L=%d", L);
+       ATF_CHECK_EQ_MSG((L = ilog2(0x0000000000000200ULL)), 9, "L=%d", L);
+       ATF_CHECK_EQ_MSG((L = ilog2(0x0000000000000400ULL)), 10, "L=%d", L);
+       ATF_CHECK_EQ_MSG((L = ilog2(0x0000000000000800ULL)), 11, "L=%d", L);
+       ATF_CHECK_EQ_MSG((L = ilog2(0x0000000000001000ULL)), 12, "L=%d", L);
+       ATF_CHECK_EQ_MSG((L = ilog2(0x0000000000002000ULL)), 13, "L=%d", L);
+       ATF_CHECK_EQ_MSG((L = ilog2(0x0000000000004000ULL)), 14, "L=%d", L);
+       ATF_CHECK_EQ_MSG((L = ilog2(0x0000000000008000ULL)), 15, "L=%d", L);
+       ATF_CHECK_EQ_MSG((L = ilog2(0x0000000000010000ULL)), 16, "L=%d", L);
+       ATF_CHECK_EQ_MSG((L = ilog2(0x0000000000020000ULL)), 17, "L=%d", L);
+       ATF_CHECK_EQ_MSG((L = ilog2(0x0000000000040000ULL)), 18, "L=%d", L);
+       ATF_CHECK_EQ_MSG((L = ilog2(0x0000000000080000ULL)), 19, "L=%d", L);
+       ATF_CHECK_EQ_MSG((L = ilog2(0x0000000000100000ULL)), 20, "L=%d", L);
+       ATF_CHECK_EQ_MSG((L = ilog2(0x0000000000200000ULL)), 21, "L=%d", L);



Home | Main Index | Thread Index | Old Index