Module Name:    src
Committed By:   jakllsch
Date:           Fri Jan  1 21:38:54 UTC 2016

Modified Files:
        src/distrib/sets/lists/debug: mi
        src/distrib/sets/lists/tests: mi
        src/etc/mtree: NetBSD.dist.tests
        src/tests/lib: Makefile
Added Files:
        src/tests/lib/libusbhid: Makefile t_usbhid.c test_usb_hid_usages

Log Message:
tests for libusbhid (many of which fail)


To generate a diff of this commit:
cvs rdiff -u -r1.138 -r1.139 src/distrib/sets/lists/debug/mi
cvs rdiff -u -r1.657 -r1.658 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.122 -r1.123 src/etc/mtree/NetBSD.dist.tests
cvs rdiff -u -r1.24 -r1.25 src/tests/lib/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/lib/libusbhid/Makefile \
    src/tests/lib/libusbhid/t_usbhid.c \
    src/tests/lib/libusbhid/test_usb_hid_usages

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/debug/mi
diff -u src/distrib/sets/lists/debug/mi:1.138 src/distrib/sets/lists/debug/mi:1.139
--- src/distrib/sets/lists/debug/mi:1.138	Fri Dec 18 19:00:45 2015
+++ src/distrib/sets/lists/debug/mi	Fri Jan  1 21:38:53 2016
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.138 2015/12/18 19:00:45 christos Exp $
+# $NetBSD: mi,v 1.139 2016/01/01 21:38:53 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
@@ -2149,6 +2149,7 @@
 ./usr/libdata/debug/usr/tests/lib/libtre/h_regex_att.debug		tests-obsolete		obsolete,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libtre/t_exhaust.debug		tests-lib-debug		debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libtre/t_regex_att.debug		tests-lib-debug		debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/lib/libusbhid/t_usbhid.debug		tests-lib-debug		debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libutil/t_efun.debug			tests-lib-debug		debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libutil/t_parsedate.debug		tests-lib-debug		debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libutil/t_pidfile.debug		tests-lib-debug		debug,atf,compattestfile

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.657 src/distrib/sets/lists/tests/mi:1.658
--- src/distrib/sets/lists/tests/mi:1.657	Sat Dec  5 18:47:43 2015
+++ src/distrib/sets/lists/tests/mi	Fri Jan  1 21:38:54 2016
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.657 2015/12/05 18:47:43 christos Exp $
+# $NetBSD: mi,v 1.658 2016/01/01 21:38:54 jakllsch Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -131,6 +131,7 @@
 ./usr/libdata/debug/usr/tests/lib/libskey				tests-lib-debug		compattestfile,atf
 ./usr/libdata/debug/usr/tests/lib/libsljit				tests-lib-debug		compattestfile,atf
 ./usr/libdata/debug/usr/tests/lib/libtre				tests-lib-debug		compattestfile,atf
+./usr/libdata/debug/usr/tests/lib/libusbhid				tests-lib-debug		compattestfile,atf
 ./usr/libdata/debug/usr/tests/lib/libutil				tests-lib-debug		compattestfile,atf
 ./usr/libdata/debug/usr/tests/lib/semaphore				tests-lib-debug		compattestfile,atf
 ./usr/libdata/debug/usr/tests/lib/semaphore/pthread			tests-lib-debug		compattestfile,atf
@@ -3042,6 +3043,10 @@
 ./usr/tests/lib/libtre/h_regex_att		tests-obsolete		obsolete
 ./usr/tests/lib/libtre/t_exhaust		tests-lib-tests		compattestfile,atf
 ./usr/tests/lib/libtre/t_regex_att		tests-lib-tests		compattestfile,atf
+./usr/tests/lib/libusbhid			tests-lib-tests		compattestfile,atf
+./usr/tests/lib/libusbhid/Atffile		tests-lib-tests		compattestfile,atf
+./usr/tests/lib/libusbhid/t_usbhid		tests-lib-tests		compattestfile,atf
+./usr/tests/lib/libusbhid/test_usb_hid_usages	tests-lib-tests		compattestfile,atf
 ./usr/tests/lib/libutil				tests-lib-tests		compattestfile,atf
 ./usr/tests/lib/libutil/Atffile			tests-lib-tests		compattestfile,atf
 ./usr/tests/lib/libutil/Kyuafile		tests-lib-tests		compattestfile,atf,kyua

Index: src/etc/mtree/NetBSD.dist.tests
diff -u src/etc/mtree/NetBSD.dist.tests:1.122 src/etc/mtree/NetBSD.dist.tests:1.123
--- src/etc/mtree/NetBSD.dist.tests:1.122	Fri Dec  4 17:20:12 2015
+++ src/etc/mtree/NetBSD.dist.tests	Fri Jan  1 21:38:54 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: NetBSD.dist.tests,v 1.122 2015/12/04 17:20:12 christos Exp $
+#	$NetBSD: NetBSD.dist.tests,v 1.123 2016/01/01 21:38:54 jakllsch Exp $
 
 ./usr/libdata/debug/usr/tests
 ./usr/libdata/debug/usr/tests/atf
@@ -119,6 +119,7 @@
 ./usr/libdata/debug/usr/tests/lib/libskey
 ./usr/libdata/debug/usr/tests/lib/libsljit
 ./usr/libdata/debug/usr/tests/lib/libtre
+./usr/libdata/debug/usr/tests/lib/libusbhid
 ./usr/libdata/debug/usr/tests/lib/libutil
 ./usr/libdata/debug/usr/tests/libexec
 ./usr/libdata/debug/usr/tests/libexec/ld.elf_so
@@ -300,6 +301,7 @@
 ./usr/tests/lib/libsljit
 ./usr/tests/lib/libtre
 ./usr/tests/lib/libtre/data
+./usr/tests/lib/libusbhid
 ./usr/tests/lib/libutil
 ./usr/tests/libexec
 ./usr/tests/libexec/ld.elf_so

Index: src/tests/lib/Makefile
diff -u src/tests/lib/Makefile:1.24 src/tests/lib/Makefile:1.25
--- src/tests/lib/Makefile:1.24	Mon Jun 22 00:05:23 2015
+++ src/tests/lib/Makefile	Fri Jan  1 21:38:54 2016
@@ -1,10 +1,10 @@
-# $NetBSD: Makefile,v 1.24 2015/06/22 00:05:23 matt Exp $
+# $NetBSD: Makefile,v 1.25 2016/01/01 21:38:54 jakllsch Exp $
 
 .include <bsd.own.mk>
 
 TESTS_SUBDIRS=	csu libbluetooth libc libcrypt libcurses libevent libexecinfo \
 		libm libobjc libposix libppath libprop libpthread \
-		librt libtre libutil semaphore
+		librt libtre libusbhid libutil semaphore
 
 .if (${MKRUMP} != "no") && !defined(BSD_MK_COMPAT_FILE)
 TESTS_SUBDIRS+= librumpclient librumphijack

Added files:

Index: src/tests/lib/libusbhid/Makefile
diff -u /dev/null src/tests/lib/libusbhid/Makefile:1.1
--- /dev/null	Fri Jan  1 21:38:54 2016
+++ src/tests/lib/libusbhid/Makefile	Fri Jan  1 21:38:54 2016
@@ -0,0 +1,15 @@
+#	$NetBSD: Makefile,v 1.1 2016/01/01 21:38:54 jakllsch Exp $
+
+.include <bsd.own.mk>
+
+TESTSDIR=	${TESTSBASE}/lib/libusbhid
+
+DPADD+=		${LIBUSBHID}
+LDADD+=		-lusbhid
+
+TESTS_C+=	t_usbhid
+
+FILES=          test_usb_hid_usages
+FILESDIR=       ${TESTSDIR}
+
+.include <bsd.test.mk>
Index: src/tests/lib/libusbhid/t_usbhid.c
diff -u /dev/null src/tests/lib/libusbhid/t_usbhid.c:1.1
--- /dev/null	Fri Jan  1 21:38:54 2016
+++ src/tests/lib/libusbhid/t_usbhid.c	Fri Jan  1 21:38:54 2016
@@ -0,0 +1,510 @@
+/*	$NetBSD: t_usbhid.c,v 1.1 2016/01/01 21:38:54 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_usbhid.c,v 1.1 2016/01/01 21:38:54 jakllsch Exp $");
+
+#include <atf-c.h>
+
+#include <inttypes.h>
+#include <usbhid.h>
+#include <string.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <limits.h>
+
+ATF_TC(check_hid_logical_range);
+ATF_TC(check_hid_physical_range);
+ATF_TC(check_hid_usage);
+ATF_TC(check_hid_get_data);
+ATF_TC(check_hid_set_data);
+
+static const uint8_t range_test_report_descriptor[] = {
+	0x0b, 0x03, 0x00, 0x00, 0xff,	// Usage
+	0x75, 0x20,			// Report Size
+	0x95, 0x01,			// Report Count
+	0x17, 0x00, 0x00, 0x00, 0x80,	// Logical Minimum
+	0x27, 0xff, 0xff, 0xff, 0x7f,	// Logical Maximum
+	0x37, 0x00, 0x00, 0x00, 0x80,	// Physical Minimum
+	0x47, 0xff, 0xff, 0xff, 0x7f,	// Physical Maximum
+	0x81, 0x00,			// Input
+
+	0x0b, 0x02, 0x00, 0x00, 0xff,	// Usage
+	0x75, 0x10,			// Report Size
+	0x95, 0x01,			// Report Count
+	0x16, 0x00, 0x80,		// Logical Minimum
+	0x26, 0xff, 0x7f,		// Logical Maximum
+	0x36, 0x00, 0x80,		// Physical Minimum
+	0x46, 0xff, 0x7f,		// Physical Maximum
+	0x81, 0x00,			// Input
+
+	0x0b, 0x01, 0x00, 0x00, 0xff,	// Usage
+	0x75, 0x08,			// Report Size
+	0x95, 0x01,			// Report Count
+	0x15, 0x80,			// Logical Minimum
+	0x25, 0x7f,			// Logical Maximum
+	0x35, 0x80,			// Physical Minimum
+	0x45, 0x7f,			// Physical Maximum
+	0x81, 0x00,			// Input
+};
+
+static const uint8_t unsigned_range_test_report_descriptor[] = {
+	0x0b, 0x13, 0x00, 0x00, 0xff,	// Usage
+	0x75, 0x20,			// Report Size
+	0x95, 0x01,			// Report Count
+	0x17, 0x00, 0x00, 0x00, 0x00,	// Logical Minimum
+	0x27, 0xff, 0xff, 0xff, 0xff,	// Logical Maximum
+	0x37, 0x00, 0x00, 0x00, 0x00,	// Physical Minimum
+	0x47, 0xff, 0xff, 0xff, 0xff,	// Physical Maximum
+	0x81, 0x00,			// Input
+
+	0x0b, 0x12, 0x00, 0x00, 0xff,	// Usage
+	0x75, 0x10,			// Report Size
+	0x95, 0x01,			// Report Count
+	0x16, 0x00, 0x00,		// Logical Minimum
+	0x26, 0xff, 0xff,		// Logical Maximum
+	0x36, 0x00, 0x00,		// Physical Minimum
+	0x46, 0xff, 0xff,		// Physical Maximum
+	0x81, 0x00,			// Input
+
+	0x0b, 0x11, 0x00, 0x00, 0xff,	// Usage
+	0x75, 0x08,			// Report Size
+	0x95, 0x01,			// Report Count
+	0x15, 0x00,			// Logical Minimum
+	0x25, 0xff,			// Logical Maximum
+	0x35, 0x00,			// Physical Minimum
+	0x45, 0xff,			// Physical Maximum
+	0x81, 0x00,			// Input
+};
+
+static const uint8_t range_test_minimum_report[7] = {
+	0x00, 0x00, 0x00, 0x80,
+	0x00, 0x80,
+	0x80,
+};
+
+static const uint8_t unsigned_range_test_minimum_report[7] = {
+	0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00,
+	0x00,
+};
+
+static const uint8_t range_test_maximum_report[7] = {
+	0xff, 0xff, 0xff, 0x7f,
+	0xff, 0x7f,
+	0x7f,
+};
+
+static const uint8_t unsigned_range_test_maximum_report[7] = {
+	0xff, 0xff, 0xff, 0xff,
+	0xff, 0xff,
+	0xff,
+};
+
+static const uint8_t range_test_positive_one_report[7] = {
+	0x01, 0x00, 0x00, 0x00,
+	0x01, 0x00,
+	0x01,
+};
+
+static const uint8_t unsigned_range_test_positive_one_report[7] = {
+	0x01, 0x00, 0x00, 0x00,
+	0x01, 0x00,
+	0x01,
+};
+
+static const uint8_t range_test_negative_one_report[7] = {
+	0xff, 0xff, 0xff, 0xff,
+	0xff, 0xff,
+	0xff,
+};
+
+static const uint8_t unsigned_range_test_negative_one_report[7] = {
+	0xfe, 0xff, 0xff, 0xff,
+	0xfe, 0xff,
+	0xfe,
+};
+
+ATF_TC_HEAD(check_hid_usage, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr", "Test libusbhid usage.c");
+}
+
+ATF_TC_BODY(check_hid_usage, tc)
+{
+	char usages_path[PATH_MAX];
+
+	(void)strlcpy(usages_path, atf_tc_get_config_var(tc, "srcdir"),
+	    sizeof(usages_path));
+	(void)strlcat(usages_path, "/test_usb_hid_usages",
+	    sizeof(usages_path));
+
+	atf_tc_expect_fail("hid_parse_*() fails because it doesn't use "
+	    "scanf()");
+
+	hid_init(usages_path);
+
+	ATF_CHECK_STREQ("t_usbhid_page", hid_usage_page(0xff1b));
+	ATF_CHECK_EQ((uint32_t)hid_parse_usage_page("t_usbhid_page"), 0xff1b);
+
+	ATF_CHECK_STREQ("t_usbhid_usage", hid_usage_in_page(0xff1bff2a));
+	ATF_CHECK_EQ((uint32_t)hid_parse_usage_in_page(
+	    "t_usbhid_page:t_usbhid_usage"), 0xff1bff2a);
+
+	ATF_CHECK_STREQ("Quick_zephyrs_blow_vexing_daft_Jim_",
+	    hid_usage_page(0xff2a));
+	ATF_CHECK_EQ((uint32_t)hid_parse_usage_page(
+	    "Quick_zephyrs_blow_vexing_daft_Jim_"), 0xff2a);
+
+	ATF_CHECK_STREQ("Usage_ID_Zero_%", hid_usage_in_page(0xff2a0000));
+	ATF_CHECK_EQ((uint32_t)hid_parse_usage_in_page(
+	    "Quick_zephyrs_blow_vexing_daft_Jim_:Usage_ID_Zero_%"),
+	    0xff2a0000);
+
+	//ATF_CHECK_STREQ("Usage_ID_0_%", hid_usage_in_page(0xff2a0000));
+	ATF_CHECK_EQ((uint32_t)hid_parse_usage_in_page(
+	    "Quick_zephyrs_blow_vexing_daft_Jim_:Usage_ID_0_%"), 0xff2a0000);
+
+	ATF_CHECK_STREQ("Usage_ID_65535_%", hid_usage_in_page(0xff2affff));
+	ATF_CHECK_EQ((uint32_t)hid_parse_usage_in_page(
+	    "Quick_zephyrs_blow_vexing_daft_Jim_:Usage_ID_65535_%"),
+	    0xff2affff);
+}
+
+ATF_TC_HEAD(check_hid_logical_range, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr", "Test hid_get_item "
+	    "Logical Minimum/Maximum results");
+}
+
+ATF_TC_BODY(check_hid_logical_range, tc)
+{
+	report_desc_t hrd;
+	hid_item_t hi;
+
+	atf_tc_expect_fail("only the 32-bit opcode works, "
+	    "8 and 16-bit is broken");
+
+	ATF_REQUIRE((hrd = hid_use_report_desc(range_test_report_descriptor,
+	    __arraycount(range_test_report_descriptor))) != NULL);
+	ATF_REQUIRE(hid_locate(hrd, 0xff000001U, hid_input, &hi,
+	    NO_REPORT_ID) > 0);
+	ATF_CHECK_EQ(hi.logical_minimum, -128);
+	ATF_CHECK_EQ(hi.logical_maximum, 127);
+	ATF_REQUIRE(hid_locate(hrd, 0xff000002U, hid_input, &hi,
+	    NO_REPORT_ID) > 0);
+	ATF_CHECK_EQ(hi.logical_minimum, -32768);
+	ATF_CHECK_EQ(hi.logical_maximum, 32767);
+	ATF_REQUIRE(hid_locate(hrd, 0xff000003U, hid_input, &hi,
+	    NO_REPORT_ID) > 0);
+	ATF_CHECK_EQ(hi.logical_minimum, -2147483648);
+	ATF_CHECK_EQ(hi.logical_maximum, 2147483647);
+
+	hid_dispose_report_desc(hrd);
+	hrd = NULL;
+
+	ATF_REQUIRE((hrd = hid_use_report_desc(
+	    unsigned_range_test_report_descriptor,
+	    __arraycount(unsigned_range_test_report_descriptor))) != NULL);
+
+	ATF_REQUIRE(hid_locate(hrd, 0xff000011U, hid_input, &hi,
+	    NO_REPORT_ID) > 0);
+	ATF_CHECK_EQ((uint32_t)hi.logical_minimum, 0);
+	ATF_CHECK_EQ((uint32_t)hi.logical_maximum, 255);
+	ATF_REQUIRE(hid_locate(hrd, 0xff000012U, hid_input, &hi,
+	    NO_REPORT_ID) > 0);
+	ATF_CHECK_EQ((uint32_t)hi.logical_minimum, 0);
+	ATF_CHECK_EQ((uint32_t)hi.logical_maximum, 65535);
+	ATF_REQUIRE(hid_locate(hrd, 0xff000013U, hid_input, &hi,
+	    NO_REPORT_ID) > 0);
+	ATF_CHECK_EQ((uint32_t)hi.logical_minimum, 0);
+	ATF_CHECK_EQ((uint32_t)hi.logical_maximum, 4294967295);
+
+	hid_dispose_report_desc(hrd);
+	hrd = NULL;
+}
+
+ATF_TC_HEAD(check_hid_physical_range, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr", "Test hid_get_item "
+	    "Physical Minimum/Maximum results");
+}
+
+ATF_TC_BODY(check_hid_physical_range, tc)
+{
+	report_desc_t hrd;
+	hid_item_t hi;
+
+	atf_tc_expect_fail("only the 32-bit opcode works, "
+	    "8 and 16-bit is broken");
+
+	ATF_REQUIRE((hrd = hid_use_report_desc(range_test_report_descriptor,
+	    __arraycount(range_test_report_descriptor))) != NULL);
+	ATF_REQUIRE(hid_locate(hrd, 0xff000001U, hid_input, &hi,
+	    NO_REPORT_ID) > 0);
+	ATF_CHECK_EQ(hi.physical_minimum, -128);
+	ATF_CHECK_EQ(hi.physical_maximum, 127);
+	ATF_REQUIRE(hid_locate(hrd, 0xff000002U, hid_input, &hi,
+	    NO_REPORT_ID) > 0);
+	ATF_CHECK_EQ(hi.physical_minimum, -32768);
+	ATF_CHECK_EQ(hi.physical_maximum, 32767);
+	ATF_REQUIRE(hid_locate(hrd, 0xff000003U, hid_input, &hi,
+	    NO_REPORT_ID) > 0);
+	ATF_CHECK_EQ(hi.physical_minimum, -2147483648);
+	ATF_CHECK_EQ(hi.physical_maximum, 2147483647);
+
+	hid_dispose_report_desc(hrd);
+	hrd = NULL;
+
+	ATF_REQUIRE((hrd = hid_use_report_desc(
+	    unsigned_range_test_report_descriptor,
+	    __arraycount(unsigned_range_test_report_descriptor))) != NULL);
+
+	ATF_REQUIRE(hid_locate(hrd, 0xff000011U, hid_input, &hi,
+	    NO_REPORT_ID) > 0);
+	ATF_CHECK_EQ((uint32_t)hi.physical_minimum, 0);
+	ATF_CHECK_EQ((uint32_t)hi.physical_maximum, 255);
+	ATF_REQUIRE(hid_locate(hrd, 0xff000012U, hid_input, &hi,
+	    NO_REPORT_ID) > 0);
+	ATF_CHECK_EQ((uint32_t)hi.physical_minimum, 0);
+	ATF_CHECK_EQ((uint32_t)hi.physical_maximum, 65535);
+	ATF_REQUIRE(hid_locate(hrd, 0xff000013U, hid_input, &hi,
+	    NO_REPORT_ID) > 0);
+	ATF_CHECK_EQ((uint32_t)hi.physical_minimum, 0);
+	ATF_CHECK_EQ((uint32_t)hi.physical_maximum, 4294967295);
+
+	hid_dispose_report_desc(hrd);
+	hrd = NULL;
+}
+
+ATF_TC_HEAD(check_hid_get_data, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr", "Test hid_get_data results");
+}
+
+#define MYd_ATF_CHECK_EQ(data, value) \
+	ATF_CHECK_EQ_MSG(data, value, " == %d", (data))
+
+#define MYu_ATF_CHECK_EQ(data, value) \
+	ATF_CHECK_EQ_MSG(data, value, " == %u", (data))
+
+ATF_TC_BODY(check_hid_get_data, tc)
+{
+	report_desc_t hrd;
+	hid_item_t hi;
+	int32_t data;
+	uint32_t udat;
+
+	atf_tc_expect_fail("all negative data doesn't work, "
+	    "all 32-bit data doesn't work");
+
+	ATF_REQUIRE((hrd = hid_use_report_desc(
+	    range_test_report_descriptor,
+	    __arraycount(range_test_report_descriptor))) != NULL);
+
+	ATF_REQUIRE(hid_locate(hrd, 0xff000001U, hid_input, &hi,
+	    NO_REPORT_ID) > 0);
+	data = hid_get_data(range_test_minimum_report, &hi);
+	MYd_ATF_CHECK_EQ(data, -128);
+	data = hid_get_data(range_test_negative_one_report, &hi);
+	MYd_ATF_CHECK_EQ(data, -1);
+	data = hid_get_data(range_test_positive_one_report, &hi);
+	MYd_ATF_CHECK_EQ(data, 1);
+	data = hid_get_data(range_test_maximum_report, &hi);
+	MYd_ATF_CHECK_EQ(data, 127);
+
+	ATF_REQUIRE(hid_locate(hrd, 0xff000002U, hid_input, &hi,
+	    NO_REPORT_ID) > 0);
+	data = hid_get_data(range_test_minimum_report, &hi);
+	MYd_ATF_CHECK_EQ(data, -32768);
+	data = hid_get_data(range_test_negative_one_report, &hi);
+	MYd_ATF_CHECK_EQ(data, -1);
+	data = hid_get_data(range_test_positive_one_report, &hi);
+	MYd_ATF_CHECK_EQ(data, 1);
+	data = hid_get_data(range_test_maximum_report, &hi);
+	MYd_ATF_CHECK_EQ(data, 32767);
+
+	ATF_REQUIRE(hid_locate(hrd, 0xff000003U, hid_input, &hi,
+	    NO_REPORT_ID) > 0);
+	data = hid_get_data(range_test_minimum_report, &hi);
+	MYd_ATF_CHECK_EQ(data, -2147483648);
+	data = hid_get_data(range_test_negative_one_report, &hi);
+	MYd_ATF_CHECK_EQ(data, -1);
+	data = hid_get_data(range_test_positive_one_report, &hi);
+	MYd_ATF_CHECK_EQ(data, 1);
+	data = hid_get_data(range_test_maximum_report, &hi);
+	MYd_ATF_CHECK_EQ(data, 2147483647);
+
+	hid_dispose_report_desc(hrd);
+	hrd = NULL;
+
+	ATF_REQUIRE((hrd = hid_use_report_desc(
+	    unsigned_range_test_report_descriptor,
+	    __arraycount(unsigned_range_test_report_descriptor))) != NULL);
+	ATF_REQUIRE(hid_locate(hrd, 0xff000011U, hid_input, &hi,
+	    NO_REPORT_ID) > 0);
+	udat = hid_get_data(unsigned_range_test_minimum_report, &hi);
+	MYu_ATF_CHECK_EQ(udat, 0);
+	udat = hid_get_data(unsigned_range_test_positive_one_report, &hi);
+	MYu_ATF_CHECK_EQ(udat, 1);
+	udat = hid_get_data(unsigned_range_test_negative_one_report, &hi);
+	MYu_ATF_CHECK_EQ(udat, 254);
+	udat = hid_get_data(unsigned_range_test_maximum_report, &hi);
+	MYu_ATF_CHECK_EQ(udat, 255);
+
+	ATF_REQUIRE(hid_locate(hrd, 0xff000012U, hid_input, &hi,
+	    NO_REPORT_ID) > 0);
+	udat = hid_get_data(unsigned_range_test_minimum_report, &hi);
+	MYu_ATF_CHECK_EQ(udat, 0);
+	udat = hid_get_data(unsigned_range_test_positive_one_report, &hi);
+	MYu_ATF_CHECK_EQ(udat, 1);
+	udat = hid_get_data(unsigned_range_test_negative_one_report, &hi);
+	MYu_ATF_CHECK_EQ(udat, 65534);
+	udat = hid_get_data(unsigned_range_test_maximum_report, &hi);
+	MYu_ATF_CHECK_EQ(udat, 65535);
+
+	ATF_REQUIRE(hid_locate(hrd, 0xff000013U, hid_input, &hi,
+	    NO_REPORT_ID) > 0);
+	udat = hid_get_data(unsigned_range_test_minimum_report, &hi);
+	MYu_ATF_CHECK_EQ(udat, 0);
+	udat = hid_get_data(unsigned_range_test_positive_one_report, &hi);
+	MYu_ATF_CHECK_EQ(udat, 1);
+	udat = hid_get_data(unsigned_range_test_negative_one_report, &hi);
+	MYu_ATF_CHECK_EQ(udat, 4294967294);
+	udat = hid_get_data(unsigned_range_test_maximum_report, &hi);
+	MYu_ATF_CHECK_EQ(udat, 4294967295);
+
+	hid_dispose_report_desc(hrd);
+	hrd = NULL;
+}
+
+ATF_TC_HEAD(check_hid_set_data, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr", "Test hid_set_data results");
+}
+
+ATF_TC_BODY(check_hid_set_data, tc)
+{
+	report_desc_t hrd;
+	hid_item_t hi;
+	uint8_t test_data_minimum[7];
+	uint8_t test_data_negative_one[7];
+	uint8_t test_data_positive_one[7];
+	uint8_t test_data_maximum[7];
+
+	ATF_REQUIRE((hrd = hid_use_report_desc(
+	    range_test_report_descriptor,
+	    __arraycount(range_test_report_descriptor))) != NULL);
+	ATF_REQUIRE(hid_locate(hrd, 0xff000001U, hid_input, &hi,
+	    NO_REPORT_ID) > 0);
+	hid_set_data(test_data_minimum, &hi, -128);
+	hid_set_data(test_data_negative_one, &hi, -1);
+	hid_set_data(test_data_positive_one, &hi, 1);
+	hid_set_data(test_data_maximum, &hi, 127);
+	ATF_REQUIRE(hid_locate(hrd, 0xff000002U, hid_input, &hi,
+	    NO_REPORT_ID) > 0);
+	hid_set_data(test_data_minimum, &hi, -32768);
+	hid_set_data(test_data_negative_one, &hi, -1);
+	hid_set_data(test_data_positive_one, &hi, 1);
+	hid_set_data(test_data_maximum, &hi, 32767);
+	ATF_REQUIRE(hid_locate(hrd, 0xff000003U, hid_input, &hi,
+	    NO_REPORT_ID) > 0);
+	hid_set_data(test_data_minimum, &hi, -2147483648);
+	hid_set_data(test_data_negative_one, &hi, -1);
+	hid_set_data(test_data_positive_one, &hi, 1);
+	hid_set_data(test_data_maximum, &hi, 2147483647);
+	ATF_CHECK(memcmp(test_data_minimum, range_test_minimum_report,
+	    sizeof test_data_minimum) == 0);
+	ATF_CHECK(memcmp(test_data_negative_one,
+	    range_test_negative_one_report,
+	    sizeof test_data_negative_one) == 0);
+	ATF_CHECK(memcmp(test_data_positive_one,
+	    range_test_positive_one_report,
+	    sizeof test_data_positive_one) == 0);
+	ATF_CHECK(memcmp(test_data_maximum, range_test_maximum_report,
+	    sizeof test_data_maximum) == 0);
+
+	hid_dispose_report_desc(hrd);
+	hrd = NULL;
+
+	ATF_REQUIRE((hrd = hid_use_report_desc(
+	    unsigned_range_test_report_descriptor,
+	    __arraycount(range_test_report_descriptor))) != NULL);
+	ATF_REQUIRE(hid_locate(hrd, 0xff000011U, hid_input, &hi,
+	    NO_REPORT_ID) > 0);
+	hid_set_data(test_data_minimum, &hi, 0);
+	hid_set_data(test_data_positive_one, &hi, 1);
+	hid_set_data(test_data_negative_one, &hi, 0xfffffffe);
+	hid_set_data(test_data_maximum, &hi, 0xffffffff);
+	ATF_REQUIRE(hid_locate(hrd, 0xff000012U, hid_input, &hi,
+	    NO_REPORT_ID) > 0);
+	hid_set_data(test_data_minimum, &hi, 0);
+	hid_set_data(test_data_positive_one, &hi, 1);
+	hid_set_data(test_data_negative_one, &hi, 0xfffe);
+	hid_set_data(test_data_maximum, &hi, 0xffff);
+	ATF_REQUIRE(hid_locate(hrd, 0xff000013U, hid_input, &hi,
+	    NO_REPORT_ID) > 0);
+	hid_set_data(test_data_minimum, &hi, 0);
+	hid_set_data(test_data_positive_one, &hi, 1);
+	hid_set_data(test_data_negative_one, &hi, 0xfffffffe);
+	hid_set_data(test_data_maximum, &hi, 0xffffffff);
+	ATF_CHECK(memcmp(test_data_minimum,
+	    unsigned_range_test_minimum_report,
+	    sizeof test_data_minimum) == 0);
+	ATF_CHECK(memcmp(test_data_negative_one,
+	    unsigned_range_test_negative_one_report,
+	    sizeof test_data_negative_one) == 0);
+	ATF_CHECK(memcmp(test_data_positive_one,
+	    unsigned_range_test_positive_one_report,
+	    sizeof test_data_positive_one) == 0);
+	ATF_CHECK(memcmp(test_data_maximum,
+	    unsigned_range_test_maximum_report,
+	    sizeof test_data_maximum) == 0);
+
+	hid_dispose_report_desc(hrd);
+	hrd = NULL;
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+	ATF_TP_ADD_TC(tp, check_hid_logical_range);
+	ATF_TP_ADD_TC(tp, check_hid_physical_range);
+	ATF_TP_ADD_TC(tp, check_hid_usage);
+	ATF_TP_ADD_TC(tp, check_hid_get_data);
+	ATF_TP_ADD_TC(tp, check_hid_set_data);
+
+	return atf_no_error();
+}
Index: src/tests/lib/libusbhid/test_usb_hid_usages
diff -u /dev/null src/tests/lib/libusbhid/test_usb_hid_usages:1.1
--- /dev/null	Fri Jan  1 21:38:54 2016
+++ src/tests/lib/libusbhid/test_usb_hid_usages	Fri Jan  1 21:38:54 2016
@@ -0,0 +1,17 @@
+# $NetBSD: test_usb_hid_usages,v 1.1 2016/01/01 21:38:54 jakllsch Exp $
+#
+# USB HID usage table (for t_usbhid)
+# Syntax:
+#  - lines that do not start with a white space give the number and name of
+#    a usage page.
+#  - lines that start with a white space give the number and name of
+#    a usage with the last given page.
+#    If the number is * then the line matches all usages and the name
+#    is a printf formatting string that will be given the usage number.
+#
+0xff1b	t_usbhid page
+	0xff2a	t_usbhid usage
+
+0xff2a	Quick zephyrs blow vexing daft Jim.
+	0	Usage ID Zero %
+	*	Usage ID %u %%

Reply via email to