NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
lib/49745: tests/include/sys/t_bitops: improvement
>Number: 49745
>Category: lib
>Synopsis: tests/include/sys/t_bitops: improvement
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: lib-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Mar 14 09:55:00 +0000 2015
>Originator: Tetsuya Isaki
>Release: NetBSD-current (2015/02)
>Organization:
>Environment:
NetBSD XXXXX 7.99.4 NetBSD 7.99.4 (GENERIC) #1: Wed Feb 11 12:54:54 JST 2015 isaki@XXXXX:/var/obj/current/x68k/obj/sys/arch/x68k/compile/GENERIC x68k
>Description:
The current ilog2()'s implementation consists of 32bit variable
part, 64bit variable part and constant part. But 'ilog2_basic'
test checks only 64bit variable. 32bit variable and constant
were not checked.
'ilog2_log2' test is fully meaningless. It checks only bit 0
and bit 16-31 of 64bit variable though it spent 65000 times loop.
All range of 64bit variable was already checked by 'ilog2_basic'
before.
In addition, comparing it with math log2() is also really bad
idea. It should be compared with prepared(=pre-calculated)
value. The current 'ilog2_log2' test does not seem to work
on vax and QEMU due to lack/fail of math log2() according to
source code comment (I don't know details and it seems to work
on my QEMU though..). However, it's not necessary to use math
log2() here.
>How-To-Repeat:
See source code. tests/include/sys/t_bitops.c
>Fix:
Here is my proposal.
- remove ilog2_basic and ilog2_log2 for the above reason.
- new ilog2_32bit checks ilog2() as 32bit variable.
- new ilog2_64bit checks ilog2() as 64bit variable.
- new ilog2_const checks ilog2() as constant.
I'll commit it if ok.
--- tests/include/sys/t_bitops.c 14 Mar 2015 07:23:46 -0000 1.17
+++ tests/include/sys/t_bitops.c 14 Mar 2015 07:32:40 -0000
@@ -174,55 +174,176 @@
}
}
-ATF_TC(ilog2_basic);
-ATF_TC_HEAD(ilog2_basic, tc)
+ATF_TC(ilog2_32bit);
+ATF_TC_HEAD(ilog2_32bit, tc)
{
- atf_tc_set_md_var(tc, "descr", "Test ilog2(3) for correctness");
+ atf_tc_set_md_var(tc, "descr", "Test ilog2(3) for 32bit variable");
}
-ATF_TC_BODY(ilog2_basic, tc)
+ATF_TC_BODY(ilog2_32bit, tc)
{
- uint64_t i, x;
+ int i;
+ uint32_t x;
- for (i = x = 0; i < 64; i++) {
-
- x = (uint64_t)1 << i;
-
- ATF_REQUIRE(i == (uint64_t)ilog2(x));
+ for (i = 0; i < 32; i++) {
+ x = 1 << i;
+ ATF_REQUIRE(ilog2(x) == i);
}
}
-ATF_TC(ilog2_log2);
-ATF_TC_HEAD(ilog2_log2, tc)
+ATF_TC(ilog2_64bit);
+ATF_TC_HEAD(ilog2_64bit, tc)
{
- atf_tc_set_md_var(tc, "descr", "Test log2(3) vs. ilog2(3)");
+ atf_tc_set_md_var(tc, "descr", "Test ilog2(3) for 64bit variable");
}
-ATF_TC_BODY(ilog2_log2, tc)
+ATF_TC_BODY(ilog2_64bit, tc)
{
-#ifdef __vax__
- atf_tc_skip("Test is unavailable on vax because of lack of log2()");
-#else
- double x, y;
- uint64_t i;
-
- /*
- * This may fail under QEMU; see PR misc/44767.
- */
- for (i = 1; i < UINT32_MAX; i += UINT16_MAX) {
+ int i;
+ uint64_t x;
- x = log2(i);
- y = (double)(ilog2(i));
+ for (i = 0; i < 64; i++) {
+ x = ((uint64_t)1) << i;
+ ATF_REQUIRE(ilog2(x) == i);
+ }
+}
- ATF_REQUIRE(ceil(x) >= y);
+ATF_TC(ilog2_const);
+ATF_TC_HEAD(ilog2_const, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test ilog2(3) for constant");
+}
- if (fabs(floor(x) - y) > 1.0e-40) {
- atf_tc_expect_fail("PR misc/44767");
- atf_tc_fail("log2(%"PRIu64") != "
- "ilog2(%"PRIu64")", i, i);
- }
- }
-#endif
+ATF_TC_BODY(ilog2_const, tc)
+{
+ 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_REQUIRE(ilog2(0x0000000000000003ULL) == 1);
+ ATF_REQUIRE(ilog2(0x0000000000000007ULL) == 2);
+ ATF_REQUIRE(ilog2(0x000000000000000fULL) == 3);
+ ATF_REQUIRE(ilog2(0x000000000000001fULL) == 4);
+ ATF_REQUIRE(ilog2(0x000000000000003fULL) == 5);
+ ATF_REQUIRE(ilog2(0x000000000000007fULL) == 6);
+ ATF_REQUIRE(ilog2(0x00000000000000ffULL) == 7);
+ ATF_REQUIRE(ilog2(0x00000000000001ffULL) == 8);
+ ATF_REQUIRE(ilog2(0x00000000000003ffULL) == 9);
+ ATF_REQUIRE(ilog2(0x00000000000007ffULL) == 10);
+ ATF_REQUIRE(ilog2(0x0000000000000fffULL) == 11);
+ ATF_REQUIRE(ilog2(0x0000000000001fffULL) == 12);
+ ATF_REQUIRE(ilog2(0x0000000000003fffULL) == 13);
+ ATF_REQUIRE(ilog2(0x0000000000007fffULL) == 14);
+ ATF_REQUIRE(ilog2(0x000000000000ffffULL) == 15);
+ ATF_REQUIRE(ilog2(0x000000000001ffffULL) == 16);
+ ATF_REQUIRE(ilog2(0x000000000003ffffULL) == 17);
+ ATF_REQUIRE(ilog2(0x000000000007ffffULL) == 18);
+ ATF_REQUIRE(ilog2(0x00000000000fffffULL) == 19);
+ ATF_REQUIRE(ilog2(0x00000000001fffffULL) == 20);
+ ATF_REQUIRE(ilog2(0x00000000003fffffULL) == 21);
+ ATF_REQUIRE(ilog2(0x00000000007fffffULL) == 22);
+ ATF_REQUIRE(ilog2(0x0000000000ffffffULL) == 23);
+ ATF_REQUIRE(ilog2(0x0000000001ffffffULL) == 24);
+ ATF_REQUIRE(ilog2(0x0000000003ffffffULL) == 25);
+ ATF_REQUIRE(ilog2(0x0000000007ffffffULL) == 26);
+ ATF_REQUIRE(ilog2(0x000000000fffffffULL) == 27);
+ ATF_REQUIRE(ilog2(0x000000001fffffffULL) == 28);
+ ATF_REQUIRE(ilog2(0x000000003fffffffULL) == 29);
+ ATF_REQUIRE(ilog2(0x000000007fffffffULL) == 30);
+ ATF_REQUIRE(ilog2(0x00000000ffffffffULL) == 31);
+ ATF_REQUIRE(ilog2(0x00000001ffffffffULL) == 32);
+ ATF_REQUIRE(ilog2(0x00000003ffffffffULL) == 33);
+ ATF_REQUIRE(ilog2(0x00000007ffffffffULL) == 34);
+ ATF_REQUIRE(ilog2(0x0000000fffffffffULL) == 35);
+ ATF_REQUIRE(ilog2(0x0000001fffffffffULL) == 36);
+ ATF_REQUIRE(ilog2(0x0000003fffffffffULL) == 37);
+ ATF_REQUIRE(ilog2(0x0000007fffffffffULL) == 38);
+ ATF_REQUIRE(ilog2(0x000000ffffffffffULL) == 39);
+ ATF_REQUIRE(ilog2(0x000001ffffffffffULL) == 40);
+ ATF_REQUIRE(ilog2(0x000003ffffffffffULL) == 41);
+ ATF_REQUIRE(ilog2(0x000007ffffffffffULL) == 42);
+ ATF_REQUIRE(ilog2(0x00000fffffffffffULL) == 43);
+ ATF_REQUIRE(ilog2(0x00001fffffffffffULL) == 44);
+ ATF_REQUIRE(ilog2(0x00003fffffffffffULL) == 45);
+ ATF_REQUIRE(ilog2(0x00007fffffffffffULL) == 46);
+ ATF_REQUIRE(ilog2(0x0000ffffffffffffULL) == 47);
+ ATF_REQUIRE(ilog2(0x0001ffffffffffffULL) == 48);
+ ATF_REQUIRE(ilog2(0x0003ffffffffffffULL) == 49);
+ ATF_REQUIRE(ilog2(0x0007ffffffffffffULL) == 50);
+ ATF_REQUIRE(ilog2(0x000fffffffffffffULL) == 51);
+ ATF_REQUIRE(ilog2(0x001fffffffffffffULL) == 52);
+ ATF_REQUIRE(ilog2(0x003fffffffffffffULL) == 53);
+ ATF_REQUIRE(ilog2(0x007fffffffffffffULL) == 54);
+ ATF_REQUIRE(ilog2(0x00ffffffffffffffULL) == 55);
+ ATF_REQUIRE(ilog2(0x01ffffffffffffffULL) == 56);
+ ATF_REQUIRE(ilog2(0x03ffffffffffffffULL) == 57);
+ ATF_REQUIRE(ilog2(0x07ffffffffffffffULL) == 58);
+ ATF_REQUIRE(ilog2(0x0fffffffffffffffULL) == 59);
+ ATF_REQUIRE(ilog2(0x1fffffffffffffffULL) == 60);
+ ATF_REQUIRE(ilog2(0x3fffffffffffffffULL) == 61);
+ ATF_REQUIRE(ilog2(0x7fffffffffffffffULL) == 62);
+ ATF_REQUIRE(ilog2(0xffffffffffffffffULL) == 63);
}
ATF_TP_ADD_TCS(tp)
@@ -231,8 +352,9 @@
ATF_TP_ADD_TC(tp, bitmap_basic);
ATF_TP_ADD_TC(tp, fast_divide32);
ATF_TP_ADD_TC(tp, ffsfls);
- ATF_TP_ADD_TC(tp, ilog2_basic);
- ATF_TP_ADD_TC(tp, ilog2_log2);
+ ATF_TP_ADD_TC(tp, ilog2_32bit);
+ ATF_TP_ADD_TC(tp, ilog2_64bit);
+ ATF_TP_ADD_TC(tp, ilog2_const);
return atf_no_error();
}
Home |
Main Index |
Thread Index |
Old Index