t_usbhid.c revision 1.4 1 /* $NetBSD: t_usbhid.c,v 1.4 2016/01/01 23:46:04 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.4 2016/01/01 23:46:04 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
43 ATF_TC(check_hid_logical_range);
44 ATF_TC(check_hid_physical_range);
45 ATF_TC(check_hid_usage);
46 ATF_TC(check_hid_get_data);
47 ATF_TC(check_hid_set_data);
48
49 static 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
78 static 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
107 static const uint8_t range_test_minimum_report[7] = {
108 0x00, 0x00, 0x00, 0x80,
109 0x00, 0x80,
110 0x80,
111 };
112
113 static const uint8_t unsigned_range_test_minimum_report[7] = {
114 0x00, 0x00, 0x00, 0x00,
115 0x00, 0x00,
116 0x00,
117 };
118
119 static const uint8_t range_test_maximum_report[7] = {
120 0xff, 0xff, 0xff, 0x7f,
121 0xff, 0x7f,
122 0x7f,
123 };
124
125 static const uint8_t unsigned_range_test_maximum_report[7] = {
126 0xff, 0xff, 0xff, 0xff,
127 0xff, 0xff,
128 0xff,
129 };
130
131 static const uint8_t range_test_positive_one_report[7] = {
132 0x01, 0x00, 0x00, 0x00,
133 0x01, 0x00,
134 0x01,
135 };
136
137 static const uint8_t unsigned_range_test_positive_one_report[7] = {
138 0x01, 0x00, 0x00, 0x00,
139 0x01, 0x00,
140 0x01,
141 };
142
143 static const uint8_t range_test_negative_one_report[7] = {
144 0xff, 0xff, 0xff, 0xff,
145 0xff, 0xff,
146 0xff,
147 };
148
149 static const uint8_t unsigned_range_test_negative_one_report[7] = {
150 0xfe, 0xff, 0xff, 0xff,
151 0xfe, 0xff,
152 0xfe,
153 };
154
155 ATF_TC_HEAD(check_hid_usage, tc)
156 {
157
158 atf_tc_set_md_var(tc, "descr", "Test libusbhid usage.c");
159 }
160
161 ATF_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 atf_tc_expect_fail("hid_parse_*() fails because it doesn't use "
171 "scanf()");
172
173 hid_init(usages_path);
174
175 ATF_CHECK_STREQ("t_usbhid_page", hid_usage_page(0xff1b));
176 ATF_CHECK_EQ((uint32_t)hid_parse_usage_page("t_usbhid_page"), 0xff1b);
177
178 ATF_CHECK_STREQ("t_usbhid_usage", hid_usage_in_page(0xff1bff2a));
179 ATF_CHECK_EQ((uint32_t)hid_parse_usage_in_page(
180 "t_usbhid_page:t_usbhid_usage"), 0xff1bff2a);
181
182 ATF_CHECK_STREQ("Quick_zephyrs_blow_vexing_daft_Jim_",
183 hid_usage_page(0xff2a));
184 ATF_CHECK_EQ((uint32_t)hid_parse_usage_page(
185 "Quick_zephyrs_blow_vexing_daft_Jim_"), 0xff2a);
186
187 ATF_CHECK_STREQ("Usage_ID_Zero_%", hid_usage_in_page(0xff2a0000));
188 ATF_CHECK_EQ((uint32_t)hid_parse_usage_in_page(
189 "Quick_zephyrs_blow_vexing_daft_Jim_:Usage_ID_Zero_%"),
190 0xff2a0000);
191
192 //ATF_CHECK_STREQ("Usage_ID_0_%", hid_usage_in_page(0xff2a0000));
193 ATF_CHECK_EQ((uint32_t)hid_parse_usage_in_page(
194 "Quick_zephyrs_blow_vexing_daft_Jim_:Usage_ID_0_%"), 0xff2a0000);
195
196 ATF_CHECK_STREQ("Usage_ID_65535_%", hid_usage_in_page(0xff2affff));
197 ATF_CHECK_EQ((uint32_t)hid_parse_usage_in_page(
198 "Quick_zephyrs_blow_vexing_daft_Jim_:Usage_ID_65535_%"),
199 0xff2affff);
200 }
201
202 #define MYd_ATF_CHECK_EQ(d, v) \
203 ATF_CHECK_EQ_MSG(d, v, "== %d", (d))
204
205 #define MYu_ATF_CHECK_EQ(d, v) \
206 ATF_CHECK_EQ_MSG(d, v, "== %u", (d))
207
208 ATF_TC_HEAD(check_hid_logical_range, tc)
209 {
210
211 atf_tc_set_md_var(tc, "descr", "Test hid_get_item "
212 "Logical Minimum/Maximum results");
213 }
214
215 ATF_TC_BODY(check_hid_logical_range, tc)
216 {
217 report_desc_t hrd;
218 hid_item_t hi;
219 uint32_t minimum, maximum;
220
221 atf_tc_expect_fail("only the 32-bit opcode works, "
222 "8 and 16-bit is broken");
223
224 ATF_REQUIRE((hrd = hid_use_report_desc(range_test_report_descriptor,
225 __arraycount(range_test_report_descriptor))) != NULL);
226 ATF_REQUIRE(hid_locate(hrd, 0xff000001U, hid_input, &hi,
227 NO_REPORT_ID) > 0);
228 MYd_ATF_CHECK_EQ(hi.logical_minimum, -128);
229 MYd_ATF_CHECK_EQ(hi.logical_maximum, 127);
230 ATF_REQUIRE(hid_locate(hrd, 0xff000002U, hid_input, &hi,
231 NO_REPORT_ID) > 0);
232 MYd_ATF_CHECK_EQ(hi.logical_minimum, -32768);
233 MYd_ATF_CHECK_EQ(hi.logical_maximum, 32767);
234 ATF_REQUIRE(hid_locate(hrd, 0xff000003U, hid_input, &hi,
235 NO_REPORT_ID) > 0);
236 MYd_ATF_CHECK_EQ(hi.logical_minimum, -2147483648);
237 MYd_ATF_CHECK_EQ(hi.logical_maximum, 2147483647);
238
239 hid_dispose_report_desc(hrd);
240 hrd = NULL;
241
242 ATF_REQUIRE((hrd = hid_use_report_desc(
243 unsigned_range_test_report_descriptor,
244 __arraycount(unsigned_range_test_report_descriptor))) != NULL);
245 ATF_REQUIRE(hid_locate(hrd, 0xff000011U, hid_input, &hi,
246 NO_REPORT_ID) > 0);
247 ATF_CHECK(hi.logical_minimum > hi.logical_maximum);
248 minimum = (uint32_t)hi.logical_minimum & ((1ULL<<hi.report_size)-1);
249 MYu_ATF_CHECK_EQ(minimum, 0);
250 maximum = (uint32_t)hi.logical_maximum & ((1ULL<<hi.report_size)-1);
251 MYu_ATF_CHECK_EQ(maximum, 255);
252 ATF_REQUIRE(hid_locate(hrd, 0xff000012U, hid_input, &hi,
253 NO_REPORT_ID) > 0);
254 ATF_CHECK(hi.logical_minimum > hi.logical_maximum);
255 minimum = hi.logical_minimum & ((1ULL<<hi.report_size)-1);
256 MYu_ATF_CHECK_EQ(minimum, 0);
257 maximum = hi.logical_maximum & ((1ULL<<hi.report_size)-1);
258 MYu_ATF_CHECK_EQ(maximum, 65535);
259 ATF_REQUIRE(hid_locate(hrd, 0xff000013U, hid_input, &hi,
260 NO_REPORT_ID) > 0);
261 ATF_CHECK(hi.logical_minimum > hi.logical_maximum);
262 minimum = hi.logical_minimum & ((1ULL<<hi.report_size)-1);
263 MYu_ATF_CHECK_EQ(minimum, 0);
264 maximum = hi.logical_maximum & ((1ULL<<hi.report_size)-1);
265 MYu_ATF_CHECK_EQ(maximum, 4294967295);
266
267 hid_dispose_report_desc(hrd);
268 hrd = NULL;
269 }
270
271 ATF_TC_HEAD(check_hid_physical_range, tc)
272 {
273
274 atf_tc_set_md_var(tc, "descr", "Test hid_get_item "
275 "Physical Minimum/Maximum results");
276 }
277
278 ATF_TC_BODY(check_hid_physical_range, tc)
279 {
280 report_desc_t hrd;
281 hid_item_t hi;
282 uint32_t minimum, maximum;
283
284 atf_tc_expect_fail("only the 32-bit opcode works, "
285 "8 and 16-bit is broken");
286
287 ATF_REQUIRE((hrd = hid_use_report_desc(range_test_report_descriptor,
288 __arraycount(range_test_report_descriptor))) != NULL);
289 ATF_REQUIRE(hid_locate(hrd, 0xff000001U, hid_input, &hi,
290 NO_REPORT_ID) > 0);
291 MYd_ATF_CHECK_EQ(hi.physical_minimum, -128);
292 MYd_ATF_CHECK_EQ(hi.physical_maximum, 127);
293 ATF_REQUIRE(hid_locate(hrd, 0xff000002U, hid_input, &hi,
294 NO_REPORT_ID) > 0);
295 MYd_ATF_CHECK_EQ(hi.physical_minimum, -32768);
296 MYd_ATF_CHECK_EQ(hi.physical_maximum, 32767);
297 ATF_REQUIRE(hid_locate(hrd, 0xff000003U, hid_input, &hi,
298 NO_REPORT_ID) > 0);
299 MYd_ATF_CHECK_EQ(hi.physical_minimum, -2147483648);
300 MYd_ATF_CHECK_EQ(hi.physical_maximum, 2147483647);
301
302 hid_dispose_report_desc(hrd);
303 hrd = NULL;
304
305 ATF_REQUIRE((hrd = hid_use_report_desc(
306 unsigned_range_test_report_descriptor,
307 __arraycount(unsigned_range_test_report_descriptor))) != NULL);
308 ATF_REQUIRE(hid_locate(hrd, 0xff000011U, hid_input, &hi,
309 NO_REPORT_ID) > 0);
310 ATF_CHECK(hi.physical_minimum > hi.physical_maximum);
311 minimum = (uint32_t)hi.physical_minimum & ((1ULL<<hi.report_size)-1);
312 MYu_ATF_CHECK_EQ(minimum, 0);
313 maximum = (uint32_t)hi.physical_maximum & ((1ULL<<hi.report_size)-1);
314 MYu_ATF_CHECK_EQ(maximum, 255);
315 ATF_REQUIRE(hid_locate(hrd, 0xff000012U, hid_input, &hi,
316 NO_REPORT_ID) > 0);
317 ATF_CHECK(hi.physical_minimum > hi.physical_maximum);
318 minimum = hi.physical_minimum & ((1ULL<<hi.report_size)-1);
319 MYu_ATF_CHECK_EQ(minimum, 0);
320 maximum = hi.physical_maximum & ((1ULL<<hi.report_size)-1);
321 MYu_ATF_CHECK_EQ(maximum, 65535);
322 ATF_REQUIRE(hid_locate(hrd, 0xff000013U, hid_input, &hi,
323 NO_REPORT_ID) > 0);
324 ATF_CHECK(hi.physical_minimum > hi.physical_maximum);
325 minimum = hi.physical_minimum & ((1ULL<<hi.report_size)-1);
326 MYu_ATF_CHECK_EQ(minimum, 0);
327 maximum = hi.physical_maximum & ((1ULL<<hi.report_size)-1);
328 MYu_ATF_CHECK_EQ(maximum, 4294967295);
329
330 hid_dispose_report_desc(hrd);
331 hrd = NULL;
332 }
333
334 ATF_TC_HEAD(check_hid_get_data, tc)
335 {
336
337 atf_tc_set_md_var(tc, "descr", "Test hid_get_data results");
338 }
339
340 ATF_TC_BODY(check_hid_get_data, tc)
341 {
342 report_desc_t hrd;
343 hid_item_t hi;
344 int32_t data;
345 uint32_t udat;
346
347 ATF_REQUIRE((hrd = hid_use_report_desc(
348 range_test_report_descriptor,
349 __arraycount(range_test_report_descriptor))) != NULL);
350
351 ATF_REQUIRE(hid_locate(hrd, 0xff000001U, hid_input, &hi,
352 NO_REPORT_ID) > 0);
353 data = hid_get_data(range_test_minimum_report, &hi);
354 MYd_ATF_CHECK_EQ(data, -128);
355 data = hid_get_data(range_test_negative_one_report, &hi);
356 MYd_ATF_CHECK_EQ(data, -1);
357 data = hid_get_data(range_test_positive_one_report, &hi);
358 MYd_ATF_CHECK_EQ(data, 1);
359 data = hid_get_data(range_test_maximum_report, &hi);
360 MYd_ATF_CHECK_EQ(data, 127);
361
362 ATF_REQUIRE(hid_locate(hrd, 0xff000002U, hid_input, &hi,
363 NO_REPORT_ID) > 0);
364 data = hid_get_data(range_test_minimum_report, &hi);
365 MYd_ATF_CHECK_EQ(data, -32768);
366 data = hid_get_data(range_test_negative_one_report, &hi);
367 MYd_ATF_CHECK_EQ(data, -1);
368 data = hid_get_data(range_test_positive_one_report, &hi);
369 MYd_ATF_CHECK_EQ(data, 1);
370 data = hid_get_data(range_test_maximum_report, &hi);
371 MYd_ATF_CHECK_EQ(data, 32767);
372
373 ATF_REQUIRE(hid_locate(hrd, 0xff000003U, hid_input, &hi,
374 NO_REPORT_ID) > 0);
375 data = hid_get_data(range_test_minimum_report, &hi);
376 MYd_ATF_CHECK_EQ(data, -2147483648);
377 data = hid_get_data(range_test_negative_one_report, &hi);
378 MYd_ATF_CHECK_EQ(data, -1);
379 data = hid_get_data(range_test_positive_one_report, &hi);
380 MYd_ATF_CHECK_EQ(data, 1);
381 data = hid_get_data(range_test_maximum_report, &hi);
382 MYd_ATF_CHECK_EQ(data, 2147483647);
383
384 hid_dispose_report_desc(hrd);
385 hrd = NULL;
386
387 ATF_REQUIRE((hrd = hid_use_report_desc(
388 unsigned_range_test_report_descriptor,
389 __arraycount(unsigned_range_test_report_descriptor))) != NULL);
390 ATF_REQUIRE(hid_locate(hrd, 0xff000011U, hid_input, &hi,
391 NO_REPORT_ID) > 0);
392 udat = hid_get_data(unsigned_range_test_minimum_report, &hi);
393 MYu_ATF_CHECK_EQ(udat, 0);
394 udat = hid_get_data(unsigned_range_test_positive_one_report, &hi);
395 MYu_ATF_CHECK_EQ(udat, 1);
396 udat = hid_get_data(unsigned_range_test_negative_one_report, &hi);
397 MYu_ATF_CHECK_EQ(udat, 254);
398 udat = hid_get_data(unsigned_range_test_maximum_report, &hi);
399 MYu_ATF_CHECK_EQ(udat, 255);
400
401 ATF_REQUIRE(hid_locate(hrd, 0xff000012U, hid_input, &hi,
402 NO_REPORT_ID) > 0);
403 udat = hid_get_data(unsigned_range_test_minimum_report, &hi);
404 MYu_ATF_CHECK_EQ(udat, 0);
405 udat = hid_get_data(unsigned_range_test_positive_one_report, &hi);
406 MYu_ATF_CHECK_EQ(udat, 1);
407 udat = hid_get_data(unsigned_range_test_negative_one_report, &hi);
408 MYu_ATF_CHECK_EQ(udat, 65534);
409 udat = hid_get_data(unsigned_range_test_maximum_report, &hi);
410 MYu_ATF_CHECK_EQ(udat, 65535);
411
412 ATF_REQUIRE(hid_locate(hrd, 0xff000013U, hid_input, &hi,
413 NO_REPORT_ID) > 0);
414 udat = hid_get_data(unsigned_range_test_minimum_report, &hi);
415 MYu_ATF_CHECK_EQ(udat, 0);
416 udat = hid_get_data(unsigned_range_test_positive_one_report, &hi);
417 MYu_ATF_CHECK_EQ(udat, 1);
418 udat = hid_get_data(unsigned_range_test_negative_one_report, &hi);
419 MYu_ATF_CHECK_EQ(udat, 4294967294);
420 udat = hid_get_data(unsigned_range_test_maximum_report, &hi);
421 MYu_ATF_CHECK_EQ(udat, 4294967295);
422
423 hid_dispose_report_desc(hrd);
424 hrd = NULL;
425 }
426
427 ATF_TC_HEAD(check_hid_set_data, tc)
428 {
429
430 atf_tc_set_md_var(tc, "descr", "Test hid_set_data results");
431 }
432
433 ATF_TC_BODY(check_hid_set_data, tc)
434 {
435 report_desc_t hrd;
436 hid_item_t hi;
437 uint8_t test_data_minimum[7];
438 uint8_t test_data_negative_one[7];
439 uint8_t test_data_positive_one[7];
440 uint8_t test_data_maximum[7];
441
442 ATF_REQUIRE((hrd = hid_use_report_desc(
443 range_test_report_descriptor,
444 __arraycount(range_test_report_descriptor))) != NULL);
445 ATF_REQUIRE(hid_locate(hrd, 0xff000001U, hid_input, &hi,
446 NO_REPORT_ID) > 0);
447 hid_set_data(test_data_minimum, &hi, -128);
448 hid_set_data(test_data_negative_one, &hi, -1);
449 hid_set_data(test_data_positive_one, &hi, 1);
450 hid_set_data(test_data_maximum, &hi, 127);
451 ATF_REQUIRE(hid_locate(hrd, 0xff000002U, hid_input, &hi,
452 NO_REPORT_ID) > 0);
453 hid_set_data(test_data_minimum, &hi, -32768);
454 hid_set_data(test_data_negative_one, &hi, -1);
455 hid_set_data(test_data_positive_one, &hi, 1);
456 hid_set_data(test_data_maximum, &hi, 32767);
457 ATF_REQUIRE(hid_locate(hrd, 0xff000003U, hid_input, &hi,
458 NO_REPORT_ID) > 0);
459 hid_set_data(test_data_minimum, &hi, -2147483648);
460 hid_set_data(test_data_negative_one, &hi, -1);
461 hid_set_data(test_data_positive_one, &hi, 1);
462 hid_set_data(test_data_maximum, &hi, 2147483647);
463 ATF_CHECK(memcmp(test_data_minimum, range_test_minimum_report,
464 sizeof test_data_minimum) == 0);
465 ATF_CHECK(memcmp(test_data_negative_one,
466 range_test_negative_one_report,
467 sizeof test_data_negative_one) == 0);
468 ATF_CHECK(memcmp(test_data_positive_one,
469 range_test_positive_one_report,
470 sizeof test_data_positive_one) == 0);
471 ATF_CHECK(memcmp(test_data_maximum, range_test_maximum_report,
472 sizeof test_data_maximum) == 0);
473
474 hid_dispose_report_desc(hrd);
475 hrd = NULL;
476
477 ATF_REQUIRE((hrd = hid_use_report_desc(
478 unsigned_range_test_report_descriptor,
479 __arraycount(range_test_report_descriptor))) != NULL);
480 ATF_REQUIRE(hid_locate(hrd, 0xff000011U, hid_input, &hi,
481 NO_REPORT_ID) > 0);
482 hid_set_data(test_data_minimum, &hi, 0);
483 hid_set_data(test_data_positive_one, &hi, 1);
484 hid_set_data(test_data_negative_one, &hi, 0xfffffffe);
485 hid_set_data(test_data_maximum, &hi, 0xffffffff);
486 ATF_REQUIRE(hid_locate(hrd, 0xff000012U, hid_input, &hi,
487 NO_REPORT_ID) > 0);
488 hid_set_data(test_data_minimum, &hi, 0);
489 hid_set_data(test_data_positive_one, &hi, 1);
490 hid_set_data(test_data_negative_one, &hi, 0xfffe);
491 hid_set_data(test_data_maximum, &hi, 0xffff);
492 ATF_REQUIRE(hid_locate(hrd, 0xff000013U, hid_input, &hi,
493 NO_REPORT_ID) > 0);
494 hid_set_data(test_data_minimum, &hi, 0);
495 hid_set_data(test_data_positive_one, &hi, 1);
496 hid_set_data(test_data_negative_one, &hi, 0xfffffffe);
497 hid_set_data(test_data_maximum, &hi, 0xffffffff);
498 ATF_CHECK(memcmp(test_data_minimum,
499 unsigned_range_test_minimum_report,
500 sizeof test_data_minimum) == 0);
501 ATF_CHECK(memcmp(test_data_negative_one,
502 unsigned_range_test_negative_one_report,
503 sizeof test_data_negative_one) == 0);
504 ATF_CHECK(memcmp(test_data_positive_one,
505 unsigned_range_test_positive_one_report,
506 sizeof test_data_positive_one) == 0);
507 ATF_CHECK(memcmp(test_data_maximum,
508 unsigned_range_test_maximum_report,
509 sizeof test_data_maximum) == 0);
510
511 hid_dispose_report_desc(hrd);
512 hrd = NULL;
513 }
514
515 ATF_TP_ADD_TCS(tp)
516 {
517
518 ATF_TP_ADD_TC(tp, check_hid_logical_range);
519 ATF_TP_ADD_TC(tp, check_hid_physical_range);
520 ATF_TP_ADD_TC(tp, check_hid_usage);
521 ATF_TP_ADD_TC(tp, check_hid_get_data);
522 ATF_TP_ADD_TC(tp, check_hid_set_data);
523
524 return atf_no_error();
525 }
526