Source-Changes-HG archive

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

[src/trunk]: src Add a simple test file for <sys/bitops.h>. For now, only ilo...



details:   https://anonhg.NetBSD.org/src/rev/cc07deb3394b
branches:  trunk
changeset: 763427:cc07deb3394b
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Sat Mar 19 06:39:17 2011 +0000

description:
Add a simple test file for <sys/bitops.h>. For now, only ilog2(3) is tested.

diffstat:

 distrib/sets/lists/tests/mi  |   4 +-
 tests/include/sys/Makefile   |   7 ++-
 tests/include/sys/t_bitops.c |  83 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 90 insertions(+), 4 deletions(-)

diffs (131 lines):

diff -r 399215effc2d -r cc07deb3394b distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sat Mar 19 06:15:12 2011 +0000
+++ b/distrib/sets/lists/tests/mi       Sat Mar 19 06:39:17 2011 +0000
@@ -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
diff -r 399215effc2d -r cc07deb3394b tests/include/sys/Makefile
--- a/tests/include/sys/Makefile        Sat Mar 19 06:15:12 2011 +0000
+++ b/tests/include/sys/Makefile        Sat Mar 19 06:39:17 2011 +0000
@@ -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>
diff -r 399215effc2d -r cc07deb3394b tests/include/sys/t_bitops.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/include/sys/t_bitops.c      Sat Mar 19 06:39:17 2011 +0000
@@ -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();
+}



Home | Main Index | Thread Index | Old Index