mirror of
https://github.com/hathach/tinyusb.git
synced 2025-03-14 04:18:56 +00:00
add more tests, fix an issue with tud_descriptor_configuration_cb() return NULL
This commit is contained in:
parent
d9ba4d90a8
commit
6de9eb4b1a
@ -785,6 +785,8 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const
|
||||
case TUSB_DESC_CONFIGURATION:
|
||||
{
|
||||
tusb_desc_configuration_t const* desc_config = (tusb_desc_configuration_t const*) tud_descriptor_configuration_cb(desc_index);
|
||||
TU_ASSERT(desc_config);
|
||||
|
||||
uint16_t total_len;
|
||||
memcpy(&total_len, &desc_config->wTotalLength, 2); // possibly mis-aligned memory
|
||||
|
||||
|
@ -40,7 +40,7 @@ TEST_FILE("usbd_control.c")
|
||||
|
||||
uint8_t const rhport = 0;
|
||||
|
||||
tusb_desc_device_t const desc_device =
|
||||
tusb_desc_device_t const data_desc_device =
|
||||
{
|
||||
.bLength = sizeof(tusb_desc_device_t),
|
||||
.bDescriptorType = TUSB_DESC_DEVICE,
|
||||
@ -65,6 +65,12 @@ tusb_desc_device_t const desc_device =
|
||||
.bNumConfigurations = 0x01
|
||||
};
|
||||
|
||||
uint8_t const data_desc_configuration[] =
|
||||
{
|
||||
// Interface count, string index, total length, attribute, power in mA
|
||||
TUD_CONFIG_DESCRIPTOR(0, 0, TUD_CONFIG_DESC_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
|
||||
};
|
||||
|
||||
tusb_control_request_t const req_get_desc_device =
|
||||
{
|
||||
.bmRequestType = 0x80,
|
||||
@ -74,20 +80,29 @@ tusb_control_request_t const req_get_desc_device =
|
||||
.wLength = 64
|
||||
};
|
||||
|
||||
tusb_control_request_t const req_get_desc_configuration =
|
||||
{
|
||||
.bmRequestType = 0x80,
|
||||
.bRequest = TUSB_REQ_GET_DESCRIPTOR,
|
||||
.wValue = (TUSB_DESC_CONFIGURATION << 8),
|
||||
.wIndex = 0x0000,
|
||||
.wLength = 256
|
||||
};
|
||||
|
||||
uint8_t const* desc_device;
|
||||
uint8_t const* desc_configuration;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
//
|
||||
//--------------------------------------------------------------------+
|
||||
uint8_t const * ptr_desc_device;
|
||||
|
||||
uint8_t const * tud_descriptor_device_cb(void)
|
||||
{
|
||||
return ptr_desc_device;
|
||||
return desc_device;
|
||||
}
|
||||
|
||||
uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
|
||||
{
|
||||
TEST_FAIL();
|
||||
return NULL;
|
||||
return desc_configuration;
|
||||
}
|
||||
|
||||
uint16_t const* tud_descriptor_string_cb(uint8_t index)
|
||||
@ -105,8 +120,6 @@ void setUp(void)
|
||||
dcd_init_Expect(rhport);
|
||||
tusb_init();
|
||||
}
|
||||
|
||||
ptr_desc_device = (uint8_t const *) &desc_device;
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
@ -114,20 +127,23 @@ void tearDown(void)
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
//
|
||||
// Get Descriptor
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
//------------- Device -------------//
|
||||
void test_usbd_get_device_descriptor(void)
|
||||
{
|
||||
desc_device = (uint8_t const *) &data_desc_device;
|
||||
dcd_event_setup_received(rhport, (uint8_t*) &req_get_desc_device, false);
|
||||
|
||||
dcd_edpt_xfer_ExpectWithArrayAndReturn(rhport, 0x80, (uint8_t*)&desc_device, sizeof(tusb_desc_device_t), sizeof(tusb_desc_device_t), true);
|
||||
dcd_edpt_xfer_ExpectWithArrayAndReturn(rhport, 0x80, (uint8_t*)&data_desc_device, sizeof(tusb_desc_device_t), sizeof(tusb_desc_device_t), true);
|
||||
|
||||
tud_task();
|
||||
}
|
||||
|
||||
void test_usbd_get_device_descriptor_null(void)
|
||||
{
|
||||
ptr_desc_device = NULL;
|
||||
desc_device = NULL;
|
||||
|
||||
dcd_event_setup_received(rhport, (uint8_t*) &req_get_desc_device, false);
|
||||
|
||||
@ -136,3 +152,37 @@ void test_usbd_get_device_descriptor_null(void)
|
||||
|
||||
tud_task();
|
||||
}
|
||||
|
||||
//------------- Configuration -------------//
|
||||
|
||||
void test_usbd_get_configuration_descriptor(void)
|
||||
{
|
||||
desc_configuration = data_desc_configuration;
|
||||
uint16_t total_len = ((tusb_desc_configuration_t const*) data_desc_configuration)->wTotalLength;
|
||||
|
||||
dcd_event_setup_received(rhport, (uint8_t*) &req_get_desc_configuration, false);
|
||||
|
||||
dcd_edpt_xfer_ExpectWithArrayAndReturn(rhport, 0x80, (uint8_t*) data_desc_configuration, total_len, total_len, true);
|
||||
|
||||
tud_task();
|
||||
}
|
||||
|
||||
void test_usbd_get_configuration_descriptor_null(void)
|
||||
{
|
||||
desc_configuration = NULL;
|
||||
dcd_event_setup_received(rhport, (uint8_t*) &req_get_desc_configuration, false);
|
||||
|
||||
dcd_edpt_stall_Expect(rhport, 0);
|
||||
dcd_edpt_stall_Expect(rhport, 0x80);
|
||||
|
||||
tud_task();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Control ZLP
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
//void test_control_zlp(void)
|
||||
//{
|
||||
//
|
||||
//}
|
||||
|
Loading…
x
Reference in New Issue
Block a user