Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Add some tests for the kernel HID parser.
details: https://anonhg.NetBSD.org/src/rev/4f2a941b77f8
branches: trunk
changeset: 342698:4f2a941b77f8
user: jakllsch <jakllsch%NetBSD.org@localhost>
date: Tue Jan 05 17:22:38 2016 +0000
description:
Add some tests for the kernel HID parser.
diffstat:
distrib/sets/lists/debug/mi | 3 +-
distrib/sets/lists/tests/mi | 7 +-
etc/mtree/NetBSD.dist.tests | 4 +-
tests/dev/Makefile | 4 +-
tests/dev/usb/Makefile | 22 ++++
tests/dev/usb/libhid/Makefile | 16 +++
tests/dev/usb/t_hid.c | 210 ++++++++++++++++++++++++++++++++++++++++++
7 files changed, 261 insertions(+), 5 deletions(-)
diffs (truncated from 348 to 300 lines):
diff -r cf16fb046e58 -r 4f2a941b77f8 distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi Tue Jan 05 17:06:34 2016 +0000
+++ b/distrib/sets/lists/debug/mi Tue Jan 05 17:22:38 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.139 2016/01/01 21:38:53 jakllsch Exp $
+# $NetBSD: mi,v 1.140 2016/01/05 17:22:38 jakllsch Exp $
./etc/mtree/set.debug comp-sys-root
./usr/lib comp-sys-usr compatdir
./usr/lib/i18n/libBIG5_g.a comp-c-debuglib debuglib,compatfile
@@ -1579,6 +1579,7 @@
./usr/libdata/debug/usr/tests/dev/md/h_mdserv.debug tests-fs-debug debug,atf,rump
./usr/libdata/debug/usr/tests/dev/scsipi/t_cd.debug tests-fs-debug debug,atf,rump
./usr/libdata/debug/usr/tests/dev/sysmon/t_swwdog.debug tests-fs-debug debug,atf,rump
+./usr/libdata/debug/usr/tests/dev/usb/t_hid.debug tests-fs-debug debug,atf,rump
./usr/libdata/debug/usr/tests/fs/ffs/h_ffs_server.debug tests-fs-debug debug,atf,rump
./usr/libdata/debug/usr/tests/fs/ffs/h_quota2_server.debug tests-obsolete obsolete,compattestfile
./usr/libdata/debug/usr/tests/fs/ffs/h_quota2_tests.debug tests-fs-debug debug,atf,rump
diff -r cf16fb046e58 -r 4f2a941b77f8 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi Tue Jan 05 17:06:34 2016 +0000
+++ b/distrib/sets/lists/tests/mi Tue Jan 05 17:22:38 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.658 2016/01/01 21:38:54 jakllsch Exp $
+# $NetBSD: mi,v 1.659 2016/01/05 17:22:38 jakllsch Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -29,6 +29,7 @@
./usr/libdata/debug/usr/tests/dev/md tests-fs-debug compattestfile,atf
./usr/libdata/debug/usr/tests/dev/scsipi tests-fs-debug compattestfile,atf
./usr/libdata/debug/usr/tests/dev/sysmon tests-fs-debug compattestfile,atf
+./usr/libdata/debug/usr/tests/dev/usb tests-fs-debug compattestfile,atf
./usr/libdata/debug/usr/tests/fs tests-fs-debug compattestfile,atf
./usr/libdata/debug/usr/tests/fs/ffs tests-fs-debug compattestfile,atf
./usr/libdata/debug/usr/tests/fs/fifofs tests-fs-debug compattestfile,atf
@@ -1372,6 +1373,10 @@
./usr/tests/dev/sysmon/Kyuafile tests-fs-tests atf,rump,kyua
./usr/tests/dev/sysmon/t_swsensor tests-fs-tests atf,rump
./usr/tests/dev/sysmon/t_swwdog tests-fs-tests atf,rump
+./usr/tests/dev/usb tests-fs-tests compattestfile,atf
+./usr/tests/dev/usb/Atffile tests-fs-tests atf,rump
+./usr/tests/dev/usb/Kyuafile tests-fs-tests atf,rump,kyua
+./usr/tests/dev/usb/t_hid tests-fs-tests atf,rump
./usr/tests/examples tests-obsolete obsolete
./usr/tests/examples/Atffile tests-obsolete obsolete
./usr/tests/examples/t_asm tests-obsolete obsolete
diff -r cf16fb046e58 -r 4f2a941b77f8 etc/mtree/NetBSD.dist.tests
--- a/etc/mtree/NetBSD.dist.tests Tue Jan 05 17:06:34 2016 +0000
+++ b/etc/mtree/NetBSD.dist.tests Tue Jan 05 17:22:38 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: NetBSD.dist.tests,v 1.123 2016/01/01 21:38:54 jakllsch Exp $
+# $NetBSD: NetBSD.dist.tests,v 1.124 2016/01/05 17:22:38 jakllsch Exp $
./usr/libdata/debug/usr/tests
./usr/libdata/debug/usr/tests/atf
@@ -20,6 +20,7 @@
./usr/libdata/debug/usr/tests/dev/md
./usr/libdata/debug/usr/tests/dev/scsipi
./usr/libdata/debug/usr/tests/dev/sysmon
+./usr/libdata/debug/usr/tests/dev/usb
./usr/libdata/debug/usr/tests/fs
./usr/libdata/debug/usr/tests/fs/ffs
./usr/libdata/debug/usr/tests/fs/fifofs
@@ -189,6 +190,7 @@
./usr/tests/dev/raidframe
./usr/tests/dev/scsipi
./usr/tests/dev/sysmon
+./usr/tests/dev/usb
./usr/tests/fs
./usr/tests/fs/cd9660
./usr/tests/fs/ffs
diff -r cf16fb046e58 -r 4f2a941b77f8 tests/dev/Makefile
--- a/tests/dev/Makefile Tue Jan 05 17:06:34 2016 +0000
+++ b/tests/dev/Makefile Tue Jan 05 17:22:38 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.9 2015/06/22 00:05:23 matt Exp $
+# $NetBSD: Makefile,v 1.10 2016/01/05 17:22:38 jakllsch Exp $
#
.include <bsd.own.mk>
@@ -7,7 +7,7 @@
TESTS_SUBDIRS+= cgd raidframe
.if (${MKRUMP} != "no") && !defined(BSD_MK_COMPAT_FILE)
-TESTS_SUBDIRS+= audio md scsipi sysmon
+TESTS_SUBDIRS+= audio md scsipi sysmon usb
.endif
diff -r cf16fb046e58 -r 4f2a941b77f8 tests/dev/usb/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/dev/usb/Makefile Tue Jan 05 17:22:38 2016 +0000
@@ -0,0 +1,22 @@
+# $NetBSD: Makefile,v 1.1 2016/01/05 17:22:38 jakllsch Exp $
+#
+
+.include <bsd.own.mk>
+
+TESTSDIR= ${TESTSBASE}/dev/usb
+
+TESTS_C= t_hid
+
+CPPFLAGS.t_hid.c= -I${.CURDIR}/../../../sys/dev/usb
+
+SUBDIR= libhid
+LIBHIDDIR!= cd ${.CURDIR}/libhid && ${PRINTOBJDIR}
+LDFLAGS.t_hid+= -L${LIBHIDDIR}
+LDADD.t_hid+= -Wl,--whole-archive -lrumpdev_hid -Wl,--no-whole-archive
+
+LDADD+= -lrump
+LDADD+= -lrumpuser
+LDADD+= -lrump
+LDADD+= -lpthread
+
+.include <bsd.test.mk>
diff -r cf16fb046e58 -r 4f2a941b77f8 tests/dev/usb/libhid/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/dev/usb/libhid/Makefile Tue Jan 05 17:22:38 2016 +0000
@@ -0,0 +1,16 @@
+# $NetBSD: Makefile,v 1.1 2016/01/05 17:22:39 jakllsch Exp $
+#
+
+.include <bsd.own.mk>
+
+RUMPTOP= ${NETBSDSRCDIR}/sys/rump
+.PATH: ${.CURDIR}/../../../../sys/dev/usb
+
+LIB= rumpdev_hid
+LIBISPRIVATE= #defined
+
+SRCS= hid.c
+
+.include "${RUMPTOP}/Makefile.rump"
+.include <bsd.lib.mk>
+.include <bsd.klinks.mk>
diff -r cf16fb046e58 -r 4f2a941b77f8 tests/dev/usb/t_hid.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/dev/usb/t_hid.c Tue Jan 05 17:22:38 2016 +0000
@@ -0,0 +1,210 @@
+/* $NetBSD: t_hid.c,v 1.1 2016/01/05 17:22:38 jakllsch Exp $ */
+
+/*
+ * Copyright (c) 2016 Jonathan A. Kollasch
+ * All rights reserved.
+ *
+ * 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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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_hid.c,v 1.1 2016/01/05 17:22:38 jakllsch Exp $");
+
+#include <machine/types.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <atf-c.h>
+#define hid_start_parse rumpns_hid_start_parse
+#define hid_end_parse rumpns_hid_end_parse
+#define hid_get_item rumpns_hid_get_item
+#define hid_locate rumpns_hid_locate
+#define hid_report_size rumpns_hid_report_size
+#define hid_get_data rumpns_hid_get_data
+#define hid_get_udata rumpns_hid_get_udata
+#define uhidevdebug rumpns_uhidevdebug
+#include <hid.h>
+
+#include "../../lib/libusbhid/hid_test_data.c"
+
+#define MYd_ATF_CHECK_EQ(d, v) \
+ ATF_CHECK_EQ_MSG(d, v, "== %d", (d))
+
+#define MYld_ATF_CHECK_EQ(d, v) \
+ ATF_CHECK_EQ_MSG(d, v, "== %ld", (d))
+
+#define MYu_ATF_CHECK_EQ(d, v) \
+ ATF_CHECK_EQ_MSG(d, v, "== %u", (d))
+
+#define MYlu_ATF_CHECK_EQ(d, v) \
+ ATF_CHECK_EQ_MSG(d, v, "== %lu", (d))
+
+#define MYx_ATF_CHECK_EQ(d, v) \
+ ATF_CHECK_EQ_MSG(d, v, "== 0x%x", (d))
+
+#define MYlx_ATF_CHECK_EQ(d, v) \
+ ATF_CHECK_EQ_MSG(d, v, "== 0x%lx", (d))
+
+int uhidevdebug;
+
+ATF_TC(khid);
+
+ATF_TC_HEAD(khid, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "check kernel hid.c");
+}
+
+ATF_TC_BODY(khid, tc)
+{
+ int ret;
+ struct hid_item hi;
+ u_int32_t flags;
+
+ uhidevdebug = 0;
+
+ atf_tc_expect_fail("logical/physical range appears broken");
+
+ ret = hid_locate(range_test_report_descriptor,
+ sizeof(range_test_report_descriptor), 0xff000003, 0, hid_input,
+ &hi.loc, &flags);
+ ATF_REQUIRE(ret > 0);
+ MYu_ATF_CHECK_EQ(hi.loc.size, 32);
+ MYu_ATF_CHECK_EQ(hi.loc.count, 1);
+ MYu_ATF_CHECK_EQ(hi.loc.pos, 0);
+ MYx_ATF_CHECK_EQ(flags, 0);
+ MYd_ATF_CHECK_EQ(hi.logical_minimum, -2147483648);
+ MYd_ATF_CHECK_EQ(hi.logical_maximum, 2147483647);
+ MYd_ATF_CHECK_EQ(hi.physical_minimum, -2147483648);
+ MYd_ATF_CHECK_EQ(hi.physical_maximum, 2147483647);
+ MYld_ATF_CHECK_EQ(hid_get_data(range_test_minimum_report,
+ &hi.loc), -2147483648);
+ MYld_ATF_CHECK_EQ(hid_get_data(range_test_negative_one_report,
+ &hi.loc), -1);
+ MYld_ATF_CHECK_EQ(hid_get_data(range_test_positive_one_report,
+ &hi.loc), 1);
+ MYld_ATF_CHECK_EQ(hid_get_data(range_test_maximum_report,
+ &hi.loc), 2147483647);
+
+ ret = hid_locate(range_test_report_descriptor,
+ sizeof(range_test_report_descriptor), 0xff000002, 0, hid_input,
+ &hi.loc, &flags);
+ ATF_REQUIRE(ret > 0);
+ MYu_ATF_CHECK_EQ(hi.loc.size, 16);
+ MYu_ATF_CHECK_EQ(hi.loc.count, 1);
+ MYu_ATF_CHECK_EQ(hi.loc.pos, 32);
+ MYx_ATF_CHECK_EQ(flags, 0);
+ MYd_ATF_CHECK_EQ(hi.logical_minimum, -32768);
+ MYd_ATF_CHECK_EQ(hi.logical_maximum, 32767);
+ MYd_ATF_CHECK_EQ(hi.physical_minimum, -32768);
+ MYd_ATF_CHECK_EQ(hi.physical_maximum, 32767);
+ MYld_ATF_CHECK_EQ(hid_get_data(range_test_minimum_report,
+ &hi.loc), -32768);
+ MYld_ATF_CHECK_EQ(hid_get_data(range_test_negative_one_report,
+ &hi.loc), -1);
+ MYld_ATF_CHECK_EQ(hid_get_data(range_test_positive_one_report,
+ &hi.loc), 1);
+ MYld_ATF_CHECK_EQ(hid_get_data(range_test_maximum_report,
+ &hi.loc), 32767);
+
+ ret = hid_locate(range_test_report_descriptor,
+ sizeof(range_test_report_descriptor), 0xff000001, 0, hid_input,
+ &hi.loc, &flags);
+ ATF_REQUIRE(ret > 0);
+ MYu_ATF_CHECK_EQ(hi.loc.size, 8);
+ MYu_ATF_CHECK_EQ(hi.loc.count, 1);
+ MYu_ATF_CHECK_EQ(hi.loc.pos, 48);
+ MYx_ATF_CHECK_EQ(flags, 0);
+ MYd_ATF_CHECK_EQ(hi.logical_minimum, -128);
+ MYd_ATF_CHECK_EQ(hi.logical_maximum, 127);
+ MYd_ATF_CHECK_EQ(hi.physical_minimum, -128);
+ MYd_ATF_CHECK_EQ(hi.physical_maximum, 127);
+ MYld_ATF_CHECK_EQ(hid_get_data(range_test_minimum_report,
+ &hi.loc), -128);
+ MYld_ATF_CHECK_EQ(hid_get_data(range_test_negative_one_report,
+ &hi.loc), -1);
+ MYld_ATF_CHECK_EQ(hid_get_data(range_test_positive_one_report,
+ &hi.loc), 1);
+ MYld_ATF_CHECK_EQ(hid_get_data(range_test_maximum_report,
+ &hi.loc), 127);
+
+
+ ret = hid_locate(unsigned_range_test_report_descriptor,
+ sizeof(unsigned_range_test_report_descriptor), 0xff000013, 0,
+ hid_input, &hi.loc, &flags);
+ ATF_REQUIRE(ret > 0);
+ MYu_ATF_CHECK_EQ(hi.loc.size, 32);
+ MYu_ATF_CHECK_EQ(hi.loc.count, 1);
+ MYu_ATF_CHECK_EQ(hi.loc.pos, 0);
+ MYx_ATF_CHECK_EQ(flags, 0);
+ MYlx_ATF_CHECK_EQ(hid_get_udata(unsigned_range_test_minimum_report,
+ &hi.loc), 0x0);
+ MYlx_ATF_CHECK_EQ(hid_get_udata(unsigned_range_test_positive_one_report,
+ &hi.loc), 0x1);
Home |
Main Index |
Thread Index |
Old Index