refactor(usb): Remove use of usb_phy_action() from unit tests

Currently, USB Host unit tests that require a software triggered disconnection/
reconnection rely on the 'usb_phy_action()' function.

This commit replaces those calls with 'hcd_port_command()' or
'usb_host_lib_set_root_port_power()'.

Note: Also removed 'test_usb_common.h/c' as it is no longer necessary are the
function call replacements.
This commit is contained in:
Darian Leung
2024-09-27 11:31:42 +02:00
committed by Tomas Rezucha
parent 318c69a671
commit 802ab4c2cc
15 changed files with 50 additions and 110 deletions
@@ -10,7 +10,6 @@
#include "freertos/task.h"
#include "esp_err.h"
#include "esp_log.h"
#include "test_usb_common.h"
#include "dev_msc.h"
#include "ctrl_client.h"
#include "usb/usb_host.h"
@@ -14,7 +14,6 @@
#include "esp_log.h"
#include "mock_msc.h"
#include "dev_msc.h"
#include "test_usb_common.h"
#include "msc_client.h"
#include "usb/usb_types_ch9.h"
#include "usb/usb_host.h"
@@ -251,8 +250,8 @@ void msc_client_async_dconn_task(void *arg)
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
test_usb_set_phy_state(false, 0);
// Trigger a disconnect by powering OFF the root port
usb_host_lib_set_root_port_power(false);
// Next stage set from transfer callback
break;
}
@@ -265,7 +264,8 @@ void msc_client_async_dconn_task(void *arg)
// 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
test_usb_set_phy_state(true, 0);
// Allow connections again by powering ON the root port
usb_host_lib_set_root_port_power(true);
} else {
exit_loop = true;
}
@@ -14,7 +14,6 @@
#include "esp_log.h"
#include "dev_msc.h"
#include "mock_msc.h"
#include "test_usb_common.h"
#include "msc_client.h"
#include "usb/usb_host.h"
#include "unity.h"
@@ -177,8 +176,8 @@ void msc_client_async_enum_task(void *arg)
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
test_usb_set_phy_state(false, 0);
test_usb_set_phy_state(true, 0);
usb_host_lib_set_root_port_power(false);
usb_host_lib_set_root_port_power(true);
msc_obj.next_stage = TEST_STAGE_WAIT_CONN;
skip_event_handling = true; // Need to execute TEST_STAGE_WAIT_CONN
} else {
@@ -12,7 +12,6 @@
#include "freertos/task.h"
#include "esp_err.h"
#include "esp_log.h"
#include "test_usb_common.h"
#include "mock_msc.h"
#include "dev_msc.h"
#include "msc_client.h"
@@ -11,7 +11,6 @@
#include "freertos/semphr.h"
#include "esp_err.h"
#include "esp_log.h"
#include "test_usb_common.h"
#include "multiconf_client.h"
#include "mock_msc.h"
#include "dev_msc.h"
@@ -9,7 +9,6 @@
#include "unity_test_utils_memory.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "test_usb_common.h"
#include "dev_msc.h"
#include "usb/usb_host.h"
@@ -17,10 +16,10 @@ void setUp(void)
{
unity_utils_record_free_mem();
dev_msc_init();
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 = false,
.root_port_unpowered = false,
.intr_flags = ESP_INTR_FLAG_LEVEL1,
};
ESP_ERROR_CHECK(usb_host_install(&host_config));
@@ -35,7 +34,6 @@ void tearDown(void)
ESP_ERROR_CHECK(usb_host_uninstall());
// Short delay to allow task to be cleaned up after client uninstall
vTaskDelay(10);
test_usb_deinit_phy(); // Deinitialize the internal USB PHY after testing
unity_utils_evaluate_leaks();
}
@@ -10,7 +10,6 @@
#include "freertos/semphr.h"
#include "esp_err.h"
#include "esp_intr_alloc.h"
#include "test_usb_common.h"
#include "dev_msc.h"
#include "msc_client.h"
#include "ctrl_client.h"
@@ -252,8 +251,9 @@ TEST_CASE("Test USB Host async API", "[usb_host][full_speed][low_speed]")
client0_dev_hdl,
dev_info->bInterfaceNumber));
// Trigger a disconnect by powering OFF the root port
usb_host_lib_set_root_port_power(false);
// 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);
usb_host_client_handle_events(client0_hdl, 0);
@@ -9,7 +9,6 @@
#include "freertos/task.h"
#include "esp_err.h"
#include "esp_intr_alloc.h"
#include "test_usb_common.h"
#include "mock_msc.h"
#include "dev_msc.h"
#include "msc_client.h"
@@ -49,7 +48,8 @@ TEST_CASE("Test USB Host sudden disconnection (no client)", "[usb_host][full_spe
// We've just connected. Trigger a disconnect
connected = true;
printf("Forcing Sudden Disconnect\n");
test_usb_set_phy_state(false, 0);
// Trigger a disconnect by powering OFF the root port
usb_host_lib_set_root_port_power(false);
}
}
if (event_flags & USB_HOST_LIB_EVENT_FLAGS_ALL_FREE) {
@@ -58,7 +58,8 @@ TEST_CASE("Test USB Host sudden disconnection (no client)", "[usb_host][full_spe
if (++dconn_iter < TEST_DCONN_NO_CLIENT_ITERATIONS) {
// Start next iteration
connected = false;
test_usb_set_phy_state(true, 0);
// Allow connections again by powering ON the root port
usb_host_lib_set_root_port_power(true);
} else {
break;
}