From d0c8b019562b2fda595c58b75ea12e916b891c07 Mon Sep 17 00:00:00 2001 From: Mahavir Jain Date: Fri, 17 Mar 2023 09:43:40 +0530 Subject: [PATCH] test_apps: add test case for flash mmap data integrity in ram loadable app --- .../main/ram_loadable_app_test.c | 30 +++++++++++++++++++ .../pytest_ram_loadable_app.py | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/tools/test_apps/system/ram_loadable_app/main/ram_loadable_app_test.c b/tools/test_apps/system/ram_loadable_app/main/ram_loadable_app_test.c index 6daa76aa67..fa96f283ee 100644 --- a/tools/test_apps/system/ram_loadable_app/main/ram_loadable_app_test.c +++ b/tools/test_apps/system/ram_loadable_app/main/ram_loadable_app_test.c @@ -5,6 +5,7 @@ */ #include +#include #include #include "sdkconfig.h" #include "freertos/FreeRTOS.h" @@ -12,6 +13,10 @@ #include "esp_chip_info.h" #include "hal/mmu_hal.h" #include "soc/soc.h" +#include "unity.h" +#include "spi_flash_mmap.h" +#include "esp_flash.h" +#include "esp_err.h" #if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP @@ -35,6 +40,30 @@ static void s_test_ext_vaddr(void) assert(my_var || my_var == 0); } } + +static void s_test_flash_mmap_data_integrity(void) +{ + char src_p_1[32] = "Test data pattern 123456789"; + char src_p_2[32] = "Test data pattern 987654321"; + char buf[32]; + const int addr = 0x10000; + + spi_flash_mmap_handle_t handle1; + const void *ptr1; + TEST_ESP_OK(spi_flash_mmap(addr, SPI_FLASH_SEC_SIZE, SPI_FLASH_MMAP_DATA, &ptr1, &handle1)); + TEST_ESP_OK(esp_flash_erase_region(NULL, addr, SPI_FLASH_SEC_SIZE)); + TEST_ESP_OK(esp_flash_write(NULL, src_p_1, addr, sizeof(src_p_1))); + memcpy(buf, ptr1, sizeof(buf)); + + TEST_ASSERT_EQUAL(0, memcmp(buf, src_p_1, sizeof(buf))); + TEST_ESP_OK(esp_flash_erase_region(NULL, addr, SPI_FLASH_SEC_SIZE)); + TEST_ESP_OK(esp_flash_write(NULL, src_p_2, addr, sizeof(src_p_2))); + memcpy(buf, ptr1, sizeof(buf)); + + TEST_ASSERT_EQUAL(0, memcmp(buf, src_p_2, sizeof(buf))); + spi_flash_munmap(handle1); +} + #endif //#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP void app_main(void) @@ -56,6 +85,7 @@ void app_main(void) #if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP s_test_ext_vaddr(); + s_test_flash_mmap_data_integrity(); #endif uint32_t uptime = 0; diff --git a/tools/test_apps/system/ram_loadable_app/pytest_ram_loadable_app.py b/tools/test_apps/system/ram_loadable_app/pytest_ram_loadable_app.py index 8068351016..2d3eb0e223 100644 --- a/tools/test_apps/system/ram_loadable_app/pytest_ram_loadable_app.py +++ b/tools/test_apps/system/ram_loadable_app/pytest_ram_loadable_app.py @@ -27,4 +27,4 @@ def test_pure_ram_loadable_app(dut: IdfDut) -> None: @pytest.mark.parametrize('config', ['defaults',], indirect=True,) def test_ram_loadable_app(dut: IdfDut) -> None: dut.expect('spi_flash: detected chip', timeout=10) - dut.expect('Time since boot: 3 seconds...', timeout=10) + dut.expect('Time since boot: 3 seconds...', timeout=30)