From ff6855c4b11eb2b66a1a21d808d55ea3a28655ba Mon Sep 17 00:00:00 2001 From: morris Date: Wed, 21 Sep 2022 22:30:20 +0800 Subject: [PATCH] gdma: migrate ut to pytest --- .../esp_hw_support/.build-test-rules.yml | 7 +++ .../test_apps/dma/CMakeLists.txt | 7 +++ .../esp_hw_support/test_apps/dma/README.md | 2 + .../test_apps/dma/main/CMakeLists.txt | 14 +++++ .../test_apps/dma/main/test_app_main.c | 51 +++++++++++++++++++ .../dma/main}/test_async_memcpy.c | 13 ++--- .../{test => test_apps/dma/main}/test_gdma.c | 4 -- .../test_apps/dma/pytest_dma.py | 23 +++++++++ .../test_apps/dma/sdkconfig.ci.release | 6 +++ .../test_apps/dma/sdkconfig.defaults | 2 + 10 files changed, 117 insertions(+), 12 deletions(-) create mode 100644 components/esp_hw_support/.build-test-rules.yml create mode 100644 components/esp_hw_support/test_apps/dma/CMakeLists.txt create mode 100644 components/esp_hw_support/test_apps/dma/README.md create mode 100644 components/esp_hw_support/test_apps/dma/main/CMakeLists.txt create mode 100644 components/esp_hw_support/test_apps/dma/main/test_app_main.c rename components/esp_hw_support/{test => test_apps/dma/main}/test_async_memcpy.c (97%) rename components/esp_hw_support/{test => test_apps/dma/main}/test_gdma.c (98%) create mode 100644 components/esp_hw_support/test_apps/dma/pytest_dma.py create mode 100644 components/esp_hw_support/test_apps/dma/sdkconfig.ci.release create mode 100644 components/esp_hw_support/test_apps/dma/sdkconfig.defaults diff --git a/components/esp_hw_support/.build-test-rules.yml b/components/esp_hw_support/.build-test-rules.yml new file mode 100644 index 0000000000..01b0ede9a7 --- /dev/null +++ b/components/esp_hw_support/.build-test-rules.yml @@ -0,0 +1,7 @@ +# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps + +components/esp_hw_support/test_apps/dma: + disable_test: + - if: IDF_TARGET in ["esp32"] + temporary: false + reason: Neither GDMA nor CPDMA is supported on ESP32 diff --git a/components/esp_hw_support/test_apps/dma/CMakeLists.txt b/components/esp_hw_support/test_apps/dma/CMakeLists.txt new file mode 100644 index 0000000000..349909489f --- /dev/null +++ b/components/esp_hw_support/test_apps/dma/CMakeLists.txt @@ -0,0 +1,7 @@ +# This is the project CMakeLists.txt file for the test subproject +cmake_minimum_required(VERSION 3.16) + +set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components") + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(dma_test) diff --git a/components/esp_hw_support/test_apps/dma/README.md b/components/esp_hw_support/test_apps/dma/README.md new file mode 100644 index 0000000000..b5be4985c5 --- /dev/null +++ b/components/esp_hw_support/test_apps/dma/README.md @@ -0,0 +1,2 @@ +| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S2 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | diff --git a/components/esp_hw_support/test_apps/dma/main/CMakeLists.txt b/components/esp_hw_support/test_apps/dma/main/CMakeLists.txt new file mode 100644 index 0000000000..0fb8a69f50 --- /dev/null +++ b/components/esp_hw_support/test_apps/dma/main/CMakeLists.txt @@ -0,0 +1,14 @@ +set(srcs "test_app_main.c") + +if(CONFIG_SOC_ASYNC_MEMCPY_SUPPORTED) + list(APPEND srcs "test_async_memcpy.c") +endif() + +if(CONFIG_SOC_GDMA_SUPPORTED) + list(APPEND srcs "test_gdma.c") +endif() + +# 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 ${srcs} + WHOLE_ARCHIVE) diff --git a/components/esp_hw_support/test_apps/dma/main/test_app_main.c b/components/esp_hw_support/test_apps/dma/main/test_app_main.c new file mode 100644 index 0000000000..311f7bbb72 --- /dev/null +++ b/components/esp_hw_support/test_apps/dma/main/test_app_main.c @@ -0,0 +1,51 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "unity.h" +#include "unity_test_runner.h" +#include "esp_heap_caps.h" + +// Some resources are lazy allocated in pulse_cnt driver, the threshold is left for that case +#define TEST_MEMORY_LEAK_THRESHOLD (-300) + +static size_t before_free_8bit; +static size_t before_free_32bit; + +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 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); + check_leak(before_free_8bit, after_free_8bit, "8BIT"); + check_leak(before_free_32bit, after_free_32bit, "32BIT"); +} + +void app_main(void) +{ + // ____ __ __ _ _____ _ + // | _ \| \/ | / \ |_ _|__ ___| |_ + // | | | | |\/| | / _ \ | |/ _ \/ __| __| + // | |_| | | | |/ ___ \ | | __/\__ \ |_ + // |____/|_| |_/_/ \_\ |_|\___||___/\__| + printf(" ____ __ __ _ _____ _\r\n"); + printf("| _ \\| \\/ | / \\ |_ _|__ ___| |_\r\n"); + printf("| | | | |\\/| | / _ \\ | |/ _ \\/ __| __|\r\n"); + printf("| |_| | | | |/ ___ \\ | | __/\\__ \\ |_\r\n"); + printf("|____/|_| |_/_/ \\_\\ |_|\\___||___/\\__|\r\n"); + unity_run_menu(); +} diff --git a/components/esp_hw_support/test/test_async_memcpy.c b/components/esp_hw_support/test_apps/dma/main/test_async_memcpy.c similarity index 97% rename from components/esp_hw_support/test/test_async_memcpy.c rename to components/esp_hw_support/test_apps/dma/main/test_async_memcpy.c index 60e84cca79..8d05e7ae6e 100644 --- a/components/esp_hw_support/test/test_async_memcpy.c +++ b/components/esp_hw_support/test_apps/dma/main/test_async_memcpy.c @@ -1,11 +1,12 @@ /* - * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #include #include #include +#include #include #include "esp_heap_caps.h" #include "esp_rom_sys.h" @@ -19,14 +20,12 @@ #include "soc/soc_caps.h" #include "hal/dma_types.h" -#if SOC_CP_DMA_SUPPORTED || SOC_GDMA_SUPPORTED - #define ALIGN_UP(addr, align) (((addr) + (align)-1) & ~((align)-1)) #define ALIGN_DOWN(size, align) ((size) & ~((align) - 1)) typedef struct { uint32_t seed; - uint32_t buffer_size; + size_t buffer_size; uint8_t *src_buf; uint8_t *dst_buf; uint8_t *from_addr; @@ -41,7 +40,7 @@ static void async_memcpy_setup_testbench(memcpy_testbench_context_t *test_contex { srand(test_context->seed); printf("allocating memory buffer...\r\n"); - uint32_t buffer_size = test_context->buffer_size; + size_t buffer_size = test_context->buffer_size; uint8_t *src_buf = NULL; uint8_t *dst_buf = NULL; uint8_t *from_addr = NULL; @@ -75,7 +74,7 @@ static void async_memcpy_setup_testbench(memcpy_testbench_context_t *test_contex to_addr += test_context->offset; buffer_size -= test_context->offset; - printf("...size %d Bytes, src@%p, dst@%p\r\n", buffer_size, from_addr, to_addr); + printf("...size %zu Bytes, src@%p, dst@%p\r\n", buffer_size, from_addr, to_addr); printf("fill src buffer with random data\r\n"); for (int i = 0; i < buffer_size; i++) { from_addr[i] = rand() % 256; @@ -332,5 +331,3 @@ TEST_CASE("memory copy performance test 4KB", "[async mcp]") { memcpy_performance_test(4 * 1024); } - -#endif //SOC_CP_DMA_SUPPORTED || SOC_GDMA_SUPPORTED diff --git a/components/esp_hw_support/test/test_gdma.c b/components/esp_hw_support/test_apps/dma/main/test_gdma.c similarity index 98% rename from components/esp_hw_support/test/test_gdma.c rename to components/esp_hw_support/test_apps/dma/main/test_gdma.c index 6dc447ddcb..8d4e74fd6f 100644 --- a/components/esp_hw_support/test/test_gdma.c +++ b/components/esp_hw_support/test_apps/dma/main/test_gdma.c @@ -7,8 +7,6 @@ #include "esp_private/gdma.h" #include "soc/soc_caps.h" -#if SOC_GDMA_SUPPORTED - TEST_CASE("GDMA channel allocation", "[gdma]") { gdma_channel_alloc_config_t channel_config = {}; @@ -69,5 +67,3 @@ TEST_CASE("GDMA channel allocation", "[gdma]") } #endif } - -#endif diff --git a/components/esp_hw_support/test_apps/dma/pytest_dma.py b/components/esp_hw_support/test_apps/dma/pytest_dma.py new file mode 100644 index 0000000000..d15a0ea289 --- /dev/null +++ b/components/esp_hw_support/test_apps/dma/pytest_dma.py @@ -0,0 +1,23 @@ +# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 + +import pytest +from pytest_embedded import Dut + + +@pytest.mark.esp32s2 +@pytest.mark.esp32s3 +@pytest.mark.esp32c2 +@pytest.mark.esp32c3 +@pytest.mark.generic +@pytest.mark.parametrize( + 'config', + [ + 'release', + ], + indirect=True, +) +def test_dma(dut: Dut) -> None: + dut.expect_exact('Press ENTER to see the list of tests') + dut.write('*') + dut.expect_unity_test_output() diff --git a/components/esp_hw_support/test_apps/dma/sdkconfig.ci.release b/components/esp_hw_support/test_apps/dma/sdkconfig.ci.release new file mode 100644 index 0000000000..22bd3f16c0 --- /dev/null +++ b/components/esp_hw_support/test_apps/dma/sdkconfig.ci.release @@ -0,0 +1,6 @@ +# set compilier optimization level +CONFIG_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y + +# we can silent the assertion to save the binary footprint +CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y diff --git a/components/esp_hw_support/test_apps/dma/sdkconfig.defaults b/components/esp_hw_support/test_apps/dma/sdkconfig.defaults new file mode 100644 index 0000000000..b308cb2ddd --- /dev/null +++ b/components/esp_hw_support/test_apps/dma/sdkconfig.defaults @@ -0,0 +1,2 @@ +CONFIG_FREERTOS_HZ=1000 +CONFIG_ESP_TASK_WDT=n