diff --git a/.gitlab/ci/target-test.yml b/.gitlab/ci/target-test.yml index d3fea30137..e1a6f7bdf2 100644 --- a/.gitlab/ci/target-test.yml +++ b/.gitlab/ci/target-test.yml @@ -853,6 +853,14 @@ pytest_components_esp32s3_mspi_f8r8: - build_pytest_components_esp32s3 tags: [ esp32s3, MSPI_F8R8 ] +pytest_components_esp32s3_usb_serial_jtag: + extends: + - .pytest_components_dir_template + - .rules:test:component_ut-esp32s3 + needs: + - build_pytest_components_esp32s3 + tags: [ esp32s3, usb_serial_jtag ] + pytest_components_esp32c2_generic: extends: - .pytest_components_dir_template @@ -919,6 +927,14 @@ pytest_components_esp32c3_wifi_two_dut: - build_pytest_components_esp32c3 tags: [ esp32c3, wifi_two_dut ] +pytest_components_esp32c3_usb_serial_jtag: + extends: + - .pytest_components_dir_template + - .rules:test:component_ut-esp32c3 + needs: + - build_pytest_components_esp32c3 + tags: [ esp32c3, usb_serial_jtag ] + pytest_components_esp32s3_wifi_two_dut: extends: - .pytest_components_dir_template @@ -1008,6 +1024,14 @@ pytest_components_esp32c6_generic: tags: [ esp32c6, generic ] parallel: 2 +pytest_components_esp32c6_usb_serial_jtag: + extends: + - .pytest_components_dir_template + - .rules:test:component_ut-esp32c6 + needs: + - build_pytest_components_esp32c6 + tags: [ esp32c6, usb_serial_jtag ] + pytest_components_esp32h2_generic: extends: - .pytest_components_dir_template @@ -1041,6 +1065,14 @@ component_ut_pytest_esp32h2_ecdsa: - build_pytest_components_esp32h2 tags: [ esp32h2, ecdsa_efuse ] +pytest_components_esp32h2_usb_serial_jtag: + extends: + - .pytest_components_dir_template + - .rules:test:component_ut-esp32h2 + needs: + - build_pytest_components_esp32h2 + tags: [ esp32h2, usb_serial_jtag ] + pytest_components_esp32c6_generic_multi_device: extends: - .pytest_components_dir_template diff --git a/components/driver/test_apps/.build-test-rules.yml b/components/driver/test_apps/.build-test-rules.yml index ee1ae4391f..98a33dbdf7 100644 --- a/components/driver/test_apps/.build-test-rules.yml +++ b/components/driver/test_apps/.build-test-rules.yml @@ -184,3 +184,14 @@ components/driver/test_apps/uart: - if: IDF_TARGET in ["esp32p4"] temporary: true reason: target(s) is not supported yet # TODO: IDF-6511 + +components/driver/test_apps/usb_serial_jtag: + disable: + - if: SOC_USB_SERIAL_JTAG_SUPPORTED != 1 + depends_filepatterns: + - components/driver/gpio/**/* + - components/driver/usb_serial_jtag/**/* + depends_components: + - hal + - esp_hw_support # for clock + - vfs diff --git a/components/driver/test_apps/usb_serial_jtag/CMakeLists.txt b/components/driver/test_apps/usb_serial_jtag/CMakeLists.txt new file mode 100644 index 0000000000..0881e007a7 --- /dev/null +++ b/components/driver/test_apps/usb_serial_jtag/CMakeLists.txt @@ -0,0 +1,8 @@ +# This is the project CMakeLists.txt file for the test subproject +cmake_minimum_required(VERSION 3.16) + +# "Trim" the build. Include the minimal set of components, main, and anything it depends on. +set(COMPONENTS main) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(usb_serial_test) diff --git a/components/driver/test_apps/usb_serial_jtag/README.md b/components/driver/test_apps/usb_serial_jtag/README.md new file mode 100644 index 0000000000..f1988f4a40 --- /dev/null +++ b/components/driver/test_apps/usb_serial_jtag/README.md @@ -0,0 +1,2 @@ +| Supported Targets | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S3 | +| ----------------- | -------- | -------- | -------- | -------- | diff --git a/components/driver/test_apps/usb_serial_jtag/main/CMakeLists.txt b/components/driver/test_apps/usb_serial_jtag/main/CMakeLists.txt new file mode 100644 index 0000000000..f1b9135ba6 --- /dev/null +++ b/components/driver/test_apps/usb_serial_jtag/main/CMakeLists.txt @@ -0,0 +1,7 @@ +# In order for the cases defined by `TEST_CASE` to be linked into the final elf, +# the component can be registered as WHOLE_ARCHIVE +idf_component_register( + SRCS "test_app_main.c" "test_usb_serial_jtag.c" + REQUIRES driver unity vfs + WHOLE_ARCHIVE +) diff --git a/components/driver/test_apps/usb_serial_jtag/main/test_app_main.c b/components/driver/test_apps/usb_serial_jtag/main/test_app_main.c new file mode 100644 index 0000000000..dead56be55 --- /dev/null +++ b/components/driver/test_apps/usb_serial_jtag/main/test_app_main.c @@ -0,0 +1,50 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "unity.h" +#include "unity_test_utils.h" +#include "esp_heap_caps.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" + +#define TEST_MEMORY_LEAK_THRESHOLD (200) + +static size_t before_free_8bit; +static size_t before_free_32bit; + +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); +} + +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); + printf("\n"); + unity_utils_check_leak(before_free_8bit, after_free_8bit, "8BIT", TEST_MEMORY_LEAK_THRESHOLD); + unity_utils_check_leak(before_free_32bit, after_free_32bit, "32BIT", TEST_MEMORY_LEAK_THRESHOLD); +} + +void app_main(void) +{ + // _ _ _____ ____ _____ ______ _____ _____ _ + // | | | |/ ____| _ \ / ____| ____| __ \|_ _| /\ | | + // | | | | (___ | |_) || (___ | |__ | |__) | | | / \ | | + // | | | |\___ \| _ < \___ \| __| | _ / | | / /\ \ | | + // | |__| |____) | |_) | ____) | |____| | \ \ _| |_ / ____ \| |____ + // \____/|_____/|____/ |_____/|______|_| \_\_____/_/ \_\______| + printf("\n"); + printf(" _ _ _____ ____ _____ ______ _____ _____ _ \n"); + printf("| | | |/ ____| _ \\ / ____| ____| __ \\|_ _| /\\ | | \n"); + printf("| | | | (___ | |_) || (___ | |__ | |__) | | | / \\ | | \n"); + printf("| | | |\\___ \\| _ < \\___ \\| __| | _ / | | / /\\ \\ | | \n"); + printf("| |__| |____) | |_) | ____) | |____| | \\ \\ _| |_ / ____ \\| |____ \n"); + printf(" \\____/|_____/|____/ |_____/|______|_| \\_\\_____/_/ \\_\\______|\n"); + + unity_run_menu(); +} diff --git a/components/driver/test_apps/usb_serial_jtag/main/test_usb_serial_jtag.c b/components/driver/test_apps/usb_serial_jtag/main/test_usb_serial_jtag.c new file mode 100644 index 0000000000..9d55d6f1e6 --- /dev/null +++ b/components/driver/test_apps/usb_serial_jtag/main/test_usb_serial_jtag.c @@ -0,0 +1,66 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include +#include +#include "unity.h" +#include "driver/usb_serial_jtag.h" +#include "esp_log.h" +#include "esp_vfs_dev.h" +#include "esp_vfs_usb_serial_jtag.h" +#include "driver/usb_serial_jtag.h" +#include +#include +#include + +#define PRINT_TIMES (300) +static const char TAG[] = "usb_serial_test"; + +static void test_task_driver1(void *pvParameters) +{ + SemaphoreHandle_t sem = (SemaphoreHandle_t)pvParameters; + for (int i = 0; i < PRINT_TIMES; i++) { + ESP_LOGI(TAG, "Oh, hello world 1, this test is for testing message and parse in python, time %d", i); + vTaskDelay(11); + } + xSemaphoreGive(sem); + vTaskDelete(NULL); +} + +static void test_task_driver2(void *pvParameters) +{ + SemaphoreHandle_t sem = (SemaphoreHandle_t)pvParameters; + for (int i = 0; i < PRINT_TIMES; i++) { + ESP_LOGI(TAG, "Oh, hello world 2, this test is for testing message and parse in python, time %d", i); + vTaskDelay(10); + } + xSemaphoreGive(sem); + vTaskDelete(NULL); +} + + +TEST_CASE("test print via usb_serial_jtag driver multiple times in different tasks", "[usb_serial_jtag]") +{ + usb_serial_jtag_driver_config_t cfg = USB_SERIAL_JTAG_DRIVER_CONFIG_DEFAULT(); + SemaphoreHandle_t sem = xSemaphoreCreateCounting(2, 0); + + TEST_ESP_OK(usb_serial_jtag_driver_install(&cfg)); + + // Tell vfs to use usb-serial-jtag driver + esp_vfs_usb_serial_jtag_use_driver(); + + xTaskCreate(test_task_driver2, "usj_print_1", 4096, sem, 10, NULL); + xTaskCreate(test_task_driver1, "usj_print_2", 4096, sem, 10, NULL); + for (int i = 0; i < 2; i++) { + xSemaphoreTake(sem, portMAX_DELAY); + } + + vSemaphoreDelete(sem); + vTaskDelay(5); + + esp_vfs_usb_serial_jtag_use_nonblocking(); + usb_serial_jtag_driver_uninstall(); +} diff --git a/components/driver/test_apps/usb_serial_jtag/pytest_usb_serial_jtag.py b/components/driver/test_apps/usb_serial_jtag/pytest_usb_serial_jtag.py new file mode 100644 index 0000000000..d76ee7fdba --- /dev/null +++ b/components/driver/test_apps/usb_serial_jtag/pytest_usb_serial_jtag.py @@ -0,0 +1,24 @@ +# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 + +import pytest +from pytest_embedded import Dut + + +@pytest.mark.esp32s3 +@pytest.mark.esp32c3 +@pytest.mark.esp32c6 +@pytest.mark.esp32h2 +@pytest.mark.usb_serial_jtag +@pytest.mark.parametrize( + 'port, config', + [ + ('/dev/ttyACM0', 'release'), + ], + indirect=True, +) +def test_usb_serial_jtag_dev(dut: Dut) -> None: # type: ignore + dut.expect_exact('Press ENTER to see the list of tests') + dut.write('\"test print via usb_serial_jtag driver multiple times in different tasks\"') + for i in range(300 * 2): + dut.expect(r'Oh, hello world (\d), this test is for testing message and parse in python, time (\d+)', timeout=10) diff --git a/components/driver/test_apps/usb_serial_jtag/sdkconfig.ci.release b/components/driver/test_apps/usb_serial_jtag/sdkconfig.ci.release new file mode 100644 index 0000000000..673b6f8f74 --- /dev/null +++ b/components/driver/test_apps/usb_serial_jtag/sdkconfig.ci.release @@ -0,0 +1,6 @@ +CONFIG_PM_ENABLE=y +CONFIG_FREERTOS_USE_TICKLESS_IDLE=y +CONFIG_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y +CONFIG_COMPILER_OPTIMIZATION_NONE=y diff --git a/components/driver/test_apps/usb_serial_jtag/sdkconfig.defaults b/components/driver/test_apps/usb_serial_jtag/sdkconfig.defaults new file mode 100644 index 0000000000..7c1a0ceba9 --- /dev/null +++ b/components/driver/test_apps/usb_serial_jtag/sdkconfig.defaults @@ -0,0 +1,3 @@ +CONFIG_FREERTOS_HZ=1000 +CONFIG_ESP_TASK_WDT_INIT=n +CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y diff --git a/tools/test_apps/system/build_test/sdkconfig.ci.usb_serial_jtag b/tools/test_apps/system/build_test/sdkconfig.ci.usb_serial_jtag deleted file mode 100644 index 5e9f8e25bd..0000000000 --- a/tools/test_apps/system/build_test/sdkconfig.ci.usb_serial_jtag +++ /dev/null @@ -1 +0,0 @@ -CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y