Source-Changes-HG archive

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

[src/trunk]: src Some naive tests for the bswap(3) family.



details:   https://anonhg.NetBSD.org/src/rev/4cb931ad8fec
branches:  trunk
changeset: 764755:4cb931ad8fec
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Tue May 03 04:50:30 2011 +0000

description:
Some naive tests for the bswap(3) family.

diffstat:

 distrib/sets/lists/tests/mi |    4 +-
 tests/include/Makefile      |    3 +-
 tests/include/t_bswap.c     |  178 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 183 insertions(+), 2 deletions(-)

diffs (224 lines):

diff -r 0a1ecd37e998 -r 4cb931ad8fec distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Tue May 03 04:27:13 2011 +0000
+++ b/distrib/sets/lists/tests/mi       Tue May 03 04:50:30 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.320 2011/05/02 17:26:23 jruoho Exp $
+# $NetBSD: mi,v 1.321 2011/05/03 04:50:30 jruoho Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -284,6 +284,7 @@
 ./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_bswap.debug                    tests-ipf-tests         debug,atf
 ./usr/libdata/debug/usr/tests/include/t_errno.debug                    tests-ipf-tests         debug,atf
 ./usr/libdata/debug/usr/tests/include/t_glob.debug                     tests-ipf-tests         debug,atf
 ./usr/libdata/debug/usr/tests/include/t_inttypes.debug                 tests-ipf-tests         debug,atf
@@ -1384,6 +1385,7 @@
 ./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_bswap                    tests-include-tests     atf
 ./usr/tests/include/t_errno                    tests-include-tests     atf
 ./usr/tests/include/t_glob                     tests-include-tests     atf
 ./usr/tests/include/t_inttypes                 tests-include-tests     atf
diff -r 0a1ecd37e998 -r 4cb931ad8fec tests/include/Makefile
--- a/tests/include/Makefile    Tue May 03 04:27:13 2011 +0000
+++ b/tests/include/Makefile    Tue May 03 04:50:30 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.6 2011/05/01 17:07:06 jruoho Exp $
+# $NetBSD: Makefile,v 1.7 2011/05/03 04:50:31 jruoho Exp $
 
 NOMAN=         # defined
 
@@ -8,6 +8,7 @@
 TESTS_SUBDIRS= sys
 
 TESTS_C=       t_bitstring
+TESTS_C+=      t_bswap
 TESTS_C+=      t_errno
 TESTS_C+=      t_glob
 TESTS_C+=      t_inttypes
diff -r 0a1ecd37e998 -r 4cb931ad8fec tests/include/t_bswap.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/include/t_bswap.c   Tue May 03 04:50:30 2011 +0000
@@ -0,0 +1,178 @@
+/* $NetBSD: t_bswap.c,v 1.1 2011/05/03 04:50:31 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 <sys/cdefs.h>
+__RCSID("$NetBSD: t_bswap.c,v 1.1 2011/05/03 04:50:31 jruoho Exp $");
+
+#include <sys/types.h>
+#include <machine/bswap.h>
+
+#include <atf-c.h>
+
+static uint16_t x16;
+static uint32_t x32;
+static uint64_t x64;
+
+static uint16_t        unconst16(uint16_t);
+static uint32_t        unconst32(uint32_t);
+static uint64_t        unconst64(uint64_t);
+
+/*
+ * Given the use of __builtin_constant_p(3),
+ * these functions try to avoid gcc(1) from
+ * treating the arguments as constants.
+ */
+static uint16_t
+unconst16(uint16_t val)
+{
+       return val + x16;
+}
+
+static uint32_t
+unconst32(uint32_t val)
+{
+       return val + x32;
+}
+
+static uint64_t
+unconst64(uint64_t val)
+{
+       return val + x64;
+}
+
+ATF_TC(bswap16_basic);
+ATF_TC_HEAD(bswap16_basic, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "A naive test of bswap16(3), #1");
+}
+
+ATF_TC_BODY(bswap16_basic, tc)
+{
+       ATF_REQUIRE_EQ(bswap16(0x0000), 0x0000);
+       ATF_REQUIRE_EQ(bswap16(0xff00), 0x00ff);
+       ATF_REQUIRE_EQ(bswap16(0xffff), 0xffff);
+       ATF_REQUIRE_EQ(bswap16(0x1234), 0x3412);
+}
+
+ATF_TC(bswap16_unconst);
+ATF_TC_HEAD(bswap16_unconst, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "A naive test of bswap16(3), #2");
+}
+
+ATF_TC_BODY(bswap16_unconst, tc)
+{
+       x16 = 0;
+
+       ATF_REQUIRE_EQ(bswap16(unconst16(0x0000)), 0x0000);
+       ATF_REQUIRE_EQ(bswap16(unconst16(0xff00)), 0x00ff);
+       ATF_REQUIRE_EQ(bswap16(unconst16(0xffff)), 0xffff);
+       ATF_REQUIRE_EQ(bswap16(unconst16(0x1234)), 0x3412);
+}
+
+ATF_TC(bswap32_basic);
+ATF_TC_HEAD(bswap32_basic, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "A naive test of bswap32(3), #1");
+}
+
+ATF_TC_BODY(bswap32_basic, tc)
+{
+       ATF_REQUIRE_EQ(bswap32(0x00000000), 0x00000000);
+       ATF_REQUIRE_EQ(bswap32(0xffff0000), 0x0000ffff);
+       ATF_REQUIRE_EQ(bswap32(0xffffffff), 0xffffffff);
+       ATF_REQUIRE_EQ(bswap32(0x12345678), 0x78563412);
+}
+
+ATF_TC(bswap32_unconst);
+ATF_TC_HEAD(bswap32_unconst, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "A naive test of bswap32(3), #2");
+}
+
+ATF_TC_BODY(bswap32_unconst, tc)
+{
+       x32 = 0;
+
+       ATF_REQUIRE_EQ(bswap32(unconst32(0x00000000)), 0x00000000);
+       ATF_REQUIRE_EQ(bswap32(unconst32(0xffff0000)), 0x0000ffff);
+       ATF_REQUIRE_EQ(bswap32(unconst32(0xffffffff)), 0xffffffff);
+       ATF_REQUIRE_EQ(bswap32(unconst32(0x12345678)), 0x78563412);
+}
+
+ATF_TC(bswap64_basic);
+ATF_TC_HEAD(bswap64_basic, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "A naive test of bswap64(3), #1");
+}
+
+ATF_TC_BODY(bswap64_basic, tc)
+{
+       ATF_REQUIRE_EQ(bswap64(0x0000000000000000), 0x0000000000000000);
+       ATF_REQUIRE_EQ(bswap64(0xffffffff00000000), 0x00000000ffffffff);
+       ATF_REQUIRE_EQ(bswap64(0xffffffffffffffff), 0xffffffffffffffff);
+       ATF_REQUIRE_EQ(bswap64(0x123456789abcdeff), 0xffdebc9a78563412);
+}
+
+ATF_TC(bswap64_unconst);
+ATF_TC_HEAD(bswap64_unconst, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "A naive test of bswap64(3), #2");
+}
+
+ATF_TC_BODY(bswap64_unconst, tc)
+{
+       x64 = 0;
+
+       ATF_REQUIRE_EQ(bswap64(unconst64(0x0000000000000000)),
+           0x0000000000000000);
+
+       ATF_REQUIRE_EQ(bswap64(unconst64(0xffffffff00000000)),
+           0x00000000ffffffff);
+
+       ATF_REQUIRE_EQ(bswap64(unconst64(0xffffffffffffffff)),
+           0xffffffffffffffff);
+
+       ATF_REQUIRE_EQ(bswap64(unconst64(0x123456789abcdeff)),
+           0xffdebc9a78563412);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+       ATF_TP_ADD_TC(tp, bswap16_basic);
+       ATF_TP_ADD_TC(tp, bswap16_unconst);
+       ATF_TP_ADD_TC(tp, bswap32_basic);
+       ATF_TP_ADD_TC(tp, bswap32_unconst);
+       ATF_TP_ADD_TC(tp, bswap64_basic);
+       ATF_TP_ADD_TC(tp, bswap64_unconst);
+
+       return atf_no_error();
+}



Home | Main Index | Thread Index | Old Index