mirror of
https://github.com/espressif/esp-idf.git
synced 2025-12-07 09:02:08 +00:00
refactor(usb): Rename mock class files
- Rename "test_usb_mock_..." class files to "mock_..." - Fixed some codespell issues - Fixed comment spacing
This commit is contained in:
@@ -20,7 +20,7 @@ void setUp(void)
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
//Short delay to allow task to be cleaned up
|
||||
// Short delay to allow task to be cleaned up
|
||||
vTaskDelay(10);
|
||||
test_hcd_teardown(port_hdl);
|
||||
port_hdl = NULL;
|
||||
|
||||
@@ -9,24 +9,24 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "unity.h"
|
||||
#include "test_usb_mock_msc.h"
|
||||
#include "mock_msc.h"
|
||||
#include "test_hcd_common.h"
|
||||
|
||||
// --------------------------------------------------- Test Cases ------------------------------------------------------
|
||||
|
||||
static void mock_msc_reset_req(hcd_pipe_handle_t default_pipe)
|
||||
{
|
||||
//Create URB
|
||||
// Create URB
|
||||
urb_t *urb = test_hcd_alloc_urb(0, sizeof(usb_setup_packet_t));
|
||||
usb_setup_packet_t *setup_pkt = (usb_setup_packet_t *)urb->transfer.data_buffer;
|
||||
MOCK_MSC_SCSI_REQ_INIT_RESET(setup_pkt, MOCK_MSC_SCSI_INTF_NUMBER);
|
||||
urb->transfer.num_bytes = sizeof(usb_setup_packet_t);
|
||||
//Enqueue, wait, dequeue, and check URB
|
||||
// Enqueue, wait, dequeue, and check URB
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_urb_enqueue(default_pipe, urb));
|
||||
test_hcd_expect_pipe_event(default_pipe, HCD_PIPE_EVENT_URB_DONE);
|
||||
TEST_ASSERT_EQUAL_PTR(urb, hcd_urb_dequeue(default_pipe));
|
||||
TEST_ASSERT_EQUAL_MESSAGE(USB_TRANSFER_STATUS_COMPLETED, urb->transfer.status, "Transfer NOT completed");
|
||||
//Free URB
|
||||
// Free URB
|
||||
test_hcd_free_urb(urb);
|
||||
}
|
||||
|
||||
@@ -54,19 +54,19 @@ Procedure:
|
||||
|
||||
TEST_CASE("Test HCD bulk pipe URBs", "[bulk][full_speed]")
|
||||
{
|
||||
usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); //Trigger a connection
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); //Short delay send of SOF (for FS) or EOPs (for LS)
|
||||
usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); // Trigger a connection
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); // Short delay send of SOF (for FS) or EOPs (for LS)
|
||||
|
||||
//Enumerate and reset MSC SCSI device
|
||||
hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc(port_hdl, NULL, 0, port_speed); //Create a default pipe (using a NULL EP descriptor)
|
||||
// Enumerate and reset MSC SCSI device
|
||||
hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc(port_hdl, NULL, 0, port_speed); // Create a default pipe (using a NULL EP descriptor)
|
||||
uint8_t dev_addr = test_hcd_enum_device(default_pipe);
|
||||
mock_msc_reset_req(default_pipe);
|
||||
test_hcd_set_mock_msc_ep_descriptor(port_speed);
|
||||
|
||||
//Create BULK IN and BULK OUT pipes for SCSI
|
||||
// Create BULK IN and BULK OUT pipes for SCSI
|
||||
hcd_pipe_handle_t bulk_out_pipe = test_hcd_pipe_alloc(port_hdl, &mock_msc_scsi_bulk_out_ep_desc, dev_addr, port_speed);
|
||||
hcd_pipe_handle_t bulk_in_pipe = test_hcd_pipe_alloc(port_hdl, &mock_msc_scsi_bulk_in_ep_desc, dev_addr, port_speed);
|
||||
//Create URBs for CBW, Data, and CSW transport. IN Buffer sizes are rounded up to nearest MPS
|
||||
// Create URBs for CBW, Data, and CSW transport. IN Buffer sizes are rounded up to nearest MPS
|
||||
urb_t *urb_cbw = test_hcd_alloc_urb(0, sizeof(mock_msc_bulk_cbw_t));
|
||||
urb_t *urb_data = test_hcd_alloc_urb(0, TEST_NUM_SECTORS_PER_XFER * MOCK_MSC_SCSI_SECTOR_SIZE);
|
||||
const uint16_t mps = USB_EP_DESC_GET_MPS(&mock_msc_scsi_bulk_in_ep_desc) ;
|
||||
@@ -76,25 +76,25 @@ TEST_CASE("Test HCD bulk pipe URBs", "[bulk][full_speed]")
|
||||
urb_csw->transfer.num_bytes = sizeof(mock_msc_bulk_csw_t) + (mps - (sizeof(mock_msc_bulk_csw_t) % mps));
|
||||
|
||||
for (int block_num = 0; block_num < TEST_NUM_SECTORS_TOTAL; block_num += TEST_NUM_SECTORS_PER_XFER) {
|
||||
//Initialize CBW URB, then send it on the BULK OUT pipe
|
||||
// Initialize CBW URB, then send it on the BULK OUT pipe
|
||||
mock_msc_scsi_init_cbw((mock_msc_bulk_cbw_t *)urb_cbw->transfer.data_buffer, true, block_num, TEST_NUM_SECTORS_PER_XFER, 0xAAAAAAAA);
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_urb_enqueue(bulk_out_pipe, urb_cbw));
|
||||
test_hcd_expect_pipe_event(bulk_out_pipe, HCD_PIPE_EVENT_URB_DONE);
|
||||
TEST_ASSERT_EQUAL_PTR(urb_cbw, hcd_urb_dequeue(bulk_out_pipe));
|
||||
TEST_ASSERT_EQUAL_MESSAGE(USB_TRANSFER_STATUS_COMPLETED, urb_cbw->transfer.status, "Transfer NOT completed");
|
||||
//Read data through BULK IN pipe
|
||||
// Read data through BULK IN pipe
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_urb_enqueue(bulk_in_pipe, urb_data));
|
||||
test_hcd_expect_pipe_event(bulk_in_pipe, HCD_PIPE_EVENT_URB_DONE);
|
||||
TEST_ASSERT_EQUAL_PTR(urb_data, hcd_urb_dequeue(bulk_in_pipe));
|
||||
TEST_ASSERT_EQUAL_MESSAGE(USB_TRANSFER_STATUS_COMPLETED, urb_data->transfer.status, "Transfer NOT completed");
|
||||
//Read the CSW through BULK IN pipe
|
||||
// Read the CSW through BULK IN pipe
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_urb_enqueue(bulk_in_pipe, urb_csw));
|
||||
test_hcd_expect_pipe_event(bulk_in_pipe, HCD_PIPE_EVENT_URB_DONE);
|
||||
TEST_ASSERT_EQUAL_PTR(urb_csw, hcd_urb_dequeue(bulk_in_pipe));
|
||||
TEST_ASSERT_EQUAL_MESSAGE(USB_TRANSFER_STATUS_COMPLETED, urb_data->transfer.status, "Transfer NOT completed");
|
||||
TEST_ASSERT_EQUAL(sizeof(mock_msc_bulk_csw_t), urb_csw->transfer.actual_num_bytes);
|
||||
TEST_ASSERT_TRUE(mock_msc_scsi_check_csw((mock_msc_bulk_csw_t *)urb_csw->transfer.data_buffer, 0xAAAAAAAA));
|
||||
//Print the read data
|
||||
// Print the read data
|
||||
printf("Block %d to %d:\n", block_num, block_num + TEST_NUM_SECTORS_PER_XFER);
|
||||
for (int i = 0; i < urb_data->transfer.actual_num_bytes; i++) {
|
||||
printf("0x%02x,", ((char *)urb_data->transfer.data_buffer)[i]);
|
||||
@@ -108,6 +108,6 @@ TEST_CASE("Test HCD bulk pipe URBs", "[bulk][full_speed]")
|
||||
test_hcd_pipe_free(bulk_out_pipe);
|
||||
test_hcd_pipe_free(bulk_in_pipe);
|
||||
test_hcd_pipe_free(default_pipe);
|
||||
//Cleanup
|
||||
// Cleanup
|
||||
test_hcd_wait_for_disconn(port_hdl, false);
|
||||
}
|
||||
|
||||
@@ -19,14 +19,14 @@
|
||||
#include "usb/usb_types_ch9.h"
|
||||
#include "test_hcd_common.h"
|
||||
#include "test_usb_common.h"
|
||||
#include "test_usb_mock_msc.h"
|
||||
#include "mock_msc.h"
|
||||
#include "unity.h"
|
||||
#include "esp_dma_utils.h"
|
||||
|
||||
#define PORT_NUM 1
|
||||
#define EVENT_QUEUE_LEN 5
|
||||
#define ENUM_ADDR 1 //Device address to use for tests that enumerate the device
|
||||
#define ENUM_CONFIG 1 //Device configuration number to use for tests that enumerate the device
|
||||
#define ENUM_ADDR 1 // Device address to use for tests that enumerate the device
|
||||
#define ENUM_CONFIG 1 // Device configuration number to use for tests that enumerate the device
|
||||
|
||||
typedef struct {
|
||||
hcd_port_handle_t port_hdl;
|
||||
@@ -54,10 +54,10 @@ hcd_port_handle_t port_hdl = NULL;
|
||||
*/
|
||||
static bool port_callback(hcd_port_handle_t port_hdl, hcd_port_event_t port_event, void *user_arg, bool in_isr)
|
||||
{
|
||||
//We store the port's queue handle in the port's context variable
|
||||
// We store the port's queue handle in the port's context variable
|
||||
void *port_ctx = hcd_port_get_context(port_hdl);
|
||||
QueueHandle_t port_evt_queue = (QueueHandle_t)port_ctx;
|
||||
TEST_ASSERT_TRUE(in_isr); //Current HCD implementation should never call a port callback in a task context
|
||||
TEST_ASSERT_TRUE(in_isr); // Current HCD implementation should never call a port callback in a task context
|
||||
port_event_msg_t msg = {
|
||||
.port_hdl = port_hdl,
|
||||
.port_event = port_event,
|
||||
@@ -98,14 +98,14 @@ static bool pipe_callback(hcd_pipe_handle_t pipe_hdl, hcd_pipe_event_t pipe_even
|
||||
|
||||
void test_hcd_expect_port_event(hcd_port_handle_t port_hdl, hcd_port_event_t expected_event)
|
||||
{
|
||||
//Get the port event queue from the port's context variable
|
||||
// Get the port event queue from the port's context variable
|
||||
QueueHandle_t port_evt_queue = (QueueHandle_t)hcd_port_get_context(port_hdl);
|
||||
TEST_ASSERT_NOT_NULL(port_evt_queue);
|
||||
//Wait for port callback to send an event message
|
||||
// Wait for port callback to send an event message
|
||||
port_event_msg_t msg;
|
||||
BaseType_t ret = xQueueReceive(port_evt_queue, &msg, pdMS_TO_TICKS(5000));
|
||||
TEST_ASSERT_EQUAL_MESSAGE(pdPASS, ret, "Port event not generated on time");
|
||||
//Check the contents of that event message
|
||||
// Check the contents of that event message
|
||||
TEST_ASSERT_EQUAL(port_hdl, msg.port_hdl);
|
||||
TEST_ASSERT_EQUAL_MESSAGE(expected_event, msg.port_event, "Unexpected event");
|
||||
printf("\t-> Port event\n");
|
||||
@@ -113,21 +113,21 @@ void test_hcd_expect_port_event(hcd_port_handle_t port_hdl, hcd_port_event_t exp
|
||||
|
||||
void test_hcd_expect_pipe_event(hcd_pipe_handle_t pipe_hdl, hcd_pipe_event_t expected_event)
|
||||
{
|
||||
//Get the pipe's event queue from the pipe's context variable
|
||||
// Get the pipe's event queue from the pipe's context variable
|
||||
QueueHandle_t pipe_evt_queue = (QueueHandle_t)hcd_pipe_get_context(pipe_hdl);
|
||||
TEST_ASSERT_NOT_NULL(pipe_evt_queue);
|
||||
//Wait for pipe callback to send an event message
|
||||
// Wait for pipe callback to send an event message
|
||||
pipe_event_msg_t msg;
|
||||
BaseType_t ret = xQueueReceive(pipe_evt_queue, &msg, pdMS_TO_TICKS(5000));
|
||||
TEST_ASSERT_EQUAL_MESSAGE(pdPASS, ret, "Pipe event not generated on time");
|
||||
//Check the contents of that event message
|
||||
// Check the contents of that event message
|
||||
TEST_ASSERT_EQUAL(pipe_hdl, msg.pipe_hdl);
|
||||
TEST_ASSERT_EQUAL_MESSAGE(expected_event, msg.pipe_event, "Unexpected event");
|
||||
}
|
||||
|
||||
int test_hcd_get_num_port_events(hcd_port_handle_t port_hdl)
|
||||
{
|
||||
//Get the port event queue from the port's context variable
|
||||
// Get the port event queue from the port's context variable
|
||||
QueueHandle_t port_evt_queue = (QueueHandle_t)hcd_port_get_context(port_hdl);
|
||||
TEST_ASSERT_NOT_NULL(port_evt_queue);
|
||||
return EVENT_QUEUE_LEN - uxQueueSpacesAvailable(port_evt_queue);
|
||||
@@ -135,7 +135,7 @@ int test_hcd_get_num_port_events(hcd_port_handle_t port_hdl)
|
||||
|
||||
int test_hcd_get_num_pipe_events(hcd_pipe_handle_t pipe_hdl)
|
||||
{
|
||||
//Get the pipe's event queue from the pipe's context variable
|
||||
// Get the pipe's event queue from the pipe's context variable
|
||||
QueueHandle_t pipe_evt_queue = (QueueHandle_t)hcd_pipe_get_context(pipe_hdl);
|
||||
TEST_ASSERT_NOT_NULL(pipe_evt_queue);
|
||||
return EVENT_QUEUE_LEN - uxQueueSpacesAvailable(pipe_evt_queue);
|
||||
@@ -145,16 +145,16 @@ int test_hcd_get_num_pipe_events(hcd_pipe_handle_t pipe_hdl)
|
||||
|
||||
hcd_port_handle_t test_hcd_setup(void)
|
||||
{
|
||||
test_usb_init_phy(); //Initialize the internal USB PHY and USB Controller for testing
|
||||
//Create a queue for port callback to queue up port events
|
||||
test_usb_init_phy(); // Initialize the internal USB PHY and USB Controller for testing
|
||||
// Create a queue for port callback to queue up port events
|
||||
QueueHandle_t port_evt_queue = xQueueCreate(EVENT_QUEUE_LEN, sizeof(port_event_msg_t));
|
||||
TEST_ASSERT_NOT_NULL(port_evt_queue);
|
||||
//Install HCD
|
||||
// Install HCD
|
||||
hcd_config_t hcd_config = {
|
||||
.intr_flags = ESP_INTR_FLAG_LEVEL1,
|
||||
};
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_install(&hcd_config));
|
||||
//Initialize a port
|
||||
// Initialize a port
|
||||
hcd_port_config_t port_config = {
|
||||
.fifo_bias = HCD_PORT_FIFO_BIAS_BALANCED,
|
||||
.callback = port_callback,
|
||||
@@ -165,7 +165,7 @@ hcd_port_handle_t test_hcd_setup(void)
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_port_init(PORT_NUM, &port_config, &port_hdl));
|
||||
TEST_ASSERT_NOT_NULL(port_hdl);
|
||||
TEST_ASSERT_EQUAL(HCD_PORT_STATE_NOT_POWERED, hcd_port_get_state(port_hdl));
|
||||
test_usb_set_phy_state(false, 0); //Force disconnected state on PHY
|
||||
test_usb_set_phy_state(false, 0); // Force disconnected state on PHY
|
||||
return port_hdl;
|
||||
}
|
||||
|
||||
@@ -174,33 +174,33 @@ void test_hcd_teardown(hcd_port_handle_t port_hdl)
|
||||
if (!port_hdl) {
|
||||
return; // In case of setup stage failure, don't run tear-down stage
|
||||
}
|
||||
//Get the queue handle from the port's context variable
|
||||
// Get the queue handle from the port's context variable
|
||||
QueueHandle_t port_evt_queue = (QueueHandle_t)hcd_port_get_context(port_hdl);
|
||||
TEST_ASSERT_NOT_NULL(port_evt_queue);
|
||||
//Deinitialize a port
|
||||
// Deinitialize a port
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_port_deinit(port_hdl));
|
||||
//Uninstall the HCD
|
||||
// Uninstall the HCD
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_uninstall());
|
||||
vQueueDelete(port_evt_queue);
|
||||
test_usb_deinit_phy(); //Deinitialize the internal USB PHY after testing
|
||||
test_usb_deinit_phy(); // Deinitialize the internal USB PHY after testing
|
||||
}
|
||||
|
||||
usb_speed_t test_hcd_wait_for_conn(hcd_port_handle_t port_hdl)
|
||||
{
|
||||
//Power ON the port
|
||||
// Power ON the port
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_port_command(port_hdl, HCD_PORT_CMD_POWER_ON));
|
||||
TEST_ASSERT_EQUAL(HCD_PORT_STATE_DISCONNECTED, hcd_port_get_state(port_hdl));
|
||||
//Wait for connection event
|
||||
// Wait for connection event
|
||||
printf("Waiting for connection\n");
|
||||
test_usb_set_phy_state(true, pdMS_TO_TICKS(100)); //Allow for connected state on PHY
|
||||
test_usb_set_phy_state(true, pdMS_TO_TICKS(100)); // Allow for connected state on PHY
|
||||
test_hcd_expect_port_event(port_hdl, HCD_PORT_EVENT_CONNECTION);
|
||||
TEST_ASSERT_EQUAL(HCD_PORT_EVENT_CONNECTION, hcd_port_handle_event(port_hdl));
|
||||
TEST_ASSERT_EQUAL(HCD_PORT_STATE_DISABLED, hcd_port_get_state(port_hdl));
|
||||
//Reset newly connected device
|
||||
// Reset newly connected device
|
||||
printf("Resetting\n");
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_port_command(port_hdl, HCD_PORT_CMD_RESET));
|
||||
TEST_ASSERT_EQUAL(HCD_PORT_STATE_ENABLED, hcd_port_get_state(port_hdl));
|
||||
//Get speed of connected
|
||||
// Get speed of connected
|
||||
usb_speed_t port_speed;
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_port_get_speed(port_hdl, &port_speed));
|
||||
TEST_ASSERT_LESS_OR_EQUAL_MESSAGE(USB_SPEED_HIGH, port_speed, "Invalid port speed");
|
||||
@@ -213,18 +213,18 @@ usb_speed_t test_hcd_wait_for_conn(hcd_port_handle_t port_hdl)
|
||||
void test_hcd_wait_for_disconn(hcd_port_handle_t port_hdl, bool already_disabled)
|
||||
{
|
||||
if (!already_disabled) {
|
||||
//Disable the device
|
||||
// Disable the device
|
||||
printf("Disabling\n");
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_port_command(port_hdl, HCD_PORT_CMD_DISABLE));
|
||||
TEST_ASSERT_EQUAL(HCD_PORT_STATE_DISABLED, hcd_port_get_state(port_hdl));
|
||||
}
|
||||
//Wait for a safe disconnect
|
||||
// Wait for a safe disconnect
|
||||
printf("Waiting for disconnection\n");
|
||||
test_usb_set_phy_state(false, pdMS_TO_TICKS(100)); //Force disconnected state on PHY
|
||||
test_usb_set_phy_state(false, pdMS_TO_TICKS(100)); // Force disconnected state on PHY
|
||||
test_hcd_expect_port_event(port_hdl, HCD_PORT_EVENT_DISCONNECTION);
|
||||
TEST_ASSERT_EQUAL(HCD_PORT_EVENT_DISCONNECTION, hcd_port_handle_event(port_hdl));
|
||||
TEST_ASSERT_EQUAL(HCD_PORT_STATE_RECOVERY, hcd_port_get_state(port_hdl));
|
||||
//Power down the port
|
||||
// Power down the port
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_port_command(port_hdl, HCD_PORT_CMD_POWER_OFF));
|
||||
TEST_ASSERT_EQUAL(HCD_PORT_STATE_NOT_POWERED, hcd_port_get_state(port_hdl));
|
||||
}
|
||||
@@ -233,7 +233,7 @@ void test_hcd_wait_for_disconn(hcd_port_handle_t port_hdl, bool already_disabled
|
||||
|
||||
hcd_pipe_handle_t test_hcd_pipe_alloc(hcd_port_handle_t port_hdl, const usb_ep_desc_t *ep_desc, uint8_t dev_addr, usb_speed_t dev_speed)
|
||||
{
|
||||
//Create a queue for pipe callback to queue up pipe events
|
||||
// Create a queue for pipe callback to queue up pipe events
|
||||
QueueHandle_t pipe_evt_queue = xQueueCreate(EVENT_QUEUE_LEN, sizeof(pipe_event_msg_t));
|
||||
TEST_ASSERT_NOT_NULL(pipe_evt_queue);
|
||||
hcd_pipe_config_t pipe_config = {
|
||||
@@ -252,17 +252,17 @@ hcd_pipe_handle_t test_hcd_pipe_alloc(hcd_port_handle_t port_hdl, const usb_ep_d
|
||||
|
||||
void test_hcd_pipe_free(hcd_pipe_handle_t pipe_hdl)
|
||||
{
|
||||
//Get the pipe's event queue from its context variable
|
||||
// Get the pipe's event queue from its context variable
|
||||
QueueHandle_t pipe_evt_queue = (QueueHandle_t)hcd_pipe_get_context(pipe_hdl);
|
||||
TEST_ASSERT_NOT_NULL(pipe_evt_queue);
|
||||
//Free the pipe and queue
|
||||
// Free the pipe and queue
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_pipe_free(pipe_hdl));
|
||||
vQueueDelete(pipe_evt_queue);
|
||||
}
|
||||
|
||||
urb_t *test_hcd_alloc_urb(int num_isoc_packets, size_t data_buffer_size)
|
||||
{
|
||||
//Allocate a URB and data buffer
|
||||
// Allocate a URB and data buffer
|
||||
urb_t *urb = heap_caps_calloc(1, sizeof(urb_t) + (sizeof(usb_isoc_packet_desc_t) * num_isoc_packets), MALLOC_CAP_DEFAULT);
|
||||
void *data_buffer;
|
||||
size_t real_size;
|
||||
@@ -273,7 +273,7 @@ urb_t *test_hcd_alloc_urb(int num_isoc_packets, size_t data_buffer_size)
|
||||
TEST_ASSERT_NOT_NULL_MESSAGE(urb, "Failed to allocate URB");
|
||||
TEST_ASSERT_NOT_NULL_MESSAGE(data_buffer, "Failed to allocate transfer buffer");
|
||||
|
||||
//Initialize URB and underlying transfer structure. Need to cast to dummy due to const fields
|
||||
// Initialize URB and underlying transfer structure. Need to cast to dummy due to const fields
|
||||
usb_transfer_dummy_t *transfer_dummy = (usb_transfer_dummy_t *)&urb->transfer;
|
||||
transfer_dummy->data_buffer = data_buffer;
|
||||
transfer_dummy->data_buffer_size = real_size;
|
||||
@@ -283,19 +283,19 @@ urb_t *test_hcd_alloc_urb(int num_isoc_packets, size_t data_buffer_size)
|
||||
|
||||
void test_hcd_free_urb(urb_t *urb)
|
||||
{
|
||||
//Free data buffer of the transfer
|
||||
// Free data buffer of the transfer
|
||||
heap_caps_free(urb->transfer.data_buffer);
|
||||
//Free the URB
|
||||
// Free the URB
|
||||
heap_caps_free(urb);
|
||||
}
|
||||
|
||||
uint8_t test_hcd_enum_device(hcd_pipe_handle_t default_pipe)
|
||||
{
|
||||
//We need to create a URB for the enumeration control transfers
|
||||
// We need to create a URB for the enumeration control transfers
|
||||
urb_t *urb = test_hcd_alloc_urb(0, sizeof(usb_setup_packet_t) + 256);
|
||||
usb_setup_packet_t *setup_pkt = (usb_setup_packet_t *)urb->transfer.data_buffer;
|
||||
|
||||
//Get the device descriptor (note that device might only return 8 bytes)
|
||||
// Get the device descriptor (note that device might only return 8 bytes)
|
||||
USB_SETUP_PACKET_INIT_GET_DEVICE_DESC(setup_pkt);
|
||||
urb->transfer.num_bytes = sizeof(usb_setup_packet_t) + sizeof(usb_device_desc_t);
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_urb_enqueue(default_pipe, urb));
|
||||
@@ -303,22 +303,22 @@ uint8_t test_hcd_enum_device(hcd_pipe_handle_t default_pipe)
|
||||
TEST_ASSERT_EQUAL(urb, hcd_urb_dequeue(default_pipe));
|
||||
TEST_ASSERT_EQUAL_MESSAGE(USB_TRANSFER_STATUS_COMPLETED, urb->transfer.status, "Transfer NOT completed");
|
||||
|
||||
//Update the MPS of the default pipe
|
||||
// Update the MPS of the default pipe
|
||||
usb_device_desc_t *device_desc = (usb_device_desc_t *)(urb->transfer.data_buffer + sizeof(usb_setup_packet_t));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_pipe_update_mps(default_pipe, device_desc->bMaxPacketSize0));
|
||||
|
||||
//Send a set address request
|
||||
USB_SETUP_PACKET_INIT_SET_ADDR(setup_pkt, ENUM_ADDR); //We only support one device for now so use address 1
|
||||
// Send a set address request
|
||||
USB_SETUP_PACKET_INIT_SET_ADDR(setup_pkt, ENUM_ADDR); // We only support one device for now so use address 1
|
||||
urb->transfer.num_bytes = sizeof(usb_setup_packet_t);
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_urb_enqueue(default_pipe, urb));
|
||||
test_hcd_expect_pipe_event(default_pipe, HCD_PIPE_EVENT_URB_DONE);
|
||||
TEST_ASSERT_EQUAL(urb, hcd_urb_dequeue(default_pipe));
|
||||
TEST_ASSERT_EQUAL_MESSAGE(USB_TRANSFER_STATUS_COMPLETED, urb->transfer.status, "Transfer NOT completed");
|
||||
|
||||
//Update address of default pipe
|
||||
// Update address of default pipe
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_pipe_update_dev_addr(default_pipe, ENUM_ADDR));
|
||||
|
||||
//Send a set configuration request
|
||||
// Send a set configuration request
|
||||
USB_SETUP_PACKET_INIT_SET_CONFIG(setup_pkt, ENUM_CONFIG);
|
||||
urb->transfer.num_bytes = sizeof(usb_setup_packet_t);
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_urb_enqueue(default_pipe, urb));
|
||||
@@ -326,7 +326,7 @@ uint8_t test_hcd_enum_device(hcd_pipe_handle_t default_pipe)
|
||||
TEST_ASSERT_EQUAL(urb, hcd_urb_dequeue(default_pipe));
|
||||
TEST_ASSERT_EQUAL_MESSAGE(USB_TRANSFER_STATUS_COMPLETED, urb->transfer.status, "Transfer NOT completed");
|
||||
|
||||
//Free URB
|
||||
// Free URB
|
||||
test_hcd_free_urb(urb);
|
||||
return ENUM_ADDR;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#define TEST_DEV_ADDR 0
|
||||
#define NUM_URBS 3
|
||||
#define TRANSFER_MAX_BYTES 256
|
||||
#define URB_DATA_BUFF_SIZE (sizeof(usb_setup_packet_t) + TRANSFER_MAX_BYTES) //256 is worst case size for configuration descriptors
|
||||
#define URB_DATA_BUFF_SIZE (sizeof(usb_setup_packet_t) + TRANSFER_MAX_BYTES) // 256 is worst case size for configuration descriptors
|
||||
|
||||
/*
|
||||
Test HCD control pipe URBs (normal completion and early abort)
|
||||
@@ -35,36 +35,36 @@ Procedure:
|
||||
*/
|
||||
TEST_CASE("Test HCD control pipe URBs", "[ctrl][low_speed][full_speed]")
|
||||
{
|
||||
usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); //Trigger a connection
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); //Short delay send of SOF (for FS) or EOPs (for LS)
|
||||
usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); // Trigger a connection
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); // Short delay send of SOF (for FS) or EOPs (for LS)
|
||||
|
||||
//Allocate some URBs and initialize their data buffers with control transfers
|
||||
hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc(port_hdl, NULL, TEST_DEV_ADDR, port_speed); //Create a default pipe (using a NULL EP descriptor)
|
||||
// Allocate some URBs and initialize their data buffers with control transfers
|
||||
hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc(port_hdl, NULL, TEST_DEV_ADDR, port_speed); // Create a default pipe (using a NULL EP descriptor)
|
||||
urb_t *urb_list[NUM_URBS];
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
urb_list[i] = test_hcd_alloc_urb(0, URB_DATA_BUFF_SIZE);
|
||||
//Initialize with a "Get Config Descriptor request"
|
||||
// Initialize with a "Get Config Descriptor request"
|
||||
urb_list[i]->transfer.num_bytes = sizeof(usb_setup_packet_t) + TRANSFER_MAX_BYTES;
|
||||
USB_SETUP_PACKET_INIT_GET_CONFIG_DESC((usb_setup_packet_t *)urb_list[i]->transfer.data_buffer, 0, TRANSFER_MAX_BYTES);
|
||||
urb_list[i]->transfer.context = URB_CONTEXT_VAL;
|
||||
}
|
||||
|
||||
//Enqueue URBs but immediately suspend the port
|
||||
// Enqueue URBs but immediately suspend the port
|
||||
printf("Enqueuing URBs\n");
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_urb_enqueue(default_pipe, urb_list[i]));
|
||||
}
|
||||
//Wait for each done event of each URB
|
||||
// Wait for each done event of each URB
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
test_hcd_expect_pipe_event(default_pipe, HCD_PIPE_EVENT_URB_DONE);
|
||||
}
|
||||
//Dequeue URBs, check, and print
|
||||
// Dequeue URBs, check, and print
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
urb_t *urb = hcd_urb_dequeue(default_pipe);
|
||||
TEST_ASSERT_EQUAL(urb_list[i], urb);
|
||||
TEST_ASSERT_EQUAL_MESSAGE(USB_TRANSFER_STATUS_COMPLETED, urb->transfer.status, "Transfer NOT completed");
|
||||
TEST_ASSERT_EQUAL(URB_CONTEXT_VAL, urb->transfer.context);
|
||||
//We must have transmitted at least the setup packet, but device may return less than bytes requested
|
||||
// We must have transmitted at least the setup packet, but device may return less than bytes requested
|
||||
TEST_ASSERT_GREATER_OR_EQUAL(sizeof(usb_setup_packet_t), urb->transfer.actual_num_bytes);
|
||||
TEST_ASSERT_LESS_OR_EQUAL(urb->transfer.num_bytes, urb->transfer.actual_num_bytes);
|
||||
usb_config_desc_t *config_desc = (usb_config_desc_t *)(urb->transfer.data_buffer + sizeof(usb_setup_packet_t));
|
||||
@@ -72,38 +72,38 @@ TEST_CASE("Test HCD control pipe URBs", "[ctrl][low_speed][full_speed]")
|
||||
printf("Config Desc wTotalLength %d\n", config_desc->wTotalLength);
|
||||
}
|
||||
|
||||
//Enqueue URBs again but abort them short after
|
||||
// Enqueue URBs again but abort them short after
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_urb_enqueue(default_pipe, urb_list[i]));
|
||||
}
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_urb_abort(urb_list[i]));
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); //Give some time for any inflight transfers to complete
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); // Give some time for any inflight transfers to complete
|
||||
|
||||
//Wait for the URBs to complete and dequeue them, then check results
|
||||
//Dequeue URBs
|
||||
// Wait for the URBs to complete and dequeue them, then check results
|
||||
// Dequeue URBs
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
urb_t *urb = hcd_urb_dequeue(default_pipe);
|
||||
//No need to check for URB pointer address as they may be out of order
|
||||
// No need to check for URB pointer address as they may be out of order
|
||||
TEST_ASSERT(urb->transfer.status == USB_TRANSFER_STATUS_COMPLETED || urb->transfer.status == USB_TRANSFER_STATUS_CANCELED);
|
||||
if (urb->transfer.status == USB_TRANSFER_STATUS_COMPLETED) {
|
||||
//We must have transmitted at least the setup packet, but device may return less than bytes requested
|
||||
// We must have transmitted at least the setup packet, but device may return less than bytes requested
|
||||
TEST_ASSERT_GREATER_OR_EQUAL(sizeof(usb_setup_packet_t), urb->transfer.actual_num_bytes);
|
||||
TEST_ASSERT_LESS_OR_EQUAL(urb->transfer.num_bytes, urb->transfer.actual_num_bytes);
|
||||
} else {
|
||||
//A failed transfer should 0 actual number of bytes transmitted
|
||||
// A failed transfer should 0 actual number of bytes transmitted
|
||||
TEST_ASSERT_EQUAL(0, urb->transfer.actual_num_bytes);
|
||||
}
|
||||
TEST_ASSERT_EQUAL(urb->transfer.context, URB_CONTEXT_VAL);
|
||||
}
|
||||
|
||||
//Free URB list and pipe
|
||||
// Free URB list and pipe
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
test_hcd_free_urb(urb_list[i]);
|
||||
}
|
||||
test_hcd_pipe_free(default_pipe);
|
||||
//Cleanup
|
||||
// Cleanup
|
||||
test_hcd_wait_for_disconn(port_hdl, false);
|
||||
}
|
||||
|
||||
@@ -130,27 +130,27 @@ Procedure:
|
||||
*/
|
||||
TEST_CASE("Test HCD control pipe STALL", "[ctrl][full_speed]")
|
||||
{
|
||||
usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); //Trigger a connection
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); //Short delay send of SOF (for FS) or EOPs (for LS)
|
||||
usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); // Trigger a connection
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); // Short delay send of SOF (for FS) or EOPs (for LS)
|
||||
|
||||
//Allocate some URBs and initialize their data buffers with control transfers
|
||||
hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc(port_hdl, NULL, TEST_DEV_ADDR, port_speed); //Create a default pipe (using a NULL EP descriptor)
|
||||
// Allocate some URBs and initialize their data buffers with control transfers
|
||||
hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc(port_hdl, NULL, TEST_DEV_ADDR, port_speed); // Create a default pipe (using a NULL EP descriptor)
|
||||
urb_t *urb_list[NUM_URBS];
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
urb_list[i] = test_hcd_alloc_urb(0, URB_DATA_BUFF_SIZE);
|
||||
//Initialize with a "Get Config Descriptor request"
|
||||
// Initialize with a "Get Config Descriptor request"
|
||||
urb_list[i]->transfer.num_bytes = sizeof(usb_setup_packet_t) + TRANSFER_MAX_BYTES;
|
||||
USB_SETUP_PACKET_INIT_GET_CONFIG_DESC((usb_setup_packet_t *)urb_list[i]->transfer.data_buffer, 0, TRANSFER_MAX_BYTES);
|
||||
urb_list[i]->transfer.context = URB_CONTEXT_VAL;
|
||||
}
|
||||
//Corrupt the first URB so that it triggers a STALL
|
||||
// Corrupt the first URB so that it triggers a STALL
|
||||
((usb_setup_packet_t *)urb_list[0]->transfer.data_buffer)->bRequest = 0xAA;
|
||||
|
||||
//Enqueue URBs. A STALL should occur
|
||||
// Enqueue URBs. A STALL should occur
|
||||
int num_enqueued = 0;
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
if (hcd_urb_enqueue(default_pipe, urb_list[i]) != ESP_OK) {
|
||||
//STALL may occur before we are done enqueing
|
||||
// STALL may occur before we are done enqueuing
|
||||
break;
|
||||
}
|
||||
num_enqueued++;
|
||||
@@ -160,7 +160,7 @@ TEST_CASE("Test HCD control pipe STALL", "[ctrl][full_speed]")
|
||||
test_hcd_expect_pipe_event(default_pipe, HCD_PIPE_EVENT_ERROR_STALL);
|
||||
TEST_ASSERT_EQUAL(HCD_PIPE_STATE_HALTED, hcd_pipe_get_state(default_pipe));
|
||||
|
||||
//Call the pipe abort command to retire all URBs then dequeue them all
|
||||
// Call the pipe abort command to retire all URBs then dequeue them all
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_pipe_command(default_pipe, HCD_PIPE_CMD_FLUSH));
|
||||
test_hcd_expect_pipe_event(default_pipe, HCD_PIPE_EVENT_URB_DONE);
|
||||
for (int i = 0; i < num_enqueued; i++) {
|
||||
@@ -168,36 +168,36 @@ TEST_CASE("Test HCD control pipe STALL", "[ctrl][full_speed]")
|
||||
TEST_ASSERT_EQUAL(urb_list[i], urb);
|
||||
TEST_ASSERT(urb->transfer.status == USB_TRANSFER_STATUS_STALL || urb->transfer.status == USB_TRANSFER_STATUS_CANCELED);
|
||||
if (urb->transfer.status == USB_TRANSFER_STATUS_COMPLETED) {
|
||||
//We must have transmitted at least the setup packet, but device may return less than bytes requested
|
||||
// We must have transmitted at least the setup packet, but device may return less than bytes requested
|
||||
TEST_ASSERT_GREATER_OR_EQUAL(sizeof(usb_setup_packet_t), urb->transfer.actual_num_bytes);
|
||||
TEST_ASSERT_LESS_OR_EQUAL(urb->transfer.num_bytes, urb->transfer.actual_num_bytes);
|
||||
} else {
|
||||
//A failed transfer should 0 actual number of bytes transmitted
|
||||
// A failed transfer should 0 actual number of bytes transmitted
|
||||
TEST_ASSERT_EQUAL(0, urb->transfer.actual_num_bytes);
|
||||
}
|
||||
TEST_ASSERT_EQUAL(URB_CONTEXT_VAL, urb->transfer.context);
|
||||
}
|
||||
|
||||
//Call the clear command to un-stall the pipe
|
||||
// Call the clear command to un-stall the pipe
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_pipe_command(default_pipe, HCD_PIPE_CMD_CLEAR));
|
||||
TEST_ASSERT_EQUAL(HCD_PIPE_STATE_ACTIVE, hcd_pipe_get_state(default_pipe));
|
||||
|
||||
printf("Retrying\n");
|
||||
//Correct first URB then requeue
|
||||
// Correct first URB then requeue
|
||||
USB_SETUP_PACKET_INIT_GET_CONFIG_DESC((usb_setup_packet_t *)urb_list[0]->transfer.data_buffer, 0, TRANSFER_MAX_BYTES);
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_urb_enqueue(default_pipe, urb_list[i]));
|
||||
}
|
||||
|
||||
//Wait for each URB to be done, deequeue, and check results
|
||||
// Wait for each URB to be done, deequeue, and check results
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
test_hcd_expect_pipe_event(default_pipe, HCD_PIPE_EVENT_URB_DONE);
|
||||
//expect_pipe_event(pipe_evt_queue, default_pipe, HCD_PIPE_EVENT_URB_DONE);
|
||||
// expect_pipe_event(pipe_evt_queue, default_pipe, HCD_PIPE_EVENT_URB_DONE);
|
||||
urb_t *urb = hcd_urb_dequeue(default_pipe);
|
||||
TEST_ASSERT_EQUAL(urb_list[i], urb);
|
||||
TEST_ASSERT_EQUAL_MESSAGE(USB_TRANSFER_STATUS_COMPLETED, urb->transfer.status, "Transfer NOT completed");
|
||||
TEST_ASSERT_EQUAL(URB_CONTEXT_VAL, urb->transfer.context);
|
||||
//We must have transmitted at least the setup packet, but device may return less than bytes requested
|
||||
// We must have transmitted at least the setup packet, but device may return less than bytes requested
|
||||
TEST_ASSERT_GREATER_OR_EQUAL(sizeof(usb_setup_packet_t), urb->transfer.actual_num_bytes);
|
||||
TEST_ASSERT_LESS_OR_EQUAL(urb->transfer.num_bytes, urb->transfer.actual_num_bytes);
|
||||
usb_config_desc_t *config_desc = (usb_config_desc_t *)(urb->transfer.data_buffer + sizeof(usb_setup_packet_t));
|
||||
@@ -205,12 +205,12 @@ TEST_CASE("Test HCD control pipe STALL", "[ctrl][full_speed]")
|
||||
printf("Config Desc wTotalLength %d\n", config_desc->wTotalLength);
|
||||
}
|
||||
|
||||
//Free URB list and pipe
|
||||
// Free URB list and pipe
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
test_hcd_free_urb(urb_list[i]);
|
||||
}
|
||||
test_hcd_pipe_free(default_pipe);
|
||||
//Cleanup
|
||||
// Cleanup
|
||||
test_hcd_wait_for_disconn(port_hdl, false);
|
||||
}
|
||||
|
||||
@@ -234,21 +234,21 @@ Procedure:
|
||||
*/
|
||||
TEST_CASE("Test HCD control pipe runtime halt and clear", "[ctrl][low_speed][full_speed]")
|
||||
{
|
||||
usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); //Trigger a connection
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); //Short delay send of SOF (for FS) or EOPs (for LS)
|
||||
usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); // Trigger a connection
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); // Short delay send of SOF (for FS) or EOPs (for LS)
|
||||
|
||||
//Allocate some URBs and initialize their data buffers with control transfers
|
||||
hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc(port_hdl, NULL, TEST_DEV_ADDR, port_speed); //Create a default pipe (using a NULL EP descriptor)
|
||||
// Allocate some URBs and initialize their data buffers with control transfers
|
||||
hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc(port_hdl, NULL, TEST_DEV_ADDR, port_speed); // Create a default pipe (using a NULL EP descriptor)
|
||||
urb_t *urb_list[NUM_URBS];
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
urb_list[i] = test_hcd_alloc_urb(0, URB_DATA_BUFF_SIZE);
|
||||
//Initialize with a "Get Config Descriptor request"
|
||||
// Initialize with a "Get Config Descriptor request"
|
||||
urb_list[i]->transfer.num_bytes = sizeof(usb_setup_packet_t) + TRANSFER_MAX_BYTES;
|
||||
USB_SETUP_PACKET_INIT_GET_CONFIG_DESC((usb_setup_packet_t *)urb_list[i]->transfer.data_buffer, 0, TRANSFER_MAX_BYTES);
|
||||
urb_list[i]->transfer.context = URB_CONTEXT_VAL;
|
||||
}
|
||||
|
||||
//Enqueue URBs but immediately halt the pipe
|
||||
// Enqueue URBs but immediately halt the pipe
|
||||
printf("Enqueuing URBs\n");
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_urb_enqueue(default_pipe, urb_list[i]));
|
||||
@@ -258,36 +258,36 @@ TEST_CASE("Test HCD control pipe runtime halt and clear", "[ctrl][low_speed][ful
|
||||
TEST_ASSERT_EQUAL(HCD_PIPE_STATE_HALTED, hcd_pipe_get_state(default_pipe));
|
||||
printf("Pipe halted\n");
|
||||
|
||||
//Un-halt the pipe
|
||||
// Un-halt the pipe
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_pipe_command(default_pipe, HCD_PIPE_CMD_CLEAR));
|
||||
TEST_ASSERT_EQUAL(HCD_PIPE_STATE_ACTIVE, hcd_pipe_get_state(default_pipe));
|
||||
printf("Pipe cleared\n");
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); //Give some time pending for transfers to restart and complete
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); // Give some time pending for transfers to restart and complete
|
||||
|
||||
//Wait for each URB to be done, dequeue, and check results
|
||||
// Wait for each URB to be done, dequeue, and check results
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
urb_t *urb = hcd_urb_dequeue(default_pipe);
|
||||
TEST_ASSERT_EQUAL_PTR(urb_list[i], urb);
|
||||
TEST_ASSERT(urb->transfer.status == USB_TRANSFER_STATUS_COMPLETED || urb->transfer.status == USB_TRANSFER_STATUS_CANCELED);
|
||||
if (urb->transfer.status == USB_TRANSFER_STATUS_COMPLETED) {
|
||||
//We must have transmitted at least the setup packet, but device may return less than bytes requested
|
||||
// We must have transmitted at least the setup packet, but device may return less than bytes requested
|
||||
TEST_ASSERT_GREATER_OR_EQUAL(sizeof(usb_setup_packet_t), urb->transfer.actual_num_bytes);
|
||||
TEST_ASSERT_LESS_OR_EQUAL(urb->transfer.num_bytes, urb->transfer.actual_num_bytes);
|
||||
usb_config_desc_t *config_desc = (usb_config_desc_t *)(urb->transfer.data_buffer + sizeof(usb_setup_packet_t));
|
||||
TEST_ASSERT_EQUAL(USB_B_DESCRIPTOR_TYPE_CONFIGURATION, config_desc->bDescriptorType);
|
||||
printf("Config Desc wTotalLength %d\n", config_desc->wTotalLength);
|
||||
} else {
|
||||
//A failed transfer should 0 actual number of bytes transmitted
|
||||
// A failed transfer should 0 actual number of bytes transmitted
|
||||
TEST_ASSERT_EQUAL(0, urb->transfer.actual_num_bytes);
|
||||
}
|
||||
TEST_ASSERT_EQUAL(URB_CONTEXT_VAL, urb->transfer.context);
|
||||
}
|
||||
|
||||
//Free URB list and pipe
|
||||
// Free URB list and pipe
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
test_hcd_free_urb(urb_list[i]);
|
||||
}
|
||||
test_hcd_pipe_free(default_pipe);
|
||||
//Cleanup
|
||||
// Cleanup
|
||||
test_hcd_wait_for_disconn(port_hdl, false);
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "unity.h"
|
||||
#include "test_usb_mock_msc.h"
|
||||
#include "test_usb_mock_hid.h"
|
||||
#include "mock_msc.h"
|
||||
#include "mock_hid.h"
|
||||
#include "test_hcd_common.h"
|
||||
|
||||
// --------------------------------------------------- Test Cases ------------------------------------------------------
|
||||
@@ -41,14 +41,14 @@ Note: Some mice will NAK until it is moved, so try moving the mouse around if th
|
||||
|
||||
TEST_CASE("Test HCD interrupt pipe URBs", "[intr][low_speed]")
|
||||
{
|
||||
usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); //Trigger a connection
|
||||
usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); // Trigger a connection
|
||||
TEST_ASSERT_EQUAL_MESSAGE(TEST_HID_DEV_SPEED, port_speed, "Connected device is not Low Speed!");
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); //Short delay send of SOF (for FS) or EOPs (for LS)
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); // Short delay send of SOF (for FS) or EOPs (for LS)
|
||||
|
||||
hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc(port_hdl, NULL, 0, port_speed); //Create a default pipe (using a NULL EP descriptor)
|
||||
hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc(port_hdl, NULL, 0, port_speed); // Create a default pipe (using a NULL EP descriptor)
|
||||
uint8_t dev_addr = test_hcd_enum_device(default_pipe);
|
||||
|
||||
//Allocate interrupt pipe and URBS
|
||||
// Allocate interrupt pipe and URBS
|
||||
hcd_pipe_handle_t intr_pipe = test_hcd_pipe_alloc(port_hdl, &mock_hid_mouse_in_ep_desc, dev_addr, port_speed);
|
||||
urb_t *urb_list[NUM_URBS];
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
@@ -57,31 +57,31 @@ TEST_CASE("Test HCD interrupt pipe URBs", "[intr][low_speed]")
|
||||
urb_list[i]->transfer.context = URB_CONTEXT_VAL;
|
||||
}
|
||||
|
||||
//Enqueue URBs
|
||||
// Enqueue URBs
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_urb_enqueue(intr_pipe, urb_list[i]));
|
||||
}
|
||||
int iter_count = NUM_URB_ITERS;
|
||||
for (iter_count = NUM_URB_ITERS; iter_count > 0; iter_count--) {
|
||||
//Wait for an URB to be done
|
||||
// Wait for an URB to be done
|
||||
test_hcd_expect_pipe_event(intr_pipe, HCD_PIPE_EVENT_URB_DONE);
|
||||
//Dequeue the URB and check results
|
||||
// Dequeue the URB and check results
|
||||
urb_t *urb = hcd_urb_dequeue(intr_pipe);
|
||||
TEST_ASSERT_EQUAL_MESSAGE(USB_TRANSFER_STATUS_COMPLETED, urb->transfer.status, "Transfer NOT completed");
|
||||
TEST_ASSERT_EQUAL(URB_CONTEXT_VAL, urb->transfer.context);
|
||||
mock_hid_process_report((mock_hid_mouse_report_t *)urb->transfer.data_buffer, iter_count);
|
||||
//Requeue URB
|
||||
// Requeue URB
|
||||
if (iter_count > NUM_URBS) {
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_urb_enqueue(intr_pipe, urb));
|
||||
}
|
||||
}
|
||||
|
||||
//Free URB list and pipe
|
||||
// Free URB list and pipe
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
test_hcd_free_urb(urb_list[i]);
|
||||
}
|
||||
test_hcd_pipe_free(intr_pipe);
|
||||
test_hcd_pipe_free(default_pipe);
|
||||
//Clearnup
|
||||
// Clearnup
|
||||
test_hcd_wait_for_disconn(port_hdl, false);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "unity.h"
|
||||
#include "test_usb_mock_msc.h"
|
||||
#include "mock_msc.h"
|
||||
#include "test_usb_common.h"
|
||||
#include "test_hcd_common.h"
|
||||
|
||||
@@ -43,57 +43,57 @@ Procedure:
|
||||
|
||||
TEST_CASE("Test HCD isochronous pipe URBs", "[isoc][full_speed]")
|
||||
{
|
||||
usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); //Trigger a connection
|
||||
//The MPS of the ISOC OUT pipe is quite large, so we need to bias the FIFO sizing
|
||||
usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); // Trigger a connection
|
||||
// The MPS of the ISOC OUT pipe is quite large, so we need to bias the FIFO sizing
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_port_set_fifo_bias(port_hdl, HCD_PORT_FIFO_BIAS_PTX));
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); //Short delay send of SOF (for FS) or EOPs (for LS)
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); // Short delay send of SOF (for FS) or EOPs (for LS)
|
||||
|
||||
//Enumerate and reset device
|
||||
hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc(port_hdl, NULL, 0, port_speed); //Create a default pipe (using a NULL EP descriptor)
|
||||
// Enumerate and reset device
|
||||
hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc(port_hdl, NULL, 0, port_speed); // Create a default pipe (using a NULL EP descriptor)
|
||||
uint8_t dev_addr = test_hcd_enum_device(default_pipe);
|
||||
|
||||
//Create ISOC OUT pipe to non-existent device
|
||||
// Create ISOC OUT pipe to non-existent device
|
||||
hcd_pipe_handle_t isoc_out_pipe = test_hcd_pipe_alloc(port_hdl, &mock_isoc_out_ep_desc, dev_addr + 1, port_speed);
|
||||
//Create URBs
|
||||
// Create URBs
|
||||
urb_t *urb_list[NUM_URBS];
|
||||
//Initialize URBs
|
||||
// Initialize URBs
|
||||
for (int urb_idx = 0; urb_idx < NUM_URBS; urb_idx++) {
|
||||
urb_list[urb_idx] = test_hcd_alloc_urb(NUM_PACKETS_PER_URB, URB_DATA_BUFF_SIZE);
|
||||
urb_list[urb_idx]->transfer.num_bytes = URB_DATA_BUFF_SIZE;
|
||||
urb_list[urb_idx]->transfer.context = URB_CONTEXT_VAL;
|
||||
for (int pkt_idx = 0; pkt_idx < NUM_PACKETS_PER_URB; pkt_idx++) {
|
||||
urb_list[urb_idx]->transfer.isoc_packet_desc[pkt_idx].num_bytes = ISOC_PACKET_SIZE;
|
||||
//Each packet will consist of the same byte, but each subsequent packet's byte will increment (i.e., packet 0 transmits all 0x0, packet 1 transmits all 0x1)
|
||||
// Each packet will consist of the same byte, but each subsequent packet's byte will increment (i.e., packet 0 transmits all 0x0, packet 1 transmits all 0x1)
|
||||
memset(&urb_list[urb_idx]->transfer.data_buffer[pkt_idx * ISOC_PACKET_SIZE], (urb_idx * NUM_URBS) + pkt_idx, ISOC_PACKET_SIZE);
|
||||
}
|
||||
}
|
||||
//Enqueue URBs
|
||||
// Enqueue URBs
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_urb_enqueue(isoc_out_pipe, urb_list[i]));
|
||||
}
|
||||
//Wait for each done event from each URB
|
||||
// Wait for each done event from each URB
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
test_hcd_expect_pipe_event(isoc_out_pipe, HCD_PIPE_EVENT_URB_DONE);
|
||||
}
|
||||
//Dequeue URBs
|
||||
// Dequeue URBs
|
||||
for (int urb_idx = 0; urb_idx < NUM_URBS; urb_idx++) {
|
||||
urb_t *urb = hcd_urb_dequeue(isoc_out_pipe);
|
||||
TEST_ASSERT_EQUAL(urb_list[urb_idx], urb);
|
||||
TEST_ASSERT_EQUAL(URB_CONTEXT_VAL, urb->transfer.context);
|
||||
//Overall URB status and overall number of bytes
|
||||
// Overall URB status and overall number of bytes
|
||||
TEST_ASSERT_EQUAL(URB_DATA_BUFF_SIZE, urb->transfer.actual_num_bytes);
|
||||
TEST_ASSERT_EQUAL_MESSAGE(USB_TRANSFER_STATUS_COMPLETED, urb->transfer.status, "Transfer NOT completed");
|
||||
for (int pkt_idx = 0; pkt_idx < NUM_PACKETS_PER_URB; pkt_idx++) {
|
||||
TEST_ASSERT_EQUAL_MESSAGE(USB_TRANSFER_STATUS_COMPLETED, urb->transfer.isoc_packet_desc[pkt_idx].status, "Transfer NOT completed");
|
||||
}
|
||||
}
|
||||
//Free URB list and pipe
|
||||
// Free URB list and pipe
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
test_hcd_free_urb(urb_list[i]);
|
||||
}
|
||||
test_hcd_pipe_free(isoc_out_pipe);
|
||||
test_hcd_pipe_free(default_pipe);
|
||||
//Cleanup
|
||||
// Cleanup
|
||||
test_hcd_wait_for_disconn(port_hdl, false);
|
||||
}
|
||||
|
||||
@@ -116,13 +116,13 @@ Procedure:
|
||||
*/
|
||||
TEST_CASE("Test HCD isochronous pipe URBs all", "[isoc][full_speed]")
|
||||
{
|
||||
usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); //Trigger a connection
|
||||
//The MPS of the ISOC OUT pipe is quite large, so we need to bias the FIFO sizing
|
||||
usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); // Trigger a connection
|
||||
// The MPS of the ISOC OUT pipe is quite large, so we need to bias the FIFO sizing
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_port_set_fifo_bias(port_hdl, HCD_PORT_FIFO_BIAS_PTX));
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); //Short delay send of SOF (for FS) or EOPs (for LS)
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); // Short delay send of SOF (for FS) or EOPs (for LS)
|
||||
|
||||
//Enumerate and reset device
|
||||
hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc(port_hdl, NULL, 0, port_speed); //Create a default pipe (using a NULL EP descriptor)
|
||||
// Enumerate and reset device
|
||||
hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc(port_hdl, NULL, 0, port_speed); // Create a default pipe (using a NULL EP descriptor)
|
||||
uint8_t dev_addr = test_hcd_enum_device(default_pipe);
|
||||
|
||||
urb_t *urb_list[NUM_URBS];
|
||||
@@ -141,20 +141,20 @@ TEST_CASE("Test HCD isochronous pipe URBs all", "[isoc][full_speed]")
|
||||
vTaskDelay(5);
|
||||
unsigned num_packets_per_urb = 32; // This is maximum number of packets if interval = 1. This is limited by FRAME_LIST_LEN
|
||||
num_packets_per_urb >>= (interval - 1);
|
||||
//Create ISOC OUT pipe
|
||||
// Create ISOC OUT pipe
|
||||
usb_ep_desc_t isoc_out_ep = mock_isoc_out_ep_desc; // Implicit copy
|
||||
isoc_out_ep.bInterval = interval;
|
||||
isoc_out_ep.bEndpointAddress = interval; // So you can see the bInterval value in trace
|
||||
hcd_pipe_handle_t isoc_out_pipe = test_hcd_pipe_alloc(port_hdl, &isoc_out_ep, channel + 1, port_speed); // Channel number represented in dev_num, so you can see it in trace
|
||||
|
||||
//Initialize URBs
|
||||
// Initialize URBs
|
||||
for (int urb_idx = 0; urb_idx < NUM_URBS; urb_idx++) {
|
||||
urb_list[urb_idx] = test_hcd_alloc_urb(num_packets_per_urb, num_packets_per_urb * ISOC_PACKET_SIZE);
|
||||
urb_list[urb_idx]->transfer.num_bytes = num_packets_per_urb * ISOC_PACKET_SIZE;
|
||||
urb_list[urb_idx]->transfer.context = URB_CONTEXT_VAL;
|
||||
for (int pkt_idx = 0; pkt_idx < num_packets_per_urb; pkt_idx++) {
|
||||
urb_list[urb_idx]->transfer.isoc_packet_desc[pkt_idx].num_bytes = ISOC_PACKET_SIZE;
|
||||
//Each packet will consist of the same byte, but each subsequent packet's byte will increment (i.e., packet 0 transmits all 0x0, packet 1 transmits all 0x1)
|
||||
// Each packet will consist of the same byte, but each subsequent packet's byte will increment (i.e., packet 0 transmits all 0x0, packet 1 transmits all 0x1)
|
||||
memset(&urb_list[urb_idx]->transfer.data_buffer[pkt_idx * ISOC_PACKET_SIZE], (urb_idx * num_packets_per_urb) + pkt_idx, ISOC_PACKET_SIZE);
|
||||
}
|
||||
}
|
||||
@@ -162,27 +162,27 @@ TEST_CASE("Test HCD isochronous pipe URBs all", "[isoc][full_speed]")
|
||||
// Add a delay so we start scheduling the transactions at different time in USB frame
|
||||
esp_rom_delay_us(ENQUEUE_DELAY * interval + ENQUEUE_DELAY * channel);
|
||||
|
||||
//Enqueue URBs
|
||||
// Enqueue URBs
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_urb_enqueue(isoc_out_pipe, urb_list[i]));
|
||||
}
|
||||
//Wait for each done event from each URB
|
||||
// Wait for each done event from each URB
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
test_hcd_expect_pipe_event(isoc_out_pipe, HCD_PIPE_EVENT_URB_DONE);
|
||||
}
|
||||
//Dequeue URBs
|
||||
// Dequeue URBs
|
||||
for (int urb_idx = 0; urb_idx < NUM_URBS; urb_idx++) {
|
||||
urb_t *urb = hcd_urb_dequeue(isoc_out_pipe);
|
||||
TEST_ASSERT_EQUAL(urb_list[urb_idx], urb);
|
||||
TEST_ASSERT_EQUAL(URB_CONTEXT_VAL, urb->transfer.context);
|
||||
//Overall URB status and overall number of bytes
|
||||
// Overall URB status and overall number of bytes
|
||||
TEST_ASSERT_EQUAL(num_packets_per_urb * ISOC_PACKET_SIZE, urb->transfer.actual_num_bytes);
|
||||
TEST_ASSERT_EQUAL_MESSAGE(USB_TRANSFER_STATUS_COMPLETED, urb->transfer.status, "Transfer NOT completed");
|
||||
for (int pkt_idx = 0; pkt_idx < num_packets_per_urb; pkt_idx++) {
|
||||
TEST_ASSERT_EQUAL_MESSAGE(USB_TRANSFER_STATUS_COMPLETED, urb->transfer.isoc_packet_desc[pkt_idx].status, "Transfer NOT completed");
|
||||
}
|
||||
}
|
||||
//Free URB list and pipe
|
||||
// Free URB list and pipe
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
test_hcd_free_urb(urb_list[i]);
|
||||
}
|
||||
@@ -195,7 +195,7 @@ TEST_CASE("Test HCD isochronous pipe URBs all", "[isoc][full_speed]")
|
||||
}
|
||||
}
|
||||
test_hcd_pipe_free(default_pipe);
|
||||
//Cleanup
|
||||
// Cleanup
|
||||
test_hcd_wait_for_disconn(port_hdl, false);
|
||||
}
|
||||
|
||||
@@ -225,65 +225,65 @@ Procedure:
|
||||
*/
|
||||
TEST_CASE("Test HCD isochronous pipe sudden disconnect", "[isoc][full_speed]")
|
||||
{
|
||||
usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); //Trigger a connection
|
||||
//The MPS of the ISOC OUT pipe is quite large, so we need to bias the FIFO sizing
|
||||
usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); // Trigger a connection
|
||||
// The MPS of the ISOC OUT pipe is quite large, so we need to bias the FIFO sizing
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_port_set_fifo_bias(port_hdl, HCD_PORT_FIFO_BIAS_PTX));
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); //Short delay send of SOF (for FS) or EOPs (for LS)
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); // Short delay send of SOF (for FS) or EOPs (for LS)
|
||||
|
||||
//Enumerate and reset device
|
||||
hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc(port_hdl, NULL, 0, port_speed); //Create a default pipe (using a NULL EP descriptor)
|
||||
// Enumerate and reset device
|
||||
hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc(port_hdl, NULL, 0, port_speed); // Create a default pipe (using a NULL EP descriptor)
|
||||
uint8_t dev_addr = test_hcd_enum_device(default_pipe);
|
||||
|
||||
//Create ISOC OUT pipe to non-existent device
|
||||
// Create ISOC OUT pipe to non-existent device
|
||||
hcd_pipe_handle_t isoc_out_pipe = test_hcd_pipe_alloc(port_hdl, &mock_isoc_out_ep_desc, dev_addr + 1, port_speed);
|
||||
//Create URBs
|
||||
// Create URBs
|
||||
urb_t *urb_list[NUM_URBS];
|
||||
//Initialize URBs
|
||||
// Initialize URBs
|
||||
for (int urb_idx = 0; urb_idx < NUM_URBS; urb_idx++) {
|
||||
urb_list[urb_idx] = test_hcd_alloc_urb(NUM_PACKETS_PER_URB, URB_DATA_BUFF_SIZE);
|
||||
urb_list[urb_idx]->transfer.num_bytes = URB_DATA_BUFF_SIZE;
|
||||
urb_list[urb_idx]->transfer.context = URB_CONTEXT_VAL;
|
||||
for (int pkt_idx = 0; pkt_idx < NUM_PACKETS_PER_URB; pkt_idx++) {
|
||||
urb_list[urb_idx]->transfer.isoc_packet_desc[pkt_idx].num_bytes = ISOC_PACKET_SIZE;
|
||||
//Each packet will consist of the same byte, but each subsequent packet's byte will increment (i.e., packet 0 transmits all 0x0, packet 1 transmits all 0x1)
|
||||
// Each packet will consist of the same byte, but each subsequent packet's byte will increment (i.e., packet 0 transmits all 0x0, packet 1 transmits all 0x1)
|
||||
memset(&urb_list[urb_idx]->transfer.data_buffer[pkt_idx * ISOC_PACKET_SIZE], (urb_idx * NUM_URBS) + pkt_idx, ISOC_PACKET_SIZE);
|
||||
}
|
||||
}
|
||||
//Enqueue URBs
|
||||
// Enqueue URBs
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_urb_enqueue(isoc_out_pipe, urb_list[i]));
|
||||
}
|
||||
//Add a short delay to let the transfers run for a bit
|
||||
// Add a short delay to let the transfers run for a bit
|
||||
esp_rom_delay_us(POST_ENQUEUE_DELAY_US);
|
||||
test_usb_set_phy_state(false, 0);
|
||||
//Disconnect event should have occurred. Handle the port event
|
||||
// Disconnect event should have occurred. Handle the port event
|
||||
test_hcd_expect_port_event(port_hdl, HCD_PORT_EVENT_DISCONNECTION);
|
||||
TEST_ASSERT_EQUAL(HCD_PORT_EVENT_DISCONNECTION, hcd_port_handle_event(port_hdl));
|
||||
TEST_ASSERT_EQUAL(HCD_PORT_STATE_RECOVERY, hcd_port_get_state(port_hdl));
|
||||
printf("Sudden disconnect\n");
|
||||
|
||||
//Both pipes should still be active
|
||||
// Both pipes should still be active
|
||||
TEST_ASSERT_EQUAL(HCD_PIPE_STATE_ACTIVE, hcd_pipe_get_state(default_pipe));
|
||||
TEST_ASSERT_EQUAL(HCD_PIPE_STATE_ACTIVE, hcd_pipe_get_state(isoc_out_pipe));
|
||||
//Halt both pipes
|
||||
// Halt both pipes
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_pipe_command(default_pipe, HCD_PIPE_CMD_HALT));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_pipe_command(isoc_out_pipe, HCD_PIPE_CMD_HALT));
|
||||
TEST_ASSERT_EQUAL(HCD_PIPE_STATE_HALTED, hcd_pipe_get_state(default_pipe));
|
||||
TEST_ASSERT_EQUAL(HCD_PIPE_STATE_HALTED, hcd_pipe_get_state(isoc_out_pipe));
|
||||
//Flush both pipes. ISOC pipe should return completed URBs
|
||||
// Flush both pipes. ISOC pipe should return completed URBs
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_pipe_command(default_pipe, HCD_PIPE_CMD_FLUSH));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_pipe_command(isoc_out_pipe, HCD_PIPE_CMD_FLUSH));
|
||||
|
||||
//Dequeue ISOC URBs
|
||||
// Dequeue ISOC URBs
|
||||
for (int urb_idx = 0; urb_idx < NUM_URBS; urb_idx++) {
|
||||
urb_t *urb = hcd_urb_dequeue(isoc_out_pipe);
|
||||
TEST_ASSERT_EQUAL(urb_list[urb_idx], urb);
|
||||
TEST_ASSERT_EQUAL(URB_CONTEXT_VAL, urb->transfer.context);
|
||||
//The URB has either completed entirely or is marked as no_device
|
||||
// The URB has either completed entirely or is marked as no_device
|
||||
TEST_ASSERT(urb->transfer.status == USB_TRANSFER_STATUS_COMPLETED || urb->transfer.status == USB_TRANSFER_STATUS_NO_DEVICE);
|
||||
}
|
||||
|
||||
//Free URB list and pipe
|
||||
// Free URB list and pipe
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
test_hcd_free_urb(urb_list[i]);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#define TEST_DEV_ADDR 0
|
||||
#define NUM_URBS 3
|
||||
#define TRANSFER_MAX_BYTES 256
|
||||
#define URB_DATA_BUFF_SIZE (sizeof(usb_setup_packet_t) + TRANSFER_MAX_BYTES) //256 is worst case size for configuration descriptors
|
||||
#define URB_DATA_BUFF_SIZE (sizeof(usb_setup_packet_t) + TRANSFER_MAX_BYTES) // 256 is worst case size for configuration descriptors
|
||||
#define POST_ENQUEUE_DELAY_US 10
|
||||
|
||||
/*
|
||||
@@ -43,35 +43,35 @@ Procedure:
|
||||
|
||||
TEST_CASE("Test HCD port sudden disconnect", "[port][low_speed][full_speed]")
|
||||
{
|
||||
usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); //Trigger a connection
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); //Short delay send of SOF (for FS) or EOPs (for LS)
|
||||
usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); // Trigger a connection
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); // Short delay send of SOF (for FS) or EOPs (for LS)
|
||||
|
||||
//Allocate some URBs and initialize their data buffers with control transfers
|
||||
hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc(port_hdl, NULL, TEST_DEV_ADDR, port_speed); //Create a default pipe (using a NULL EP descriptor)
|
||||
// Allocate some URBs and initialize their data buffers with control transfers
|
||||
hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc(port_hdl, NULL, TEST_DEV_ADDR, port_speed); // Create a default pipe (using a NULL EP descriptor)
|
||||
urb_t *urb_list[NUM_URBS];
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
urb_list[i] = test_hcd_alloc_urb(0, URB_DATA_BUFF_SIZE);
|
||||
//Initialize with a "Get Config Descriptor request"
|
||||
// Initialize with a "Get Config Descriptor request"
|
||||
urb_list[i]->transfer.num_bytes = sizeof(usb_setup_packet_t) + TRANSFER_MAX_BYTES;
|
||||
USB_SETUP_PACKET_INIT_GET_CONFIG_DESC((usb_setup_packet_t *)urb_list[i]->transfer.data_buffer, 0, TRANSFER_MAX_BYTES);
|
||||
urb_list[i]->transfer.context = (void *)0xDEADBEEF;
|
||||
}
|
||||
|
||||
//Enqueue URBs but immediately trigger a disconnect
|
||||
// Enqueue URBs but immediately trigger a disconnect
|
||||
printf("Enqueuing URBs\n");
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_urb_enqueue(default_pipe, urb_list[i]));
|
||||
}
|
||||
//Add a short delay to let the transfers run for a bit
|
||||
// Add a short delay to let the transfers run for a bit
|
||||
esp_rom_delay_us(POST_ENQUEUE_DELAY_US);
|
||||
test_usb_set_phy_state(false, 0);
|
||||
//Disconnect event should have occurred. Handle the port event
|
||||
// Disconnect event should have occurred. Handle the port event
|
||||
test_hcd_expect_port_event(port_hdl, HCD_PORT_EVENT_DISCONNECTION);
|
||||
TEST_ASSERT_EQUAL(HCD_PORT_EVENT_DISCONNECTION, hcd_port_handle_event(port_hdl));
|
||||
TEST_ASSERT_EQUAL(HCD_PORT_STATE_RECOVERY, hcd_port_get_state(port_hdl));
|
||||
printf("Sudden disconnect\n");
|
||||
|
||||
//We should be able to halt then flush the pipe
|
||||
// We should be able to halt then flush the pipe
|
||||
TEST_ASSERT_EQUAL(HCD_PIPE_STATE_ACTIVE, hcd_pipe_get_state(default_pipe));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_pipe_command(default_pipe, HCD_PIPE_CMD_HALT));
|
||||
printf("Pipe halted\n");
|
||||
@@ -80,32 +80,32 @@ TEST_CASE("Test HCD port sudden disconnect", "[port][low_speed][full_speed]")
|
||||
test_hcd_expect_pipe_event(default_pipe, HCD_PIPE_EVENT_URB_DONE);
|
||||
printf("Pipe flushed\n");
|
||||
|
||||
//Dequeue URBs
|
||||
// Dequeue URBs
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
urb_t *urb = hcd_urb_dequeue(default_pipe);
|
||||
TEST_ASSERT_EQUAL(urb_list[i], urb);
|
||||
TEST_ASSERT(urb->transfer.status == USB_TRANSFER_STATUS_COMPLETED || urb->transfer.status == USB_TRANSFER_STATUS_NO_DEVICE);
|
||||
if (urb->transfer.status == USB_TRANSFER_STATUS_COMPLETED) {
|
||||
//We must have transmitted at least the setup packet, but device may return less than bytes requested
|
||||
// We must have transmitted at least the setup packet, but device may return less than bytes requested
|
||||
TEST_ASSERT_GREATER_OR_EQUAL(sizeof(usb_setup_packet_t), urb->transfer.actual_num_bytes);
|
||||
TEST_ASSERT_LESS_OR_EQUAL(urb->transfer.num_bytes, urb->transfer.actual_num_bytes);
|
||||
} else {
|
||||
//A failed transfer should 0 actual number of bytes transmitted
|
||||
// A failed transfer should 0 actual number of bytes transmitted
|
||||
TEST_ASSERT_EQUAL(0, urb->transfer.actual_num_bytes);
|
||||
}
|
||||
TEST_ASSERT_EQUAL(0xDEADBEEF, urb->transfer.context);
|
||||
}
|
||||
//Free URB list and pipe
|
||||
// Free URB list and pipe
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
test_hcd_free_urb(urb_list[i]);
|
||||
}
|
||||
test_hcd_pipe_free(default_pipe);
|
||||
|
||||
//Recover the port should return to the to NOT POWERED state
|
||||
// Recover the port should return to the to NOT POWERED state
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_port_recover(port_hdl));
|
||||
TEST_ASSERT_EQUAL(HCD_PORT_STATE_NOT_POWERED, hcd_port_get_state(port_hdl));
|
||||
|
||||
//Recovered port should be able to connect and disconnect again
|
||||
// Recovered port should be able to connect and disconnect again
|
||||
test_hcd_wait_for_conn(port_hdl);
|
||||
test_hcd_wait_for_disconn(port_hdl, false);
|
||||
}
|
||||
@@ -132,38 +132,38 @@ Procedure:
|
||||
*/
|
||||
TEST_CASE("Test HCD port suspend and resume", "[port][low_speed][full_speed]")
|
||||
{
|
||||
usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); //Trigger a connection
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); //Short delay send of SOF (for FS) or EOPs (for LS)
|
||||
usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); // Trigger a connection
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); // Short delay send of SOF (for FS) or EOPs (for LS)
|
||||
|
||||
//Allocate some URBs and initialize their data buffers with control transfers
|
||||
hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc(port_hdl, NULL, TEST_DEV_ADDR, port_speed); //Create a default pipe (using a NULL EP descriptor)
|
||||
// Allocate some URBs and initialize their data buffers with control transfers
|
||||
hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc(port_hdl, NULL, TEST_DEV_ADDR, port_speed); // Create a default pipe (using a NULL EP descriptor)
|
||||
|
||||
//Test that suspending the port now fails as there is an active pipe
|
||||
// Test that suspending the port now fails as there is an active pipe
|
||||
TEST_ASSERT_NOT_EQUAL(ESP_OK, hcd_port_command(port_hdl, HCD_PORT_CMD_SUSPEND));
|
||||
|
||||
//Halt the default pipe before suspending
|
||||
// Halt the default pipe before suspending
|
||||
TEST_ASSERT_EQUAL(HCD_PIPE_STATE_ACTIVE, hcd_pipe_get_state(default_pipe));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_pipe_command(default_pipe, HCD_PIPE_CMD_HALT));
|
||||
TEST_ASSERT_EQUAL(HCD_PIPE_STATE_HALTED, hcd_pipe_get_state(default_pipe));
|
||||
|
||||
//Suspend the port
|
||||
// Suspend the port
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_port_command(port_hdl, HCD_PORT_CMD_SUSPEND));
|
||||
TEST_ASSERT_EQUAL(HCD_PORT_STATE_SUSPENDED, hcd_port_get_state(port_hdl));
|
||||
printf("Suspended\n");
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); //Give some time for bus to remain suspended
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); // Give some time for bus to remain suspended
|
||||
|
||||
//Resume the port
|
||||
// Resume the port
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_port_command(port_hdl, HCD_PORT_CMD_RESUME));
|
||||
TEST_ASSERT_EQUAL(HCD_PORT_STATE_ENABLED, hcd_port_get_state(port_hdl));
|
||||
printf("Resumed\n");
|
||||
|
||||
//Clear the default pipe's halt
|
||||
// Clear the default pipe's halt
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_pipe_command(default_pipe, HCD_PIPE_CMD_CLEAR));
|
||||
TEST_ASSERT_EQUAL(HCD_PIPE_STATE_ACTIVE, hcd_pipe_get_state(default_pipe));
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); //Give some time for resumed URBs to complete
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); // Give some time for resumed URBs to complete
|
||||
|
||||
test_hcd_pipe_free(default_pipe);
|
||||
//Cleanup
|
||||
// Cleanup
|
||||
test_hcd_wait_for_disconn(port_hdl, false);
|
||||
}
|
||||
|
||||
@@ -186,65 +186,65 @@ Procedure:
|
||||
*/
|
||||
TEST_CASE("Test HCD port disable", "[port][low_speed][full_speed]")
|
||||
{
|
||||
usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); //Trigger a connection
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); //Short delay send of SOF (for FS) or EOPs (for LS)
|
||||
usb_speed_t port_speed = test_hcd_wait_for_conn(port_hdl); // Trigger a connection
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); // Short delay send of SOF (for FS) or EOPs (for LS)
|
||||
|
||||
//Allocate some URBs and initialize their data buffers with control transfers
|
||||
hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc(port_hdl, NULL, TEST_DEV_ADDR, port_speed); //Create a default pipe (using a NULL EP descriptor)
|
||||
// Allocate some URBs and initialize their data buffers with control transfers
|
||||
hcd_pipe_handle_t default_pipe = test_hcd_pipe_alloc(port_hdl, NULL, TEST_DEV_ADDR, port_speed); // Create a default pipe (using a NULL EP descriptor)
|
||||
urb_t *urb_list[NUM_URBS];
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
urb_list[i] = test_hcd_alloc_urb(0, URB_DATA_BUFF_SIZE);
|
||||
//Initialize with a "Get Config Descriptor request"
|
||||
// Initialize with a "Get Config Descriptor request"
|
||||
urb_list[i]->transfer.num_bytes = sizeof(usb_setup_packet_t) + TRANSFER_MAX_BYTES;
|
||||
USB_SETUP_PACKET_INIT_GET_CONFIG_DESC((usb_setup_packet_t *)urb_list[i]->transfer.data_buffer, 0, TRANSFER_MAX_BYTES);
|
||||
urb_list[i]->transfer.context = (void *)0xDEADBEEF;
|
||||
}
|
||||
|
||||
//Enqueue URBs but immediately disable the port
|
||||
// Enqueue URBs but immediately disable the port
|
||||
printf("Enqueuing URBs\n");
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_urb_enqueue(default_pipe, urb_list[i]));
|
||||
//Add a short delay to let the transfers run for a bit
|
||||
// Add a short delay to let the transfers run for a bit
|
||||
esp_rom_delay_us(POST_ENQUEUE_DELAY_US);
|
||||
}
|
||||
|
||||
//Halt the default pipe before suspending
|
||||
// Halt the default pipe before suspending
|
||||
TEST_ASSERT_EQUAL(HCD_PIPE_STATE_ACTIVE, hcd_pipe_get_state(default_pipe));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_pipe_command(default_pipe, HCD_PIPE_CMD_HALT));
|
||||
TEST_ASSERT_EQUAL(HCD_PIPE_STATE_HALTED, hcd_pipe_get_state(default_pipe));
|
||||
|
||||
//Check that port can be disabled
|
||||
// Check that port can be disabled
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_port_command(port_hdl, HCD_PORT_CMD_DISABLE));
|
||||
TEST_ASSERT_EQUAL(HCD_PORT_STATE_DISABLED, hcd_port_get_state(port_hdl));
|
||||
printf("Disabled\n");
|
||||
|
||||
//Flush pipe
|
||||
// Flush pipe
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_pipe_command(default_pipe, HCD_PIPE_CMD_FLUSH));
|
||||
//Dequeue URBs
|
||||
// Dequeue URBs
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
urb_t *urb = hcd_urb_dequeue(default_pipe);
|
||||
TEST_ASSERT_EQUAL(urb_list[i], urb);
|
||||
TEST_ASSERT(urb->transfer.status == USB_TRANSFER_STATUS_COMPLETED || //The transfer completed before the pipe halted
|
||||
urb->transfer.status == USB_TRANSFER_STATUS_CANCELED || //The transfer was stopped mid-way by the halt
|
||||
urb->transfer.status == USB_TRANSFER_STATUS_NO_DEVICE); //The transfer was never started
|
||||
TEST_ASSERT(urb->transfer.status == USB_TRANSFER_STATUS_COMPLETED || // The transfer completed before the pipe halted
|
||||
urb->transfer.status == USB_TRANSFER_STATUS_CANCELED || // The transfer was stopped mid-way by the halt
|
||||
urb->transfer.status == USB_TRANSFER_STATUS_NO_DEVICE); // The transfer was never started
|
||||
if (urb->transfer.status == USB_TRANSFER_STATUS_COMPLETED) {
|
||||
//We must have transmitted at least the setup packet, but device may return less than bytes requested
|
||||
// We must have transmitted at least the setup packet, but device may return less than bytes requested
|
||||
TEST_ASSERT_GREATER_OR_EQUAL(sizeof(usb_setup_packet_t), urb->transfer.actual_num_bytes);
|
||||
TEST_ASSERT_LESS_OR_EQUAL(urb->transfer.num_bytes, urb->transfer.actual_num_bytes);
|
||||
} else {
|
||||
//A failed transfer should 0 actual number of bytes transmitted
|
||||
// A failed transfer should 0 actual number of bytes transmitted
|
||||
TEST_ASSERT_EQUAL(0, urb->transfer.actual_num_bytes);
|
||||
}
|
||||
TEST_ASSERT_EQUAL(0xDEADBEEF, urb->transfer.context);
|
||||
}
|
||||
|
||||
//Free URB list and pipe
|
||||
// Free URB list and pipe
|
||||
for (int i = 0; i < NUM_URBS; i++) {
|
||||
test_hcd_free_urb(urb_list[i]);
|
||||
}
|
||||
test_hcd_pipe_free(default_pipe);
|
||||
|
||||
//Trigger a disconnection and cleanup
|
||||
// Trigger a disconnection and cleanup
|
||||
test_hcd_wait_for_disconn(port_hdl, true);
|
||||
}
|
||||
|
||||
@@ -266,40 +266,40 @@ static void concurrent_task(void *arg)
|
||||
{
|
||||
SemaphoreHandle_t sync_sem = (SemaphoreHandle_t) arg;
|
||||
xSemaphoreTake(sync_sem, portMAX_DELAY);
|
||||
vTaskDelay(pdMS_TO_TICKS(10)); //Give a short delay let reset command start in main thread
|
||||
//Force a disconnection
|
||||
vTaskDelay(pdMS_TO_TICKS(10)); // Give a short delay let reset command start in main thread
|
||||
// Force a disconnection
|
||||
test_usb_set_phy_state(false, 0);
|
||||
vTaskDelay(portMAX_DELAY); //Block forever and wait to be deleted
|
||||
vTaskDelay(portMAX_DELAY); // Block forever and wait to be deleted
|
||||
}
|
||||
|
||||
TEST_CASE("Test HCD port command bailout", "[port][low_speed][full_speed]")
|
||||
{
|
||||
test_hcd_wait_for_conn(port_hdl); //Trigger a connection
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); //Short delay send of SOF (for FS) or EOPs (for LS)
|
||||
test_hcd_wait_for_conn(port_hdl); // Trigger a connection
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); // Short delay send of SOF (for FS) or EOPs (for LS)
|
||||
|
||||
//Create task to run port commands concurrently
|
||||
// Create task to run port commands concurrently
|
||||
SemaphoreHandle_t sync_sem = xSemaphoreCreateBinary();
|
||||
TaskHandle_t task_handle;
|
||||
TEST_ASSERT_NOT_NULL(sync_sem);
|
||||
TEST_ASSERT_EQUAL(pdTRUE, xTaskCreatePinnedToCore(concurrent_task, "tsk", 4096, (void *) sync_sem, uxTaskPriorityGet(NULL) + 1, &task_handle, 0));
|
||||
|
||||
//Suspend the device
|
||||
// Suspend the device
|
||||
printf("Suspending\n");
|
||||
TEST_ASSERT_EQUAL(ESP_OK, hcd_port_command(port_hdl, HCD_PORT_CMD_SUSPEND));
|
||||
vTaskDelay(pdMS_TO_TICKS(20)); //Short delay for device to enter suspend state
|
||||
vTaskDelay(pdMS_TO_TICKS(20)); // Short delay for device to enter suspend state
|
||||
|
||||
//Attempt to resume the port. But the concurrent task should override this with a disconnection event
|
||||
// Attempt to resume the port. But the concurrent task should override this with a disconnection event
|
||||
printf("Attempting to resume\n");
|
||||
xSemaphoreGive(sync_sem); //Trigger concurrent task
|
||||
xSemaphoreGive(sync_sem); // Trigger concurrent task
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_RESPONSE, hcd_port_command(port_hdl, HCD_PORT_CMD_RESUME));
|
||||
|
||||
//Check that concurrent task triggered a sudden disconnection
|
||||
// Check that concurrent task triggered a sudden disconnection
|
||||
test_hcd_expect_port_event(port_hdl, HCD_PORT_EVENT_DISCONNECTION);
|
||||
TEST_ASSERT_EQUAL(HCD_PORT_EVENT_DISCONNECTION, hcd_port_handle_event(port_hdl));
|
||||
TEST_ASSERT_EQUAL(HCD_PORT_STATE_RECOVERY, hcd_port_get_state(port_hdl));
|
||||
|
||||
//Cleanup task and semaphore
|
||||
vTaskDelay(pdMS_TO_TICKS(10)); //Short delay for concurrent task finish running
|
||||
// Cleanup task and semaphore
|
||||
vTaskDelay(pdMS_TO_TICKS(10)); // Short delay for concurrent task finish running
|
||||
vTaskDelete(task_handle);
|
||||
vSemaphoreDelete(sync_sem);
|
||||
}
|
||||
|
||||
@@ -333,7 +333,7 @@ static uint8_t config_desc_bytes [] = {
|
||||
};
|
||||
_Static_assert(sizeof(config_desc_bytes) == 0x0185, "Configuration Descriptor size does not match");
|
||||
|
||||
#define TEST_NUM_INTF_DESC 3 //Total number of interface descriptors (including alternate)
|
||||
#define TEST_NUM_INTF_DESC 3 // Total number of interface descriptors (including alternate)
|
||||
|
||||
// --------------------- Sub-Test 1 ------------------------
|
||||
|
||||
@@ -348,7 +348,7 @@ static void test_walk_desc(const usb_config_desc_t *config_desc)
|
||||
cur_desc = usb_parse_next_descriptor_of_type(cur_desc, config_desc->wTotalLength, USB_B_DESCRIPTOR_TYPE_INTERFACE, &offset);
|
||||
TEST_ASSERT_NOT_NULL(cur_desc);
|
||||
}
|
||||
//Attempting to look for another interface descriptor should result in NULL
|
||||
// Attempting to look for another interface descriptor should result in NULL
|
||||
cur_desc = usb_parse_next_descriptor_of_type(cur_desc, config_desc->wTotalLength, USB_B_DESCRIPTOR_TYPE_INTERFACE, &offset);
|
||||
TEST_ASSERT_NULL(cur_desc);
|
||||
}
|
||||
@@ -358,11 +358,11 @@ Test if the count of number of alternate descriptors is correct
|
||||
*/
|
||||
static void test_alt_intf_desc_count(const usb_config_desc_t *config_desc)
|
||||
{
|
||||
//bInterface 0 has no alternate interfaces
|
||||
// bInterface 0 has no alternate interfaces
|
||||
TEST_ASSERT_EQUAL(0, usb_parse_interface_number_of_alternate(config_desc, 0));
|
||||
//bInterface 1 has 1 alternate interface
|
||||
// bInterface 1 has 1 alternate interface
|
||||
TEST_ASSERT_EQUAL(1, usb_parse_interface_number_of_alternate(config_desc, 1));
|
||||
//Non existent bInterface 2 should return -1
|
||||
// Non existent bInterface 2 should return -1
|
||||
TEST_ASSERT_EQUAL(-1, usb_parse_interface_number_of_alternate(config_desc, 2));
|
||||
}
|
||||
|
||||
@@ -370,10 +370,10 @@ static void test_parse_intf_and_ep(const usb_config_desc_t *config_desc)
|
||||
{
|
||||
int offset_intf = 0;
|
||||
|
||||
//Get bInterfaceNumber 0 (index 0)
|
||||
// Get bInterfaceNumber 0 (index 0)
|
||||
const usb_intf_desc_t *intf_desc = usb_parse_interface_descriptor(config_desc, 0, 0, &offset_intf);
|
||||
TEST_ASSERT_NOT_NULL(intf_desc);
|
||||
//Should only have one endpoint
|
||||
// Should only have one endpoint
|
||||
int offset_ep = offset_intf;
|
||||
const usb_ep_desc_t *ep_desc = usb_parse_endpoint_descriptor_by_index(intf_desc, 0, config_desc->wTotalLength, &offset_ep);
|
||||
TEST_ASSERT_NOT_NULL(ep_desc);
|
||||
@@ -382,20 +382,20 @@ static void test_parse_intf_and_ep(const usb_config_desc_t *config_desc)
|
||||
ep_desc = usb_parse_endpoint_descriptor_by_index(intf_desc, 1, config_desc->wTotalLength, &offset_ep);
|
||||
TEST_ASSERT_NULL(ep_desc);
|
||||
|
||||
//Get bInterfaceNumber 1 alternate setting 0
|
||||
// Get bInterfaceNumber 1 alternate setting 0
|
||||
offset_intf = 0;
|
||||
intf_desc = usb_parse_interface_descriptor(config_desc, 1, 0, &offset_intf);
|
||||
TEST_ASSERT_NOT_NULL(intf_desc);
|
||||
//Should have no endpoints
|
||||
// Should have no endpoints
|
||||
offset_ep = offset_intf;
|
||||
ep_desc = usb_parse_endpoint_descriptor_by_index(intf_desc, 0, config_desc->wTotalLength, &offset_ep);
|
||||
TEST_ASSERT_NULL(ep_desc);
|
||||
|
||||
//Get bInterfaceNumber 1 alternate setting 1
|
||||
// Get bInterfaceNumber 1 alternate setting 1
|
||||
offset_intf = 0;
|
||||
intf_desc = usb_parse_interface_descriptor(config_desc, 1, 1, &offset_intf);
|
||||
TEST_ASSERT_NOT_NULL(intf_desc);
|
||||
//Should only have one endpoint
|
||||
// Should only have one endpoint
|
||||
offset_ep = offset_intf;
|
||||
ep_desc = usb_parse_endpoint_descriptor_by_index(intf_desc, 0, config_desc->wTotalLength, &offset_ep);
|
||||
TEST_ASSERT_NOT_NULL(ep_desc);
|
||||
@@ -408,21 +408,21 @@ static void test_parse_intf_and_ep(const usb_config_desc_t *config_desc)
|
||||
static void test_parse_ep_by_address(const usb_config_desc_t *config_desc)
|
||||
{
|
||||
int offset_ep = 0;
|
||||
//Get bInterface 0 bAlternateSetting 0 EP 0x83
|
||||
// Get bInterface 0 bAlternateSetting 0 EP 0x83
|
||||
const usb_ep_desc_t *ep_desc = usb_parse_endpoint_descriptor_by_address(config_desc, 0, 0, 0x83, &offset_ep);
|
||||
TEST_ASSERT_NOT_NULL(ep_desc);
|
||||
TEST_ASSERT_EQUAL(0x83, ep_desc->bEndpointAddress);
|
||||
//Getting same EP address under different interface should return NULL
|
||||
// Getting same EP address under different interface should return NULL
|
||||
offset_ep = 0;
|
||||
ep_desc = usb_parse_endpoint_descriptor_by_address(config_desc, 1, 0, 0x83, &offset_ep);
|
||||
TEST_ASSERT_NULL(ep_desc);
|
||||
|
||||
//Get bInterface 1 bAlternateSetting 1 EP 0x81
|
||||
// Get bInterface 1 bAlternateSetting 1 EP 0x81
|
||||
offset_ep = 0;
|
||||
ep_desc = usb_parse_endpoint_descriptor_by_address(config_desc, 1, 1, 0x81, &offset_ep);
|
||||
TEST_ASSERT_NOT_NULL(ep_desc);
|
||||
TEST_ASSERT_EQUAL(0x81, ep_desc->bEndpointAddress);
|
||||
//Getting same EP address under different interface should return NULL
|
||||
// Getting same EP address under different interface should return NULL
|
||||
offset_ep = 0;
|
||||
ep_desc = usb_parse_endpoint_descriptor_by_address(config_desc, 1, 0, 0x81, &offset_ep);
|
||||
TEST_ASSERT_NULL(ep_desc);
|
||||
|
||||
Reference in New Issue
Block a user