From e672d49db7455ee7e39153c65c736ae34f3dfd13 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Thu, 2 May 2024 16:37:45 +0200 Subject: [PATCH 1/3] fix(sdspi): fix memory leak in do_one_sdspi_probe test --- .../sdspi/components/sdspi_tests/sdmmc_test_probe_spi.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/components/esp_driver_sdspi/test_apps/sdspi/components/sdspi_tests/sdmmc_test_probe_spi.c b/components/esp_driver_sdspi/test_apps/sdspi/components/sdspi_tests/sdmmc_test_probe_spi.c index 42da8c1e93..cfaa5e02bd 100644 --- a/components/esp_driver_sdspi/test_apps/sdspi/components/sdspi_tests/sdmmc_test_probe_spi.c +++ b/components/esp_driver_sdspi/test_apps/sdspi/components/sdspi_tests/sdmmc_test_probe_spi.c @@ -18,6 +18,7 @@ static void do_one_sdspi_probe(int slot, int freq_khz) sdmmc_card_print_info(stdout, &card); uint8_t* buffer = heap_caps_calloc(512, 1, MALLOC_CAP_DMA); TEST_ESP_OK(sdmmc_read_sectors(&card, buffer, 0, 1)); + free(buffer); sdmmc_test_spi_end(slot, &card); } @@ -32,15 +33,12 @@ TEST_CASE("sdspi probe, slot 0, HS", "[sdspi]") do_one_sdspi_probe(SLOT_0, SDMMC_FREQ_HIGHSPEED); } -#if !CONFIG_IDF_TARGET_ESP32 && !CONFIG_IDF_TARGET_ESP32S3 -//TODO: IDF-8750. Leaks too much memory, needs check TEST_CASE("sdspi probe, slot 1", "[sdspi]") { do_one_sdspi_probe(SLOT_1, SDMMC_FREQ_PROBING); do_one_sdspi_probe(SLOT_1, SDMMC_FREQ_DEFAULT); do_one_sdspi_probe(SLOT_1, SDMMC_FREQ_CUSTOM_10M); } -#endif #if !CONFIG_IDF_TARGET_ESP32 && !CONFIG_IDF_TARGET_ESP32S3 //TODO: IDF-8749 From f355ecac401d91b89a64c79a554d4751a22165a3 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Thu, 2 May 2024 16:39:39 +0200 Subject: [PATCH 2/3] ci(sdspi): re-enable probe/rw tests for slot 1 These tests were disabled since SDMMC_FREQ_HIGHSPEED with sdspi didn't work on ESP32 and ESP32-S3. However we don't have other tests for slot 1, meaning that we weren't running probe and perf tests at all. This commit re-enables the tests, keeping them with SDMMC_FREQ_DEFAULT --- .../components/sdspi_tests/sdmmc_test_probe_spi.c | 8 +++----- .../components/sdspi_tests/sdmmc_test_rw_spi.c | 14 +++++--------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/components/esp_driver_sdspi/test_apps/sdspi/components/sdspi_tests/sdmmc_test_probe_spi.c b/components/esp_driver_sdspi/test_apps/sdspi/components/sdspi_tests/sdmmc_test_probe_spi.c index cfaa5e02bd..f765e52a65 100644 --- a/components/esp_driver_sdspi/test_apps/sdspi/components/sdspi_tests/sdmmc_test_probe_spi.c +++ b/components/esp_driver_sdspi/test_apps/sdspi/components/sdspi_tests/sdmmc_test_probe_spi.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -40,11 +40,9 @@ TEST_CASE("sdspi probe, slot 1", "[sdspi]") do_one_sdspi_probe(SLOT_1, SDMMC_FREQ_CUSTOM_10M); } -#if !CONFIG_IDF_TARGET_ESP32 && !CONFIG_IDF_TARGET_ESP32S3 -//TODO: IDF-8749 -//here freq should be changed to SDMMC_FREQ_HIGHSPEED after fixing IDF-8749 TEST_CASE("sdspi probe, slot 1, HS", "[sdspi]") { + //TODO: IDF-8749 + //here freq should be changed to SDMMC_FREQ_HIGHSPEED after fixing IDF-8749 do_one_sdspi_probe(SLOT_1, SDMMC_FREQ_DEFAULT); } -#endif diff --git a/components/esp_driver_sdspi/test_apps/sdspi/components/sdspi_tests/sdmmc_test_rw_spi.c b/components/esp_driver_sdspi/test_apps/sdspi/components/sdspi_tests/sdmmc_test_rw_spi.c index a45e5f0c13..916498b3c9 100644 --- a/components/esp_driver_sdspi/test_apps/sdspi/components/sdspi_tests/sdmmc_test_rw_spi.c +++ b/components/esp_driver_sdspi/test_apps/sdspi/components/sdspi_tests/sdmmc_test_rw_spi.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -26,14 +26,12 @@ TEST_CASE("sdspi read/write performance, slot 0", "[sdspi]") do_one_sdspi_perf_test(SLOT_0, SDMMC_FREQ_HIGHSPEED); } -#if !CONFIG_IDF_TARGET_ESP32 && !CONFIG_IDF_TARGET_ESP32S3 -//TODO: IDF-8749 -//here freq should be changed to SDMMC_FREQ_HIGHSPEED after fixing IDF-8749 TEST_CASE("sdspi read/write performance, slot 1", "[sdspi]") { + //TODO: IDF-8749 + //here freq should be changed to SDMMC_FREQ_HIGHSPEED after fixing IDF-8749 do_one_sdspi_perf_test(SLOT_1, SDMMC_FREQ_DEFAULT); } -#endif /* ========== Read/write tests with offset, SPI ========== */ @@ -52,14 +50,12 @@ TEST_CASE("sdspi read/write performance with offset, slot 0", "[sdspi]") do_one_sdspi_rw_test_with_offset(SLOT_0, SDMMC_FREQ_HIGHSPEED); } -#if !CONFIG_IDF_TARGET_ESP32 && !CONFIG_IDF_TARGET_ESP32S3 -//TODO: IDF-8749 -//here freq should be changed to SDMMC_FREQ_HIGHSPEED after fixing IDF-8749 TEST_CASE("sdspi read/write performance with offset, slot 1", "[sdspi]") { + //TODO: IDF-8749 + //here freq should be changed to SDMMC_FREQ_HIGHSPEED after fixing IDF-8749 do_one_sdspi_rw_test_with_offset(SLOT_1, SDMMC_FREQ_DEFAULT); } -#endif /* ========== Read/write tests with unaligned source/destination buffer, SPI ========== */ From 30abe85a25956900ba944491e140d6794798cbf8 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Thu, 2 May 2024 16:42:01 +0200 Subject: [PATCH 3/3] ci(sdspi): clean up newlib memory, reset between tests Two changes to make the tests less susceptible to random failures: - Free up newlib memory to not have false-positive memory leaks due to lazy allocations in reent structure - Reset between tests, so that one failing test doesn't cause subsequent tests to fail Both changes are already applied to esp_driver_sdmmc test app. --- .../esp_driver_sdspi/test_apps/sdspi/main/test_app_main.c | 2 ++ components/esp_driver_sdspi/test_apps/sdspi/pytest_sdspi.py | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/components/esp_driver_sdspi/test_apps/sdspi/main/test_app_main.c b/components/esp_driver_sdspi/test_apps/sdspi/main/test_app_main.c index 274579059d..b165025bc9 100644 --- a/components/esp_driver_sdspi/test_apps/sdspi/main/test_app_main.c +++ b/components/esp_driver_sdspi/test_apps/sdspi/main/test_app_main.c @@ -13,11 +13,13 @@ void setUp(void) { + printf("%s", ""); /* sneakily lazy-allocate the reent structure for this test task */ unity_utils_record_free_mem(); } void tearDown(void) { + esp_reent_cleanup(); unity_utils_evaluate_leaks_direct(TEST_MEMORY_LEAK_THRESHOLD); } diff --git a/components/esp_driver_sdspi/test_apps/sdspi/pytest_sdspi.py b/components/esp_driver_sdspi/test_apps/sdspi/pytest_sdspi.py index f2d30a8c2d..1364f7e91d 100644 --- a/components/esp_driver_sdspi/test_apps/sdspi/pytest_sdspi.py +++ b/components/esp_driver_sdspi/test_apps/sdspi/pytest_sdspi.py @@ -1,8 +1,7 @@ # SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: CC0-1.0 - from pytest_embedded_idf import IdfDut def test_sdspi(dut: IdfDut) -> None: - dut.run_all_single_board_cases() + dut.run_all_single_board_cases(reset=True)