Преглед изворни кода

gdma: migrate ut to pytest

morris пре 3 година
родитељ
комит
ff6855c4b1

+ 7 - 0
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

+ 7 - 0
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)

+ 2 - 0
components/esp_hw_support/test_apps/dma/README.md

@@ -0,0 +1,2 @@
+| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S2 | ESP32-S3 |
+| ----------------- | ----- | -------- | -------- | -------- | -------- |

+ 14 - 0
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)

+ 51 - 0
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();
+}

+ 5 - 8
components/esp_hw_support/test/test_async_memcpy.c → 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 <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <inttypes.h>
 #include <sys/param.h>
 #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

+ 0 - 4
components/esp_hw_support/test/test_gdma.c → 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

+ 23 - 0
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()

+ 6 - 0
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

+ 2 - 0
components/esp_hw_support/test_apps/dma/sdkconfig.defaults

@@ -0,0 +1,2 @@
+CONFIG_FREERTOS_HZ=1000
+CONFIG_ESP_TASK_WDT=n