Sat Mar 19 06:39:17 2011 UTC ()
Add a simple test file for <sys/bitops.h>. For now, only ilog2(3) is tested.


(jruoho)
diff -r1.271 -r1.272 src/distrib/sets/lists/tests/mi
diff -r1.1 -r1.2 src/tests/include/sys/Makefile
diff -r0 -r1.1 src/tests/include/sys/t_bitops.c

cvs diff -r1.271 -r1.272 src/distrib/sets/lists/tests/mi (expand / switch to unified diff)

--- src/distrib/sets/lists/tests/mi 2011/03/14 15:57:33 1.271
+++ src/distrib/sets/lists/tests/mi 2011/03/19 06:39:17 1.272
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: mi,v 1.271 2011/03/14 15:57:33 pooka Exp $ 1# $NetBSD: mi,v 1.272 2011/03/19 06:39:17 jruoho Exp $
2# 2#
3# Note: don't delete entries from here - mark them as "obsolete" instead. 3# Note: don't delete entries from here - mark them as "obsolete" instead.
4# 4#
5./etc/mtree/set.tests tests-sys-root 5./etc/mtree/set.tests tests-sys-root
6./usr/libdata/debug/usr/tests tests-base-debug 6./usr/libdata/debug/usr/tests tests-base-debug
7./usr/libdata/debug/usr/tests/atf tests-atf-debug 7./usr/libdata/debug/usr/tests/atf tests-atf-debug
8./usr/libdata/debug/usr/tests/atf/atf-c tests-atf-debug 8./usr/libdata/debug/usr/tests/atf/atf-c tests-atf-debug
9./usr/libdata/debug/usr/tests/atf/atf-c/atf_c_test.debug tests-atf-debug debug,atf 9./usr/libdata/debug/usr/tests/atf/atf-c/atf_c_test.debug tests-atf-debug debug,atf
10./usr/libdata/debug/usr/tests/atf/atf-c/build_test.debug tests-atf-debug debug,atf 10./usr/libdata/debug/usr/tests/atf/atf-c/build_test.debug tests-atf-debug debug,atf
11./usr/libdata/debug/usr/tests/atf/atf-c/check_test.debug tests-atf-debug debug,atf 11./usr/libdata/debug/usr/tests/atf/atf-c/check_test.debug tests-atf-debug debug,atf
12./usr/libdata/debug/usr/tests/atf/atf-c/config_test.debug tests-atf-debug debug,atf 12./usr/libdata/debug/usr/tests/atf/atf-c/config_test.debug tests-atf-debug debug,atf
13./usr/libdata/debug/usr/tests/atf/atf-c/detail tests-atf-debug 13./usr/libdata/debug/usr/tests/atf/atf-c/detail tests-atf-debug
14./usr/libdata/debug/usr/tests/atf/atf-c/detail/dynstr_test.debug tests-atf-debug debug,atf 14./usr/libdata/debug/usr/tests/atf/atf-c/detail/dynstr_test.debug tests-atf-debug debug,atf
@@ -271,26 +271,27 @@ @@ -271,26 +271,27 @@
271./usr/libdata/debug/usr/tests/fs/union/t_pr.debug tests-fs-debug debug,atf 271./usr/libdata/debug/usr/tests/fs/union/t_pr.debug tests-fs-debug debug,atf
272./usr/libdata/debug/usr/tests/fs/vfs tests-fs-debug 272./usr/libdata/debug/usr/tests/fs/vfs tests-fs-debug
273./usr/libdata/debug/usr/tests/fs/vfs/t_full.debug tests-fs-debug debug,atf 273./usr/libdata/debug/usr/tests/fs/vfs/t_full.debug tests-fs-debug debug,atf
274./usr/libdata/debug/usr/tests/fs/vfs/t_io.debug tests-fs-debug debug,atf 274./usr/libdata/debug/usr/tests/fs/vfs/t_io.debug tests-fs-debug debug,atf
275./usr/libdata/debug/usr/tests/fs/vfs/t_renamerace.debug tests-fs-debug debug,atf 275./usr/libdata/debug/usr/tests/fs/vfs/t_renamerace.debug tests-fs-debug debug,atf
276./usr/libdata/debug/usr/tests/fs/vfs/t_rmdirrace.debug tests-fs-debug debug,atf 276./usr/libdata/debug/usr/tests/fs/vfs/t_rmdirrace.debug tests-fs-debug debug,atf
277./usr/libdata/debug/usr/tests/fs/vfs/t_ro.debug tests-fs-debug debug,atf 277./usr/libdata/debug/usr/tests/fs/vfs/t_ro.debug tests-fs-debug debug,atf
278./usr/libdata/debug/usr/tests/fs/vfs/t_union.debug tests-obsolete debug,atf 278./usr/libdata/debug/usr/tests/fs/vfs/t_union.debug tests-obsolete debug,atf
279./usr/libdata/debug/usr/tests/fs/vfs/t_unpriv.debug tests-fs-debug debug,atf 279./usr/libdata/debug/usr/tests/fs/vfs/t_unpriv.debug tests-fs-debug debug,atf
280./usr/libdata/debug/usr/tests/fs/vfs/t_vfsops.debug tests-fs-debug debug,atf 280./usr/libdata/debug/usr/tests/fs/vfs/t_vfsops.debug tests-fs-debug debug,atf
281./usr/libdata/debug/usr/tests/fs/vfs/t_vnops.debug tests-fs-debug debug,atf 281./usr/libdata/debug/usr/tests/fs/vfs/t_vnops.debug tests-fs-debug debug,atf
282./usr/libdata/debug/usr/tests/include tests-ipf-tests 282./usr/libdata/debug/usr/tests/include tests-ipf-tests
283./usr/libdata/debug/usr/tests/include/sys tests-ipf-tests 283./usr/libdata/debug/usr/tests/include/sys tests-ipf-tests
 284./usr/libdata/debug/usr/tests/include/sys/t_bitops.debug tests-ipf-tests debug,atf
284./usr/libdata/debug/usr/tests/include/sys/t_bootblock.debug tests-ipf-tests debug,atf 285./usr/libdata/debug/usr/tests/include/sys/t_bootblock.debug tests-ipf-tests debug,atf
285./usr/libdata/debug/usr/tests/include/t_bitstring.debug tests-ipf-tests debug,atf 286./usr/libdata/debug/usr/tests/include/t_bitstring.debug tests-ipf-tests debug,atf
286./usr/libdata/debug/usr/tests/include/t_inttypes.debug tests-ipf-tests debug,atf 287./usr/libdata/debug/usr/tests/include/t_inttypes.debug tests-ipf-tests debug,atf
287./usr/libdata/debug/usr/tests/include/t_limits.debug tests-ipf-tests debug,atf 288./usr/libdata/debug/usr/tests/include/t_limits.debug tests-ipf-tests debug,atf
288./usr/libdata/debug/usr/tests/include/t_stdint.debug tests-ipf-tests debug,atf 289./usr/libdata/debug/usr/tests/include/t_stdint.debug tests-ipf-tests debug,atf
289./usr/libdata/debug/usr/tests/ipf tests-ipf-tests 290./usr/libdata/debug/usr/tests/ipf tests-ipf-tests
290./usr/libdata/debug/usr/tests/kernel tests-kernel-tests 291./usr/libdata/debug/usr/tests/kernel tests-kernel-tests
291./usr/libdata/debug/usr/tests/kernel/h_ps_strings1.debug tests-kernel-tests debug,atf 292./usr/libdata/debug/usr/tests/kernel/h_ps_strings1.debug tests-kernel-tests debug,atf
292./usr/libdata/debug/usr/tests/kernel/h_ps_strings2.debug tests-kernel-tests debug,atf 293./usr/libdata/debug/usr/tests/kernel/h_ps_strings2.debug tests-kernel-tests debug,atf
293./usr/libdata/debug/usr/tests/kernel/kqueue tests-kernel-tests 294./usr/libdata/debug/usr/tests/kernel/kqueue tests-kernel-tests
294./usr/libdata/debug/usr/tests/kernel/kqueue/read tests-kernel-tests 295./usr/libdata/debug/usr/tests/kernel/kqueue/read tests-kernel-tests
295./usr/libdata/debug/usr/tests/kernel/kqueue/read/t_fifo.debug tests-kernel-tests debug,atf 296./usr/libdata/debug/usr/tests/kernel/kqueue/read/t_fifo.debug tests-kernel-tests debug,atf
296./usr/libdata/debug/usr/tests/kernel/kqueue/read/t_file.debug tests-kernel-tests debug,atf 297./usr/libdata/debug/usr/tests/kernel/kqueue/read/t_file.debug tests-kernel-tests debug,atf
@@ -1314,26 +1315,27 @@ @@ -1314,26 +1315,27 @@
1314./usr/tests/games tests-games-tests 1315./usr/tests/games tests-games-tests
1315./usr/tests/games/Atffile tests-games-tests 1316./usr/tests/games/Atffile tests-games-tests
1316./usr/tests/games/t_factor tests-games-tests 1317./usr/tests/games/t_factor tests-games-tests
1317./usr/tests/include tests-include-tests 1318./usr/tests/include tests-include-tests
1318./usr/tests/include/Atffile tests-include-tests atf 1319./usr/tests/include/Atffile tests-include-tests atf
1319./usr/tests/include/d_bitstring_27.out tests-include-tests atf 1320./usr/tests/include/d_bitstring_27.out tests-include-tests atf
1320./usr/tests/include/d_bitstring_32.out tests-include-tests atf 1321./usr/tests/include/d_bitstring_32.out tests-include-tests atf
1321./usr/tests/include/d_bitstring_49.out tests-include-tests atf 1322./usr/tests/include/d_bitstring_49.out tests-include-tests atf
1322./usr/tests/include/d_bitstring_64.out tests-include-tests atf 1323./usr/tests/include/d_bitstring_64.out tests-include-tests atf
1323./usr/tests/include/d_bitstring_67.out tests-include-tests atf 1324./usr/tests/include/d_bitstring_67.out tests-include-tests atf
1324./usr/tests/include/d_bitstring_8.out tests-include-tests atf 1325./usr/tests/include/d_bitstring_8.out tests-include-tests atf
1325./usr/tests/include/sys tests-include-tests 1326./usr/tests/include/sys tests-include-tests
1326./usr/tests/include/sys/Atffile tests-include-tests atf 1327./usr/tests/include/sys/Atffile tests-include-tests atf
 1328./usr/tests/include/sys/t_bitops tests-include-tests atf
1327./usr/tests/include/sys/t_bootblock tests-include-tests atf 1329./usr/tests/include/sys/t_bootblock tests-include-tests atf
1328./usr/tests/include/t_bitstring tests-include-tests atf 1330./usr/tests/include/t_bitstring tests-include-tests atf
1329./usr/tests/include/t_inttypes tests-include-tests atf 1331./usr/tests/include/t_inttypes tests-include-tests atf
1330./usr/tests/include/t_limits tests-include-tests atf 1332./usr/tests/include/t_limits tests-include-tests atf
1331./usr/tests/include/t_stdint tests-include-tests atf 1333./usr/tests/include/t_stdint tests-include-tests atf
1332./usr/tests/ipf tests-ipf-tests 1334./usr/tests/ipf tests-ipf-tests
1333./usr/tests/ipf/Atffile tests-ipf-tests 1335./usr/tests/ipf/Atffile tests-ipf-tests
1334./usr/tests/ipf/expected tests-ipf-tests 1336./usr/tests/ipf/expected tests-ipf-tests
1335./usr/tests/ipf/expected/bpf-f1 tests-ipf-tests 1337./usr/tests/ipf/expected/bpf-f1 tests-ipf-tests
1336./usr/tests/ipf/expected/bpf1 tests-ipf-tests 1338./usr/tests/ipf/expected/bpf1 tests-ipf-tests
1337./usr/tests/ipf/expected/f1 tests-ipf-tests 1339./usr/tests/ipf/expected/f1 tests-ipf-tests
1338./usr/tests/ipf/expected/f10 tests-ipf-tests 1340./usr/tests/ipf/expected/f10 tests-ipf-tests
1339./usr/tests/ipf/expected/f11 tests-ipf-tests 1341./usr/tests/ipf/expected/f11 tests-ipf-tests

cvs diff -r1.1 -r1.2 src/tests/include/sys/Makefile (expand / switch to unified diff)

--- src/tests/include/sys/Makefile 2010/07/17 19:26:27 1.1
+++ src/tests/include/sys/Makefile 2011/03/19 06:39:17 1.2
@@ -1,11 +1,12 @@ @@ -1,11 +1,12 @@
1# $NetBSD: Makefile,v 1.1 2010/07/17 19:26:27 jmmv Exp $ 1# $NetBSD: Makefile,v 1.2 2011/03/19 06:39:17 jruoho Exp $
2 2
3NOMAN= # defined 3NOMAN= # defined
4 4
5.include <bsd.own.mk> 5.include <bsd.own.mk>
6 6
7TESTSDIR= ${TESTSBASE}/include/sys 7TESTSDIR= ${TESTSBASE}/include/sys
8 8
9TESTS_C= t_bootblock 9LDADD.t_bitops+= -lm
 10TESTS_C= t_bitops t_bootblock
10 11
11.include <bsd.test.mk> 12.include <bsd.test.mk>

File Added: src/tests/include/sys/t_bitops.c
/*	$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();
}