Skip to content

Commit

Permalink
ci: Modernize esp_tinyusb test_app
Browse files Browse the repository at this point in the history
  • Loading branch information
tore-espressif committed Sep 18, 2024
1 parent 9c94c5f commit aff7183
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 63 deletions.
6 changes: 2 additions & 4 deletions .build-test-rules.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
device/esp_tinyusb:
enable:
- if: IDF_TARGET in ["esp32s2", "esp32s3"]
disable:
- if: IDF_VERSION < 5.0
- if: SOC_USB_OTG_SUPPORTED == 1

host/class:
enable:
- if: IDF_TARGET in ["esp32s2", "esp32s3"]
- if: SOC_USB_OTG_SUPPORTED == 1
9 changes: 2 additions & 7 deletions .idf_build_apps.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
target = "all"
paths = [
"device/esp_tinyusb/test_app",
"host/class/cdc/usb_host_cdc_acm/test_app",
"host/class/hid/usb_host_hid/test_app",
"host/class/msc/usb_host_msc/test_app",
"host/class/uac/usb_host_uac/test_app",
"host/class/uvc/usb_host_uvc/test_app",
exclude = [
"clang_tidy",
]
recursive = true
manifest_file = ".build-test-rules.yml"
Expand Down
6 changes: 2 additions & 4 deletions device/esp_tinyusb/test_app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)

# Set the components to include the tests for.
set(EXTRA_COMPONENT_DIRS
../
)
# "Trim" the build. Include the minimal set of components, main, and anything it depends on.
set(COMPONENTS main)

project(test_app_usb_device_esp_tinyusb)
6 changes: 3 additions & 3 deletions device/esp_tinyusb/test_app/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
| Supported Targets | ESP32-S2 | ESP32-S3 |
| ----------------- | -------- | -------- |
| Supported Targets | ESP32-S2 | ESP32-S3 | ESP32-P4 |
| ----------------- | -------- | -------- | -------- |

# USB: esp_tinyusb test application
# USB: esp_tinyusb test application
4 changes: 1 addition & 3 deletions device/esp_tinyusb/test_app/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
include($ENV{IDF_PATH}/tools/cmake/version.cmake)

idf_component_register(SRC_DIRS .
INCLUDE_DIRS .
REQUIRES unity esp_tinyusb
REQUIRES unity
WHOLE_ARCHIVE)
2 changes: 0 additions & 2 deletions device/esp_tinyusb/test_app/main/idf_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ dependencies:
espressif/esp_tinyusb:
version: "*"
override_path: "../../"
rules:
- if: "idf_version >= 5.0"
69 changes: 37 additions & 32 deletions device/esp_tinyusb/test_app/main/test_app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,56 @@
#include <stdio.h>
#include <string.h>
#include "unity.h"
#include "esp_heap_caps.h"

static size_t before_free_8bit;
static size_t before_free_32bit;

#define TEST_MEMORY_LEAK_THRESHOLD (-530)
static void check_leak(size_t before_free, size_t after_free, const char *type)
{
ssize_t delta = after_free - before_free;
printf("MALLOC_CAP_%s: Before %u bytes free, After %u bytes free (delta %d)\n", type, before_free, after_free, delta);
TEST_ASSERT_MESSAGE(delta >= TEST_MEMORY_LEAK_THRESHOLD, "memory leak");
}
#include "unity_test_runner.h"
#include "unity_test_utils_memory.h"

void app_main(void)
{
// ____ ___ ___________________ __ __
// | | \/ _____/\______ \ _/ |_ ____ _______/ |_
// | | /\_____ \ | | _/ \ __\/ __ \ / ___/\ __\.
// | | / / \ | | \ | | \ ___/ \___ \ | |
// |______/ /_______ / |______ / |__| \___ >____ > |__|
// \/ \/ \/ \/
printf(" ____ ___ ___________________ __ __ \r\n");
printf("| | \\/ _____/\\______ \\ _/ |_ ____ _______/ |_ \r\n");
printf("| | /\\_____ \\ | | _/ \\ __\\/ __ \\ / ___/\\ __\\\r\n");
printf("| | / / \\ | | \\ | | \\ ___/ \\___ \\ | | \r\n");
printf("|______/ /_______ / |______ / |__| \\___ >____ > |__| \r\n");
printf(" \\/ \\/ \\/ \\/ \r\n");
/*
_ _ _
| | (_) | |
___ ___ _ __ | |_ _ _ __ _ _ _ _ ___| |__
/ _ \/ __| '_ \| __| | '_ \| | | | | | / __| '_ \
| __/\__ \ |_) | |_| | | | | |_| | |_| \__ \ |_) |
\___||___/ .__/ \__|_|_| |_|\__, |\__,_|___/_.__/
| |______ __/ |
|_|______| |___/
_____ _____ _____ _____
|_ _| ___/ ___|_ _|
| | | |__ \ `--. | |
| | | __| `--. \ | |
| | | |___/\__/ / | |
\_/ \____/\____/ \_/
*/

printf(" _ _ _ \n");
printf(" | | (_) | | \n");
printf(" ___ ___ _ __ | |_ _ _ __ _ _ _ _ ___| |__ \n");
printf(" / _ \\/ __| '_ \\| __| | '_ \\| | | | | | / __| '_ \\ \n");
printf("| __/\\__ \\ |_) | |_| | | | | |_| | |_| \\__ \\ |_) |\n");
printf(" \\___||___/ .__/ \\__|_|_| |_|\\__, |\\__,_|___/_.__/ \n");
printf(" | |______ __/ | \n");
printf(" |_|______| |___/ \n");
printf(" _____ _____ _____ _____ \n");
printf("|_ _| ___/ ___|_ _| \n");
printf(" | | | |__ \\ `--. | | \n");
printf(" | | | __| `--. \\ | | \n");
printf(" | | | |___/\\__/ / | | \n");
printf(" \\_/ \\____/\\____/ \\_/ \n");

UNITY_BEGIN();
unity_utils_setup_heap_record(80);
unity_utils_set_leak_level(128);
unity_run_menu();
UNITY_END();
}

/* 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);
unity_utils_record_free_mem();
}

/* tearDown runs after every test */
void tearDown(void)
{
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");
check_leak(before_free_32bit, after_free_32bit, "32BIT");
unity_utils_evaluate_leaks();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

#define VFS_PATH "/dev/usb-cdc1"

// idf_component_register(WHOLE_ARCHIVE) backward compatibility to IDF_v4.4
void linker_hook(void) {};

static const tusb_desc_device_t cdc_device_descriptor = {
.bLength = sizeof(cdc_device_descriptor),
.bDescriptorType = TUSB_DESC_DEVICE,
Expand Down Expand Up @@ -65,7 +62,7 @@ static void tinyusb_cdc_rx_callback(int itf, cdcacm_event_t *event)
*
* Note: CDC0 appends 'novfs' to echoed data, so the host (test runner) can easily determine which port is which.
*/
TEST_CASE("tinyusb_cdc", "[esp_tinyusb]")
TEST_CASE("tinyusb_cdc", "[esp_tinyusb][cdc]")
{
// Install TinyUSB driver
const tinyusb_config_t tusb_cfg = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.esp32p4
@pytest.mark.usb_device
def test_usb_device_cdc(dut) -> None:
'''
Expand All @@ -24,7 +25,7 @@ def test_usb_device_cdc(dut) -> None:
3. Open both comports and send some data. Expect echoed data
'''
dut.expect_exact('Press ENTER to see the list of tests.')
dut.write('[esp_tinyusb]')
dut.write('[cdc]')
dut.expect_exact('TinyUSB: TinyUSB Driver installed')
sleep(2) # Some time for the OS to enumerate our USB device

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

@pytest.mark.esp32s2
@pytest.mark.esp32s3
@pytest.mark.esp32p4
@pytest.mark.usb_device
def test_usb_device_esp_tinyusb(dut: IdfDut) -> None:
dut.run_all_single_board_cases(group='usb_device')
1 change: 0 additions & 1 deletion device/esp_tinyusb/test_app/sdkconfig.defaults
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Configure TinyUSB, it will be used to mock USB devices
CONFIG_TINYUSB=y
CONFIG_TINYUSB_MSC_ENABLED=n
CONFIG_TINYUSB_CDC_ENABLED=y
CONFIG_TINYUSB_CDC_COUNT=2
Expand Down
4 changes: 2 additions & 2 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ markers =
# target markers
esp32s2: support esp32s2 target
esp32s3: support esp32s3 target
supported_targets: support all supported targets ('esp32s2', 'esp32s3')
esp32p4: support esp32p4 target
supported_targets: support all supported targets ('esp32s2', 'esp32s3', 'esp32p4')

# env markers
generic: generic runner
usb_host: usb host runners
usb_device: usb device runners

Expand Down

0 comments on commit aff7183

Please sign in to comment.