Skip to content

Commit

Permalink
Tests: USBHID: Handle variable driver setup time
Browse files Browse the repository at this point in the history
Wait for the host driver to finish setup before sending any HID reports
from the device.

USBHID::wait_ready() blocks until the device reaches 'configured' state,
but the state of the host HID driver remains unknown to the device.
  • Loading branch information
Filip Jagodzinski committed Mar 22, 2019
1 parent cd703e3 commit 8c6f63e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion TESTS/host_tests/usb_device_hid.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
HID_PROTOCOL_MOUSE = 2

# Greentea message keys used for callbacks
MSG_KEY_DEVICE_READY = 'ready'
MSG_KEY_DEVICE_READY = 'dev_ready'
MSG_KEY_HOST_READY = 'host_ready'
MSG_KEY_SERIAL_NUMBER = 'usb_dev_sn'
MSG_KEY_TEST_GET_DESCRIPTOR_HID = 'test_get_desc_hid'
MSG_KEY_TEST_GET_DESCRIPTOR_CFG = 'test_get_desc_cfg'
Expand Down Expand Up @@ -495,6 +496,8 @@ def raw_loopback(self, report_size):
except RetryError as exc:
self.notify_error(exc)
return
# Notify the device it can send reports now.
self.send_kv(MSG_KEY_HOST_READY, MSG_VALUE_DUMMY)
try:
for _ in range(RAW_IO_REPS):
# There are no Report ID tags in the Report descriptor.
Expand Down
8 changes: 8 additions & 0 deletions TESTS/usb_device/hid/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#define MSG_VALUE_LEN 24
#define MSG_KEY_LEN 24
#define MSG_KEY_DEVICE_READY "ready"
#define MSG_KEY_DEVICE_READY "dev_ready"
#define MSG_KEY_HOST_READY "host_ready"
#define MSG_KEY_SERIAL_NUMBER "usb_dev_sn"
#define MSG_KEY_TEST_GET_DESCRIPTOR_HID "test_get_desc_hid"
#define MSG_KEY_TEST_GET_DESCRIPTOR_CFG "test_get_desc_cfg"
Expand Down Expand Up @@ -307,6 +309,12 @@ void test_generic_raw_io()
greentea_send_kv(MSG_KEY_TEST_RAW_IO, REPORT_SIZE);
usb_hid.wait_ready();

// Wait for the host HID driver to complete setup.
char key[MSG_KEY_LEN + 1] = { };
char value[MSG_VALUE_LEN + 1] = { };
greentea_parse_kv(key, value, MSG_KEY_LEN, MSG_VALUE_LEN);
TEST_ASSERT_EQUAL_STRING(MSG_KEY_HOST_READY, key);

// Report ID omitted here. There are no Report ID tags in the Report descriptor.
HID_REPORT input_report = {};
HID_REPORT output_report = {};
Expand Down

0 comments on commit 8c6f63e

Please sign in to comment.