Ver Fonte

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

Mahavir Jain há 2 anos atrás
pai
commit
d0c8b01956

+ 30 - 0
tools/test_apps/system/ram_loadable_app/main/ram_loadable_app_test.c

@@ -5,6 +5,7 @@
  */
 
 #include <stdio.h>
+#include <string.h>
 #include <inttypes.h>
 #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;

+ 1 - 1
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)