Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions device/esp_tinyusb/test_apps/runtime_config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
| Supported Targets | ESP32-H4 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | -------- | -------- | -------- | -------- |

# Espressif's Additions to TinyUSB - Runtime Configuration Test Application

This directory contains Unity tests that validate Espressif-specific integration of TinyUSB.

The tests focus on:

- TinyUSB configuration helpers (default macros, per-port config).
- USB Device descriptors (FS/HS, string descriptors, edge cases).
- USB peripheral / PHY configuration for full-speed and high-speed.
- TinyUSB task configuration (CPU pinning, invalid parameters).
- Multitask access to the TinyUSB driver (concurrent installs).

The test prints a numbered menu, for example:

```
(1) "Config: Default macros arguments" [runtime_config][default]
(2) "Config: Full-speed (High-speed)" [runtime_config][full_speed]
...
```

You can run all tests by running `pytest` or select individual ones by name and number.

## Tags

Each test is tagged with categories and modes:

### Categories

- [runtime_config] – Tests focusing on `tinyusb_config_t` and runtime configuration.
- [periph] – Tests that directly exercise the USB peripheral (USB OTG 1.1 or USB OTG 2.0).
- [task] – Tests related to the dedicated TinyUSB task configuration.

### Speed / Mode

- [default] – Generic, target-agnostic.
- [full_speed] – Tests specific to USB OTG 1.1 / Full-speed port.
- [high_speed] – Tests specific to USB OTG 2.0 / High-speed port.

These tags can be used by test runners / CI to select or filter tests.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@

#define MULTIPLE_THREADS_TASKS_NUM 5

static int nb_of_success = 0;
// Unlocked spinlock, ready to use
static portMUX_TYPE _spinlock = portMUX_INITIALIZER_UNLOCKED;
static volatile int nb_of_success = 0;

static void test_task_install(void *arg)
{
Expand All @@ -42,7 +44,9 @@ static void test_task_install(void *arg)
if (tinyusb_driver_install(&tusb_cfg) == ESP_OK) {
test_device_wait();
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_uninstall());
taskENTER_CRITICAL(&_spinlock);
nb_of_success++;
taskEXIT_CRITICAL(&_spinlock);
}

// Notify the parent task that the task completed the job
Expand Down Expand Up @@ -70,19 +74,20 @@ TEST_CASE("Multitask: Install", "[runtime_config][full_speed][high_speed]")
};
TEST_ASSERT_EQUAL_MESSAGE(ESP_OK, usb_new_phy(&phy_conf, &phy_hdl), "Unable to install USB PHY ");

taskENTER_CRITICAL(&_spinlock);
nb_of_success = 0;
taskEXIT_CRITICAL(&_spinlock);
// Create tasks that will start the driver
for (int i = 0; i < MULTIPLE_THREADS_TASKS_NUM; i++) {
TEST_ASSERT_EQUAL(pdTRUE, xTaskCreate(test_task_install,
TEST_ASSERT_EQUAL(pdPASS, xTaskCreate(test_task_install,
"InstallTask",
4096,
(void *) xTaskGetCurrentTaskHandle(),
4 + i,
NULL));
}

// Wait until all tasks are finished
vTaskDelay(pdMS_TO_TICKS(5000));
// Wait some time for all tasks to complete
vTaskDelay(pdMS_TO_TICKS(1000));
Comment on lines +89 to +90
Copy link

Copilot AI Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The delay was reduced from 5000ms to 1000ms, but tasks may still be running after this delay. This creates a race condition where ulTaskNotifyTake() on line 92 might wait for notifications from tasks that haven't completed yet. Consider removing this delay entirely and relying solely on ulTaskNotifyTake() timeout, or ensure the delay is sufficient for all tasks to complete.

Suggested change
// Wait some time for all tasks to complete
vTaskDelay(pdMS_TO_TICKS(1000));

Copilot uses AI. Check for mistakes.
// Check if all tasks finished, we should get all notification from the tasks
TEST_ASSERT_EQUAL_MESSAGE(MULTIPLE_THREADS_TASKS_NUM, ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(5000)), "Not all tasks finished");
// There should be only one task that was able to install the driver
Expand Down
Loading