fix(usb): Make string descriptor checks in unit tests optional

Checking for an exact match for product or serial and string descriptors can
lead to test failures if the USB devices connected to the runner is changed. This
commit adds some kconfig options to make the string descriptor checks optional,
with the product and serial string checks being disabled by default.
This commit is contained in:
Darian Leung 2024-05-30 19:25:18 +08:00
parent 1572df3bb8
commit 4954884527
No known key found for this signature in database
GPG Key ID: 8AC9127B487AA4EF
2 changed files with 36 additions and 5 deletions

View File

@ -0,0 +1,24 @@
menu "USB Host Library Test"
config USB_HOST_TEST_CHECK_MANU_STR
bool "Check manufacturer string descriptor"
default y
help
USB Host tests that check string descriptors will check the manufacturer string
descriptor of the connected device.
config USB_HOST_TEST_CHECK_PROD_STR
bool "Check product string descriptor"
default n
help
USB Host tests that check string descriptors will check the product string descriptor
of the connected device.
config USB_HOST_TEST_CHECK_SERIAL_STR
bool "Check serial string descriptor"
default n
help
USB Host tests that check string descriptors will check the serial string descriptor
of the connected device.
endmenu

View File

@ -146,19 +146,26 @@ void msc_client_async_enum_task(void *arg)
break;
}
case TEST_STAGE_CHECK_STR_DESC: {
// Get dev info and compare
usb_device_info_t dev_info;
TEST_ASSERT_EQUAL(ESP_OK, usb_host_device_info(msc_obj.dev_hdl, &dev_info));
#if CONFIG_USB_HOST_TEST_CHECK_MANU_STR
// Check manufacturer string descriptors
const usb_str_desc_t *manu_str_desc_ref = dev_msc_get_str_desc_manu();
const usb_str_desc_t *product_str_desc_ref = dev_msc_get_str_desc_prod();
const usb_str_desc_t *ser_num_str_desc_ref = dev_msc_get_str_desc_ser();
TEST_ASSERT_EQUAL(manu_str_desc_ref->bLength, dev_info.str_desc_manufacturer->bLength);
TEST_ASSERT_EQUAL(product_str_desc_ref->bLength, dev_info.str_desc_product->bLength);
TEST_ASSERT_EQUAL(ser_num_str_desc_ref->bLength, dev_info.str_desc_serial_num->bLength);
TEST_ASSERT_EQUAL_MEMORY_MESSAGE(manu_str_desc_ref, dev_info.str_desc_manufacturer, manu_str_desc_ref->bLength, "Manufacturer string descriptors do not match.");
#endif // CONFIG_USB_HOST_TEST_CHECK_MANU_STR
#if CONFIG_USB_HOST_TEST_CHECK_PROD_STR
const usb_str_desc_t *product_str_desc_ref = dev_msc_get_str_desc_prod();
TEST_ASSERT_EQUAL(product_str_desc_ref->bLength, dev_info.str_desc_product->bLength);
TEST_ASSERT_EQUAL_MEMORY_MESSAGE(product_str_desc_ref, dev_info.str_desc_product, manu_str_desc_ref->bLength, "Product string descriptors do not match.");
#endif // CONFIG_USB_HOST_TEST_CHECK_PROD_STR
#if CONFIG_USB_HOST_TEST_CHECK_SERIAL_STR
const usb_str_desc_t *ser_num_str_desc_ref = dev_msc_get_str_desc_ser();
TEST_ASSERT_EQUAL(ser_num_str_desc_ref->bLength, dev_info.str_desc_serial_num->bLength);
TEST_ASSERT_EQUAL_MEMORY_MESSAGE(ser_num_str_desc_ref, dev_info.str_desc_serial_num, manu_str_desc_ref->bLength, "Serial number string descriptors do not match.");
// Get dev info and compare
#endif // CONFIG_USB_HOST_TEST_CHECK_SERIAL_STR
(void) dev_info; // Unused if all string descriptor checks are disabled
msc_obj.next_stage = TEST_STAGE_DEV_CLOSE;
skip_event_handling = true; // Need to execute TEST_STAGE_DEV_CLOSE
break;