Просмотр исходного кода

Merge branch 'tests/migrate_esp_ringbuf_tests_to_pytest' into 'master'

esp_ringbuf: migrated esp_ringbuf component tests to pytest framework

Closes IDF-5582

See merge request espressif/esp-idf!20476
Sudeep Mohanty 3 лет назад
Родитель
Сommit
952ba77edb

+ 6 - 0
components/esp_ringbuf/.build-test-rules.yml

@@ -0,0 +1,6 @@
+# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps
+
+components/esp_ringbuf/test_apps:
+  enable:
+    - if: IDF_TARGET in ["esp32", "esp32c3", "esp32s2"]
+      reason: covers all target types

+ 0 - 4
components/esp_ringbuf/test/CMakeLists.txt

@@ -1,4 +0,0 @@
-idf_component_register(SRC_DIRS "."
-                    PRIV_INCLUDE_DIRS "."
-                    PRIV_REQUIRES cmock test_utils esp_ringbuf driver)
-target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

+ 8 - 0
components/esp_ringbuf/test_apps/CMakeLists.txt

@@ -0,0 +1,8 @@
+# The following lines of boilerplate have to be in your project's
+# CMakeLists in this exact order for cmake to work correctly
+cmake_minimum_required(VERSION 3.16)
+
+set(COMPONENTS main)
+
+include($ENV{IDF_PATH}/tools/cmake/project.cmake)
+project(test_esp_ringbuf)

+ 3 - 0
components/esp_ringbuf/test_apps/README.md

@@ -0,0 +1,3 @@
+| Supported Targets | ESP32 | ESP32-C3 | ESP32-S2 |
+| ----------------- | ----- | -------- | -------- |
+

+ 6 - 0
components/esp_ringbuf/test_apps/main/CMakeLists.txt

@@ -0,0 +1,6 @@
+set(srcs "test_ringbuf_main.c"
+         "test_ringbuf.c")
+
+idf_component_register(SRCS ${srcs}
+                       PRIV_REQUIRES esp_ringbuf driver spi_flash unity
+                       WHOLE_ARCHIVE)

+ 4 - 2
components/esp_ringbuf/test/test_ringbuf.c → components/esp_ringbuf/test_apps/main/test_ringbuf.c

@@ -16,7 +16,6 @@
 #include "esp_heap_caps.h"
 #include "spi_flash_mmap.h"
 #include "unity.h"
-#include "test_utils.h"
 #include "esp_rom_sys.h"
 
 //Definitions used in multiple test cases
@@ -678,7 +677,7 @@ TEST_CASE("Test ring buffer with queue sets", "[esp_ringbuf]")
     }
     //Create a task to send items to each ring buffer
     int no_of_items = BUFFER_SIZE / SMALL_ITEM_SIZE;
-    xTaskCreatePinnedToCore(queue_set_receiving_task, "rec tsk", 2048, (void *)queue_set, UNITY_FREERTOS_PRIORITY + 1, NULL, 0);
+    xTaskCreatePinnedToCore(queue_set_receiving_task, "rec tsk", 2048, (void *)queue_set, 10, NULL, 0);
 
     //Send multiple items to each type of ring buffer
     for (int i = 0; i < no_of_items; i++) {
@@ -695,6 +694,7 @@ TEST_CASE("Test ring buffer with queue sets", "[esp_ringbuf]")
         vRingbufferDelete(buffer_handles[i]);
     }
     vQueueDelete(queue_set);
+    vTaskDelay(1);
 }
 
 /* -------------------------- Test ring buffer ISR -----------------------------
@@ -1019,6 +1019,7 @@ TEST_CASE("Test static ring buffer SMP", "[esp_ringbuf]")
 }
 #endif
 
+#if !CONFIG_RINGBUF_PLACE_FUNCTIONS_INTO_FLASH && !CONFIG_RINGBUF_PLACE_ISR_FUNCTIONS_INTO_FLASH
 /* -------------------------- Test ring buffer IRAM ------------------------- */
 
 static IRAM_ATTR __attribute__((noinline)) bool iram_ringbuf_test(void)
@@ -1044,3 +1045,4 @@ TEST_CASE("Test ringbuffer functions work with flash cache disabled", "[esp_ring
 {
     TEST_ASSERT( iram_ringbuf_test() );
 }
+#endif /* !CONFIG_RINGBUF_PLACE_FUNCTIONS_INTO_FLASH && !CONFIG_RINGBUF_PLACE_ISR_FUNCTIONS_INTO_FLASH */

+ 41 - 0
components/esp_ringbuf/test_apps/main/test_ringbuf_main.c

@@ -0,0 +1,41 @@
+/*
+ * 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 the sleep code, the threshold is left for that case
+#define TEST_MEMORY_LEAK_THRESHOLD (-500)
+
+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)
+{
+    unity_run_menu();
+}

+ 22 - 0
components/esp_ringbuf/test_apps/pytest_esp_ringbuf.py

@@ -0,0 +1,22 @@
+# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
+# SPDX-License-Identifier: CC0-1.0
+
+import pytest
+from pytest_embedded import Dut
+
+
+@pytest.mark.esp32
+@pytest.mark.esp32s2
+@pytest.mark.esp32c3
+@pytest.mark.generic
+@pytest.mark.parametrize(
+    'config',
+    [
+        'default',
+        'ringbuf_flash'
+    ]
+)
+def test_esp_ringbuf(dut: Dut) -> None:
+    dut.expect('Press ENTER to see the list of tests')
+    dut.write('*')
+    dut.expect_unity_test_output()

+ 1 - 0
components/esp_ringbuf/test_apps/sdkconfig.ci.default

@@ -0,0 +1 @@
+# Default configuration

+ 2 - 0
components/esp_ringbuf/test_apps/sdkconfig.ci.ringbuf_flash

@@ -0,0 +1,2 @@
+CONFIG_RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y
+CONFIG_RINGBUF_PLACE_ISR_FUNCTIONS_INTO_FLASH=y

+ 1 - 1
tools/unit-test-app/configs/default_2_c2

@@ -1,3 +1,3 @@
 # This config is split between targets since different component needs to be included
 CONFIG_IDF_TARGET="esp32c2"
-TEST_COMPONENTS=app_trace efuse esp_common esp_eth esp_event esp_hid esp_netif esp_phy esp_ringbuf esp_wifi espcoredump hal lwip mdns mqtt newlib nvs_flash partition_table sdmmc spiffs
+TEST_COMPONENTS=app_trace efuse esp_common esp_eth esp_event esp_hid esp_netif esp_phy esp_wifi espcoredump hal lwip mdns mqtt newlib nvs_flash partition_table sdmmc spiffs

+ 1 - 2
tools/unit-test-app/configs/freertos_flash

@@ -1,3 +1,2 @@
-TEST_COMPONENTS=freertos driver spi_flash esp_ringbuf
+TEST_COMPONENTS=freertos driver spi_flash
 CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH=y
-CONFIG_RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y