refactor(usb_serial_jtag): make usb_serial_jtag as component

This commit is contained in:
Cao Sen Miao
2024-01-02 18:08:35 +08:00
parent 32e2101c0d
commit 3dc76e9360
33 changed files with 244 additions and 168 deletions

View File

@@ -97,14 +97,3 @@ components/driver/test_apps/twai:
- components/driver/twai/**/*
depends_components:
- esp_driver_gpio
components/driver/test_apps/usb_serial_jtag:
disable:
- if: SOC_USB_SERIAL_JTAG_SUPPORTED != 1
depends_filepatterns:
- components/driver/usb_serial_jtag/**/*
depends_components:
- hal
- esp_hw_support # for clock
- vfs
- esp_driver_gpio

View File

@@ -1,8 +0,0 @@
# 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)

View File

@@ -1,2 +0,0 @@
| Supported Targets | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S3 |
| ----------------- | -------- | -------- | -------- | -------- |

View File

@@ -1,7 +0,0 @@
# 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
)

View File

@@ -1,50 +0,0 @@
/*
* 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();
}

View File

@@ -1,66 +0,0 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include <string.h>
#include <sys/param.h>
#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 <freertos/FreeRTOS.h>
#include <freertos/semphr.h>
#include <freertos/task.h>
#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();
}

View File

@@ -1,24 +0,0 @@
# 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)

View File

@@ -1,6 +0,0 @@
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

View File

@@ -1,3 +0,0 @@
CONFIG_FREERTOS_HZ=1000
CONFIG_ESP_TASK_WDT_INIT=n
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y