diff options
| author | hathach <[email protected]> | 2026-03-18 00:02:47 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2026-03-18 00:02:47 +0700 |
| commit | b2a592d42a871cadca269ff496ed723daa3c51b7 (patch) | |
| tree | ee1877ddea98cfcb593d38e1b9faeece6bacf2ef /test | |
| parent | 55994bc1d5ac80ced3f7a8383e7537967a572ed2 (diff) | |
add hil test for device hid_generic_inout functionality
Diffstat (limited to 'test')
| -rwxr-xr-x | test/hil/hil_test.py | 37 | ||||
| -rw-r--r-- | test/hil/requirements.txt | 2 |
2 files changed, 39 insertions, 0 deletions
diff --git a/test/hil/hil_test.py b/test/hil/hil_test.py index 2100fb7fc..41e9fad88 100755 --- a/test/hil/hil_test.py +++ b/test/hil/hil_test.py @@ -1014,6 +1014,42 @@ def test_device_midi_test(board): assert n in note_sequence, f'Unexpected MIDI note {n}' +def test_device_hid_generic_inout(board): + uid = board['uid'] + import hid + + # Find HID device by UID (VID=0xCafe) + timeout = ENUM_TIMEOUT + dev = None + while timeout > 0: + for d in hid.enumerate(0xCafe): + if d['serial_number'] == uid: + dev = d + break + if dev: + break + time.sleep(1) + timeout -= 1 + assert dev is not None, f'HID device not found for {uid}' + + h = hid.Device(vid=dev['vendor_id'], pid=dev['product_id'], serial=uid) + + # Echo test: send random data and verify echo + for size in [8, 32, 63]: + # Report ID (0) + payload, padded to 64 bytes + payload = bytes([random.randint(1, 255) for _ in range(size)]) + report = bytes([0]) + payload + bytes(64 - size) + h.write(report) + echo = h.read(64, timeout=2000) + assert echo is not None and len(echo) >= size, ( + f'HID echo timeout or short read ({size} bytes)') + assert bytes(echo[:size]) == payload, ( + f'HID echo wrong data ({size} bytes):\n' + f' expected: {payload.hex()}\n received: {bytes(echo[:size]).hex()}') + + h.close() + + # ------------------------------------------------------------- # Main # ------------------------------------------------------------- @@ -1027,6 +1063,7 @@ device_tests = [ 'device/cdc_msc_freertos', 'device/hid_boot_interface', 'device/msc_dual_lun', + 'device/hid_generic_inout', 'device/printer_to_cdc', 'device/midi_test', 'device/mtp' diff --git a/test/hil/requirements.txt b/test/hil/requirements.txt index c33980c9d..ef2fecebe 100644 --- a/test/hil/requirements.txt +++ b/test/hil/requirements.txt @@ -1,2 +1,4 @@ fs +hid pyfatfs +pyserial |
