test_apps: add test case for flash mmap data integrity in ram loadable app

This commit is contained in:
Mahavir Jain
2023-03-17 09:43:40 +05:30
parent 7b995355ba
commit d0c8b01956
2 changed files with 31 additions and 1 deletions

View File

@@ -5,6 +5,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <inttypes.h> #include <inttypes.h>
#include "sdkconfig.h" #include "sdkconfig.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
@@ -12,6 +13,10 @@
#include "esp_chip_info.h" #include "esp_chip_info.h"
#include "hal/mmu_hal.h" #include "hal/mmu_hal.h"
#include "soc/soc.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 #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); 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 #endif //#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
void app_main(void) void app_main(void)
@@ -56,6 +85,7 @@ void app_main(void)
#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP #if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
s_test_ext_vaddr(); s_test_ext_vaddr();
s_test_flash_mmap_data_integrity();
#endif #endif
uint32_t uptime = 0; uint32_t uptime = 0;

View File

@@ -27,4 +27,4 @@ def test_pure_ram_loadable_app(dut: IdfDut) -> None:
@pytest.mark.parametrize('config', ['defaults',], indirect=True,) @pytest.mark.parametrize('config', ['defaults',], indirect=True,)
def test_ram_loadable_app(dut: IdfDut) -> None: def test_ram_loadable_app(dut: IdfDut) -> None:
dut.expect('spi_flash: detected chip', timeout=10) 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)