Skip to content

Commit 36eb700

Browse files
author
Filip Jagodzinski
committed
Tests: USBHID: Handle variable driver setup time
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.
1 parent 4f88069 commit 36eb700

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

TESTS/host_tests/usb_device_hid.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
HID_PROTOCOL_MOUSE = 2
7070

7171
# Greentea message keys used for callbacks
72-
MSG_KEY_DEVICE_READY = 'ready'
72+
MSG_KEY_DEVICE_READY = 'dev_ready'
73+
MSG_KEY_HOST_READY = 'host_ready'
7374
MSG_KEY_SERIAL_NUMBER = 'usb_dev_sn'
7475
MSG_KEY_TEST_GET_DESCRIPTOR_HID = 'test_get_desc_hid'
7576
MSG_KEY_TEST_GET_DESCRIPTOR_CFG = 'test_get_desc_cfg'
@@ -495,6 +496,8 @@ def raw_loopback(self, report_size):
495496
except RetryError as exc:
496497
self.notify_error(exc)
497498
return
499+
# Notify the device it can send reports now.
500+
self.send_kv(MSG_KEY_HOST_READY, MSG_VALUE_DUMMY)
498501
try:
499502
for _ in range(RAW_IO_REPS):
500503
# There are no Report ID tags in the Report descriptor.

TESTS/usb_device/hid/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#define MSG_VALUE_LEN 24
3939
#define MSG_KEY_LEN 24
4040
#define MSG_KEY_DEVICE_READY "ready"
41+
#define MSG_KEY_DEVICE_READY "dev_ready"
42+
#define MSG_KEY_HOST_READY "host_ready"
4143
#define MSG_KEY_SERIAL_NUMBER "usb_dev_sn"
4244
#define MSG_KEY_TEST_GET_DESCRIPTOR_HID "test_get_desc_hid"
4345
#define MSG_KEY_TEST_GET_DESCRIPTOR_CFG "test_get_desc_cfg"
@@ -307,6 +309,12 @@ void test_generic_raw_io()
307309
greentea_send_kv(MSG_KEY_TEST_RAW_IO, REPORT_SIZE);
308310
usb_hid.wait_ready();
309311

312+
// Wait for the host HID driver to complete setup.
313+
char key[MSG_KEY_LEN + 1] = { };
314+
char value[MSG_VALUE_LEN + 1] = { };
315+
greentea_parse_kv(key, value, MSG_KEY_LEN, MSG_VALUE_LEN);
316+
TEST_ASSERT_EQUAL_STRING(MSG_KEY_HOST_READY, key);
317+
310318
// Report ID omitted here. There are no Report ID tags in the Report descriptor.
311319
HID_REPORT input_report = {};
312320
HID_REPORT output_report = {};

0 commit comments

Comments
 (0)