Module Name: src Committed By: jruoho Date: Thu Mar 24 07:37:05 UTC 2011
Modified Files: src/tests/include/sys: t_bitops.c Log Message: Add also a basic, naive, test for fast_divide32(3). To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/include/sys/t_bitops.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/include/sys/t_bitops.c diff -u src/tests/include/sys/t_bitops.c:1.2 src/tests/include/sys/t_bitops.c:1.3 --- src/tests/include/sys/t_bitops.c:1.2 Thu Mar 24 07:06:34 2011 +++ src/tests/include/sys/t_bitops.c Thu Mar 24 07:37:04 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: t_bitops.c,v 1.2 2011/03/24 07:06:34 jruoho Exp $ */ +/* $NetBSD: t_bitops.c,v 1.3 2011/03/24 07:37:04 jruoho Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -59,6 +59,42 @@ }; +ATF_TC(fast_divide32); +ATF_TC_HEAD(fast_divide32, tc) +{ + atf_tc_set_md_var(tc, "descr", "A basic test of fast_divide32(3)"); +} + +ATF_TC_BODY(fast_divide32, tc) +{ + uint32_t a, b, q, r, m; + uint8_t i, s1, s2; + + a = 0xFFFF; + b = 0x000F; + + fast_divide32_prepare(b, &m, &s1, &s2); + + q = fast_divide32(a, b, m, s1, s2); + r = fast_remainder32(a, b, m, s1, s2); + + ATF_REQUIRE(q == 0x1111 && r == 0); + + for (i = 1; i < __arraycount(bits); i++) { + + a = bits[i].val; + b = bits[i].ffs; + + fast_divide32_prepare(b, &m, &s1, &s2); + + 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_TC(ffsfls); ATF_TC_HEAD(ffsfls, tc) { @@ -140,6 +176,7 @@ ATF_TP_ADD_TCS(tp) { + ATF_TP_ADD_TC(tp, fast_divide32); ATF_TP_ADD_TC(tp, ffsfls); ATF_TP_ADD_TC(tp, ilog2_1); ATF_TP_ADD_TC(tp, ilog2_2);