mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
gdma: migrate ut to pytest
This commit is contained in:
parent
d609884407
commit
ff6855c4b1
7
components/esp_hw_support/.build-test-rules.yml
Normal file
7
components/esp_hw_support/.build-test-rules.yml
Normal file
@ -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
|
7
components/esp_hw_support/test_apps/dma/CMakeLists.txt
Normal file
7
components/esp_hw_support/test_apps/dma/CMakeLists.txt
Normal file
@ -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)
|
2
components/esp_hw_support/test_apps/dma/README.md
Normal file
2
components/esp_hw_support/test_apps/dma/README.md
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S2 | ESP32-S3 |
|
||||||
|
| ----------------- | ----- | -------- | -------- | -------- | -------- |
|
14
components/esp_hw_support/test_apps/dma/main/CMakeLists.txt
Normal file
14
components/esp_hw_support/test_apps/dma/main/CMakeLists.txt
Normal file
@ -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)
|
51
components/esp_hw_support/test_apps/dma/main/test_app_main.c
Normal file
51
components/esp_hw_support/test_apps/dma/main/test_app_main.c
Normal file
@ -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();
|
||||||
|
}
|
@ -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
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include "esp_heap_caps.h"
|
#include "esp_heap_caps.h"
|
||||||
#include "esp_rom_sys.h"
|
#include "esp_rom_sys.h"
|
||||||
@ -19,14 +20,12 @@
|
|||||||
#include "soc/soc_caps.h"
|
#include "soc/soc_caps.h"
|
||||||
#include "hal/dma_types.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_UP(addr, align) (((addr) + (align)-1) & ~((align)-1))
|
||||||
#define ALIGN_DOWN(size, align) ((size) & ~((align) - 1))
|
#define ALIGN_DOWN(size, align) ((size) & ~((align) - 1))
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t seed;
|
uint32_t seed;
|
||||||
uint32_t buffer_size;
|
size_t buffer_size;
|
||||||
uint8_t *src_buf;
|
uint8_t *src_buf;
|
||||||
uint8_t *dst_buf;
|
uint8_t *dst_buf;
|
||||||
uint8_t *from_addr;
|
uint8_t *from_addr;
|
||||||
@ -41,7 +40,7 @@ static void async_memcpy_setup_testbench(memcpy_testbench_context_t *test_contex
|
|||||||
{
|
{
|
||||||
srand(test_context->seed);
|
srand(test_context->seed);
|
||||||
printf("allocating memory buffer...\r\n");
|
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 *src_buf = NULL;
|
||||||
uint8_t *dst_buf = NULL;
|
uint8_t *dst_buf = NULL;
|
||||||
uint8_t *from_addr = 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;
|
to_addr += test_context->offset;
|
||||||
buffer_size -= 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");
|
printf("fill src buffer with random data\r\n");
|
||||||
for (int i = 0; i < buffer_size; i++) {
|
for (int i = 0; i < buffer_size; i++) {
|
||||||
from_addr[i] = rand() % 256;
|
from_addr[i] = rand() % 256;
|
||||||
@ -332,5 +331,3 @@ TEST_CASE("memory copy performance test 4KB", "[async mcp]")
|
|||||||
{
|
{
|
||||||
memcpy_performance_test(4 * 1024);
|
memcpy_performance_test(4 * 1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //SOC_CP_DMA_SUPPORTED || SOC_GDMA_SUPPORTED
|
|
@ -7,8 +7,6 @@
|
|||||||
#include "esp_private/gdma.h"
|
#include "esp_private/gdma.h"
|
||||||
#include "soc/soc_caps.h"
|
#include "soc/soc_caps.h"
|
||||||
|
|
||||||
#if SOC_GDMA_SUPPORTED
|
|
||||||
|
|
||||||
TEST_CASE("GDMA channel allocation", "[gdma]")
|
TEST_CASE("GDMA channel allocation", "[gdma]")
|
||||||
{
|
{
|
||||||
gdma_channel_alloc_config_t channel_config = {};
|
gdma_channel_alloc_config_t channel_config = {};
|
||||||
@ -69,5 +67,3 @@ TEST_CASE("GDMA channel allocation", "[gdma]")
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
23
components/esp_hw_support/test_apps/dma/pytest_dma.py
Normal file
23
components/esp_hw_support/test_apps/dma/pytest_dma.py
Normal file
@ -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()
|
@ -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
|
@ -0,0 +1,2 @@
|
|||||||
|
CONFIG_FREERTOS_HZ=1000
|
||||||
|
CONFIG_ESP_TASK_WDT=n
|
Loading…
Reference in New Issue
Block a user