From 4e6af199f20ebacbcfef3473bb0c3837b7a63e61 Mon Sep 17 00:00:00 2001 From: Xiao Xufeng Date: Mon, 27 May 2024 01:45:02 +0800 Subject: [PATCH] ci(spi_flash): add tests for cache2phys with XIP --- components/app_update/test/test_ota_ops.c | 9 +++++++++ components/spi_flash/test/test_mmap.c | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/components/app_update/test/test_ota_ops.c b/components/app_update/test/test_ota_ops.c index b72142d6e1..0dbfabb76c 100644 --- a/components/app_update/test/test_ota_ops.c +++ b/components/app_update/test/test_ota_ops.c @@ -6,6 +6,7 @@ #include #include #include +#include "esp_log.h" #include #include #include @@ -113,3 +114,11 @@ TEST_CASE("esp_ota_get_partition_description", "[ota]") }; TEST_ESP_ERR(ESP_ERR_NOT_FOUND, bootloader_common_get_partition_description(¬_app_pos, &app_desc1)); } + +TEST_CASE("esp_ota_get_running_partition points to correct address", "[spi_flash]") +{ + const esp_partition_t *factory = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, "factory"); + const esp_partition_t* part = esp_ota_get_running_partition(); + ESP_LOGI("running bin", "0x%p", (void*)part->address); + TEST_ASSERT_EQUAL_HEX32(factory->address, part->address); +} diff --git a/components/spi_flash/test/test_mmap.c b/components/spi_flash/test/test_mmap.c index 7dc3e8d104..be28feac28 100644 --- a/components/spi_flash/test/test_mmap.c +++ b/components/spi_flash/test/test_mmap.c @@ -1,6 +1,7 @@ #include #include #include +#include "esp_log.h" #include #include #include @@ -475,4 +476,15 @@ TEST_CASE("no stale data read post mmap and write partition", "[spi_flash][mmap] esp_partition_munmap(handle); TEST_ASSERT_EQUAL(0, memcmp(buf, read_data, sizeof(buf))); } + +TEST_CASE("spi_flash_cache2phys points to correct address", "[spi_flash]") +{ + //_rodata_start, which begins with appdesc, is always the first segment of the bin. + extern int _rodata_start; + size_t addr = spi_flash_cache2phys(&_rodata_start); + + const esp_partition_t *factory = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, "factory"); + ESP_LOGI("running bin", "0x%p", (void*)addr); + TEST_ASSERT_HEX32_WITHIN(CONFIG_MMU_PAGE_SIZE/2, factory->address + CONFIG_MMU_PAGE_SIZE/2, addr); +} #endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)