Module Name: src Committed By: jruoho Date: Sat Mar 19 06:39:17 UTC 2011
Modified Files: src/distrib/sets/lists/tests: mi src/tests/include/sys: Makefile Added Files: src/tests/include/sys: t_bitops.c Log Message: Add a simple test file for <sys/bitops.h>. For now, only ilog2(3) is tested. To generate a diff of this commit: cvs rdiff -u -r1.271 -r1.272 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.1 -r1.2 src/tests/include/sys/Makefile cvs rdiff -u -r0 -r1.1 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/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.271 src/distrib/sets/lists/tests/mi:1.272 --- src/distrib/sets/lists/tests/mi:1.271 Mon Mar 14 15:57:33 2011 +++ src/distrib/sets/lists/tests/mi Sat Mar 19 06:39:17 2011 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.271 2011/03/14 15:57:33 pooka Exp $ +# $NetBSD: mi,v 1.272 2011/03/19 06:39:17 jruoho Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -281,6 +281,7 @@ ./usr/libdata/debug/usr/tests/fs/vfs/t_vnops.debug tests-fs-debug debug,atf ./usr/libdata/debug/usr/tests/include tests-ipf-tests ./usr/libdata/debug/usr/tests/include/sys tests-ipf-tests +./usr/libdata/debug/usr/tests/include/sys/t_bitops.debug tests-ipf-tests debug,atf ./usr/libdata/debug/usr/tests/include/sys/t_bootblock.debug tests-ipf-tests debug,atf ./usr/libdata/debug/usr/tests/include/t_bitstring.debug tests-ipf-tests debug,atf ./usr/libdata/debug/usr/tests/include/t_inttypes.debug tests-ipf-tests debug,atf @@ -1324,6 +1325,7 @@ ./usr/tests/include/d_bitstring_8.out tests-include-tests atf ./usr/tests/include/sys tests-include-tests ./usr/tests/include/sys/Atffile tests-include-tests atf +./usr/tests/include/sys/t_bitops tests-include-tests atf ./usr/tests/include/sys/t_bootblock tests-include-tests atf ./usr/tests/include/t_bitstring tests-include-tests atf ./usr/tests/include/t_inttypes tests-include-tests atf Index: src/tests/include/sys/Makefile diff -u src/tests/include/sys/Makefile:1.1 src/tests/include/sys/Makefile:1.2 --- src/tests/include/sys/Makefile:1.1 Sat Jul 17 19:26:27 2010 +++ src/tests/include/sys/Makefile Sat Mar 19 06:39:17 2011 @@ -1,11 +1,12 @@ -# $NetBSD: Makefile,v 1.1 2010/07/17 19:26:27 jmmv Exp $ +# $NetBSD: Makefile,v 1.2 2011/03/19 06:39:17 jruoho Exp $ NOMAN= # defined .include <bsd.own.mk> -TESTSDIR= ${TESTSBASE}/include/sys +TESTSDIR= ${TESTSBASE}/include/sys -TESTS_C= t_bootblock +LDADD.t_bitops+= -lm +TESTS_C= t_bitops t_bootblock .include <bsd.test.mk> Added files: Index: src/tests/include/sys/t_bitops.c diff -u /dev/null src/tests/include/sys/t_bitops.c:1.1 --- /dev/null Sat Mar 19 06:39:17 2011 +++ src/tests/include/sys/t_bitops.c Sat Mar 19 06:39:17 2011 @@ -0,0 +1,83 @@ +/* $NetBSD: t_bitops.c,v 1.1 2011/03/19 06:39:17 jruoho Exp $ */ + +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jukka Ruohonen. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <atf-c.h> + +#include <sys/bitops.h> +#include <math.h> + +ATF_TC(ilog2_1); +ATF_TC_HEAD(ilog2_1, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test ilog2(3) for correctness"); +} + +ATF_TC_BODY(ilog2_1, tc) +{ + uint64_t i, x; + + for (i = x = 0; i < 64; i++) { + + x = (uint64_t)1 << i; + + ATF_REQUIRE(i == (uint64_t)ilog2(x)); + } +} + +ATF_TC(ilog2_2); +ATF_TC_HEAD(ilog2_2, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test log2(3) vs. ilog2(3)"); +} + +ATF_TC_BODY(ilog2_2, tc) +{ + double x, y; + uint64_t i; + + for (i = 1; i < UINT32_MAX; i += UINT16_MAX) { + + x = log2(i); + y = (double)(ilog2(i)); + + ATF_REQUIRE(ceil(x) >= y); + ATF_REQUIRE(fabs(floor(x) - y) < 1.0e-40); + } +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, ilog2_1); + ATF_TP_ADD_TC(tp, ilog2_2); + + return atf_no_error(); +}