-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from espressif/refactor/restructure_test_app
Chore: Restructure test_app
- Loading branch information
Showing
57 changed files
with
654 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
test_app: | ||
device/esp_tinyusb: | ||
enable: | ||
- if: IDF_TARGET in ["esp32s2", "esp32s3"] | ||
disable: | ||
- if: IDF_VERSION < 5.0 | ||
|
||
host/class: | ||
enable: | ||
- if: IDF_TARGET in ["esp32s2", "esp32s3"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
target = "all" | ||
paths = "test_app" | ||
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/uvc/usb_host_uvc/test_app", | ||
] | ||
recursive = true | ||
manifest_file = ".build-test-rules.yml" | ||
check_warnings = true | ||
|
||
# build related options | ||
build_dir = "build_@t" | ||
build_dir = "build_@t_@w" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# The following lines of boilerplate have to be in your project's | ||
# CMakeLists in this exact order for cmake to work correctly | ||
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 | ||
../ | ||
) | ||
|
||
project(test_app_usb_device_esp_tinyusb) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
| Supported Targets | ESP32-S2 | ESP32-S3 | | ||
| ----------------- | -------- | -------- | | ||
|
||
# USB: esp_tinyusb test application |
6 changes: 4 additions & 2 deletions
6
device/esp_tinyusb/test/CMakeLists.txt → .../esp_tinyusb/test_app/main/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
idf_component_register(SRCS "test_esp_tinyusb.c" "test_bvalid_sig.c" | ||
include($ENV{IDF_PATH}/tools/cmake/version.cmake) | ||
|
||
idf_component_register(SRCS "test_esp_tinyusb.c" "test_bvalid_sig.c" "test_app_main.c" | ||
INCLUDE_DIRS "." | ||
REQUIRES unity esp_tinyusb | ||
) | ||
WHOLE_ARCHIVE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
device/esp_tinyusb/test_app/pytest_usb_device_esp_tinyusb.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import pytest | ||
from pytest_embedded_idf.dut import IdfDut | ||
|
||
|
||
@pytest.mark.esp32s2 | ||
@pytest.mark.esp32s3 | ||
@pytest.mark.usb_device | ||
def test_usb_device_esp_tinyusb(dut: IdfDut) -> None: | ||
dut.run_all_single_board_cases(group='usb_device') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# 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 | ||
CONFIG_TINYUSB_HID_COUNT=0 | ||
|
||
# Disable watchdogs, they'd get triggered during unity interactive menu | ||
CONFIG_ESP_INT_WDT=n | ||
CONFIG_ESP_TASK_WDT=n | ||
|
||
# Run-time checks of Heap and Stack | ||
CONFIG_HEAP_POISONING_COMPREHENSIVE=y | ||
CONFIG_COMPILER_STACK_CHECK_MODE_STRONG=y | ||
CONFIG_COMPILER_STACK_CHECK=y | ||
|
||
CONFIG_UNITY_ENABLE_BACKTRACE_ON_FAIL=y | ||
|
||
CONFIG_COMPILER_CXX_EXCEPTIONS=y |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# The following lines of boilerplate have to be in your project's | ||
# CMakeLists in this exact order for cmake to work correctly | ||
cmake_minimum_required(VERSION 3.16) | ||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
|
||
set(EXTRA_COMPONENT_DIRS | ||
../../esp_modem_usb_dte | ||
../../usb_host_cdc_acm | ||
../../usb_host_ch34x_vcp | ||
../../usb_host_cp210x_vcp | ||
../../usb_host_ftdi_vcp | ||
../../usb_host_vcp | ||
) | ||
|
||
# Set the components to include the tests for. | ||
if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.0") | ||
list(APPEND EXTRA_COMPONENT_DIRS ../../../../../device/esp_tinyusb) | ||
endif() | ||
|
||
project(test_app_usb_host_cdc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
| Supported Targets | ESP32-S2 | ESP32-S3 | | ||
| ----------------- | -------- | -------- | | ||
|
||
# USB: CDC Class test application | ||
|
||
## CDC-ACM driver | ||
|
||
It tests basic functionality of the driver like open/close/read/write operations, | ||
advanced features like CDC control request, multi-threaded or multi-device access, | ||
as well as reaction to sudden disconnection and other error states. | ||
|
||
### Hardware Required | ||
|
||
This test expects that TinyUSB dual CDC device with VID = 0x303A and PID = 0x4002 | ||
is connected to the USB host. |
23 changes: 23 additions & 0 deletions
23
host/class/cdc/usb_host_cdc_acm/test_app/main/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
include($ENV{IDF_PATH}/tools/cmake/version.cmake) | ||
set (TINYUSB_LIB) | ||
if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.0") | ||
set(TINYUSB_LIB "esp_tinyusb") | ||
else() | ||
set(TINYUSB_LIB "tinyusb") | ||
endif() | ||
|
||
# TODO: once IDF_v4.4 is at the EOL support, use WHOLE_ARCHIVE | ||
idf_component_register(SRCS "test_cdc_acm_host.c" "usb_device.c" "test_app_main.c" | ||
INCLUDE_DIRS "." | ||
REQUIRES usb_host_cdc_acm unity ${TINYUSB_LIB}) | ||
|
||
# In order for the cases defined by `TEST_CASE` to be linked into the final elf, | ||
# the component can be registered as WHOLE_ARCHIVE | ||
|
||
# Due to the backward compatibility to IDFv4.4 (in which WHOLE_ARCHIVE is not implemented) we use following approach: | ||
# Any non-static function test_app/main/*.c (apart from test_app_main.c) file is added as an undefined symbol | ||
# because otherwise the linker will ignore test_app/main/*.c as it has no other files depending on any | ||
# symbols in it. | ||
|
||
# force-link test_cdc_acm_host.c | ||
set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "-u usb_lib_task") |
57 changes: 57 additions & 0 deletions
57
host/class/cdc/usb_host_cdc_acm/test_app/main/test_app_main.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#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"); | ||
} | ||
|
||
void app_main(void) | ||
{ | ||
// ____ ___ ___________________ __ __ | ||
// | | \/ _____/\______ \ _/ |_ ____ _______/ |_ | ||
// | | /\_____ \ | | _/ \ __\/ __ \ / ___/\ __\. | ||
// | | / / \ | | \ | | \ ___/ \___ \ | | | ||
// |______/ /_______ / |______ / |__| \___ >____ > |__| | ||
// \/ \/ \/ \/ | ||
printf(" ____ ___ ___________________ __ __ \r\n"); | ||
printf("| | \\/ _____/\\______ \\ _/ |_ ____ _______/ |_ \r\n"); | ||
printf("| | /\\_____ \\ | | _/ \\ __\\/ __ \\ / ___/\\ __\\\r\n"); | ||
printf("| | / / \\ | | \\ | | \\ ___/ \\___ \\ | | \r\n"); | ||
printf("|______/ /_______ / |______ / |__| \\___ >____ > |__| \r\n"); | ||
printf(" \\/ \\/ \\/ \\/ \r\n"); | ||
|
||
UNITY_BEGIN(); | ||
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); | ||
} | ||
|
||
/* 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"); | ||
} |
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions
26
host/class/cdc/usb_host_cdc_acm/test_app/pytest_usb_host_cdc.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from typing import Tuple | ||
|
||
import pytest | ||
from pytest_embedded_idf.dut import IdfDut | ||
|
||
|
||
@pytest.mark.esp32s2 | ||
@pytest.mark.esp32s3 | ||
@pytest.mark.usb_host | ||
@pytest.mark.parametrize('count', [ | ||
2, | ||
], indirect=True) | ||
def test_usb_host(dut: Tuple[IdfDut, IdfDut]) -> None: | ||
device = dut[0] | ||
host = dut[1] | ||
|
||
# 1.1 Prepare USB device for CDC test | ||
device.expect_exact('Press ENTER to see the list of tests.') | ||
device.write('[cdc_acm_device]') | ||
device.expect_exact('USB initialization DONE') | ||
|
||
# 1.2 Run CDC test | ||
host.run_all_single_board_cases(group='cdc_acm') |
19 changes: 19 additions & 0 deletions
19
host/class/cdc/usb_host_cdc_acm/test_app/sdkconfig.defaults
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# 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 | ||
CONFIG_TINYUSB_HID_COUNT=0 | ||
|
||
# Disable watchdogs, they'd get triggered during unity interactive menu | ||
CONFIG_ESP_INT_WDT=n | ||
CONFIG_ESP_TASK_WDT=n | ||
|
||
# Run-time checks of Heap and Stack | ||
CONFIG_HEAP_POISONING_COMPREHENSIVE=y | ||
CONFIG_COMPILER_STACK_CHECK_MODE_STRONG=y | ||
CONFIG_COMPILER_STACK_CHECK=y | ||
|
||
CONFIG_UNITY_ENABLE_BACKTRACE_ON_FAIL=y | ||
|
||
CONFIG_COMPILER_CXX_EXCEPTIONS=y |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.