mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-10 20:54:24 +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:
@@ -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]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user