Skip to content

Commit

Permalink
fix(test_app): restore from failed uac test
Browse files Browse the repository at this point in the history
  • Loading branch information
leeebo committed May 23, 2024
1 parent a5da57e commit c3a9a2e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 30 deletions.
5 changes: 5 additions & 0 deletions host/class/uac/usb_host_uac/test_app/main/test_app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,21 @@ void app_main(void)
UNITY_END();
}

extern void test_uac_setup(void);
extern void test_uac_teardown(bool);

/* setUp runs before every test */
void setUp(void)
{
before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
test_uac_setup();
}

/* tearDown runs after every test */
void tearDown(void)
{
test_uac_teardown(false);
size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
check_leak(before_free_8bit, after_free_8bit, "8BIT");
Expand Down
40 changes: 10 additions & 30 deletions host/class/uac/usb_host_uac/test_app/main/test_host_uac.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static void force_conn_state(bool connected, TickType_t delay_ticks)
//Delay of 0 ticks causes a yield. So skip if delay_ticks is 0.
vTaskDelay(delay_ticks);
}
ESP_ERROR_CHECK(usb_phy_action(phy_hdl, (connected) ? USB_PHY_ACTION_HOST_ALLOW_CONN : USB_PHY_ACTION_HOST_FORCE_DISCONN));
TEST_ASSERT_EQUAL(ESP_OK, usb_phy_action(phy_hdl, (connected) ? USB_PHY_ACTION_HOST_ALLOW_CONN : USB_PHY_ACTION_HOST_FORCE_DISCONN));
}

typedef enum {
Expand Down Expand Up @@ -106,7 +106,7 @@ static void uac_device_callback(uac_host_device_handle_t uac_device_handle, cons
{
if (event == UAC_HOST_DRIVER_EVENT_DISCONNECTED) {
ESP_LOGI(TAG, "UAC Device disconnected");
ESP_ERROR_CHECK(uac_host_device_close(uac_device_handle));
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_close(uac_device_handle));
return;
}
// Send uac device event to the event queue
Expand Down Expand Up @@ -155,7 +155,7 @@ static void usb_lib_task(void *arg)
.intr_flags = ESP_INTR_FLAG_LEVEL1,
};

ESP_ERROR_CHECK(usb_host_install(&host_config));
TEST_ASSERT_EQUAL(ESP_OK, usb_host_install(&host_config));
ESP_LOGI(TAG, "USB Host installed");
xTaskNotifyGive(arg);

Expand All @@ -179,8 +179,8 @@ static void usb_lib_task(void *arg)
ESP_LOGI(TAG, "USB Host shutdown");
// Clean up USB Host
vTaskDelay(10); // Short delay to allow clients clean-up
ESP_ERROR_CHECK(usb_host_uninstall());
ESP_ERROR_CHECK(usb_del_phy(phy_hdl)); //Tear down USB PHY
TEST_ASSERT_EQUAL(ESP_OK, usb_host_uninstall());
TEST_ASSERT_EQUAL(ESP_OK, usb_del_phy(phy_hdl)); //Tear down USB PHY
phy_hdl = NULL;
// set bit BIT0_USB_HOST_DRIVER_REMOVED to notify driver removed
xEventGroupSetBits(s_evt_handle, BIT0_USB_HOST_DRIVER_REMOVED);
Expand Down Expand Up @@ -219,7 +219,7 @@ void test_uac_setup(void)
.callback_arg = NULL
};

ESP_ERROR_CHECK(uac_host_install(&uac_config));
TEST_ASSERT_EQUAL(ESP_OK, uac_host_install(&uac_config));
ESP_LOGI(TAG, "UAC Class Driver installed");
}

Expand All @@ -236,7 +236,7 @@ void test_uac_teardown(bool force)
vTaskDelay(500);
// uninstall uac host driver
ESP_LOGI(TAG, "UAC Driver uninstall");
ESP_ERROR_CHECK(uac_host_uninstall());
TEST_ASSERT_EQUAL(ESP_OK, uac_host_uninstall());
// Wait for USB lib task to finish
xEventGroupWaitBits(s_evt_handle, BIT0_USB_HOST_DRIVER_REMOVED, pdTRUE, pdTRUE, portMAX_DELAY);
// delete event queue and event group
Expand All @@ -257,7 +257,7 @@ void test_open_mic_device(uint8_t iface_num, uint32_t buffer_size, uint32_t buff
.callback = uac_device_callback,
.callback_arg = NULL,
};
ESP_ERROR_CHECK(uac_host_device_open(&dev_config, uac_device_handle));
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_open(&dev_config, uac_device_handle));
}

void test_open_spk_device(uint8_t iface_num, uint32_t buffer_size, uint32_t buffer_threshold, uac_host_device_handle_t *uac_device_handle)
Expand All @@ -271,12 +271,12 @@ void test_open_spk_device(uint8_t iface_num, uint32_t buffer_size, uint32_t buff
.callback = uac_device_callback,
.callback_arg = NULL,
};
ESP_ERROR_CHECK(uac_host_device_open(&dev_config, uac_device_handle));
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_open(&dev_config, uac_device_handle));
}

void test_close_device(uac_host_device_handle_t uac_device_handle)
{
ESP_ERROR_CHECK(uac_host_device_close(uac_device_handle));
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_close(uac_device_handle));
}

void test_handle_dev_connection(uint8_t *iface_num, uint8_t *if_rx)
Expand All @@ -300,7 +300,6 @@ void test_handle_dev_connection(uint8_t *iface_num, uint8_t *if_rx)
*/
TEST_CASE("test uac device handling", "[uac_host][known_device]")
{
test_uac_setup();
// handle device connection
uint8_t mic_iface_num = 0;
uint8_t spk_iface_num = 0;
Expand Down Expand Up @@ -369,20 +368,13 @@ TEST_CASE("test uac device handling", "[uac_host][known_device]")
// reset the queue
test_uac_queue_reset();
}

// Tear down test
test_uac_teardown(false);
// Verify the memory leackage during test environment tearDown()
}

/**
* @brief record the rx stream data from microphone
*/
TEST_CASE("test uac rx reading", "[uac_host][rx]")
{
// write test for uac rx
test_uac_setup();

uint8_t mic_iface_num = 0;
uint8_t spk_iface_num = 0;
uint8_t if_rx = false;
Expand Down Expand Up @@ -449,7 +441,6 @@ TEST_CASE("test uac rx reading", "[uac_host][rx]")
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_close(uac_device_handle));

free(rx_buffer);
test_uac_teardown(false);
}

/**
Expand All @@ -458,9 +449,6 @@ TEST_CASE("test uac rx reading", "[uac_host][rx]")
*/
TEST_CASE("test uac tx writing", "[uac_host][tx]")
{
// write test for uac tx
test_uac_setup();

// handle device connection
uint8_t mic_iface_num = 0;
uint8_t spk_iface_num = 0;
Expand Down Expand Up @@ -611,8 +599,6 @@ TEST_CASE("test uac tx writing", "[uac_host][tx]")
free(tx_buffer);
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_set_mute(uac_device_handle, 1));
TEST_ASSERT_EQUAL(ESP_OK, uac_host_device_close(uac_device_handle));

test_uac_teardown(false);
}

/**
Expand All @@ -621,8 +607,6 @@ TEST_CASE("test uac tx writing", "[uac_host][tx]")
*/
TEST_CASE("test uac tx rx loopback", "[uac_host][tx][rx]")
{
test_uac_setup();

// handle device connection
uint8_t mic_iface_num = 0;
uint8_t spk_iface_num = 0;
Expand Down Expand Up @@ -765,7 +749,6 @@ TEST_CASE("test uac tx rx loopback", "[uac_host][tx][rx]")
if (rx_buffer_stereo) {
free(rx_buffer_stereo);
}
test_uac_teardown(false);
}

/**
Expand All @@ -776,8 +759,6 @@ TEST_CASE("test uac tx rx loopback", "[uac_host][tx][rx]")
#if !CONFIG_IDF_TARGET_ESP32P4
TEST_CASE("test uac tx rx loopback with disconnect", "[uac_host][tx][rx][hot-plug]")
{
test_uac_setup();

// handle device connection
uint8_t mic_iface_num = 0;
uint8_t spk_iface_num = 0;
Expand Down Expand Up @@ -919,6 +900,5 @@ TEST_CASE("test uac tx rx loopback with disconnect", "[uac_host][tx][rx][hot-plu
if (rx_buffer_stereo) {
free(rx_buffer_stereo);
}
test_uac_teardown(false);
}
#endif

0 comments on commit c3a9a2e

Please sign in to comment.