t_usbhid.c revision 1.6
1/* $NetBSD: t_usbhid.c,v 1.6 2016/01/02 01:24:44 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.6 2016/01/02 01:24:44 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 161#define MYx_ATF_CHECK_EQ(d, v) \ 162 ATF_CHECK_EQ_MSG(d, v, "== %x", (d)) 163 164ATF_TC_BODY(check_hid_usage, tc) 165{ 166 char usages_path[PATH_MAX]; 167 168 (void)strlcpy(usages_path, atf_tc_get_config_var(tc, "srcdir"), 169 sizeof(usages_path)); 170 (void)strlcat(usages_path, "/test_usb_hid_usages", 171 sizeof(usages_path)); 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 MYx_ATF_CHECK_EQ((uint32_t)hid_parse_usage_in_page("0xff2a:0xff1b"), 202 0xff2aff1b); 203} 204 205#define MYd_ATF_CHECK_EQ(d, v) \ 206 ATF_CHECK_EQ_MSG(d, v, "== %d", (d)) 207 208#define MYu_ATF_CHECK_EQ(d, v) \ 209 ATF_CHECK_EQ_MSG(d, v, "== %u", (d)) 210 211ATF_TC_HEAD(check_hid_logical_range, tc) 212{ 213 214 atf_tc_set_md_var(tc, "descr", "Test hid_get_item " 215 "Logical Minimum/Maximum results"); 216} 217 218ATF_TC_BODY(check_hid_logical_range, tc) 219{ 220 report_desc_t hrd; 221 hid_item_t hi; 222 uint32_t minimum, maximum; 223 224 atf_tc_expect_fail("only the 32-bit opcode works, " 225 "8 and 16-bit is broken"); 226 227 ATF_REQUIRE((hrd = hid_use_report_desc(range_test_report_descriptor, 228 __arraycount(range_test_report_descriptor))) != NULL); 229 ATF_REQUIRE(hid_locate(hrd, 0xff000001U, hid_input, &hi, 230 NO_REPORT_ID) > 0); 231 MYd_ATF_CHECK_EQ(hi.logical_minimum, -128); 232 MYd_ATF_CHECK_EQ(hi.logical_maximum, 127); 233 ATF_REQUIRE(hid_locate(hrd, 0xff000002U, hid_input, &hi, 234 NO_REPORT_ID) > 0); 235 MYd_ATF_CHECK_EQ(hi.logical_minimum, -32768); 236 MYd_ATF_CHECK_EQ(hi.logical_maximum, 32767); 237 ATF_REQUIRE(hid_locate(hrd, 0xff000003U, hid_input, &hi, 238 NO_REPORT_ID) > 0); 239 MYd_ATF_CHECK_EQ(hi.logical_minimum, -2147483648); 240 MYd_ATF_CHECK_EQ(hi.logical_maximum, 2147483647); 241 242 hid_dispose_report_desc(hrd); 243 hrd = NULL; 244 245 ATF_REQUIRE((hrd = hid_use_report_desc( 246 unsigned_range_test_report_descriptor, 247 __arraycount(unsigned_range_test_report_descriptor))) != NULL); 248 ATF_REQUIRE(hid_locate(hrd, 0xff000011U, hid_input, &hi, 249 NO_REPORT_ID) > 0); 250 ATF_CHECK(hi.logical_minimum > hi.logical_maximum); 251 minimum = (uint32_t)hi.logical_minimum & ((1ULL<<hi.report_size)-1); 252 MYu_ATF_CHECK_EQ(minimum, 0); 253 maximum = (uint32_t)hi.logical_maximum & ((1ULL<<hi.report_size)-1); 254 MYu_ATF_CHECK_EQ(maximum, 255); 255 ATF_REQUIRE(hid_locate(hrd, 0xff000012U, hid_input, &hi, 256 NO_REPORT_ID) > 0); 257 ATF_CHECK(hi.logical_minimum > hi.logical_maximum); 258 minimum = hi.logical_minimum & ((1ULL<<hi.report_size)-1); 259 MYu_ATF_CHECK_EQ(minimum, 0); 260 maximum = hi.logical_maximum & ((1ULL<<hi.report_size)-1); 261 MYu_ATF_CHECK_EQ(maximum, 65535); 262 ATF_REQUIRE(hid_locate(hrd, 0xff000013U, hid_input, &hi, 263 NO_REPORT_ID) > 0); 264 ATF_CHECK(hi.logical_minimum > hi.logical_maximum); 265 minimum = hi.logical_minimum & ((1ULL<<hi.report_size)-1); 266 MYu_ATF_CHECK_EQ(minimum, 0); 267 maximum = hi.logical_maximum & ((1ULL<<hi.report_size)-1); 268 MYu_ATF_CHECK_EQ(maximum, 4294967295); 269 270 hid_dispose_report_desc(hrd); 271 hrd = NULL; 272} 273 274ATF_TC_HEAD(check_hid_physical_range, tc) 275{ 276 277 atf_tc_set_md_var(tc, "descr", "Test hid_get_item " 278 "Physical Minimum/Maximum results"); 279} 280 281ATF_TC_BODY(check_hid_physical_range, tc) 282{ 283 report_desc_t hrd; 284 hid_item_t hi; 285 uint32_t minimum, maximum; 286 287 atf_tc_expect_fail("only the 32-bit opcode works, " 288 "8 and 16-bit is broken"); 289 290 ATF_REQUIRE((hrd = hid_use_report_desc(range_test_report_descriptor, 291 __arraycount(range_test_report_descriptor))) != NULL); 292 ATF_REQUIRE(hid_locate(hrd, 0xff000001U, hid_input, &hi, 293 NO_REPORT_ID) > 0); 294 MYd_ATF_CHECK_EQ(hi.physical_minimum, -128); 295 MYd_ATF_CHECK_EQ(hi.physical_maximum, 127); 296 ATF_REQUIRE(hid_locate(hrd, 0xff000002U, hid_input, &hi, 297 NO_REPORT_ID) > 0); 298 MYd_ATF_CHECK_EQ(hi.physical_minimum, -32768); 299 MYd_ATF_CHECK_EQ(hi.physical_maximum, 32767); 300 ATF_REQUIRE(hid_locate(hrd, 0xff000003U, hid_input, &hi, 301 NO_REPORT_ID) > 0); 302 MYd_ATF_CHECK_EQ(hi.physical_minimum, -2147483648); 303 MYd_ATF_CHECK_EQ(hi.physical_maximum, 2147483647); 304 305 hid_dispose_report_desc(hrd); 306 hrd = NULL; 307 308 ATF_REQUIRE((hrd = hid_use_report_desc( 309 unsigned_range_test_report_descriptor, 310 __arraycount(unsigned_range_test_report_descriptor))) != NULL); 311 ATF_REQUIRE(hid_locate(hrd, 0xff000011U, hid_input, &hi, 312 NO_REPORT_ID) > 0); 313 ATF_CHECK(hi.physical_minimum > hi.physical_maximum); 314 minimum = (uint32_t)hi.physical_minimum & ((1ULL<<hi.report_size)-1); 315 MYu_ATF_CHECK_EQ(minimum, 0); 316 maximum = (uint32_t)hi.physical_maximum & ((1ULL<<hi.report_size)-1); 317 MYu_ATF_CHECK_EQ(maximum, 255); 318 ATF_REQUIRE(hid_locate(hrd, 0xff000012U, hid_input, &hi, 319 NO_REPORT_ID) > 0); 320 ATF_CHECK(hi.physical_minimum > hi.physical_maximum); 321 minimum = hi.physical_minimum & ((1ULL<<hi.report_size)-1); 322 MYu_ATF_CHECK_EQ(minimum, 0); 323 maximum = hi.physical_maximum & ((1ULL<<hi.report_size)-1); 324 MYu_ATF_CHECK_EQ(maximum, 65535); 325 ATF_REQUIRE(hid_locate(hrd, 0xff000013U, hid_input, &hi, 326 NO_REPORT_ID) > 0); 327 ATF_CHECK(hi.physical_minimum > hi.physical_maximum); 328 minimum = hi.physical_minimum & ((1ULL<<hi.report_size)-1); 329 MYu_ATF_CHECK_EQ(minimum, 0); 330 maximum = hi.physical_maximum & ((1ULL<<hi.report_size)-1); 331 MYu_ATF_CHECK_EQ(maximum, 4294967295); 332 333 hid_dispose_report_desc(hrd); 334 hrd = NULL; 335} 336 337ATF_TC_HEAD(check_hid_get_data, tc) 338{ 339 340 atf_tc_set_md_var(tc, "descr", "Test hid_get_data results"); 341} 342 343ATF_TC_BODY(check_hid_get_data, tc) 344{ 345 report_desc_t hrd; 346 hid_item_t hi; 347 int32_t data; 348 uint32_t udat; 349 350 ATF_REQUIRE((hrd = hid_use_report_desc( 351 range_test_report_descriptor, 352 __arraycount(range_test_report_descriptor))) != NULL); 353 354 ATF_REQUIRE(hid_locate(hrd, 0xff000001U, hid_input, &hi, 355 NO_REPORT_ID) > 0); 356 data = hid_get_data(range_test_minimum_report, &hi); 357 MYd_ATF_CHECK_EQ(data, -128); 358 data = hid_get_data(range_test_negative_one_report, &hi); 359 MYd_ATF_CHECK_EQ(data, -1); 360 data = hid_get_data(range_test_positive_one_report, &hi); 361 MYd_ATF_CHECK_EQ(data, 1); 362 data = hid_get_data(range_test_maximum_report, &hi); 363 MYd_ATF_CHECK_EQ(data, 127); 364 365 ATF_REQUIRE(hid_locate(hrd, 0xff000002U, hid_input, &hi, 366 NO_REPORT_ID) > 0); 367 data = hid_get_data(range_test_minimum_report, &hi); 368 MYd_ATF_CHECK_EQ(data, -32768); 369 data = hid_get_data(range_test_negative_one_report, &hi); 370 MYd_ATF_CHECK_EQ(data, -1); 371 data = hid_get_data(range_test_positive_one_report, &hi); 372 MYd_ATF_CHECK_EQ(data, 1); 373 data = hid_get_data(range_test_maximum_report, &hi); 374 MYd_ATF_CHECK_EQ(data, 32767); 375 376 ATF_REQUIRE(hid_locate(hrd, 0xff000003U, hid_input, &hi, 377 NO_REPORT_ID) > 0); 378 data = hid_get_data(range_test_minimum_report, &hi); 379 MYd_ATF_CHECK_EQ(data, -2147483648); 380 data = hid_get_data(range_test_negative_one_report, &hi); 381 MYd_ATF_CHECK_EQ(data, -1); 382 data = hid_get_data(range_test_positive_one_report, &hi); 383 MYd_ATF_CHECK_EQ(data, 1); 384 data = hid_get_data(range_test_maximum_report, &hi); 385 MYd_ATF_CHECK_EQ(data, 2147483647); 386 387 hid_dispose_report_desc(hrd); 388 hrd = NULL; 389 390 ATF_REQUIRE((hrd = hid_use_report_desc( 391 unsigned_range_test_report_descriptor, 392 __arraycount(unsigned_range_test_report_descriptor))) != NULL); 393 ATF_REQUIRE(hid_locate(hrd, 0xff000011U, hid_input, &hi, 394 NO_REPORT_ID) > 0); 395 udat = hid_get_data(unsigned_range_test_minimum_report, &hi); 396 MYu_ATF_CHECK_EQ(udat, 0); 397 udat = hid_get_data(unsigned_range_test_positive_one_report, &hi); 398 MYu_ATF_CHECK_EQ(udat, 1); 399 udat = hid_get_data(unsigned_range_test_negative_one_report, &hi); 400 MYu_ATF_CHECK_EQ(udat, 254); 401 udat = hid_get_data(unsigned_range_test_maximum_report, &hi); 402 MYu_ATF_CHECK_EQ(udat, 255); 403 404 ATF_REQUIRE(hid_locate(hrd, 0xff000012U, hid_input, &hi, 405 NO_REPORT_ID) > 0); 406 udat = hid_get_data(unsigned_range_test_minimum_report, &hi); 407 MYu_ATF_CHECK_EQ(udat, 0); 408 udat = hid_get_data(unsigned_range_test_positive_one_report, &hi); 409 MYu_ATF_CHECK_EQ(udat, 1); 410 udat = hid_get_data(unsigned_range_test_negative_one_report, &hi); 411 MYu_ATF_CHECK_EQ(udat, 65534); 412 udat = hid_get_data(unsigned_range_test_maximum_report, &hi); 413 MYu_ATF_CHECK_EQ(udat, 65535); 414 415 ATF_REQUIRE(hid_locate(hrd, 0xff000013U, hid_input, &hi, 416 NO_REPORT_ID) > 0); 417 udat = hid_get_data(unsigned_range_test_minimum_report, &hi); 418 MYu_ATF_CHECK_EQ(udat, 0); 419 udat = hid_get_data(unsigned_range_test_positive_one_report, &hi); 420 MYu_ATF_CHECK_EQ(udat, 1); 421 udat = hid_get_data(unsigned_range_test_negative_one_report, &hi); 422 MYu_ATF_CHECK_EQ(udat, 4294967294); 423 udat = hid_get_data(unsigned_range_test_maximum_report, &hi); 424 MYu_ATF_CHECK_EQ(udat, 4294967295); 425 426 hid_dispose_report_desc(hrd); 427 hrd = NULL; 428} 429 430ATF_TC_HEAD(check_hid_set_data, tc) 431{ 432 433 atf_tc_set_md_var(tc, "descr", "Test hid_set_data results"); 434} 435 436ATF_TC_BODY(check_hid_set_data, tc) 437{ 438 report_desc_t hrd; 439 hid_item_t hi; 440 uint8_t test_data_minimum[7]; 441 uint8_t test_data_negative_one[7]; 442 uint8_t test_data_positive_one[7]; 443 uint8_t test_data_maximum[7]; 444 445 ATF_REQUIRE((hrd = hid_use_report_desc( 446 range_test_report_descriptor, 447 __arraycount(range_test_report_descriptor))) != NULL); 448 ATF_REQUIRE(hid_locate(hrd, 0xff000001U, hid_input, &hi, 449 NO_REPORT_ID) > 0); 450 hid_set_data(test_data_minimum, &hi, -128); 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, 127); 454 ATF_REQUIRE(hid_locate(hrd, 0xff000002U, hid_input, &hi, 455 NO_REPORT_ID) > 0); 456 hid_set_data(test_data_minimum, &hi, -32768); 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, 32767); 460 ATF_REQUIRE(hid_locate(hrd, 0xff000003U, hid_input, &hi, 461 NO_REPORT_ID) > 0); 462 hid_set_data(test_data_minimum, &hi, -2147483648); 463 hid_set_data(test_data_negative_one, &hi, -1); 464 hid_set_data(test_data_positive_one, &hi, 1); 465 hid_set_data(test_data_maximum, &hi, 2147483647); 466 ATF_CHECK(memcmp(test_data_minimum, range_test_minimum_report, 467 sizeof test_data_minimum) == 0); 468 ATF_CHECK(memcmp(test_data_negative_one, 469 range_test_negative_one_report, 470 sizeof test_data_negative_one) == 0); 471 ATF_CHECK(memcmp(test_data_positive_one, 472 range_test_positive_one_report, 473 sizeof test_data_positive_one) == 0); 474 ATF_CHECK(memcmp(test_data_maximum, range_test_maximum_report, 475 sizeof test_data_maximum) == 0); 476 477 hid_dispose_report_desc(hrd); 478 hrd = NULL; 479 480 ATF_REQUIRE((hrd = hid_use_report_desc( 481 unsigned_range_test_report_descriptor, 482 __arraycount(range_test_report_descriptor))) != NULL); 483 ATF_REQUIRE(hid_locate(hrd, 0xff000011U, 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, 0xfffffffe); 488 hid_set_data(test_data_maximum, &hi, 0xffffffff); 489 ATF_REQUIRE(hid_locate(hrd, 0xff000012U, 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, 0xfffe); 494 hid_set_data(test_data_maximum, &hi, 0xffff); 495 ATF_REQUIRE(hid_locate(hrd, 0xff000013U, hid_input, &hi, 496 NO_REPORT_ID) > 0); 497 hid_set_data(test_data_minimum, &hi, 0); 498 hid_set_data(test_data_positive_one, &hi, 1); 499 hid_set_data(test_data_negative_one, &hi, 0xfffffffe); 500 hid_set_data(test_data_maximum, &hi, 0xffffffff); 501 ATF_CHECK(memcmp(test_data_minimum, 502 unsigned_range_test_minimum_report, 503 sizeof test_data_minimum) == 0); 504 ATF_CHECK(memcmp(test_data_negative_one, 505 unsigned_range_test_negative_one_report, 506 sizeof test_data_negative_one) == 0); 507 ATF_CHECK(memcmp(test_data_positive_one, 508 unsigned_range_test_positive_one_report, 509 sizeof test_data_positive_one) == 0); 510 ATF_CHECK(memcmp(test_data_maximum, 511 unsigned_range_test_maximum_report, 512 sizeof test_data_maximum) == 0); 513 514 hid_dispose_report_desc(hrd); 515 hrd = NULL; 516} 517 518ATF_TP_ADD_TCS(tp) 519{ 520 521 ATF_TP_ADD_TC(tp, check_hid_logical_range); 522 ATF_TP_ADD_TC(tp, check_hid_physical_range); 523 ATF_TP_ADD_TC(tp, check_hid_usage); 524 ATF_TP_ADD_TC(tp, check_hid_get_data); 525 ATF_TP_ADD_TC(tp, check_hid_set_data); 526 527 return atf_no_error(); 528} 529