t_usbhid.c revision 1.5
1/*	$NetBSD: t_usbhid.c,v 1.5 2016/01/02 01:04:15 jakllsch Exp $	*/
2
3/*
4 * Copyright (c) 2016 Jonathan A. Kollasch
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
30__RCSID("$NetBSD: t_usbhid.c,v 1.5 2016/01/02 01:04:15 jakllsch Exp $");
31
32#include <atf-c.h>
33
34#include <inttypes.h>
35#include <usbhid.h>
36#include <string.h>
37
38#include <stdio.h>
39#include <stdlib.h>
40
41#include <limits.h>
42
43ATF_TC(check_hid_logical_range);
44ATF_TC(check_hid_physical_range);
45ATF_TC(check_hid_usage);
46ATF_TC(check_hid_get_data);
47ATF_TC(check_hid_set_data);
48
49static const uint8_t range_test_report_descriptor[] = {
50	0x0b, 0x03, 0x00, 0x00, 0xff,	// Usage
51	0x75, 0x20,			// Report Size
52	0x95, 0x01,			// Report Count
53	0x17, 0x00, 0x00, 0x00, 0x80,	// Logical Minimum
54	0x27, 0xff, 0xff, 0xff, 0x7f,	// Logical Maximum
55	0x37, 0x00, 0x00, 0x00, 0x80,	// Physical Minimum
56	0x47, 0xff, 0xff, 0xff, 0x7f,	// Physical Maximum
57	0x81, 0x00,			// Input
58
59	0x0b, 0x02, 0x00, 0x00, 0xff,	// Usage
60	0x75, 0x10,			// Report Size
61	0x95, 0x01,			// Report Count
62	0x16, 0x00, 0x80,		// Logical Minimum
63	0x26, 0xff, 0x7f,		// Logical Maximum
64	0x36, 0x00, 0x80,		// Physical Minimum
65	0x46, 0xff, 0x7f,		// Physical Maximum
66	0x81, 0x00,			// Input
67
68	0x0b, 0x01, 0x00, 0x00, 0xff,	// Usage
69	0x75, 0x08,			// Report Size
70	0x95, 0x01,			// Report Count
71	0x15, 0x80,			// Logical Minimum
72	0x25, 0x7f,			// Logical Maximum
73	0x35, 0x80,			// Physical Minimum
74	0x45, 0x7f,			// Physical Maximum
75	0x81, 0x00,			// Input
76};
77
78static const uint8_t unsigned_range_test_report_descriptor[] = {
79	0x0b, 0x13, 0x00, 0x00, 0xff,	// Usage
80	0x75, 0x20,			// Report Size
81	0x95, 0x01,			// Report Count
82	0x17, 0x00, 0x00, 0x00, 0x00,	// Logical Minimum
83	0x27, 0xff, 0xff, 0xff, 0xff,	// Logical Maximum
84	0x37, 0x00, 0x00, 0x00, 0x00,	// Physical Minimum
85	0x47, 0xff, 0xff, 0xff, 0xff,	// Physical Maximum
86	0x81, 0x00,			// Input
87
88	0x0b, 0x12, 0x00, 0x00, 0xff,	// Usage
89	0x75, 0x10,			// Report Size
90	0x95, 0x01,			// Report Count
91	0x16, 0x00, 0x00,		// Logical Minimum
92	0x26, 0xff, 0xff,		// Logical Maximum
93	0x36, 0x00, 0x00,		// Physical Minimum
94	0x46, 0xff, 0xff,		// Physical Maximum
95	0x81, 0x00,			// Input
96
97	0x0b, 0x11, 0x00, 0x00, 0xff,	// Usage
98	0x75, 0x08,			// Report Size
99	0x95, 0x01,			// Report Count
100	0x15, 0x00,			// Logical Minimum
101	0x25, 0xff,			// Logical Maximum
102	0x35, 0x00,			// Physical Minimum
103	0x45, 0xff,			// Physical Maximum
104	0x81, 0x00,			// Input
105};
106
107static const uint8_t range_test_minimum_report[7] = {
108	0x00, 0x00, 0x00, 0x80,
109	0x00, 0x80,
110	0x80,
111};
112
113static const uint8_t unsigned_range_test_minimum_report[7] = {
114	0x00, 0x00, 0x00, 0x00,
115	0x00, 0x00,
116	0x00,
117};
118
119static const uint8_t range_test_maximum_report[7] = {
120	0xff, 0xff, 0xff, 0x7f,
121	0xff, 0x7f,
122	0x7f,
123};
124
125static const uint8_t unsigned_range_test_maximum_report[7] = {
126	0xff, 0xff, 0xff, 0xff,
127	0xff, 0xff,
128	0xff,
129};
130
131static const uint8_t range_test_positive_one_report[7] = {
132	0x01, 0x00, 0x00, 0x00,
133	0x01, 0x00,
134	0x01,
135};
136
137static const uint8_t unsigned_range_test_positive_one_report[7] = {
138	0x01, 0x00, 0x00, 0x00,
139	0x01, 0x00,
140	0x01,
141};
142
143static const uint8_t range_test_negative_one_report[7] = {
144	0xff, 0xff, 0xff, 0xff,
145	0xff, 0xff,
146	0xff,
147};
148
149static const uint8_t unsigned_range_test_negative_one_report[7] = {
150	0xfe, 0xff, 0xff, 0xff,
151	0xfe, 0xff,
152	0xfe,
153};
154
155ATF_TC_HEAD(check_hid_usage, tc)
156{
157
158	atf_tc_set_md_var(tc, "descr", "Test libusbhid usage.c");
159}
160
161ATF_TC_BODY(check_hid_usage, tc)
162{
163	char usages_path[PATH_MAX];
164
165	(void)strlcpy(usages_path, atf_tc_get_config_var(tc, "srcdir"),
166	    sizeof(usages_path));
167	(void)strlcat(usages_path, "/test_usb_hid_usages",
168	    sizeof(usages_path));
169
170	hid_init(usages_path);
171
172	ATF_CHECK_STREQ("t_usbhid_page", hid_usage_page(0xff1b));
173	ATF_CHECK_EQ((uint32_t)hid_parse_usage_page("t_usbhid_page"), 0xff1b);
174
175	ATF_CHECK_STREQ("t_usbhid_usage", hid_usage_in_page(0xff1bff2a));
176	ATF_CHECK_EQ((uint32_t)hid_parse_usage_in_page(
177	    "t_usbhid_page:t_usbhid_usage"), 0xff1bff2a);
178
179	ATF_CHECK_STREQ("Quick_zephyrs_blow_vexing_daft_Jim_",
180	    hid_usage_page(0xff2a));
181	ATF_CHECK_EQ((uint32_t)hid_parse_usage_page(
182	    "Quick_zephyrs_blow_vexing_daft_Jim_"), 0xff2a);
183
184	ATF_CHECK_STREQ("Usage_ID_Zero_%", hid_usage_in_page(0xff2a0000));
185	ATF_CHECK_EQ((uint32_t)hid_parse_usage_in_page(
186	    "Quick_zephyrs_blow_vexing_daft_Jim_:Usage_ID_Zero_%"),
187	    0xff2a0000);
188
189	//ATF_CHECK_STREQ("Usage_ID_0_%", hid_usage_in_page(0xff2a0000));
190	ATF_CHECK_EQ((uint32_t)hid_parse_usage_in_page(
191	    "Quick_zephyrs_blow_vexing_daft_Jim_:Usage_ID_0_%"), 0xff2a0000);
192
193	ATF_CHECK_STREQ("Usage_ID_65535_%", hid_usage_in_page(0xff2affff));
194	ATF_CHECK_EQ((uint32_t)hid_parse_usage_in_page(
195	    "Quick_zephyrs_blow_vexing_daft_Jim_:Usage_ID_65535_%"),
196	    0xff2affff);
197}
198
199#define MYd_ATF_CHECK_EQ(d, v) \
200	ATF_CHECK_EQ_MSG(d, v, "== %d", (d))
201
202#define MYu_ATF_CHECK_EQ(d, v) \
203	ATF_CHECK_EQ_MSG(d, v, "== %u", (d))
204
205ATF_TC_HEAD(check_hid_logical_range, tc)
206{
207
208	atf_tc_set_md_var(tc, "descr", "Test hid_get_item "
209	    "Logical Minimum/Maximum results");
210}
211
212ATF_TC_BODY(check_hid_logical_range, tc)
213{
214	report_desc_t hrd;
215	hid_item_t hi;
216	uint32_t minimum, maximum;
217
218	atf_tc_expect_fail("only the 32-bit opcode works, "
219	    "8 and 16-bit is broken");
220
221	ATF_REQUIRE((hrd = hid_use_report_desc(range_test_report_descriptor,
222	    __arraycount(range_test_report_descriptor))) != NULL);
223	ATF_REQUIRE(hid_locate(hrd, 0xff000001U, hid_input, &hi,
224	    NO_REPORT_ID) > 0);
225	MYd_ATF_CHECK_EQ(hi.logical_minimum, -128);
226	MYd_ATF_CHECK_EQ(hi.logical_maximum, 127);
227	ATF_REQUIRE(hid_locate(hrd, 0xff000002U, hid_input, &hi,
228	    NO_REPORT_ID) > 0);
229	MYd_ATF_CHECK_EQ(hi.logical_minimum, -32768);
230	MYd_ATF_CHECK_EQ(hi.logical_maximum, 32767);
231	ATF_REQUIRE(hid_locate(hrd, 0xff000003U, hid_input, &hi,
232	    NO_REPORT_ID) > 0);
233	MYd_ATF_CHECK_EQ(hi.logical_minimum, -2147483648);
234	MYd_ATF_CHECK_EQ(hi.logical_maximum, 2147483647);
235
236	hid_dispose_report_desc(hrd);
237	hrd = NULL;
238
239	ATF_REQUIRE((hrd = hid_use_report_desc(
240	    unsigned_range_test_report_descriptor,
241	    __arraycount(unsigned_range_test_report_descriptor))) != NULL);
242	ATF_REQUIRE(hid_locate(hrd, 0xff000011U, hid_input, &hi,
243	    NO_REPORT_ID) > 0);
244	ATF_CHECK(hi.logical_minimum > hi.logical_maximum);
245	minimum = (uint32_t)hi.logical_minimum & ((1ULL<<hi.report_size)-1);
246	MYu_ATF_CHECK_EQ(minimum, 0);
247	maximum = (uint32_t)hi.logical_maximum & ((1ULL<<hi.report_size)-1);
248	MYu_ATF_CHECK_EQ(maximum, 255);
249	ATF_REQUIRE(hid_locate(hrd, 0xff000012U, hid_input, &hi,
250	    NO_REPORT_ID) > 0);
251	ATF_CHECK(hi.logical_minimum > hi.logical_maximum);
252	minimum = hi.logical_minimum & ((1ULL<<hi.report_size)-1);
253	MYu_ATF_CHECK_EQ(minimum, 0);
254	maximum = hi.logical_maximum & ((1ULL<<hi.report_size)-1);
255	MYu_ATF_CHECK_EQ(maximum, 65535);
256	ATF_REQUIRE(hid_locate(hrd, 0xff000013U, hid_input, &hi,
257	    NO_REPORT_ID) > 0);
258	ATF_CHECK(hi.logical_minimum > hi.logical_maximum);
259	minimum = hi.logical_minimum & ((1ULL<<hi.report_size)-1);
260	MYu_ATF_CHECK_EQ(minimum, 0);
261	maximum = hi.logical_maximum & ((1ULL<<hi.report_size)-1);
262	MYu_ATF_CHECK_EQ(maximum, 4294967295);
263
264	hid_dispose_report_desc(hrd);
265	hrd = NULL;
266}
267
268ATF_TC_HEAD(check_hid_physical_range, tc)
269{
270
271	atf_tc_set_md_var(tc, "descr", "Test hid_get_item "
272	    "Physical Minimum/Maximum results");
273}
274
275ATF_TC_BODY(check_hid_physical_range, tc)
276{
277	report_desc_t hrd;
278	hid_item_t hi;
279	uint32_t minimum, maximum;
280
281	atf_tc_expect_fail("only the 32-bit opcode works, "
282	    "8 and 16-bit is broken");
283
284	ATF_REQUIRE((hrd = hid_use_report_desc(range_test_report_descriptor,
285	    __arraycount(range_test_report_descriptor))) != NULL);
286	ATF_REQUIRE(hid_locate(hrd, 0xff000001U, hid_input, &hi,
287	    NO_REPORT_ID) > 0);
288	MYd_ATF_CHECK_EQ(hi.physical_minimum, -128);
289	MYd_ATF_CHECK_EQ(hi.physical_maximum, 127);
290	ATF_REQUIRE(hid_locate(hrd, 0xff000002U, hid_input, &hi,
291	    NO_REPORT_ID) > 0);
292	MYd_ATF_CHECK_EQ(hi.physical_minimum, -32768);
293	MYd_ATF_CHECK_EQ(hi.physical_maximum, 32767);
294	ATF_REQUIRE(hid_locate(hrd, 0xff000003U, hid_input, &hi,
295	    NO_REPORT_ID) > 0);
296	MYd_ATF_CHECK_EQ(hi.physical_minimum, -2147483648);
297	MYd_ATF_CHECK_EQ(hi.physical_maximum, 2147483647);
298
299	hid_dispose_report_desc(hrd);
300	hrd = NULL;
301
302	ATF_REQUIRE((hrd = hid_use_report_desc(
303	    unsigned_range_test_report_descriptor,
304	    __arraycount(unsigned_range_test_report_descriptor))) != NULL);
305	ATF_REQUIRE(hid_locate(hrd, 0xff000011U, hid_input, &hi,
306	    NO_REPORT_ID) > 0);
307	ATF_CHECK(hi.physical_minimum > hi.physical_maximum);
308	minimum = (uint32_t)hi.physical_minimum & ((1ULL<<hi.report_size)-1);
309	MYu_ATF_CHECK_EQ(minimum, 0);
310	maximum = (uint32_t)hi.physical_maximum & ((1ULL<<hi.report_size)-1);
311	MYu_ATF_CHECK_EQ(maximum, 255);
312	ATF_REQUIRE(hid_locate(hrd, 0xff000012U, hid_input, &hi,
313	    NO_REPORT_ID) > 0);
314	ATF_CHECK(hi.physical_minimum > hi.physical_maximum);
315	minimum = hi.physical_minimum & ((1ULL<<hi.report_size)-1);
316	MYu_ATF_CHECK_EQ(minimum, 0);
317	maximum = hi.physical_maximum & ((1ULL<<hi.report_size)-1);
318	MYu_ATF_CHECK_EQ(maximum, 65535);
319	ATF_REQUIRE(hid_locate(hrd, 0xff000013U, hid_input, &hi,
320	    NO_REPORT_ID) > 0);
321	ATF_CHECK(hi.physical_minimum > hi.physical_maximum);
322	minimum = hi.physical_minimum & ((1ULL<<hi.report_size)-1);
323	MYu_ATF_CHECK_EQ(minimum, 0);
324	maximum = hi.physical_maximum & ((1ULL<<hi.report_size)-1);
325	MYu_ATF_CHECK_EQ(maximum, 4294967295);
326
327	hid_dispose_report_desc(hrd);
328	hrd = NULL;
329}
330
331ATF_TC_HEAD(check_hid_get_data, tc)
332{
333
334	atf_tc_set_md_var(tc, "descr", "Test hid_get_data results");
335}
336
337ATF_TC_BODY(check_hid_get_data, tc)
338{
339	report_desc_t hrd;
340	hid_item_t hi;
341	int32_t data;
342	uint32_t udat;
343
344	ATF_REQUIRE((hrd = hid_use_report_desc(
345	    range_test_report_descriptor,
346	    __arraycount(range_test_report_descriptor))) != NULL);
347
348	ATF_REQUIRE(hid_locate(hrd, 0xff000001U, hid_input, &hi,
349	    NO_REPORT_ID) > 0);
350	data = hid_get_data(range_test_minimum_report, &hi);
351	MYd_ATF_CHECK_EQ(data, -128);
352	data = hid_get_data(range_test_negative_one_report, &hi);
353	MYd_ATF_CHECK_EQ(data, -1);
354	data = hid_get_data(range_test_positive_one_report, &hi);
355	MYd_ATF_CHECK_EQ(data, 1);
356	data = hid_get_data(range_test_maximum_report, &hi);
357	MYd_ATF_CHECK_EQ(data, 127);
358
359	ATF_REQUIRE(hid_locate(hrd, 0xff000002U, hid_input, &hi,
360	    NO_REPORT_ID) > 0);
361	data = hid_get_data(range_test_minimum_report, &hi);
362	MYd_ATF_CHECK_EQ(data, -32768);
363	data = hid_get_data(range_test_negative_one_report, &hi);
364	MYd_ATF_CHECK_EQ(data, -1);
365	data = hid_get_data(range_test_positive_one_report, &hi);
366	MYd_ATF_CHECK_EQ(data, 1);
367	data = hid_get_data(range_test_maximum_report, &hi);
368	MYd_ATF_CHECK_EQ(data, 32767);
369
370	ATF_REQUIRE(hid_locate(hrd, 0xff000003U, hid_input, &hi,
371	    NO_REPORT_ID) > 0);
372	data = hid_get_data(range_test_minimum_report, &hi);
373	MYd_ATF_CHECK_EQ(data, -2147483648);
374	data = hid_get_data(range_test_negative_one_report, &hi);
375	MYd_ATF_CHECK_EQ(data, -1);
376	data = hid_get_data(range_test_positive_one_report, &hi);
377	MYd_ATF_CHECK_EQ(data, 1);
378	data = hid_get_data(range_test_maximum_report, &hi);
379	MYd_ATF_CHECK_EQ(data, 2147483647);
380
381	hid_dispose_report_desc(hrd);
382	hrd = NULL;
383
384	ATF_REQUIRE((hrd = hid_use_report_desc(
385	    unsigned_range_test_report_descriptor,
386	    __arraycount(unsigned_range_test_report_descriptor))) != NULL);
387	ATF_REQUIRE(hid_locate(hrd, 0xff000011U, hid_input, &hi,
388	    NO_REPORT_ID) > 0);
389	udat = hid_get_data(unsigned_range_test_minimum_report, &hi);
390	MYu_ATF_CHECK_EQ(udat, 0);
391	udat = hid_get_data(unsigned_range_test_positive_one_report, &hi);
392	MYu_ATF_CHECK_EQ(udat, 1);
393	udat = hid_get_data(unsigned_range_test_negative_one_report, &hi);
394	MYu_ATF_CHECK_EQ(udat, 254);
395	udat = hid_get_data(unsigned_range_test_maximum_report, &hi);
396	MYu_ATF_CHECK_EQ(udat, 255);
397
398	ATF_REQUIRE(hid_locate(hrd, 0xff000012U, hid_input, &hi,
399	    NO_REPORT_ID) > 0);
400	udat = hid_get_data(unsigned_range_test_minimum_report, &hi);
401	MYu_ATF_CHECK_EQ(udat, 0);
402	udat = hid_get_data(unsigned_range_test_positive_one_report, &hi);
403	MYu_ATF_CHECK_EQ(udat, 1);
404	udat = hid_get_data(unsigned_range_test_negative_one_report, &hi);
405	MYu_ATF_CHECK_EQ(udat, 65534);
406	udat = hid_get_data(unsigned_range_test_maximum_report, &hi);
407	MYu_ATF_CHECK_EQ(udat, 65535);
408
409	ATF_REQUIRE(hid_locate(hrd, 0xff000013U, hid_input, &hi,
410	    NO_REPORT_ID) > 0);
411	udat = hid_get_data(unsigned_range_test_minimum_report, &hi);
412	MYu_ATF_CHECK_EQ(udat, 0);
413	udat = hid_get_data(unsigned_range_test_positive_one_report, &hi);
414	MYu_ATF_CHECK_EQ(udat, 1);
415	udat = hid_get_data(unsigned_range_test_negative_one_report, &hi);
416	MYu_ATF_CHECK_EQ(udat, 4294967294);
417	udat = hid_get_data(unsigned_range_test_maximum_report, &hi);
418	MYu_ATF_CHECK_EQ(udat, 4294967295);
419
420	hid_dispose_report_desc(hrd);
421	hrd = NULL;
422}
423
424ATF_TC_HEAD(check_hid_set_data, tc)
425{
426
427	atf_tc_set_md_var(tc, "descr", "Test hid_set_data results");
428}
429
430ATF_TC_BODY(check_hid_set_data, tc)
431{
432	report_desc_t hrd;
433	hid_item_t hi;
434	uint8_t test_data_minimum[7];
435	uint8_t test_data_negative_one[7];
436	uint8_t test_data_positive_one[7];
437	uint8_t test_data_maximum[7];
438
439	ATF_REQUIRE((hrd = hid_use_report_desc(
440	    range_test_report_descriptor,
441	    __arraycount(range_test_report_descriptor))) != NULL);
442	ATF_REQUIRE(hid_locate(hrd, 0xff000001U, hid_input, &hi,
443	    NO_REPORT_ID) > 0);
444	hid_set_data(test_data_minimum, &hi, -128);
445	hid_set_data(test_data_negative_one, &hi, -1);
446	hid_set_data(test_data_positive_one, &hi, 1);
447	hid_set_data(test_data_maximum, &hi, 127);
448	ATF_REQUIRE(hid_locate(hrd, 0xff000002U, hid_input, &hi,
449	    NO_REPORT_ID) > 0);
450	hid_set_data(test_data_minimum, &hi, -32768);
451	hid_set_data(test_data_negative_one, &hi, -1);
452	hid_set_data(test_data_positive_one, &hi, 1);
453	hid_set_data(test_data_maximum, &hi, 32767);
454	ATF_REQUIRE(hid_locate(hrd, 0xff000003U, hid_input, &hi,
455	    NO_REPORT_ID) > 0);
456	hid_set_data(test_data_minimum, &hi, -2147483648);
457	hid_set_data(test_data_negative_one, &hi, -1);
458	hid_set_data(test_data_positive_one, &hi, 1);
459	hid_set_data(test_data_maximum, &hi, 2147483647);
460	ATF_CHECK(memcmp(test_data_minimum, range_test_minimum_report,
461	    sizeof test_data_minimum) == 0);
462	ATF_CHECK(memcmp(test_data_negative_one,
463	    range_test_negative_one_report,
464	    sizeof test_data_negative_one) == 0);
465	ATF_CHECK(memcmp(test_data_positive_one,
466	    range_test_positive_one_report,
467	    sizeof test_data_positive_one) == 0);
468	ATF_CHECK(memcmp(test_data_maximum, range_test_maximum_report,
469	    sizeof test_data_maximum) == 0);
470
471	hid_dispose_report_desc(hrd);
472	hrd = NULL;
473
474	ATF_REQUIRE((hrd = hid_use_report_desc(
475	    unsigned_range_test_report_descriptor,
476	    __arraycount(range_test_report_descriptor))) != NULL);
477	ATF_REQUIRE(hid_locate(hrd, 0xff000011U, hid_input, &hi,
478	    NO_REPORT_ID) > 0);
479	hid_set_data(test_data_minimum, &hi, 0);
480	hid_set_data(test_data_positive_one, &hi, 1);
481	hid_set_data(test_data_negative_one, &hi, 0xfffffffe);
482	hid_set_data(test_data_maximum, &hi, 0xffffffff);
483	ATF_REQUIRE(hid_locate(hrd, 0xff000012U, hid_input, &hi,
484	    NO_REPORT_ID) > 0);
485	hid_set_data(test_data_minimum, &hi, 0);
486	hid_set_data(test_data_positive_one, &hi, 1);
487	hid_set_data(test_data_negative_one, &hi, 0xfffe);
488	hid_set_data(test_data_maximum, &hi, 0xffff);
489	ATF_REQUIRE(hid_locate(hrd, 0xff000013U, hid_input, &hi,
490	    NO_REPORT_ID) > 0);
491	hid_set_data(test_data_minimum, &hi, 0);
492	hid_set_data(test_data_positive_one, &hi, 1);
493	hid_set_data(test_data_negative_one, &hi, 0xfffffffe);
494	hid_set_data(test_data_maximum, &hi, 0xffffffff);
495	ATF_CHECK(memcmp(test_data_minimum,
496	    unsigned_range_test_minimum_report,
497	    sizeof test_data_minimum) == 0);
498	ATF_CHECK(memcmp(test_data_negative_one,
499	    unsigned_range_test_negative_one_report,
500	    sizeof test_data_negative_one) == 0);
501	ATF_CHECK(memcmp(test_data_positive_one,
502	    unsigned_range_test_positive_one_report,
503	    sizeof test_data_positive_one) == 0);
504	ATF_CHECK(memcmp(test_data_maximum,
505	    unsigned_range_test_maximum_report,
506	    sizeof test_data_maximum) == 0);
507
508	hid_dispose_report_desc(hrd);
509	hrd = NULL;
510}
511
512ATF_TP_ADD_TCS(tp)
513{
514
515	ATF_TP_ADD_TC(tp, check_hid_logical_range);
516	ATF_TP_ADD_TC(tp, check_hid_physical_range);
517	ATF_TP_ADD_TC(tp, check_hid_usage);
518	ATF_TP_ADD_TC(tp, check_hid_get_data);
519	ATF_TP_ADD_TC(tp, check_hid_set_data);
520
521	return atf_no_error();
522}
523