refactor(ext_port): Removed ext_hub dependency: update test_app

This commit is contained in:
Roman Leonov
2025-03-04 09:55:12 +01:00
parent a807fe7940
commit 178ac8ee0f
4 changed files with 151 additions and 100 deletions

View File

@@ -8,6 +8,7 @@
#include <stdint.h>
#include "esp_err.h"
#include "usb/usb_types_stack.h"
#include "usb/usb_types_ch11.h"
#include "sdkconfig.h"
#ifdef __cplusplus

View File

@@ -73,11 +73,11 @@ const char *const ext_port_event_string[] = {
};
typedef struct {
ext_hub_handle_t hub_hdl;
ext_hub_request_data_t data;
ext_port_hdl_t port_hdl;
ext_port_parent_request_data_t data;
} ext_port_hub_request_msg_t;
static const ext_hub_port_driver_t* port_api;
static const ext_port_driver_api_t* port_api;
SemaphoreHandle_t _process_cd_req = NULL;
QueueHandle_t _ext_port_hub_req_queue = NULL;
QueueHandle_t _ext_port_event_queue = NULL;
@@ -89,22 +89,24 @@ static void test_ext_port_callback(void *user_arg)
xSemaphoreGive(process_req_cb);
}
static void test_ext_port_event_callback(ext_port_event_data_t *event_data, void *arg)
static void test_ext_port_event_callback(ext_port_hdl_t port_hdl, ext_port_event_data_t *event_data, void *arg)
{
QueueHandle_t ext_port_event_queue = (QueueHandle_t)arg;
ext_port_event_data_t msg = *event_data;
xQueueSend(ext_port_event_queue, &msg, portMAX_DELAY);
}
static esp_err_t test_ext_port_hub_class_request(ext_hub_handle_t ext_hub_hdl, ext_hub_request_data_t *request_data, void *user_arg)
static esp_err_t test_ext_port_hub_request(ext_port_hdl_t port_hdl, ext_port_parent_request_data_t *data, void *user_arg)
{
QueueHandle_t hub_req_queue = (QueueHandle_t)user_arg;
ext_port_hub_request_msg_t msg = {
.hub_hdl = ext_hub_hdl,
.port_hdl = port_hdl,
.data = {
.request = request_data->request,
.port_num = request_data->port_num,
.feature = request_data->feature,
.type = data->type,
.control = {
.req = data->control.req,
.feature = data->control.feature,
},
},
};
xQueueSend(hub_req_queue, &msg, portMAX_DELAY);
@@ -130,7 +132,7 @@ static void test_wait_ext_port_event(ext_port_event_t event)
TEST_ASSERT_EQUAL_MESSAGE(event, msg.event, "Unexpected External Hub port event");
}
static esp_err_t test_wait_ext_port_hub_request(void *ext_hub_hdl, uint8_t port_num, usb_hub_class_request_t request)
static esp_err_t test_wait_ext_port_hub_request(ext_port_hdl_t port_hdl, ext_port_parent_request_type_t type, usb_hub_class_request_t request)
{
// Get the hub request queue
TEST_ASSERT_NOT_NULL(_ext_port_hub_req_queue);
@@ -142,16 +144,24 @@ static esp_err_t test_wait_ext_port_hub_request(void *ext_hub_hdl, uint8_t port_
return ESP_ERR_TIMEOUT;
}
// Check the contents of that event message
// TEST_ASSERT_EQUAL(ext_hub_hdl, msg.hub_hdl); // TODO: Enable verification after closing IDF-10023
TEST_ASSERT_EQUAL(port_num, msg.data.port_num);
printf("\tCallback for class request: %s %s\n", hub_request_string[msg.data.request],
(msg.data.request == USB_B_REQUEST_HUB_SET_PORT_FEATURE ||
msg.data.request == USB_B_REQUEST_HUB_CLEAR_FEATURE)
? hub_feature_string[msg.data.feature]
: " ");
// Verify the request if it is not USB_B_REQUEST_ANY
if (msg.data.request != USB_B_REQUEST_ANY) {
TEST_ASSERT_EQUAL_MESSAGE(request, msg.data.request, "Unexpected request");
// TEST_ASSERT_EQUAL(port_hdl, msg.port_hdl); // TODO: Enable verification after closing IDF-10023
TEST_ASSERT_EQUAL(type, msg.data.type);
switch (type) {
case EXT_PORT_PARENT_REQ_CONTROL:
printf("\tCallback for class request: %s %s\n", hub_request_string[msg.data.control.req],
(msg.data.control.req == USB_B_REQUEST_HUB_SET_PORT_FEATURE ||
msg.data.control.req == USB_B_REQUEST_HUB_CLEAR_FEATURE)
? hub_feature_string[msg.data.control.feature]
: " ");
// Verify the request if it is not USB_B_REQUEST_ANY
if (msg.data.control.req != USB_B_REQUEST_ANY) {
TEST_ASSERT_EQUAL_MESSAGE(request, msg.data.control.req, "Unexpected request");
}
break;
default:
break;
}
return ESP_OK;
}
@@ -173,7 +183,7 @@ void test_ext_port_setup(void)
.proc_req_cb_arg = (void*)_process_cd_req,
.event_cb = test_ext_port_event_callback,
.event_cb_arg = (void*)_ext_port_event_queue,
.hub_request_cb = test_ext_port_hub_class_request,
.hub_request_cb = test_ext_port_hub_request,
.hub_request_cb_arg = (void*)_ext_port_hub_req_queue,
};
TEST_ASSERT_EQUAL(ESP_OK, ext_port_install(&ext_port_config));
@@ -200,8 +210,8 @@ ext_port_hdl_t test_ext_port_new(ext_port_config_t *config)
// Process the port
TEST_ASSERT_EQUAL(ESP_OK, ext_port_process());
// Newly added port should trigger the Get Port Status request on the parent hub
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(NULL,
config->parent_port_num,
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(port,
EXT_PORT_PARENT_REQ_CONTROL,
USB_B_REQUEST_HUB_GET_PORT_STATUS)); // Process the port
return port;
}
@@ -221,8 +231,8 @@ void test_ext_port_power_on(uint8_t port1, ext_port_hdl_t port_hdl)
// Process the port
TEST_ASSERT_EQUAL(ESP_OK, ext_port_process());
// Wait Set Feature - Port Power
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(NULL,
port1,
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(port_hdl,
EXT_PORT_PARENT_REQ_CONTROL,
USB_B_REQUEST_HUB_SET_PORT_FEATURE));
// Power on the port
hub_port_power_on(port1);
@@ -233,8 +243,8 @@ void test_ext_port_power_on(uint8_t port1, ext_port_hdl_t port_hdl)
// Process the port
TEST_ASSERT_EQUAL(ESP_OK, ext_port_process());
// Wait Get Port Status
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(NULL,
port1,
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(port_hdl,
EXT_PORT_PARENT_REQ_CONTROL,
USB_B_REQUEST_HUB_GET_PORT_STATUS));
// Get Port Status
hub_get_port_status(port1, &port_status);
@@ -260,11 +270,7 @@ void test_ext_port_disconnected(uint8_t port1, ext_port_hdl_t port_hdl)
// Process the port
TEST_ASSERT_EQUAL(ESP_OK, ext_port_process());
// Disconnected port doesn't require any processing, so there should be no process request
TEST_ASSERT_EQUAL(ESP_ERR_TIMEOUT, test_wait_ext_port_hub_request(NULL,
port1,
USB_B_REQUEST_ANY));
// Port doesn't require any processing, so there should debug message "No more ports to handle"
TEST_ASSERT_EQUAL(ESP_OK, ext_port_process()); // TODO: IDF-12562 replace with Enable INTR EP event await
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(port_hdl, EXT_PORT_PARENT_REQ_PROC_COMPLETED, 0));
// Port is idle
}
@@ -285,8 +291,8 @@ usb_speed_t test_ext_port_connected(uint8_t port1, ext_port_hdl_t port_hdl)
// Process the port
TEST_ASSERT_EQUAL(ESP_OK, ext_port_process());
// Setting the status of the port with C_CONNECTION should trigger the Clear Port Connection
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(NULL,
port1,
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(port_hdl,
EXT_PORT_PARENT_REQ_CONTROL,
USB_B_REQUEST_HUB_CLEAR_FEATURE));
// Clear Port Connection
@@ -297,8 +303,8 @@ usb_speed_t test_ext_port_connected(uint8_t port1, ext_port_hdl_t port_hdl)
// Process the port
TEST_ASSERT_EQUAL(ESP_OK, ext_port_process());
// Powered port with connection should trigger the status update
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(NULL,
port1,
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(port_hdl,
EXT_PORT_PARENT_REQ_CONTROL,
USB_B_REQUEST_HUB_GET_PORT_STATUS));
// Get Port Status
hub_get_port_status(port1, &port_status);
@@ -313,8 +319,8 @@ usb_speed_t test_ext_port_connected(uint8_t port1, ext_port_hdl_t port_hdl)
// Setting the port status should trigger the process request callback
TEST_ASSERT_EQUAL(ESP_OK, ext_port_process());
// Powered port with connection should trigger the Port Reset request on the parent hub
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(NULL,
port1,
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(port_hdl,
EXT_PORT_PARENT_REQ_CONTROL,
USB_B_REQUEST_HUB_SET_PORT_FEATURE));
// Port Reset
hub_port_reset(port1);
@@ -326,8 +332,8 @@ usb_speed_t test_ext_port_connected(uint8_t port1, ext_port_hdl_t port_hdl)
// Process the port
TEST_ASSERT_EQUAL(ESP_OK, ext_port_process());
// Powered port with connection should trigger the Get Port Status request on the parent hub
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(NULL,
port1,
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(port_hdl,
EXT_PORT_PARENT_REQ_CONTROL,
USB_B_REQUEST_HUB_GET_PORT_STATUS));
// Get Port Status
hub_get_port_status(port1, &port_status);
@@ -343,8 +349,8 @@ usb_speed_t test_ext_port_connected(uint8_t port1, ext_port_hdl_t port_hdl)
// Process the port
TEST_ASSERT_EQUAL(ESP_OK, ext_port_process());
// Powered port with connection after reset should trigger the Clear Port Reset request on the parent hub
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(NULL,
port1,
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(port_hdl,
EXT_PORT_PARENT_REQ_CONTROL,
USB_B_REQUEST_HUB_CLEAR_FEATURE));
// Clear Port reset request
hub_port_clear_reset(port1);
@@ -355,8 +361,8 @@ usb_speed_t test_ext_port_connected(uint8_t port1, ext_port_hdl_t port_hdl)
// Process the port
TEST_ASSERT_EQUAL(ESP_OK, ext_port_process());
// Powered port with connection after reset should trigger the Get Port Status request on the parent hub
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(NULL,
port1,
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(port_hdl,
EXT_PORT_PARENT_REQ_CONTROL,
USB_B_REQUEST_HUB_GET_PORT_STATUS));
// Get Port Status
@@ -407,8 +413,8 @@ void test_ext_port_imitate_disconnection(uint8_t port1, ext_port_hdl_t port_hdl)
// Process the port
TEST_ASSERT_EQUAL(ESP_OK, ext_port_process());
// Setting the status of the port with connection should trigger the Clear Port Connection
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(NULL,
port1,
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(port_hdl,
EXT_PORT_PARENT_REQ_CONTROL,
USB_B_REQUEST_HUB_CLEAR_FEATURE));
// Assume that clear connection done successfully, but we do not need actually change the port status
// Clear Port Feature: C_CONNECTION - assume we done it, ESP_OK
@@ -420,8 +426,8 @@ void test_ext_port_imitate_disconnection(uint8_t port1, ext_port_hdl_t port_hdl)
// Process the port
TEST_ASSERT_EQUAL(ESP_OK, ext_port_process());
// Cleared port connection should trigger the Get Port Status request on the parent hub
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(NULL,
port1,
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(port_hdl,
EXT_PORT_PARENT_REQ_CONTROL,
USB_B_REQUEST_HUB_GET_PORT_STATUS));
// We don't need to request actual port status, proceed with cached status
@@ -453,8 +459,8 @@ void test_ext_port_disable(uint8_t port1, ext_port_hdl_t port_hdl)
test_wait_ext_port_process_request();
// Process the port
TEST_ASSERT_EQUAL(ESP_OK, ext_port_process());
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(NULL,
port1,
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(port_hdl,
EXT_PORT_PARENT_REQ_CONTROL,
USB_B_REQUEST_HUB_CLEAR_FEATURE));
// When port is not gone, it should create a DISCONNECTION event
test_wait_ext_port_event(EXT_PORT_DISCONNECTED);
@@ -467,8 +473,8 @@ void test_ext_port_disable(uint8_t port1, ext_port_hdl_t port_hdl)
// Process the port
TEST_ASSERT_EQUAL(ESP_OK, ext_port_process());
// Cleared port enable should trigger the Get Port Status request on the parent hub
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(NULL,
port1,
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(port_hdl,
EXT_PORT_PARENT_REQ_CONTROL,
USB_B_REQUEST_HUB_GET_PORT_STATUS));
// Get Port Status
hub_get_port_status(port1, &port_status);
@@ -481,25 +487,19 @@ void test_ext_port_disable(uint8_t port1, ext_port_hdl_t port_hdl)
// Wait for the process request callback
test_wait_ext_port_process_request();
// Port doesn't require any processing, so there should debug message "No more ports to handle"
TEST_ASSERT_EQUAL(ESP_OK, ext_port_process()); // TODO: IDF-12562 replace with Enable INTR EP event await
// Disabled port doesn't require any processing, so there should be no process request
TEST_ASSERT_EQUAL(ESP_ERR_TIMEOUT, test_wait_ext_port_hub_request(NULL,
port1,
USB_B_REQUEST_HUB_GET_PORT_STATUS));
TEST_ASSERT_EQUAL(ESP_OK, ext_port_process());
// Disabled port doesn't require any processing, handling should be completed
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(port_hdl, EXT_PORT_PARENT_REQ_PROC_COMPLETED, 0));
// Port is disabled and wait device to be detached.
// Terminal state
}
void test_ext_port_gone(ext_port_hdl_t port_hdl, bool has_device)
void test_ext_port_gone(ext_port_hdl_t port_hdl, test_gone_flag_t flag)
{
if (has_device) {
if (flag == GONE_DEVICE_PRESENT) {
// Port is enabled, port gone returns ESP_ERR_NOT_FINISHED
TEST_ASSERT_EQUAL(ESP_ERR_NOT_FINISHED, port_api->gone(port_hdl));
// Wait for the process request callback
// test_ext_port_wait_process_request();
// Port doesn't require any processing, so there should debug message "No more ports to handle"
// TEST_ASSERT_EQUAL(ESP_OK, ext_port_process()); // TODO: IDF-12562 replace with Enable INTR EP event await
// Get Disconnect event
// Mark the connected port as gone should trigger disconnect event if the port has a device
test_wait_ext_port_event(EXT_PORT_DISCONNECTED);
return;
}
@@ -512,14 +512,23 @@ void test_ext_port_delete(ext_port_hdl_t port_hdl)
TEST_ASSERT_EQUAL(ESP_OK, port_api->del(port_hdl));
}
void test_ext_port_recycle(ext_port_hdl_t port_hdl)
void test_ext_port_recycle(ext_port_hdl_t port_hdl, test_recycle_flag_t flag)
{
TEST_ASSERT_EQUAL(ESP_OK, port_api->recycle(port_hdl));
// Recycling the port for the process request callback
test_wait_ext_port_process_request();
// Process the port
TEST_ASSERT_EQUAL(ESP_OK, ext_port_process());
// Port gone
// ? Port delete
// : Port is IDLE
switch (flag) {
case RECYCLE_PORT_IS_GONE:
// Recycling in not available for the gone port
TEST_ASSERT_EQUAL(ESP_ERR_INVALID_STATE, port_api->recycle(port_hdl));
break;
case RECYCLE_PORT_PRESENT:
TEST_ASSERT_EQUAL(ESP_OK, port_api->recycle(port_hdl));
// Recycling the port for the process request callback
test_wait_ext_port_process_request();
// Process the port
TEST_ASSERT_EQUAL(ESP_OK, ext_port_process());
TEST_ASSERT_EQUAL(ESP_OK, test_wait_ext_port_hub_request(port_hdl, EXT_PORT_PARENT_REQ_PROC_COMPLETED, 0));
break;
default:
TEST_ASSERT(0); // Invalid flag
break;
}
}

View File

@@ -6,6 +6,16 @@
#include "ext_port.h"
typedef enum {
RECYCLE_PORT_PRESENT = 0,
RECYCLE_PORT_IS_GONE
} test_recycle_flag_t;
typedef enum {
GONE_DEVICE_PRESENT = 0,
GONE_DEVICE_NOT_PRESENT
} test_gone_flag_t;
/**
* @brief External Port setup test
* Create queues for events/callbacks and install External Port driver
@@ -88,9 +98,9 @@ void test_ext_port_disable(uint8_t port1, ext_port_hdl_t port_hdl);
* @brief Test External Port recycle
*
* @param[in] port_hdl External Port handle
* @param[in] has_device Device presence
* @param[in] flag Device presence
*/
void test_ext_port_gone(ext_port_hdl_t port_hdl, bool has_device);
void test_ext_port_gone(ext_port_hdl_t port_hdl, test_gone_flag_t flag);
/**
* @brief Test External Port delete
@@ -103,5 +113,6 @@ void test_ext_port_delete(ext_port_hdl_t port_hdl);
* @brief Test External Port recycle
*
* @param[in] port_hdl External Port handle
* @param[in] flag Port recycle flag
*/
void test_ext_port_recycle(ext_port_hdl_t port_hdl);
void test_ext_port_recycle(ext_port_hdl_t port_hdl, test_recycle_flag_t flag);

View File

@@ -92,7 +92,7 @@ TEST_CASE("Port: disconnected", "[low_speed][full_speed][high_speed]")
TEST_ASSERT_TRUE(TEST_PORT_NUM_EMPTY <= port_num);
// Create External Port
ext_port_config_t port_config = {
.ext_hub_hdl = (void*) hub_get_context() /* use any before IDF-10023 */,
.context = (void*) hub_get_context() /* use any before IDF-10023 */,
.parent_dev_hdl = (void*) hub_get_context() /* use any before IDF-10023 */,
.parent_port_num = TEST_PORT_NUM_EMPTY,
.port_power_delay_ms = hub_get_port_poweron_delay_ms(),
@@ -105,7 +105,7 @@ TEST_CASE("Port: disconnected", "[low_speed][full_speed][high_speed]")
// Detach parent hub
hub_detach();
// Notify port
test_ext_port_gone(port_hdl, false);
test_ext_port_gone(port_hdl, GONE_DEVICE_NOT_PRESENT);
test_ext_port_delete(port_hdl);
}
@@ -136,7 +136,7 @@ TEST_CASE("Port: enumerate child device Low-speed", "[ext_port][low_speed]")
TEST_ASSERT_TRUE(TEST_PORT_NUM_DEVICE_LS <= port_num);
// Create External Port
ext_port_config_t port_config = {
.ext_hub_hdl = (void*) hub_get_context() /* use any before IDF-10023 */,
.context = (void*) hub_get_context() /* use any before IDF-10023 */,
.parent_dev_hdl = (void*) hub_get_context() /* use any before IDF-10023 */,
.parent_port_num = TEST_PORT_NUM_DEVICE_LS,
.port_power_delay_ms = hub_get_port_poweron_delay_ms(),
@@ -157,12 +157,12 @@ TEST_CASE("Port: enumerate child device Low-speed", "[ext_port][low_speed]")
hub_child_pipe_free(ctrl_pipe);
// Wait disconnection
test_ext_port_imitate_disconnection(TEST_PORT_NUM_DEVICE_LS, port_hdl);
// Recycle the port
test_ext_port_recycle(port_hdl);
// Recylce the port
test_ext_port_recycle(port_hdl, RECYCLE_PORT_PRESENT);
// Detach hub
hub_detach();
// Notify port
test_ext_port_gone(port_hdl, false);
test_ext_port_gone(port_hdl, GONE_DEVICE_NOT_PRESENT);
test_ext_port_delete(port_hdl);
}
@@ -193,7 +193,7 @@ TEST_CASE("Port: enumerate child device Full-speed", "[ext_port][full_speed]")
TEST_ASSERT_TRUE(TEST_PORT_NUM_DEVICE_FSHS <= port_num);
// Create External Port
ext_port_config_t port_config = {
.ext_hub_hdl = (void*) hub_get_context() /* use any before IDF-10023 */,
.context = (void*) hub_get_context() /* use any before IDF-10023 */,
.parent_dev_hdl = (void*) hub_get_context() /* use any before IDF-10023 */,
.parent_port_num = TEST_PORT_NUM_DEVICE_FSHS,
.port_power_delay_ms = hub_get_port_poweron_delay_ms(),
@@ -214,12 +214,12 @@ TEST_CASE("Port: enumerate child device Full-speed", "[ext_port][full_speed]")
hub_child_pipe_free(ctrl_pipe);
// Wait disconnection
test_ext_port_imitate_disconnection(TEST_PORT_NUM_DEVICE_FSHS, port_hdl);
// Recycle the port
test_ext_port_recycle(port_hdl);
// Recylce the port
test_ext_port_recycle(port_hdl, RECYCLE_PORT_PRESENT);
// Detach hub
hub_detach();
// Notify port
test_ext_port_gone(port_hdl, false);
test_ext_port_gone(port_hdl, GONE_DEVICE_NOT_PRESENT);
test_ext_port_delete(port_hdl);
}
@@ -250,7 +250,7 @@ TEST_CASE("Port: enumerate child device High-speed", "[ext_port][high_speed]")
TEST_ASSERT_TRUE(TEST_PORT_NUM_DEVICE_FSHS <= port_num);
// Create External Port
ext_port_config_t port_config = {
.ext_hub_hdl = (void*) hub_get_context() /* use any before IDF-10023 */,
.context = (void*) hub_get_context() /* use any before IDF-10023 */,
.parent_dev_hdl = (void*) hub_get_context() /* use any before IDF-10023 */,
.parent_port_num = TEST_PORT_NUM_DEVICE_FSHS,
.port_power_delay_ms = hub_get_port_poweron_delay_ms(),
@@ -271,12 +271,12 @@ TEST_CASE("Port: enumerate child device High-speed", "[ext_port][high_speed]")
hub_child_pipe_free(ctrl_pipe);
// Wait disconnection
test_ext_port_imitate_disconnection(TEST_PORT_NUM_DEVICE_FSHS, port_hdl);
// Recycle the port
test_ext_port_recycle(port_hdl);
// Recylce the port
test_ext_port_recycle(port_hdl, RECYCLE_PORT_PRESENT);
// Detach hub
hub_detach();
// Notify port
test_ext_port_gone(port_hdl, false);
test_ext_port_gone(port_hdl, GONE_DEVICE_NOT_PRESENT);
test_ext_port_delete(port_hdl);
}
@@ -307,7 +307,7 @@ TEST_CASE("Port: recycle", "[ext_port][full_speed][high_speed]")
TEST_ASSERT_TRUE(TEST_PORT_NUM_DEVICE_FSHS <= port_num);
// Create External Port
ext_port_config_t port_config = {
.ext_hub_hdl = (void*) hub_get_context() /* use any before IDF-10023 */,
.context = (void*) hub_get_context() /* use any before IDF-10023 */,
.parent_dev_hdl = (void*) hub_get_context() /* use any before IDF-10023 */,
.parent_port_num = TEST_PORT_NUM_DEVICE_FSHS,
.port_power_delay_ms = hub_get_port_poweron_delay_ms(),
@@ -324,7 +324,7 @@ TEST_CASE("Port: recycle", "[ext_port][full_speed][high_speed]")
test_ext_port_imitate_disconnection(TEST_PORT_NUM_DEVICE_FSHS, port_hdl);
// Recylce the port
printf("Recycle the port...\n");
test_ext_port_recycle(port_hdl);
test_ext_port_recycle(port_hdl, RECYCLE_PORT_PRESENT);
// Repower the port as we use imitation for disconnection. Port state in the External Port Driver is not changed during that.
hub_port_power_off(TEST_PORT_NUM_DEVICE_FSHS);
hub_port_power_on(TEST_PORT_NUM_DEVICE_FSHS);
@@ -337,14 +337,44 @@ TEST_CASE("Port: recycle", "[ext_port][full_speed][high_speed]")
// Wait disconnection
test_ext_port_imitate_disconnection(TEST_PORT_NUM_DEVICE_FSHS, port_hdl);
// Recylce the port
test_ext_port_recycle(port_hdl);
test_ext_port_recycle(port_hdl, RECYCLE_PORT_PRESENT);
// Detach hub
hub_detach();
// Notify port
test_ext_port_gone(port_hdl, false);
test_ext_port_gone(port_hdl, GONE_DEVICE_NOT_PRESENT);
test_ext_port_delete(port_hdl);
}
TEST_CASE("Port: recycle when port is gone", "[ext_port][low_speed][full_speed][high_speed]")
{
hub_attach();
uint8_t port_num = hub_get_port_num();
TEST_ASSERT_TRUE(TEST_PORT_NUM_DEVICE_FSHS <= port_num);
// Create External Port
ext_port_config_t port_config = {
.context = (void*) hub_get_context() /* use any before IDF-10023 */,
.parent_dev_hdl = (void*) hub_get_context() /* use any before IDF-10023 */,
.parent_port_num = TEST_PORT_NUM_DEVICE_FSHS,
.port_power_delay_ms = hub_get_port_poweron_delay_ms(),
};
ext_port_hdl_t port_hdl = test_ext_port_new(&port_config);
// After adding the port, it is in POWERED_OFF state
test_ext_port_power_on(TEST_PORT_NUM_DEVICE_FSHS, port_hdl);
// Wait connection
usb_speed_t port_speed = test_ext_port_connected(TEST_PORT_NUM_DEVICE_FSHS, port_hdl);
printf("Hub port: %s speed device \n", (char*[]) {
"Low", "Full", "High"
}[port_speed]);
// Detach hub
hub_detach();
// Notify port
test_ext_port_gone(port_hdl, GONE_DEVICE_PRESENT);
// Recylce the port
test_ext_port_recycle(port_hdl, RECYCLE_PORT_IS_GONE);
// test_ext_port_delete(port_hdl);
}
/*
Test the port disable procedure.
@@ -367,7 +397,7 @@ TEST_CASE("Port: disable", "[ext_port][full_speed][high_speed]")
TEST_ASSERT_TRUE(TEST_PORT_NUM_DEVICE_FSHS <= port_num);
// Create External Port
ext_port_config_t port_config = {
.ext_hub_hdl = (void*) hub_get_context() /* use any before IDF-10023 */,
.context = (void*) hub_get_context() /* use any before IDF-10023 */,
.parent_dev_hdl = (void*) hub_get_context() /* use any before IDF-10023 */,
.parent_port_num = TEST_PORT_NUM_DEVICE_FSHS,
.port_power_delay_ms = hub_get_port_poweron_delay_ms(),
@@ -385,7 +415,7 @@ TEST_CASE("Port: disable", "[ext_port][full_speed][high_speed]")
// Detach hub
hub_detach();
// Notify port
test_ext_port_gone(port_hdl, false);
test_ext_port_gone(port_hdl, GONE_DEVICE_NOT_PRESENT);
test_ext_port_delete(port_hdl);
}
@@ -410,7 +440,7 @@ TEST_CASE("Port: gone in state - powered on", "[ext_port][full_speed][high_speed
TEST_ASSERT_TRUE(TEST_PORT_NUM_DEVICE_FSHS <= port_num);
// Create External Port
ext_port_config_t port_config = {
.ext_hub_hdl = (void*) hub_get_context() /* use any before IDF-10023 */,
.context = (void*) hub_get_context() /* use any before IDF-10023 */,
.parent_dev_hdl = (void*) hub_get_context() /* use any before IDF-10023 */,
.parent_port_num = TEST_PORT_NUM_DEVICE_FSHS,
.port_power_delay_ms = hub_get_port_poweron_delay_ms(),
@@ -422,7 +452,7 @@ TEST_CASE("Port: gone in state - powered on", "[ext_port][full_speed][high_speed
printf("Port Gone...\n");
hub_detach();
// Notify port
test_ext_port_gone(port_hdl, false);
test_ext_port_gone(port_hdl, GONE_DEVICE_NOT_PRESENT);
test_ext_port_delete(port_hdl);
}
@@ -448,7 +478,7 @@ TEST_CASE("Port: gone in state - enabled", "[ext_port][full_speed][high_speed]")
TEST_ASSERT_TRUE(TEST_PORT_NUM_DEVICE_FSHS <= port_num);
// Create External Port
ext_port_config_t port_config = {
.ext_hub_hdl = (void*) hub_get_context() /* use any before IDF-10023 */,
.context = (void*) hub_get_context() /* use any before IDF-10023 */,
.parent_dev_hdl = (void*) hub_get_context() /* use any before IDF-10023 */,
.parent_port_num = TEST_PORT_NUM_DEVICE_FSHS,
.port_power_delay_ms = hub_get_port_poweron_delay_ms(),
@@ -465,6 +495,6 @@ TEST_CASE("Port: gone in state - enabled", "[ext_port][full_speed][high_speed]")
printf("Port Gone...\n");
hub_detach();
// Notify port
test_ext_port_gone(port_hdl, true);
test_ext_port_gone(port_hdl, GONE_DEVICE_PRESENT);
test_ext_port_delete(port_hdl);
}