From c67901fc07c201d3db5c47936d1f857c77f80007 Mon Sep 17 00:00:00 2001 From: "harshal.patil" Date: Thu, 13 Mar 2025 10:34:26 +0530 Subject: [PATCH] ci(esp_psram): Add a test to validate non-bootup PSRAM initialisation - Also adds a test for the newly added PSRAM helper APIs: esp_psram_get_heap_pool_size() and esp_psram_get_effective_mapped_size() --- .../esp_psram/test_apps/.build-test-rules.yml | 3 +++ .../test_apps/psram/main/CMakeLists.txt | 13 +++++++--- .../psram/main/test_psram_no_boot_init.c | 25 ++++++++++++++++++ .../esp_psram/test_apps/psram/pytest_psram.py | 26 +++++++++++++++++++ .../psram/sdkconfig.ci.psram_no_boot_init | 4 +++ .../psram/sdkconfig.ci.xip_psram_no_boot_init | 7 +++++ 6 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 components/esp_psram/test_apps/psram/main/test_psram_no_boot_init.c create mode 100644 components/esp_psram/test_apps/psram/sdkconfig.ci.psram_no_boot_init create mode 100644 components/esp_psram/test_apps/psram/sdkconfig.ci.xip_psram_no_boot_init diff --git a/components/esp_psram/test_apps/.build-test-rules.yml b/components/esp_psram/test_apps/.build-test-rules.yml index c9b865f301..14b2fd4070 100644 --- a/components/esp_psram/test_apps/.build-test-rules.yml +++ b/components/esp_psram/test_apps/.build-test-rules.yml @@ -1,8 +1,11 @@ # Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps components/esp_psram/test_apps/psram: + enable: + - if: CONFIG_NAME == "psram_no_boot_init" and SOC_SPIRAM_SUPPORTED == 1 disable: - if: SOC_SPIRAM_SUPPORTED != 1 + - if: CONFIG_NAME == "xip_psram_no_boot_init" and SOC_SPIRAM_XIP_SUPPORTED != 1 depends_components: - esp_psram - esp_mm diff --git a/components/esp_psram/test_apps/psram/main/CMakeLists.txt b/components/esp_psram/test_apps/psram/main/CMakeLists.txt index d19067a385..4bf51e380b 100644 --- a/components/esp_psram/test_apps/psram/main/CMakeLists.txt +++ b/components/esp_psram/test_apps/psram/main/CMakeLists.txt @@ -1,10 +1,15 @@ idf_build_get_property(target IDF_TARGET) -set(srcs "test_app_main.c" - "test_psram.c") +set(srcs "test_app_main.c") -if(${target} STREQUAL "esp32") - list(APPEND srcs "test_himem.c" "test_4mpsram.c") +if(CONFIG_SPIRAM_BOOT_INIT) + list(APPEND srcs "test_psram.c") + + if(${target} STREQUAL "esp32") + list(APPEND srcs "test_himem.c" "test_4mpsram.c") + endif() +else() + list(APPEND srcs "test_psram_no_boot_init.c") endif() # In order for the cases defined by `TEST_CASE` to be linked into the final elf, diff --git a/components/esp_psram/test_apps/psram/main/test_psram_no_boot_init.c b/components/esp_psram/test_apps/psram/main/test_psram_no_boot_init.c new file mode 100644 index 0000000000..f1026863bd --- /dev/null +++ b/components/esp_psram/test_apps/psram/main/test_psram_no_boot_init.c @@ -0,0 +1,25 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ +#include "sdkconfig.h" +#include "unity.h" +#include "esp_psram.h" +#include "esp_private/esp_psram_extram.h" + +TEST_CASE("test psram no boot init", "[psram_no_boot_init]") +{ +#if CONFIG_SPIRAM_PRE_CONFIGURE_MEMORY_PROTECTION + // As PSRAM is just enabled and not initialised during the boot up, the API + // esp_psram_get_heap_size_to_protect() manually calculates the size of the PSRAM heap + size_t manually_calculated_psram_heap = esp_psram_get_heap_size_to_protect(); +#endif /* CONFIG_SPIRAM_PRE_CONFIGURE_MEMORY_PROTECTION */ + + TEST_ESP_OK(esp_psram_init()); + +#if CONFIG_SPIRAM_PRE_CONFIGURE_MEMORY_PROTECTION + size_t final_psram_heap = esp_psram_get_heap_size_to_protect(); + TEST_ASSERT_EQUAL(final_psram_heap, manually_calculated_psram_heap); +#endif /* CONFIG_SPIRAM_PRE_CONFIGURE_MEMORY_PROTECTION */ +} diff --git a/components/esp_psram/test_apps/psram/pytest_psram.py b/components/esp_psram/test_apps/psram/pytest_psram.py index cf5d41b7d4..38b56d77fd 100644 --- a/components/esp_psram/test_apps/psram/pytest_psram.py +++ b/components/esp_psram/test_apps/psram/pytest_psram.py @@ -112,3 +112,29 @@ def test_psram_esp32c5(dut: Dut) -> None: @idf_parametrize('target', ['esp32c61'], indirect=['target']) def test_psram_esp32c61(dut: Dut) -> None: dut.run_all_single_board_cases() + + +@pytest.mark.generic +@pytest.mark.parametrize( + 'config', + [ + 'xip_psram_no_boot_init', + ], + indirect=True, +) +@idf_parametrize('target', ['esp32s2', 'esp32s3', 'esp32c5', 'esp32c61'], indirect=['target']) +def test_xip_psram_no_boot_init(dut: Dut) -> None: + dut.run_all_single_board_cases() + + +@pytest.mark.generic +@pytest.mark.parametrize( + 'config', + [ + 'psram_no_boot_init', + ], + indirect=True, +) +@idf_parametrize('target', ['supported_targets'], indirect=['target']) +def test_psram_no_boot_init(dut: Dut) -> None: + dut.run_all_single_board_cases() diff --git a/components/esp_psram/test_apps/psram/sdkconfig.ci.psram_no_boot_init b/components/esp_psram/test_apps/psram/sdkconfig.ci.psram_no_boot_init new file mode 100644 index 0000000000..eec27d115c --- /dev/null +++ b/components/esp_psram/test_apps/psram/sdkconfig.ci.psram_no_boot_init @@ -0,0 +1,4 @@ +CONFIG_SPIRAM=y +CONFIG_SPIRAM_BOOT_HW_INIT=y +CONFIG_SPIRAM_BOOT_INIT=n +CONFIG_SPIRAM_PRE_CONFIGURE_MEMORY_PROTECTION=y diff --git a/components/esp_psram/test_apps/psram/sdkconfig.ci.xip_psram_no_boot_init b/components/esp_psram/test_apps/psram/sdkconfig.ci.xip_psram_no_boot_init new file mode 100644 index 0000000000..a9658128bd --- /dev/null +++ b/components/esp_psram/test_apps/psram/sdkconfig.ci.xip_psram_no_boot_init @@ -0,0 +1,7 @@ +CONFIG_SPIRAM=y +CONFIG_SPIRAM_XIP_FROM_PSRAM=y +CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y +CONFIG_SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY=y +CONFIG_SPIRAM_BOOT_HW_INIT=y +CONFIG_SPIRAM_BOOT_INIT=n +CONFIG_SPIRAM_PRE_CONFIGURE_MEMORY_PROTECTION=y