mirror of
https://github.com/espressif/esp-idf.git
synced 2025-12-15 19:34:03 +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:
@@ -7,5 +7,5 @@ There are two sets of tests in this application:
|
||||
1. Low-speed: Expects low-speed USB mouse with interrupt endpoint to be connected
|
||||
2. Full-speed: Expects full-speed USB flash disk with 2 bulk endpoints to be connected
|
||||
|
||||
For running these tests locally, you will have to update device definitions (VID, PID, ...) in [test_usb_mock_msc.h](../common/test_usb_mock_msc.h) and [test_usb_mock_hid.h](../common/test_usb_mock_hid.h).
|
||||
For running these tests locally, you will have to update device definitions (VID, PID, ...) in [mock_msc.h](../common/mock_msc.h) and [mock_hid.h](../common/mock_hid.h).
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ typedef struct {
|
||||
static void ctrl_transfer_cb(usb_transfer_t *transfer)
|
||||
{
|
||||
ctrl_client_obj_t *ctrl_obj = (ctrl_client_obj_t *)transfer->context;
|
||||
//Check the completed control transfer
|
||||
// Check the completed control transfer
|
||||
TEST_ASSERT_EQUAL_MESSAGE(USB_TRANSFER_STATUS_COMPLETED, transfer->status, "Transfer NOT completed");
|
||||
TEST_ASSERT_EQUAL(ctrl_obj->config_desc_cached->wTotalLength, transfer->actual_num_bytes - sizeof(usb_setup_packet_t));
|
||||
ctrl_obj->num_xfer_done++;
|
||||
@@ -82,7 +82,7 @@ static void ctrl_client_event_cb(const usb_host_client_event_msg_t *event_msg, v
|
||||
ctrl_obj->dev_addr_to_open = event_msg->new_dev.address;
|
||||
break;
|
||||
default:
|
||||
abort(); //Should never occur in this test
|
||||
abort(); // Should never occur in this test
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,7 @@ void ctrl_client_async_seq_task(void *arg)
|
||||
ctrl_obj.cur_stage = TEST_STAGE_WAIT_CONN;
|
||||
ctrl_obj.next_stage = TEST_STAGE_WAIT_CONN;
|
||||
|
||||
//Register client
|
||||
// Register client
|
||||
usb_host_client_config_t client_config = {
|
||||
.is_synchronous = false,
|
||||
.max_num_event_msg = CTRL_CLIENT_MAX_EVENT_MSGS,
|
||||
@@ -105,7 +105,7 @@ void ctrl_client_async_seq_task(void *arg)
|
||||
};
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_client_register(&client_config, &ctrl_obj.client_hdl));
|
||||
|
||||
//Allocate transfers
|
||||
// Allocate transfers
|
||||
usb_transfer_t *ctrl_xfer[NUM_TRANSFER_OBJ] = {NULL};
|
||||
for (int i = 0; i < NUM_TRANSFER_OBJ; i++) {
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_transfer_alloc(sizeof(usb_setup_packet_t) + MAX_TRANSFER_BYTES, 0, &ctrl_xfer[i]));
|
||||
@@ -113,7 +113,7 @@ void ctrl_client_async_seq_task(void *arg)
|
||||
ctrl_xfer[i]->context = (void *)&ctrl_obj;
|
||||
}
|
||||
|
||||
//Wait to be started by main thread
|
||||
// Wait to be started by main thread
|
||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||
ESP_LOGD(CTRL_CLIENT_TAG, "Starting");
|
||||
|
||||
@@ -132,18 +132,18 @@ void ctrl_client_async_seq_task(void *arg)
|
||||
switch (ctrl_obj.next_stage) {
|
||||
case TEST_STAGE_DEV_OPEN: {
|
||||
ESP_LOGD(CTRL_CLIENT_TAG, "Open");
|
||||
//Open the device
|
||||
// Open the device
|
||||
TEST_ASSERT_EQUAL_MESSAGE(ESP_OK, usb_host_device_open(ctrl_obj.client_hdl, ctrl_obj.dev_addr_to_open, &ctrl_obj.dev_hdl), "Failed to open the device");
|
||||
//Target our transfers to the device
|
||||
// Target our transfers to the device
|
||||
for (int i = 0; i < NUM_TRANSFER_OBJ; i++) {
|
||||
ctrl_xfer[i]->device_handle = ctrl_obj.dev_hdl;
|
||||
}
|
||||
//Check the VID/PID of the opened device
|
||||
// Check the VID/PID of the opened device
|
||||
const usb_device_desc_t *device_desc;
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_get_device_descriptor(ctrl_obj.dev_hdl, &device_desc));
|
||||
TEST_ASSERT_EQUAL(ctrl_obj.test_param.idVendor, device_desc->idVendor);
|
||||
TEST_ASSERT_EQUAL(ctrl_obj.test_param.idProduct, device_desc->idProduct);
|
||||
//Cache the active configuration descriptor for later comparison
|
||||
// Cache the active configuration descriptor for later comparison
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_get_active_config_descriptor(ctrl_obj.dev_hdl, &ctrl_obj.config_desc_cached));
|
||||
ctrl_obj.next_stage = TEST_STAGE_CTRL_XFER;
|
||||
skip_event_handling = true;
|
||||
@@ -151,7 +151,7 @@ void ctrl_client_async_seq_task(void *arg)
|
||||
}
|
||||
case TEST_STAGE_CTRL_XFER: {
|
||||
ESP_LOGD(CTRL_CLIENT_TAG, "Transfer");
|
||||
//Send a control transfer to get the device's configuration descriptor
|
||||
// Send a control transfer to get the device's configuration descriptor
|
||||
usb_transfer_t *transfer = ctrl_xfer[ctrl_obj.num_xfer_sent % NUM_TRANSFER_OBJ];
|
||||
USB_SETUP_PACKET_INIT_GET_CONFIG_DESC((usb_setup_packet_t *)transfer->data_buffer, 0, MAX_TRANSFER_BYTES);
|
||||
transfer->num_bytes = sizeof(usb_setup_packet_t) + MAX_TRANSFER_BYTES;
|
||||
@@ -163,12 +163,12 @@ void ctrl_client_async_seq_task(void *arg)
|
||||
break;
|
||||
}
|
||||
case TEST_STAGE_CTRL_XFER_WAIT: {
|
||||
//Nothing to do but wait
|
||||
// Nothing to do but wait
|
||||
break;
|
||||
}
|
||||
case TEST_STAGE_DEV_CLOSE: {
|
||||
ESP_LOGD(CTRL_CLIENT_TAG, "Close");
|
||||
vTaskDelay(10); // Give USB Host Lib some time to process all trnsfers
|
||||
vTaskDelay(10); // Give USB Host Lib some time to process all transfers
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_device_close(ctrl_obj.client_hdl, ctrl_obj.dev_hdl));
|
||||
exit_loop = true;
|
||||
break;
|
||||
@@ -178,7 +178,7 @@ void ctrl_client_async_seq_task(void *arg)
|
||||
break;
|
||||
}
|
||||
}
|
||||
//Free transfers and deregister client
|
||||
// Free transfers and deregister client
|
||||
for (int i = 0; i < NUM_TRANSFER_OBJ; i++) {
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_transfer_free(ctrl_xfer[i]));
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "freertos/task.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "test_usb_mock_msc.h"
|
||||
#include "mock_msc.h"
|
||||
#include "test_usb_common.h"
|
||||
#include "msc_client.h"
|
||||
#include "usb/usb_host.h"
|
||||
@@ -61,7 +61,7 @@ typedef struct {
|
||||
static void msc_reset_cbw_transfer_cb(usb_transfer_t *transfer)
|
||||
{
|
||||
msc_client_obj_t *msc_obj = (msc_client_obj_t *)transfer->context;
|
||||
//We expect the reset and CBW transfers to complete with no issues
|
||||
// We expect the reset and CBW transfers to complete with no issues
|
||||
TEST_ASSERT_EQUAL_MESSAGE(USB_TRANSFER_STATUS_COMPLETED, transfer->status, "Transfer NOT completed");
|
||||
TEST_ASSERT_EQUAL(transfer->num_bytes, transfer->actual_num_bytes);
|
||||
switch (msc_obj->cur_stage) {
|
||||
@@ -79,7 +79,7 @@ static void msc_reset_cbw_transfer_cb(usb_transfer_t *transfer)
|
||||
|
||||
static void msc_data_transfer_cb(usb_transfer_t *transfer)
|
||||
{
|
||||
//The data stage should have either completed, or failed due to the disconnection.
|
||||
// The data stage should have either completed, or failed due to the disconnection.
|
||||
TEST_ASSERT(transfer->status == USB_TRANSFER_STATUS_COMPLETED || transfer->status == USB_TRANSFER_STATUS_NO_DEVICE);
|
||||
if (transfer->status == USB_TRANSFER_STATUS_COMPLETED) {
|
||||
TEST_ASSERT_EQUAL(transfer->num_bytes, transfer->actual_num_bytes);
|
||||
@@ -88,7 +88,7 @@ static void msc_data_transfer_cb(usb_transfer_t *transfer)
|
||||
}
|
||||
msc_client_obj_t *msc_obj = (msc_client_obj_t *)transfer->context;
|
||||
msc_obj->event_count++;
|
||||
//If all transfers dequeued and device gone event occurred. Go to next stage
|
||||
// If all transfers dequeued and device gone event occurred. Go to next stage
|
||||
if (msc_obj->event_count >= msc_obj->num_data_transfers + 1) {
|
||||
msc_obj->next_stage = TEST_STAGE_DEV_CLOSE;
|
||||
}
|
||||
@@ -105,13 +105,13 @@ static void msc_client_event_cb(const usb_host_client_event_msg_t *event_msg, vo
|
||||
break;
|
||||
case USB_HOST_CLIENT_EVENT_DEV_GONE:
|
||||
msc_obj->event_count++;
|
||||
//If all transfers dequeued and device gone event occurred. Go to next stage
|
||||
// If all transfers dequeued and device gone event occurred. Go to next stage
|
||||
if (msc_obj->event_count >= msc_obj->num_data_transfers + 1) {
|
||||
msc_obj->next_stage = TEST_STAGE_DEV_CLOSE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
abort(); //Should never occur in this test
|
||||
abort(); // Should never occur in this test
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -128,7 +128,7 @@ void msc_client_async_dconn_task(void *arg)
|
||||
msc_obj.num_data_transfers = msc_obj.test_param.num_sectors_per_xfer / MOCK_MSC_SCSI_SECTOR_SIZE;
|
||||
msc_obj.event_count = 0;
|
||||
|
||||
//Register client
|
||||
// Register client
|
||||
usb_host_client_config_t client_config = {
|
||||
.is_synchronous = false,
|
||||
.max_num_event_msg = MSC_ASYNC_CLIENT_MAX_EVENT_MSGS,
|
||||
@@ -139,9 +139,9 @@ void msc_client_async_dconn_task(void *arg)
|
||||
};
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_client_register(&client_config, &msc_obj.client_hdl));
|
||||
|
||||
//Allocate transfers
|
||||
usb_transfer_t *xfer_out; //Must be large enough to contain CBW and MSC reset control transfer
|
||||
usb_transfer_t *xfer_in[msc_obj.num_data_transfers]; //We manually split the data stage into multiple transfers
|
||||
// Allocate transfers
|
||||
usb_transfer_t *xfer_out; // Must be large enough to contain CBW and MSC reset control transfer
|
||||
usb_transfer_t *xfer_in[msc_obj.num_data_transfers]; // We manually split the data stage into multiple transfers
|
||||
size_t xfer_out_size = MAX(sizeof(mock_msc_bulk_cbw_t), sizeof(usb_setup_packet_t));
|
||||
size_t xfer_in_size = MOCK_MSC_SCSI_SECTOR_SIZE;
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_transfer_alloc(xfer_out_size, 0, &xfer_out));
|
||||
@@ -151,7 +151,7 @@ void msc_client_async_dconn_task(void *arg)
|
||||
xfer_in[i]->context = (void *)&msc_obj;
|
||||
}
|
||||
|
||||
//Wait to be started by main thread
|
||||
// Wait to be started by main thread
|
||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||
ESP_LOGD(MSC_CLIENT_TAG, "Starting");
|
||||
|
||||
@@ -170,43 +170,43 @@ void msc_client_async_dconn_task(void *arg)
|
||||
|
||||
switch (msc_obj.cur_stage) {
|
||||
case TEST_STAGE_WAIT_CONN: {
|
||||
//Nothing to do while waiting for connection
|
||||
// Nothing to do while waiting for connection
|
||||
break;
|
||||
}
|
||||
case TEST_STAGE_DEV_OPEN: {
|
||||
ESP_LOGD(MSC_CLIENT_TAG, "Open");
|
||||
//Open the device
|
||||
// Open the device
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_device_open(msc_obj.client_hdl, msc_obj.dev_addr_to_open, &msc_obj.dev_hdl));
|
||||
//Target our transfers to the device
|
||||
// Target our transfers to the device
|
||||
xfer_out->device_handle = msc_obj.dev_hdl;
|
||||
xfer_out->callback = msc_reset_cbw_transfer_cb;
|
||||
for (int i = 0; i < msc_obj.num_data_transfers; i++) {
|
||||
xfer_in[i]->device_handle = msc_obj.dev_hdl;
|
||||
xfer_in[i]->callback = msc_data_transfer_cb;
|
||||
}
|
||||
//Check the VID/PID of the opened device
|
||||
// Check the VID/PID of the opened device
|
||||
const usb_device_desc_t *device_desc;
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_get_device_descriptor(msc_obj.dev_hdl, &device_desc));
|
||||
TEST_ASSERT_EQUAL(msc_obj.test_param.idVendor, device_desc->idVendor);
|
||||
TEST_ASSERT_EQUAL(msc_obj.test_param.idProduct, device_desc->idProduct);
|
||||
//Get device info to get device speed
|
||||
// Get device info to get device speed
|
||||
usb_device_info_t dev_info;
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_device_info(msc_obj.dev_hdl, &dev_info));
|
||||
msc_obj.dev_speed = dev_info.speed;
|
||||
//Claim the MSC interface
|
||||
// Claim the MSC interface
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_interface_claim(msc_obj.client_hdl, msc_obj.dev_hdl, MOCK_MSC_SCSI_INTF_NUMBER, MOCK_MSC_SCSI_INTF_ALT_SETTING));
|
||||
msc_obj.next_stage = TEST_STAGE_MSC_RESET;
|
||||
skip_event_handling = true; //Need to execute TEST_STAGE_MSC_RESET
|
||||
skip_event_handling = true; // Need to execute TEST_STAGE_MSC_RESET
|
||||
break;
|
||||
}
|
||||
case TEST_STAGE_MSC_RESET: {
|
||||
ESP_LOGD(MSC_CLIENT_TAG, "MSC Reset");
|
||||
//Send an MSC SCSI interface reset
|
||||
// Send an MSC SCSI interface reset
|
||||
MOCK_MSC_SCSI_REQ_INIT_RESET((usb_setup_packet_t *)xfer_out->data_buffer, MOCK_MSC_SCSI_INTF_NUMBER);
|
||||
xfer_out->num_bytes = sizeof(usb_setup_packet_t);
|
||||
xfer_out->bEndpointAddress = 0;
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_transfer_submit_control(msc_obj.client_hdl, xfer_out));
|
||||
//Next stage set from transfer callback
|
||||
// Next stage set from transfer callback
|
||||
break;
|
||||
}
|
||||
case TEST_STAGE_MSC_CBW: {
|
||||
@@ -215,12 +215,12 @@ void msc_client_async_dconn_task(void *arg)
|
||||
xfer_out->num_bytes = sizeof(mock_msc_bulk_cbw_t);
|
||||
xfer_out->bEndpointAddress = MOCK_MSC_SCSI_BULK_OUT_EP_ADDR;
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_transfer_submit(xfer_out));
|
||||
//Next stage set from transfer callback
|
||||
// Next stage set from transfer callback
|
||||
break;
|
||||
}
|
||||
case TEST_STAGE_MSC_DATA_DCONN: {
|
||||
ESP_LOGD(MSC_CLIENT_TAG, "Data and disconnect");
|
||||
//Setup the Data IN transfers
|
||||
// Setup the Data IN transfers
|
||||
const int bulk_ep_mps = (msc_obj.dev_speed == USB_SPEED_HIGH)
|
||||
? MOCK_MSC_SCSI_BULK_EP_MPS_HS
|
||||
: MOCK_MSC_SCSI_BULK_EP_MPS_FS;
|
||||
@@ -228,13 +228,13 @@ void msc_client_async_dconn_task(void *arg)
|
||||
xfer_in[i]->num_bytes = usb_round_up_to_mps(MOCK_MSC_SCSI_SECTOR_SIZE, bulk_ep_mps);
|
||||
xfer_in[i]->bEndpointAddress = MOCK_MSC_SCSI_BULK_IN_EP_ADDR;
|
||||
}
|
||||
//Submit those transfers
|
||||
// Submit those transfers
|
||||
for (int i = 0; i < msc_obj.num_data_transfers; i++) {
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_transfer_submit(xfer_in[i]));
|
||||
}
|
||||
//Trigger a disconnect
|
||||
// Trigger a disconnect
|
||||
test_usb_set_phy_state(false, 0);
|
||||
//Next stage set from transfer callback
|
||||
// Next stage set from transfer callback
|
||||
break;
|
||||
}
|
||||
case TEST_STAGE_DEV_CLOSE: {
|
||||
@@ -243,9 +243,9 @@ void msc_client_async_dconn_task(void *arg)
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_device_close(msc_obj.client_hdl, msc_obj.dev_hdl));
|
||||
dconn_iter++;
|
||||
if (dconn_iter < TEST_DCONN_ITERATIONS) {
|
||||
//Start the next test iteration by going back to TEST_STAGE_WAIT_CONN and reenabling connections
|
||||
// Start the next test iteration by going back to TEST_STAGE_WAIT_CONN and reenabling connections
|
||||
msc_obj.next_stage = TEST_STAGE_WAIT_CONN;
|
||||
skip_event_handling = true; //Need to execute TEST_STAGE_WAIT_CONN
|
||||
skip_event_handling = true; // Need to execute TEST_STAGE_WAIT_CONN
|
||||
test_usb_set_phy_state(true, 0);
|
||||
} else {
|
||||
exit_loop = true;
|
||||
@@ -257,12 +257,12 @@ void msc_client_async_dconn_task(void *arg)
|
||||
break;
|
||||
}
|
||||
}
|
||||
//Free transfers
|
||||
// Free transfers
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_transfer_free(xfer_out));
|
||||
for (int i = 0; i < msc_obj.num_data_transfers; i++) {
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_transfer_free(xfer_in[i]));
|
||||
}
|
||||
//Deregister the client
|
||||
// Deregister the client
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_client_deregister(msc_obj.client_hdl));
|
||||
ESP_LOGD(MSC_CLIENT_TAG, "Done");
|
||||
vTaskDelete(NULL);
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "freertos/task.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "test_usb_mock_msc.h"
|
||||
#include "mock_msc.h"
|
||||
#include "test_usb_common.h"
|
||||
#include "msc_client.h"
|
||||
#include "usb/usb_host.h"
|
||||
@@ -61,7 +61,7 @@ static void msc_client_event_cb(const usb_host_client_event_msg_t *event_msg, vo
|
||||
msc_obj->dev_addr_to_open = event_msg->new_dev.address;
|
||||
break;
|
||||
default:
|
||||
abort(); //Should never occur in this test
|
||||
abort(); // Should never occur in this test
|
||||
break;
|
||||
|
||||
}
|
||||
@@ -94,7 +94,7 @@ void msc_client_async_enum_task(void *arg)
|
||||
msc_obj.dev_addr_to_open = 0;
|
||||
msc_obj.dev_hdl = NULL;
|
||||
|
||||
//Register client
|
||||
// Register client
|
||||
usb_host_client_config_t client_config = {
|
||||
.is_synchronous = false,
|
||||
.max_num_event_msg = MSC_ASYNC_CLIENT_MAX_EVENT_MSGS,
|
||||
@@ -105,7 +105,7 @@ void msc_client_async_enum_task(void *arg)
|
||||
};
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_client_register(&client_config, &msc_obj.client_hdl));
|
||||
|
||||
//Wait to be started by main thread
|
||||
// Wait to be started by main thread
|
||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||
ESP_LOGD(MSC_CLIENT_TAG, "Starting");
|
||||
|
||||
@@ -124,49 +124,49 @@ void msc_client_async_enum_task(void *arg)
|
||||
|
||||
switch (msc_obj.cur_stage) {
|
||||
case TEST_STAGE_WAIT_CONN: {
|
||||
//Wait for connection, nothing to do
|
||||
// Wait for connection, nothing to do
|
||||
break;
|
||||
}
|
||||
case TEST_STAGE_DEV_OPEN: {
|
||||
ESP_LOGD(MSC_CLIENT_TAG, "Open");
|
||||
//Open the device
|
||||
// Open the device
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_device_open(msc_obj.client_hdl, msc_obj.dev_addr_to_open, &msc_obj.dev_hdl));
|
||||
msc_obj.next_stage = TEST_STAGE_CHECK_DEV_DESC;
|
||||
//Get device info to get device speed
|
||||
// Get device info to get device speed
|
||||
usb_device_info_t dev_info;
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_device_info(msc_obj.dev_hdl, &dev_info));
|
||||
msc_obj.dev_speed = dev_info.speed;
|
||||
mock_msc_scsi_init_reference_ep_descriptors(&msc_obj);
|
||||
skip_event_handling = true; //Need to execute TEST_STAGE_CHECK_DEV_DESC
|
||||
skip_event_handling = true; // Need to execute TEST_STAGE_CHECK_DEV_DESC
|
||||
break;
|
||||
}
|
||||
case TEST_STAGE_CHECK_DEV_DESC: {
|
||||
//Check the device descriptor
|
||||
// Check the device descriptor
|
||||
const usb_device_desc_t *device_desc;
|
||||
const usb_device_desc_t *device_desc_ref = &mock_msc_scsi_dev_desc;
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_get_device_descriptor(msc_obj.dev_hdl, &device_desc));
|
||||
TEST_ASSERT_EQUAL(device_desc_ref->bLength, device_desc->bLength);
|
||||
TEST_ASSERT_EQUAL_MEMORY_MESSAGE(device_desc_ref, device_desc, device_desc_ref->bLength, "Device descriptors do not match.");
|
||||
msc_obj.next_stage = TEST_STAGE_CHECK_CONFIG_DESC;
|
||||
skip_event_handling = true; //Need to execute TEST_STAGE_CHECK_CONFIG_DESC
|
||||
skip_event_handling = true; // Need to execute TEST_STAGE_CHECK_CONFIG_DESC
|
||||
break;
|
||||
}
|
||||
|
||||
case TEST_STAGE_CHECK_CONFIG_DESC: {
|
||||
//Check the configuration descriptor
|
||||
// Check the configuration descriptor
|
||||
const usb_config_desc_t *config_desc;
|
||||
const usb_config_desc_t *config_desc_ref = (const usb_config_desc_t *)mock_msc_scsi_config_desc;
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_get_active_config_descriptor(msc_obj.dev_hdl, &config_desc));
|
||||
TEST_ASSERT_EQUAL_MESSAGE(config_desc_ref->wTotalLength, config_desc->wTotalLength, "Incorrent length of CFG descriptor");
|
||||
TEST_ASSERT_EQUAL_MESSAGE(config_desc_ref->wTotalLength, config_desc->wTotalLength, "Incorrect length of CFG descriptor");
|
||||
TEST_ASSERT_EQUAL_MEMORY_MESSAGE(config_desc_ref, config_desc, config_desc_ref->wTotalLength, "Configuration descriptors do not match");
|
||||
msc_obj.next_stage = TEST_STAGE_CHECK_STR_DESC;
|
||||
skip_event_handling = true; //Need to execute TEST_STAGE_CHECK_STR_DESC
|
||||
skip_event_handling = true; // Need to execute TEST_STAGE_CHECK_STR_DESC
|
||||
break;
|
||||
}
|
||||
case TEST_STAGE_CHECK_STR_DESC: {
|
||||
usb_device_info_t dev_info;
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_device_info(msc_obj.dev_hdl, &dev_info));
|
||||
//Check manufacturer string descriptors
|
||||
// Check manufacturer string descriptors
|
||||
const usb_str_desc_t *manu_str_desc_ref = (const usb_str_desc_t *)mock_msc_scsi_str_desc_manu;
|
||||
const usb_str_desc_t *product_str_desc_ref = (const usb_str_desc_t *)mock_msc_scsi_str_desc_prod;
|
||||
const usb_str_desc_t *ser_num_str_desc_ref = (const usb_str_desc_t *)mock_msc_scsi_str_desc_ser_num;
|
||||
@@ -175,10 +175,10 @@ void msc_client_async_enum_task(void *arg)
|
||||
TEST_ASSERT_EQUAL(ser_num_str_desc_ref->bLength, dev_info.str_desc_serial_num->bLength);
|
||||
TEST_ASSERT_EQUAL_MEMORY_MESSAGE(manu_str_desc_ref, dev_info.str_desc_manufacturer, manu_str_desc_ref->bLength, "Manufacturer string descriptors do not match.");
|
||||
TEST_ASSERT_EQUAL_MEMORY_MESSAGE(product_str_desc_ref, dev_info.str_desc_product, manu_str_desc_ref->bLength, "Product string descriptors do not match.");
|
||||
//TEST_ASSERT_EQUAL_MEMORY_MESSAGE(ser_num_str_desc_ref, dev_info.str_desc_serial_num , manu_str_desc_ref->bLength, "Serial number string descriptors do not match.");
|
||||
//Get dev info and compare
|
||||
// TEST_ASSERT_EQUAL_MEMORY_MESSAGE(ser_num_str_desc_ref, dev_info.str_desc_serial_num , manu_str_desc_ref->bLength, "Serial number string descriptors do not match.");
|
||||
// Get dev info and compare
|
||||
msc_obj.next_stage = TEST_STAGE_DEV_CLOSE;
|
||||
skip_event_handling = true; //Need to execute TEST_STAGE_DEV_CLOSE
|
||||
skip_event_handling = true; // Need to execute TEST_STAGE_DEV_CLOSE
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -187,11 +187,11 @@ void msc_client_async_enum_task(void *arg)
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_device_close(msc_obj.client_hdl, msc_obj.dev_hdl));
|
||||
enum_iter++;
|
||||
if (enum_iter < TEST_ENUM_ITERATIONS) {
|
||||
//Start the next test iteration by disconnecting the device, then going back to TEST_STAGE_WAIT_CONN stage
|
||||
// Start the next test iteration by disconnecting the device, then going back to TEST_STAGE_WAIT_CONN stage
|
||||
test_usb_set_phy_state(false, 0);
|
||||
test_usb_set_phy_state(true, 0);
|
||||
msc_obj.next_stage = TEST_STAGE_WAIT_CONN;
|
||||
skip_event_handling = true; //Need to execute TEST_STAGE_WAIT_CONN
|
||||
skip_event_handling = true; // Need to execute TEST_STAGE_WAIT_CONN
|
||||
} else {
|
||||
exit_loop = true;
|
||||
}
|
||||
@@ -202,7 +202,7 @@ void msc_client_async_enum_task(void *arg)
|
||||
break;
|
||||
}
|
||||
}
|
||||
//Free transfers and deregister the client
|
||||
// Free transfers and deregister the client
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_client_deregister(msc_obj.client_hdl));
|
||||
ESP_LOGD(MSC_CLIENT_TAG, "Done");
|
||||
vTaskDelete(NULL);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "test_usb_common.h"
|
||||
#include "test_usb_mock_msc.h"
|
||||
#include "mock_msc.h"
|
||||
#include "msc_client.h"
|
||||
#include "usb/usb_host.h"
|
||||
#include "unity.h"
|
||||
@@ -61,28 +61,28 @@ static void msc_transfer_cb(usb_transfer_t *transfer)
|
||||
msc_client_obj_t *msc_obj = (msc_client_obj_t *)transfer->context;
|
||||
switch (msc_obj->cur_stage) {
|
||||
case TEST_STAGE_MSC_RESET: {
|
||||
//Check MSC SCSI interface reset
|
||||
// Check MSC SCSI interface reset
|
||||
TEST_ASSERT_EQUAL_MESSAGE(USB_TRANSFER_STATUS_COMPLETED, transfer->status, "Transfer NOT completed");
|
||||
TEST_ASSERT_EQUAL(transfer->num_bytes, transfer->actual_num_bytes);
|
||||
msc_obj->next_stage = TEST_STAGE_MSC_CBW;
|
||||
break;
|
||||
}
|
||||
case TEST_STAGE_MSC_CBW: {
|
||||
//Check MSC SCSI CBW transfer
|
||||
// Check MSC SCSI CBW transfer
|
||||
TEST_ASSERT_EQUAL_MESSAGE(USB_TRANSFER_STATUS_COMPLETED, transfer->status, "Transfer NOT completed");
|
||||
TEST_ASSERT_EQUAL(sizeof(mock_msc_bulk_cbw_t), transfer->actual_num_bytes);
|
||||
msc_obj->next_stage = TEST_STAGE_MSC_DATA;
|
||||
break;
|
||||
}
|
||||
case TEST_STAGE_MSC_DATA: {
|
||||
//Check MSC SCSI data IN transfer
|
||||
// Check MSC SCSI data IN transfer
|
||||
TEST_ASSERT_EQUAL_MESSAGE(USB_TRANSFER_STATUS_COMPLETED, transfer->status, "Transfer NOT completed");
|
||||
TEST_ASSERT_EQUAL(MOCK_MSC_SCSI_SECTOR_SIZE * msc_obj->test_param.num_sectors_per_xfer, transfer->actual_num_bytes);
|
||||
msc_obj->next_stage = TEST_STAGE_MSC_CSW;
|
||||
break;
|
||||
}
|
||||
case TEST_STAGE_MSC_CSW: {
|
||||
//Check MSC SCSI CSW transfer
|
||||
// Check MSC SCSI CSW transfer
|
||||
TEST_ASSERT_EQUAL_MESSAGE(USB_TRANSFER_STATUS_COMPLETED, transfer->status, "Transfer NOT completed");
|
||||
TEST_ASSERT_TRUE(mock_msc_scsi_check_csw((mock_msc_bulk_csw_t *)transfer->data_buffer, msc_obj->test_param.msc_scsi_xfer_tag));
|
||||
msc_obj->num_sectors_read += msc_obj->test_param.num_sectors_per_xfer;
|
||||
@@ -110,7 +110,7 @@ static void msc_client_event_cb(const usb_host_client_event_msg_t *event_msg, vo
|
||||
msc_obj->dev_addr_to_open = event_msg->new_dev.address;
|
||||
break;
|
||||
default:
|
||||
abort(); //Should never occur in this test
|
||||
abort(); // Should never occur in this test
|
||||
break;
|
||||
|
||||
}
|
||||
@@ -127,7 +127,7 @@ void msc_client_async_seq_task(void *arg)
|
||||
msc_obj.dev_hdl = NULL;
|
||||
msc_obj.num_sectors_read = 0;
|
||||
|
||||
//Register client
|
||||
// Register client
|
||||
usb_host_client_config_t client_config = {
|
||||
.is_synchronous = false,
|
||||
.max_num_event_msg = MSC_ASYNC_CLIENT_MAX_EVENT_MSGS,
|
||||
@@ -138,9 +138,9 @@ void msc_client_async_seq_task(void *arg)
|
||||
};
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_client_register(&client_config, &msc_obj.client_hdl));
|
||||
|
||||
//Allocate transfers
|
||||
usb_transfer_t *xfer_out = NULL; //Must be large enough to contain CBW and MSC reset control transfer
|
||||
usb_transfer_t *xfer_in = NULL; //Must be large enough to contain CSW and Data
|
||||
// Allocate transfers
|
||||
usb_transfer_t *xfer_out = NULL; // Must be large enough to contain CBW and MSC reset control transfer
|
||||
usb_transfer_t *xfer_in = NULL; // Must be large enough to contain CSW and Data
|
||||
size_t out_worst_case_size = MAX(sizeof(mock_msc_bulk_cbw_t), sizeof(usb_setup_packet_t));
|
||||
size_t in_worst_case_size = usb_round_up_to_mps(MAX(MOCK_MSC_SCSI_SECTOR_SIZE * msc_obj.test_param.num_sectors_per_xfer, sizeof(mock_msc_bulk_csw_t)), MOCK_MSC_SCSI_BULK_EP_MPS_HS);
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_transfer_alloc(out_worst_case_size, 0, &xfer_out));
|
||||
@@ -150,7 +150,7 @@ void msc_client_async_seq_task(void *arg)
|
||||
xfer_out->context = (void *)&msc_obj;
|
||||
xfer_in->context = (void *)&msc_obj;
|
||||
|
||||
//Wait to be started by main thread
|
||||
// Wait to be started by main thread
|
||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||
ESP_LOGD(MSC_CLIENT_TAG, "Starting");
|
||||
|
||||
@@ -169,36 +169,36 @@ void msc_client_async_seq_task(void *arg)
|
||||
switch (msc_obj.cur_stage) {
|
||||
case TEST_STAGE_DEV_OPEN: {
|
||||
ESP_LOGD(MSC_CLIENT_TAG, "Open");
|
||||
//Open the device
|
||||
// Open the device
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_device_open(msc_obj.client_hdl, msc_obj.dev_addr_to_open, &msc_obj.dev_hdl));
|
||||
//Target our transfers to the device
|
||||
// Target our transfers to the device
|
||||
xfer_out->device_handle = msc_obj.dev_hdl;
|
||||
xfer_in->device_handle = msc_obj.dev_hdl;
|
||||
//Check the VID/PID of the opened device
|
||||
// Check the VID/PID of the opened device
|
||||
const usb_device_desc_t *device_desc;
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_get_device_descriptor(msc_obj.dev_hdl, &device_desc));
|
||||
TEST_ASSERT_EQUAL(msc_obj.test_param.idVendor, device_desc->idVendor);
|
||||
TEST_ASSERT_EQUAL(msc_obj.test_param.idProduct, device_desc->idProduct);
|
||||
//Get device info to get device speed
|
||||
// Get device info to get device speed
|
||||
usb_device_info_t dev_info;
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_device_info(msc_obj.dev_hdl, &dev_info));
|
||||
msc_obj.dev_speed = dev_info.speed;
|
||||
//Claim the MSC interface
|
||||
// Claim the MSC interface
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_interface_claim(msc_obj.client_hdl, msc_obj.dev_hdl, MOCK_MSC_SCSI_INTF_NUMBER, MOCK_MSC_SCSI_INTF_ALT_SETTING));
|
||||
msc_obj.next_stage = TEST_STAGE_MSC_RESET;
|
||||
skip_event_handling = true; //Need to execute TEST_STAGE_MSC_RESET
|
||||
skip_event_handling = true; // Need to execute TEST_STAGE_MSC_RESET
|
||||
break;
|
||||
}
|
||||
case TEST_STAGE_MSC_RESET: {
|
||||
ESP_LOGD(MSC_CLIENT_TAG, "MSC Reset");
|
||||
//Send an MSC SCSI interface reset
|
||||
// Send an MSC SCSI interface reset
|
||||
MOCK_MSC_SCSI_REQ_INIT_RESET((usb_setup_packet_t *)xfer_out->data_buffer, MOCK_MSC_SCSI_INTF_NUMBER);
|
||||
xfer_out->num_bytes = sizeof(usb_setup_packet_t);
|
||||
xfer_out->bEndpointAddress = 0;
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_transfer_submit_control(msc_obj.client_hdl, xfer_out));
|
||||
//Test that an inflight control transfer cannot be resubmitted
|
||||
// Test that an inflight control transfer cannot be resubmitted
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_NOT_FINISHED, usb_host_transfer_submit_control(msc_obj.client_hdl, xfer_out));
|
||||
//Next stage set from transfer callback
|
||||
// Next stage set from transfer callback
|
||||
break;
|
||||
}
|
||||
case TEST_STAGE_MSC_CBW: {
|
||||
@@ -207,9 +207,9 @@ void msc_client_async_seq_task(void *arg)
|
||||
xfer_out->num_bytes = sizeof(mock_msc_bulk_cbw_t);
|
||||
xfer_out->bEndpointAddress = MOCK_MSC_SCSI_BULK_OUT_EP_ADDR;
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_transfer_submit(xfer_out));
|
||||
//Test that an inflight transfer cannot be resubmitted
|
||||
// Test that an inflight transfer cannot be resubmitted
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_NOT_FINISHED, usb_host_transfer_submit(xfer_out));
|
||||
//Next stage set from transfer callback
|
||||
// Next stage set from transfer callback
|
||||
break;
|
||||
}
|
||||
case TEST_STAGE_MSC_DATA: {
|
||||
@@ -220,9 +220,9 @@ void msc_client_async_seq_task(void *arg)
|
||||
xfer_in->num_bytes = usb_round_up_to_mps(MOCK_MSC_SCSI_SECTOR_SIZE * msc_obj.test_param.num_sectors_per_xfer, bulk_ep_mps);
|
||||
xfer_in->bEndpointAddress = MOCK_MSC_SCSI_BULK_IN_EP_ADDR;
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_transfer_submit(xfer_in));
|
||||
//Test that an inflight transfer cannot be resubmitted
|
||||
// Test that an inflight transfer cannot be resubmitted
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_NOT_FINISHED, usb_host_transfer_submit(xfer_in));
|
||||
//Next stage set from transfer callback
|
||||
// Next stage set from transfer callback
|
||||
break;
|
||||
}
|
||||
case TEST_STAGE_MSC_CSW: {
|
||||
@@ -233,9 +233,9 @@ void msc_client_async_seq_task(void *arg)
|
||||
xfer_in->num_bytes = usb_round_up_to_mps(sizeof(mock_msc_bulk_csw_t), bulk_ep_mps);
|
||||
xfer_in->bEndpointAddress = MOCK_MSC_SCSI_BULK_IN_EP_ADDR;
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_transfer_submit(xfer_in));
|
||||
//Test that an inflight transfer cannot be resubmitted
|
||||
// Test that an inflight transfer cannot be resubmitted
|
||||
TEST_ASSERT_EQUAL(ESP_ERR_NOT_FINISHED, usb_host_transfer_submit(xfer_in));
|
||||
//Next stage set from transfer callback
|
||||
// Next stage set from transfer callback
|
||||
break;
|
||||
}
|
||||
case TEST_STAGE_DEV_CLOSE: {
|
||||
@@ -250,7 +250,7 @@ void msc_client_async_seq_task(void *arg)
|
||||
break;
|
||||
}
|
||||
}
|
||||
//Free transfers and deregister the client
|
||||
// Free transfers and deregister the client
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_transfer_free(xfer_out));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_transfer_free(xfer_in));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_client_deregister(msc_obj.client_hdl));
|
||||
|
||||
@@ -11,17 +11,17 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "test_usb_common.h"
|
||||
#include "test_usb_mock_msc.h"
|
||||
#include "mock_msc.h"
|
||||
#include "usb/usb_host.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
mock_msc_scsi_init_reference_descriptors();
|
||||
unity_utils_record_free_mem();
|
||||
test_usb_init_phy(); //Initialize the internal USB PHY and USB Controller for testing
|
||||
//Install USB Host
|
||||
test_usb_init_phy(); // Initialize the internal USB PHY and USB Controller for testing
|
||||
// Install USB Host
|
||||
usb_host_config_t host_config = {
|
||||
.skip_phy_setup = true, //test_usb_init_phy() will already have setup the internal USB PHY for us
|
||||
.skip_phy_setup = true, // test_usb_init_phy() will already have setup the internal USB PHY for us
|
||||
.intr_flags = ESP_INTR_FLAG_LEVEL1,
|
||||
};
|
||||
ESP_ERROR_CHECK(usb_host_install(&host_config));
|
||||
@@ -30,11 +30,11 @@ 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);
|
||||
//Clean up USB Host
|
||||
// Clean up USB Host
|
||||
ESP_ERROR_CHECK(usb_host_uninstall());
|
||||
test_usb_deinit_phy(); //Deinitialize the internal USB PHY after testing
|
||||
test_usb_deinit_phy(); // Deinitialize the internal USB PHY after testing
|
||||
unity_utils_evaluate_leaks();
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "esp_err.h"
|
||||
#include "esp_intr_alloc.h"
|
||||
#include "test_usb_common.h"
|
||||
#include "test_usb_mock_msc.h"
|
||||
#include "mock_msc.h"
|
||||
#include "msc_client.h"
|
||||
#include "ctrl_client.h"
|
||||
#include "usb/usb_host.h"
|
||||
@@ -46,7 +46,7 @@ Procedure:
|
||||
|
||||
TEST_CASE("Test USB Host async client (single client)", "[usb_host][full_speed][high_speed]")
|
||||
{
|
||||
//Create task to run client that communicates with MSC SCSI interface
|
||||
// Create task to run client that communicates with MSC SCSI interface
|
||||
msc_client_test_param_t params = {
|
||||
.num_sectors_to_read = TEST_MSC_NUM_SECTORS_TOTAL,
|
||||
.num_sectors_per_xfer = TEST_MSC_NUM_SECTORS_PER_XFER,
|
||||
@@ -57,11 +57,11 @@ TEST_CASE("Test USB Host async client (single client)", "[usb_host][full_speed][
|
||||
TaskHandle_t task_hdl;
|
||||
xTaskCreatePinnedToCore(msc_client_async_seq_task, "async", 4096, (void *)¶ms, 2, &task_hdl, 0);
|
||||
TEST_ASSERT_NOT_NULL_MESSAGE(task_hdl, "Failed to create async task");
|
||||
//Start the task
|
||||
// Start the task
|
||||
xTaskNotifyGive(task_hdl);
|
||||
|
||||
while (1) {
|
||||
//Start handling system events
|
||||
// Start handling system events
|
||||
uint32_t event_flags;
|
||||
usb_host_lib_handle_events(portMAX_DELAY, &event_flags);
|
||||
if (event_flags & USB_HOST_LIB_EVENT_FLAGS_NO_CLIENTS) {
|
||||
@@ -96,7 +96,7 @@ Procedure:
|
||||
*/
|
||||
TEST_CASE("Test USB Host async client (multi client)", "[usb_host][full_speed][high_speed]")
|
||||
{
|
||||
//Create task to run the MSC client
|
||||
// Create task to run the MSC client
|
||||
msc_client_test_param_t msc_params = {
|
||||
.num_sectors_to_read = TEST_MSC_NUM_SECTORS_TOTAL,
|
||||
.num_sectors_per_xfer = TEST_MSC_NUM_SECTORS_PER_XFER,
|
||||
@@ -108,7 +108,7 @@ TEST_CASE("Test USB Host async client (multi client)", "[usb_host][full_speed][h
|
||||
xTaskCreatePinnedToCore(msc_client_async_seq_task, "msc", 4096, (void *)&msc_params, 2, &msc_task_hdl, 0);
|
||||
TEST_ASSERT_NOT_NULL_MESSAGE(msc_task_hdl, "Failed to create MSC task");
|
||||
|
||||
//Create task a control transfer client
|
||||
// Create task a control transfer client
|
||||
ctrl_client_test_param_t ctrl_params = {
|
||||
.num_ctrl_xfer_to_send = TEST_CTRL_NUM_TRANSFERS,
|
||||
.idVendor = MOCK_MSC_SCSI_DEV_ID_VENDOR,
|
||||
@@ -118,12 +118,12 @@ TEST_CASE("Test USB Host async client (multi client)", "[usb_host][full_speed][h
|
||||
xTaskCreatePinnedToCore(ctrl_client_async_seq_task, "ctrl", 4096, (void *)&ctrl_params, 2, &ctrl_task_hdl, 0);
|
||||
TEST_ASSERT_NOT_NULL_MESSAGE(ctrl_task_hdl, "Failed to create CTRL task");
|
||||
|
||||
//Start both tasks
|
||||
// Start both tasks
|
||||
xTaskNotifyGive(msc_task_hdl);
|
||||
xTaskNotifyGive(ctrl_task_hdl);
|
||||
|
||||
while (1) {
|
||||
//Start handling system events
|
||||
// Start handling system events
|
||||
uint32_t event_flags;
|
||||
usb_host_lib_handle_events(portMAX_DELAY, &event_flags);
|
||||
if (event_flags & USB_HOST_LIB_EVENT_FLAGS_NO_CLIENTS) {
|
||||
@@ -188,7 +188,7 @@ static void test_async_client_cb(const usb_host_client_event_msg_t *event_msg, v
|
||||
|
||||
TEST_CASE("Test USB Host async API", "[usb_host][full_speed][low_speed]")
|
||||
{
|
||||
//Register two clients
|
||||
// Register two clients
|
||||
client_test_stage_t client0_stage = CLIENT_TEST_STAGE_NONE;
|
||||
client_test_stage_t client1_stage = CLIENT_TEST_STAGE_NONE;
|
||||
|
||||
@@ -206,7 +206,7 @@ TEST_CASE("Test USB Host async API", "[usb_host][full_speed][low_speed]")
|
||||
client_config.async.callback_arg = (void *)&client1_stage;
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_client_register(&client_config, &client1_hdl));
|
||||
|
||||
//Wait until the device connects and the clients receive the event
|
||||
// Wait until the device connects and the clients receive the event
|
||||
while (!(client0_stage == CLIENT_TEST_STAGE_CONN && client1_stage == CLIENT_TEST_STAGE_CONN)) {
|
||||
usb_host_lib_handle_events(0, NULL);
|
||||
usb_host_client_handle_events(client0_hdl, 0);
|
||||
@@ -214,35 +214,35 @@ TEST_CASE("Test USB Host async API", "[usb_host][full_speed][low_speed]")
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
|
||||
//Check that both clients can open the device
|
||||
// Check that both clients can open the device
|
||||
TEST_ASSERT_NOT_EQUAL(0, dev_addr);
|
||||
usb_device_handle_t client0_dev_hdl;
|
||||
usb_device_handle_t client1_dev_hdl;
|
||||
printf("Opening device\n");
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_device_open(client0_hdl, dev_addr, &client0_dev_hdl));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_device_open(client1_hdl, dev_addr, &client1_dev_hdl));
|
||||
TEST_ASSERT_EQUAL_PTR(client0_dev_hdl, client1_dev_hdl); //Check that its the same device
|
||||
//Check that a client cannot open a non-existent device
|
||||
TEST_ASSERT_EQUAL_PTR(client0_dev_hdl, client1_dev_hdl); // Check that its the same device
|
||||
// Check that a client cannot open a non-existent device
|
||||
TEST_ASSERT_NOT_EQUAL(ESP_OK, usb_host_device_open(client0_hdl, 0, &client0_dev_hdl));
|
||||
|
||||
//Check that the device cannot be opened again by the same client
|
||||
// Check that the device cannot be opened again by the same client
|
||||
usb_device_handle_t dummy_dev_hdl;
|
||||
TEST_ASSERT_NOT_EQUAL(ESP_OK, usb_host_device_open(client0_hdl, dev_addr, &dummy_dev_hdl));
|
||||
TEST_ASSERT_NOT_EQUAL(ESP_OK, usb_host_device_open(client1_hdl, dev_addr, &dummy_dev_hdl));
|
||||
printf("Claiming interface\n");
|
||||
//Check that both clients cannot claim the same interface
|
||||
// Check that both clients cannot claim the same interface
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_interface_claim(client0_hdl, client0_dev_hdl, MOCK_MSC_SCSI_INTF_NUMBER, MOCK_MSC_SCSI_INTF_ALT_SETTING));
|
||||
TEST_ASSERT_NOT_EQUAL(ESP_OK, usb_host_interface_claim(client1_hdl, client1_dev_hdl, MOCK_MSC_SCSI_INTF_NUMBER, MOCK_MSC_SCSI_INTF_ALT_SETTING));
|
||||
//Check that client0 cannot claim the same interface multiple times
|
||||
// Check that client0 cannot claim the same interface multiple times
|
||||
TEST_ASSERT_NOT_EQUAL(ESP_OK, usb_host_interface_claim(client0_hdl, client0_dev_hdl, MOCK_MSC_SCSI_INTF_NUMBER, MOCK_MSC_SCSI_INTF_ALT_SETTING));
|
||||
|
||||
printf("Releasing interface\n");
|
||||
//Check that client0 can release the interface
|
||||
// Check that client0 can release the interface
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_interface_release(client0_hdl, client0_dev_hdl, MOCK_MSC_SCSI_INTF_NUMBER));
|
||||
//Check that client0 cannot release interface it has not claimed
|
||||
// Check that client0 cannot release interface it has not claimed
|
||||
TEST_ASSERT_NOT_EQUAL(ESP_OK, usb_host_interface_release(client0_hdl, client0_dev_hdl, MOCK_MSC_SCSI_INTF_NUMBER));
|
||||
|
||||
//Wait until the device disconnects and the clients receive the event
|
||||
// Wait until the device disconnects and the clients receive the event
|
||||
test_usb_set_phy_state(false, 0);
|
||||
while (!(client0_stage == CLIENT_TEST_STAGE_DCONN && client1_stage == CLIENT_TEST_STAGE_DCONN)) {
|
||||
usb_host_lib_handle_events(0, NULL);
|
||||
@@ -254,7 +254,7 @@ TEST_CASE("Test USB Host async API", "[usb_host][full_speed][low_speed]")
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_device_close(client0_hdl, client0_dev_hdl));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_device_close(client1_hdl, client1_dev_hdl));
|
||||
|
||||
//Deregister the clients
|
||||
// Deregister the clients
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_client_deregister(client0_hdl));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_client_deregister(client1_hdl));
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "esp_err.h"
|
||||
#include "esp_intr_alloc.h"
|
||||
#include "test_usb_common.h"
|
||||
#include "test_usb_mock_msc.h"
|
||||
#include "mock_msc.h"
|
||||
#include "msc_client.h"
|
||||
#include "ctrl_client.h"
|
||||
#include "usb/usb_host.h"
|
||||
@@ -38,24 +38,24 @@ TEST_CASE("Test USB Host sudden disconnection (no client)", "[usb_host][full_spe
|
||||
bool connected = false;
|
||||
int dconn_iter = 0;
|
||||
while (1) {
|
||||
//Start handling system events
|
||||
// Start handling system events
|
||||
uint32_t event_flags;
|
||||
usb_host_lib_handle_events(portMAX_DELAY, &event_flags);
|
||||
if (!connected) {
|
||||
usb_host_lib_info_t lib_info;
|
||||
TEST_ASSERT_EQUAL(ESP_OK, usb_host_lib_info(&lib_info));
|
||||
if (lib_info.num_devices == 1) {
|
||||
//We've just connected. Trigger a disconnect
|
||||
// We've just connected. Trigger a disconnect
|
||||
connected = true;
|
||||
printf("Forcing Sudden Disconnect\n");
|
||||
test_usb_set_phy_state(false, 0);
|
||||
}
|
||||
}
|
||||
if (event_flags & USB_HOST_LIB_EVENT_FLAGS_ALL_FREE) {
|
||||
//The device has disconnected and it's disconnection has been handled
|
||||
// The device has disconnected and it's disconnection has been handled
|
||||
printf("Dconn iter %d done\n", dconn_iter);
|
||||
if (++dconn_iter < TEST_DCONN_NO_CLIENT_ITERATIONS) {
|
||||
//Start next iteration
|
||||
// Start next iteration
|
||||
connected = false;
|
||||
test_usb_set_phy_state(true, 0);
|
||||
} else {
|
||||
@@ -83,9 +83,9 @@ Procedure:
|
||||
|
||||
TEST_CASE("Test USB Host sudden disconnection (single client)", "[usb_host][full_speed]")
|
||||
{
|
||||
//Create task to run client that communicates with MSC SCSI interface
|
||||
// Create task to run client that communicates with MSC SCSI interface
|
||||
msc_client_test_param_t params = {
|
||||
.num_sectors_to_read = 1, //Unused by disconnect MSC client
|
||||
.num_sectors_to_read = 1, // Unused by disconnect MSC client
|
||||
.num_sectors_per_xfer = TEST_FORCE_DCONN_NUM_TRANSFERS * MOCK_MSC_SCSI_SECTOR_SIZE,
|
||||
.msc_scsi_xfer_tag = TEST_MSC_SCSI_TAG,
|
||||
.idVendor = MOCK_MSC_SCSI_DEV_ID_VENDOR,
|
||||
@@ -93,13 +93,13 @@ TEST_CASE("Test USB Host sudden disconnection (single client)", "[usb_host][full
|
||||
};
|
||||
TaskHandle_t task_hdl;
|
||||
xTaskCreatePinnedToCore(msc_client_async_dconn_task, "async", 4096, (void *)¶ms, 2, &task_hdl, 0);
|
||||
//Start the task
|
||||
// Start the task
|
||||
xTaskNotifyGive(task_hdl);
|
||||
|
||||
bool all_clients_gone = false;
|
||||
bool all_dev_free = false;
|
||||
while (!all_clients_gone || !all_dev_free) {
|
||||
//Start handling system events
|
||||
// Start handling system events
|
||||
uint32_t event_flags;
|
||||
usb_host_lib_handle_events(portMAX_DELAY, &event_flags);
|
||||
if (event_flags & USB_HOST_LIB_EVENT_FLAGS_NO_CLIENTS) {
|
||||
@@ -133,16 +133,16 @@ Procedure:
|
||||
|
||||
TEST_CASE("Test USB Host enumeration", "[usb_host][full_speed]")
|
||||
{
|
||||
//Create task to run client that checks the enumeration of the device
|
||||
// Create task to run client that checks the enumeration of the device
|
||||
TaskHandle_t task_hdl;
|
||||
xTaskCreatePinnedToCore(msc_client_async_enum_task, "async", 6144, NULL, 2, &task_hdl, 0);
|
||||
//Start the task
|
||||
// Start the task
|
||||
xTaskNotifyGive(task_hdl);
|
||||
|
||||
bool all_clients_gone = false;
|
||||
bool all_dev_free = false;
|
||||
while (!all_clients_gone || !all_dev_free) {
|
||||
//Start handling system events
|
||||
// Start handling system events
|
||||
uint32_t event_flags;
|
||||
usb_host_lib_handle_events(portMAX_DELAY, &event_flags);
|
||||
if (event_flags & USB_HOST_LIB_EVENT_FLAGS_NO_CLIENTS) {
|
||||
|
||||
Reference in New Issue
Block a user