Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: espressif/esp-usb
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: de1a18b1c068854ac8f98149b31f632e0f7aaf6a
Choose a base ref
..
head repository: espressif/esp-usb
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3345b90a128201af727c9a2c18655c0246069b40
Choose a head ref
Showing with 81 additions and 32 deletions.
  1. +81 −32 device/esp_tinyusb/test_apps/configuration_desc/main/test_config_desc.c
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
#include "tinyusb.h"
#include "tusb_tasks.h"

static const char *TAG = "teardown";
static const char *TAG = "config_test";

#define TEARDOWN_DEVICE_ATTACH_TIMEOUT_MS 1000
#define TEARDOWN_DEVICE_DETACH_DELAY_MS 1000
@@ -78,19 +78,35 @@ static const tusb_desc_device_t test_device_descriptor = {
// ========================== Private logic ====================================
SemaphoreHandle_t wait_mount = NULL;

/**
* @brief Creates test additional resources.
*
* Is called before start test to create/init internal resources.
*/
static bool __test_init(void)
{
wait_mount = xSemaphoreCreateBinary();
return (wait_mount != NULL);
}

/**
* @brief Indicates device connection event.
*
* Is called in tud_mount callback.
*/
static void __test_conn(void)
{
if (wait_mount) {
xSemaphoreGive(wait_mount);
}
}

/**
* @brief Awaits device connection event.
*
* Is used for waiting the event in test logic.
* Timeout could be configured via TEARDOWN_DEVICE_ATTACH_TIMEOUT_MS define.
*/
static esp_err_t __test_wait_conn(void)
{
if (!wait_mount) {
@@ -102,41 +118,65 @@ static esp_err_t __test_wait_conn(void)
: ESP_ERR_TIMEOUT );
}

/**
* @brief Releases test resources.
*
* Is called in the end of the test to release internal resources.
*/
static void __test_release(void)
{
if (wait_mount) {
vSemaphoreDelete(wait_mount);
}
}

/**
* @brief One round of setup configuration for TinyUSB.
*
* Steps:
* 1. Init internal resources
* 2. Installs TinyUSB with provided configuration
* 3. Waits for the connection event from the Host
* 4. Gives some extra time for Host to configure the device (configures via TEARDOWN_DEVICE_DETACH_DELAY_MS)
* 5. Uninstall TinyUSB
* 6. Release internal resources
*
* Is called in the end of the test to release internal resources.
*/
static void __test_tinyusb_set_config(const tinyusb_config_t *tusb_cfg)
{
// Install
TEST_ASSERT_EQUAL(true, __test_init());
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_install(tusb_cfg));
// Wait for mounted callback
TEST_ASSERT_EQUAL(ESP_OK, __test_wait_conn());
// Give Host some timer to init the device
vTaskDelay(pdMS_TO_TICKS(TEARDOWN_DEVICE_DETACH_DELAY_MS));
// Cleanup
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_uninstall());
// Release resources
__test_release();
}

// ========================== Callbacks ========================================
// Invoked when device is mounted
/**
* @brief TinyUSB callback for device mount.
*
* @note
* For Linux-based Hosts: Reflects the SetConfiguration() request from the Host Driver.
* For Win-based Hosts: SetConfiguration() request is present only with available Class in device descriptor.
*/
void tud_mount_cb(void)
{
ESP_LOGD(TAG, "%s", __FUNCTION__);
__test_conn();
}

// ============================= Tests =========================================

/**
* @brief TinyUSB Configuration test case.
*
* Verifies:
* Configuration without specifying any parameters.
* Confiuration & descriptors are provided by esp_tinyusb wrapper.
*/
TEST_CASE("descriptors_config_all_default", "[esp_tinyusb][usb_device][config]")
{
TEST_ASSERT_EQUAL(true, __test_init());
// Install TinyUSB driver
const tinyusb_config_t tusb_cfg = {
.external_phy = false,
.device_descriptor = NULL,
@@ -145,13 +185,19 @@ TEST_CASE("descriptors_config_all_default", "[esp_tinyusb][usb_device][config]")
.hs_configuration_descriptor = NULL,
#endif // TUD_OPT_HIGH_SPEED
};
// Install TinyUSB driver
__test_tinyusb_set_config(&tusb_cfg);
}

/**
* @brief TinyUSB Configuration test case.
*
* Verifies:
* Configuration with specifying only device descriptor.
* For High-speed qualifier descriptor as well.
*/
TEST_CASE("descriptors_config_device", "[esp_tinyusb][usb_device][config]")
{
TEST_ASSERT_EQUAL(true, __test_init());
// Install TinyUSB driver
const tinyusb_config_t tusb_cfg = {
.external_phy = false,
.device_descriptor = &test_device_descriptor,
@@ -164,10 +210,18 @@ TEST_CASE("descriptors_config_device", "[esp_tinyusb][usb_device][config]")
__test_tinyusb_set_config(&tusb_cfg);
}

/**
* @brief TinyUSB Configuration test case.
*
* Verifies:
* Configuration with specifying device & configuration descriptors.
*
* For High-speed:
* - HS configuration descriptor is not provided by user (legacy compatibility) and default HS config descriptor is using when possible.
* - Qualifier descriptor.
*/
TEST_CASE("descriptors_config_device_and_config", "[esp_tinyusb][usb_device][config]")
{
TEST_ASSERT_EQUAL(true, __test_init());
// Install TinyUSB driver
const tinyusb_config_t tusb_cfg = {
.external_phy = false,
.device_descriptor = &test_device_descriptor,
@@ -181,24 +235,15 @@ TEST_CASE("descriptors_config_device_and_config", "[esp_tinyusb][usb_device][con
}

#if (TUD_OPT_HIGH_SPEED)
TEST_CASE("descriptors_config_device_and_fs_config_only", "[esp_tinyusb][usb_device][config]")
{
TEST_ASSERT_EQUAL(true, __test_init());
// Install TinyUSB driver
const tinyusb_config_t tusb_cfg = {
.external_phy = false,
.device_descriptor = &test_device_descriptor,
.configuration_descriptor = test_fs_configuration_descriptor,
.hs_configuration_descriptor = NULL,
.qualifier_descriptor = &device_qualifier,
};
__test_tinyusb_set_config(&tusb_cfg);
}

/**
* @brief TinyUSB High-speed Configuration test case.
*
* Verifies:
* Configuration with specifying device & HS configuration descriptor only.
* FS configuration descriptor is not provided by user (legacy compatibility) and default configuration descriptor for FS is using when possible.
*/
TEST_CASE("descriptors_config_device_and_hs_config_only", "[esp_tinyusb][usb_device][config]")
{
TEST_ASSERT_EQUAL(true, __test_init());
// Install TinyUSB driver
const tinyusb_config_t tusb_cfg = {
.external_phy = false,
.device_descriptor = &test_device_descriptor,
@@ -209,10 +254,14 @@ TEST_CASE("descriptors_config_device_and_hs_config_only", "[esp_tinyusb][usb_dev
__test_tinyusb_set_config(&tusb_cfg);
}

/**
* @brief TinyUSB High-speed Configuration test case.
*
* Verifies:
* Configuration with specifying all descriptors by user.
*/
TEST_CASE("descriptors_config_all_configured", "[esp_tinyusb][usb_device][config]")
{
TEST_ASSERT_EQUAL(true, __test_init());
// Install TinyUSB driver
const tinyusb_config_t tusb_cfg = {
.external_phy = false,
.device_descriptor = &test_device_descriptor,