From 92ad6b36ad6a0a35a6423b90adc146d7cd6b7e69 Mon Sep 17 00:00:00 2001 From: Armando Date: Wed, 26 Oct 2022 11:57:49 +0800 Subject: [PATCH 1/3] flash_mmap: move mmap tests to test_app --- .../test_apps/esp_flash/main/test_app_main.c | 12 +-- .../test_apps/flash_mmap/CMakeLists.txt | 7 ++ .../spi_flash/test_apps/flash_mmap/README.md | 2 + .../test_apps/flash_mmap/main/CMakeLists.txt | 7 ++ .../test_apps/flash_mmap/main/test_app_main.c | 53 ++++++++++++ .../flash_mmap/main}/test_mmap.c | 80 +++++++++---------- .../test_apps/flash_mmap/partitions.csv | 5 ++ .../test_apps/flash_mmap/pytest_mmap.py | 20 +++++ .../test_apps/flash_mmap/sdkconfig.ci.release | 4 + .../test_apps/flash_mmap/sdkconfig.defaults | 3 + 10 files changed, 144 insertions(+), 49 deletions(-) create mode 100644 components/spi_flash/test_apps/flash_mmap/CMakeLists.txt create mode 100644 components/spi_flash/test_apps/flash_mmap/README.md create mode 100644 components/spi_flash/test_apps/flash_mmap/main/CMakeLists.txt create mode 100644 components/spi_flash/test_apps/flash_mmap/main/test_app_main.c rename components/spi_flash/{test => test_apps/flash_mmap/main}/test_mmap.c (85%) create mode 100644 components/spi_flash/test_apps/flash_mmap/partitions.csv create mode 100644 components/spi_flash/test_apps/flash_mmap/pytest_mmap.py create mode 100644 components/spi_flash/test_apps/flash_mmap/sdkconfig.ci.release create mode 100644 components/spi_flash/test_apps/flash_mmap/sdkconfig.defaults diff --git a/components/spi_flash/test_apps/esp_flash/main/test_app_main.c b/components/spi_flash/test_apps/esp_flash/main/test_app_main.c index 83b782c198..45e15bcca0 100644 --- a/components/spi_flash/test_apps/esp_flash/main/test_app_main.c +++ b/components/spi_flash/test_apps/esp_flash/main/test_app_main.c @@ -5,7 +5,7 @@ */ #include "unity.h" -#include "unity_test_runner.h" +#include "unity_test_utils.h" #include "esp_heap_caps.h" // Some resources are lazy allocated in flash encryption, the threadhold is left for that case @@ -14,12 +14,6 @@ static size_t before_free_8bit; static size_t before_free_32bit; -static void check_leak(size_t before_free, size_t after_free, const char *type) -{ - ssize_t delta = after_free - before_free; - printf("MALLOC_CAP_%s: Before %u bytes free, After %u bytes free (delta %d)\n", type, before_free, after_free, delta); - TEST_ASSERT_MESSAGE(delta >= TEST_MEMORY_LEAK_THRESHOLD, "memory leak"); -} void setUp(void) { @@ -31,8 +25,8 @@ void tearDown(void) { size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT); - check_leak(before_free_8bit, after_free_8bit, "8BIT"); - check_leak(before_free_32bit, after_free_32bit, "32BIT"); + unity_utils_check_leak(before_free_8bit, after_free_8bit, "8BIT", TEST_MEMORY_LEAK_THRESHOLD); + unity_utils_check_leak(before_free_32bit, after_free_32bit, "32BIT", TEST_MEMORY_LEAK_THRESHOLD); } void app_main(void) diff --git a/components/spi_flash/test_apps/flash_mmap/CMakeLists.txt b/components/spi_flash/test_apps/flash_mmap/CMakeLists.txt new file mode 100644 index 0000000000..6436916752 --- /dev/null +++ b/components/spi_flash/test_apps/flash_mmap/CMakeLists.txt @@ -0,0 +1,7 @@ +# This is the project CMakeLists.txt file for the test subproject +cmake_minimum_required(VERSION 3.16) + +set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components") + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(test_mmap) diff --git a/components/spi_flash/test_apps/flash_mmap/README.md b/components/spi_flash/test_apps/flash_mmap/README.md new file mode 100644 index 0000000000..284564238d --- /dev/null +++ b/components/spi_flash/test_apps/flash_mmap/README.md @@ -0,0 +1,2 @@ +| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S2 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | \ No newline at end of file diff --git a/components/spi_flash/test_apps/flash_mmap/main/CMakeLists.txt b/components/spi_flash/test_apps/flash_mmap/main/CMakeLists.txt new file mode 100644 index 0000000000..38ba2ec4a7 --- /dev/null +++ b/components/spi_flash/test_apps/flash_mmap/main/CMakeLists.txt @@ -0,0 +1,7 @@ +set(srcs "test_app_main.c" + "test_mmap.c") + +# In order for the cases defined by `TEST_CASE` to be linked into the final elf, +# the component can be registered as WHOLE_ARCHIVE +idf_component_register(SRCS ${srcs} + WHOLE_ARCHIVE) diff --git a/components/spi_flash/test_apps/flash_mmap/main/test_app_main.c b/components/spi_flash/test_apps/flash_mmap/main/test_app_main.c new file mode 100644 index 0000000000..dcd6932b69 --- /dev/null +++ b/components/spi_flash/test_apps/flash_mmap/main/test_app_main.c @@ -0,0 +1,53 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ + +#include "unity.h" +#include "unity_test_utils.h" +#include "esp_heap_caps.h" + +// Some resources are lazy allocated, the threadhold is left for that case +#define TEST_MEMORY_LEAK_THRESHOLD (-600) + +static size_t before_free_8bit; +static size_t before_free_32bit; + + +void setUp(void) +{ + before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); + before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT); +} + +void tearDown(void) +{ + size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); + size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT); + unity_utils_check_leak(before_free_8bit, after_free_8bit, "8BIT", TEST_MEMORY_LEAK_THRESHOLD); + unity_utils_check_leak(before_free_32bit, after_free_32bit, "32BIT", TEST_MEMORY_LEAK_THRESHOLD); +} + +void app_main(void) +{ + /* + ______ _ ___ _____ _ _ ___ ______ ___ ___ ______ + | ___| | / _ \ / ___| | | | | \/ || \/ | / _ \ | ___ \ + | |_ | | / /_\ \\ `--.| |_| | | . . || . . |/ /_\ \| |_/ / + | _| | | | _ | `--. \ _ | | |\/| || |\/| || _ || __/ + | | | |____| | | |/\__/ / | | | | | | || | | || | | || | + \_| \_____/\_| |_/\____/\_| |_/ \_| |_/\_| |_/\_| |_/\_| + + */ + + + printf("______ _ ___ _____ _ _ ___ ______ ___ ___ ______\n"); + printf("| ___| | / _ \\ / ___| | | | | \\/ || \\/ | / _ \\ | ___ \\\n"); + printf("| |_ | | / /_\\ \\\\ `--.| |_| | | . . || . . |/ /_\\ \\| |_/ /\n"); + printf("| _| | | | _ | `--. \\ _ | | |\\/| || |\\/| || _ || __/\n"); + printf("| | | |____| | | |/\\__/ / | | | | | | || | | || | | || |\n"); + printf("\\_| \\_____/\\_| |_/\\____/\\_| |_/ \\_| |_/\\_| |_/\\_| |_/\\_|\n"); + + unity_run_menu(); +} diff --git a/components/spi_flash/test/test_mmap.c b/components/spi_flash/test_apps/flash_mmap/main/test_mmap.c similarity index 85% rename from components/spi_flash/test/test_mmap.c rename to components/spi_flash/test_apps/flash_mmap/main/test_mmap.c index 0587ac6999..4618e581fe 100644 --- a/components/spi_flash/test/test_mmap.c +++ b/components/spi_flash/test_apps/flash_mmap/main/test_mmap.c @@ -1,6 +1,12 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ #include #include #include +#include #include #include #include @@ -14,8 +20,6 @@ #include "test_utils.h" -#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2) -//IDF-5138 static uint32_t buffer[1024]; /* read-only region used for mmap tests, intialised in setup_mmap_tests() */ @@ -23,7 +27,6 @@ static uint32_t start; static uint32_t end; static spi_flash_mmap_handle_t handle1, handle2, handle3; -#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2) static esp_err_t spi_flash_read_maybe_encrypted(size_t src_addr, void *des_addr, size_t size) { @@ -34,8 +37,6 @@ static esp_err_t spi_flash_read_maybe_encrypted(size_t src_addr, void *des_addr, } } -#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2) -//IDF-5138 static esp_err_t spi_flash_write_maybe_encrypted(size_t des_addr, const void *src_addr, size_t size) { if (!esp_flash_encryption_enabled()) { @@ -51,7 +52,7 @@ static void setup_mmap_tests(void) const esp_partition_t *part = get_test_data_partition(); start = part->address; end = part->address + part->size; - printf("Test data partition @ 0x%x - 0x%x\n", start, end); + printf("Test data partition @ 0x%"PRIx32" - 0x%"PRIx32"\n", start, end); } TEST_ASSERT(end > start); TEST_ASSERT(end - start >= 512*1024); @@ -83,7 +84,7 @@ static void setup_mmap_tests(void) for (uint32_t word = 0; word < 1024; ++word) { uint32_t val = rand(); if (block == start / 0x10000 && sector == 0 && word == 0) { - printf("setup_mmap_tests(): first prepped word: 0x%08x (flash holds 0x%08x)\n", val, buffer[word]); + printf("setup_mmap_tests(): first prepped word: 0x%08"PRIx32" (flash holds 0x%08"PRIx32")\n", val, buffer[word]); } if (buffer[word] != val) { buffer[word] = val; @@ -101,12 +102,13 @@ static void setup_mmap_tests(void) TEST_CASE("Can mmap into data address space", "[spi_flash][mmap]") { + esp_err_t ret = ESP_FAIL; setup_mmap_tests(); - printf("Mapping %x (+%x)\n", start, end - start); + printf("Mapping %"PRIx32" (+%"PRIx32")\n", start, end - start); const void *ptr1; TEST_ESP_OK( spi_flash_mmap(start, end - start, SPI_FLASH_MMAP_DATA, &ptr1, &handle1) ); - printf("mmap_res: handle=%d ptr=%p\n", handle1, ptr1); + printf("mmap_res: handle=%"PRIx32" ptr=%p\n", (uint32_t)handle1, ptr1); spi_flash_mmap_dump(); @@ -121,20 +123,22 @@ TEST_CASE("Can mmap into data address space", "[spi_flash][mmap]") } } } - printf("Mapping %x (+%x)\n", start - 0x10000, 0x20000); + printf("Mapping %"PRIx32" (+%x)\n", start - 0x10000, 0x20000); const void *ptr2; TEST_ESP_OK( spi_flash_mmap(start - 0x10000, 0x20000, SPI_FLASH_MMAP_DATA, &ptr2, &handle2) ); - printf("mmap_res: handle=%d ptr=%p\n", handle2, ptr2); + printf("mmap_res: handle=%"PRIx32" ptr=%p\n", (uint32_t)handle2, ptr2); TEST_ASSERT_EQUAL_HEX32(start - 0x10000, spi_flash_cache2phys(ptr2)); TEST_ASSERT_EQUAL_PTR(ptr2, spi_flash_phys2cache(start - 0x10000, SPI_FLASH_MMAP_DATA)); spi_flash_mmap_dump(); - printf("Mapping %x (+%x)\n", start, 0x10000); + printf("Mapping %"PRIx32" (+%x)\n", start, 0x10000); const void *ptr3; - TEST_ESP_OK( spi_flash_mmap(start, 0x10000, SPI_FLASH_MMAP_DATA, &ptr3, &handle3) ); - printf("mmap_res: handle=%d ptr=%p\n", handle3, ptr3); + ret = spi_flash_mmap(start, 0x10000, SPI_FLASH_MMAP_DATA, &ptr3, &handle3); + printf("ret: 0x%x\n", ret); + TEST_ASSERT(ret == ESP_OK); + printf("mmap_res: handle=%"PRIx32" ptr=%p\n", (uint32_t)handle3, ptr3); TEST_ASSERT_EQUAL_HEX32(start, spi_flash_cache2phys(ptr3)); TEST_ASSERT_EQUAL_PTR(ptr3, spi_flash_phys2cache(start, SPI_FLASH_MMAP_DATA)); @@ -156,24 +160,24 @@ TEST_CASE("Can mmap into data address space", "[spi_flash][mmap]") spi_flash_munmap(handle3); handle3 = 0; + printf("start corresponding vaddr: 0x%x\n", (int)spi_flash_phys2cache(start, SPI_FLASH_MMAP_DATA)); TEST_ASSERT_EQUAL_PTR(NULL, spi_flash_phys2cache(start, SPI_FLASH_MMAP_DATA)); } -#if !DISABLED_FOR_TARGETS(ESP32S3, ESP32C3) -/* On S3/C3 the cache is programmatically split between Icache and dcache and with the default setup we dont leave a lot pages +#if !(CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C2) +/* On S3/C3/C2 the cache is programmatically split between Icache and dcache and with the default setup we dont leave a lot pages available for additional mmaps into instruction space. Disabling this test for now since any hypothetical use case for this is no longer supported "out of the box" */ - TEST_CASE("Can mmap into instruction address space", "[spi_flash][mmap]") { setup_mmap_tests(); - printf("Mapping %x (+%x)\n", start, end - start); + printf("Mapping %"PRIx32" (+%"PRIx32")\n", start, end - start); spi_flash_mmap_handle_t handle1; const void *ptr1; TEST_ESP_OK( spi_flash_mmap(start, end - start, SPI_FLASH_MMAP_INST, &ptr1, &handle1) ); - printf("mmap_res: handle=%d ptr=%p\n", handle1, ptr1); + printf("mmap_res: handle=%"PRIx32" ptr=%p\n", (uint32_t)handle1, ptr1); spi_flash_mmap_dump(); @@ -186,22 +190,22 @@ TEST_CASE("Can mmap into instruction address space", "[spi_flash][mmap]") } } } - printf("Mapping %x (+%x)\n", start - 0x10000, 0x20000); + printf("Mapping %"PRIx32" (+%x)\n", start - 0x10000, 0x20000); spi_flash_mmap_handle_t handle2; const void *ptr2; TEST_ESP_OK( spi_flash_mmap(start - 0x10000, 0x20000, SPI_FLASH_MMAP_INST, &ptr2, &handle2) ); - printf("mmap_res: handle=%d ptr=%p\n", handle2, ptr2); + printf("mmap_res: handle=%"PRIx32" ptr=%p\n", (uint32_t)handle2, ptr2); TEST_ASSERT_EQUAL_HEX32(start - 0x10000, spi_flash_cache2phys(ptr2)); TEST_ASSERT_EQUAL_PTR(ptr2, spi_flash_phys2cache(start - 0x10000, SPI_FLASH_MMAP_INST)); spi_flash_mmap_dump(); - printf("Mapping %x (+%x)\n", start, 0x10000); + printf("Mapping %"PRIx32" (+%x)\n", start, 0x10000); spi_flash_mmap_handle_t handle3; const void *ptr3; TEST_ESP_OK( spi_flash_mmap(start, 0x10000, SPI_FLASH_MMAP_INST, &ptr3, &handle3) ); - printf("mmap_res: handle=%d ptr=%p\n", handle3, ptr3); + printf("mmap_res: handle=%"PRIx32" ptr=%p\n", (uint32_t)handle3, ptr3); TEST_ASSERT_EQUAL_HEX32(start, spi_flash_cache2phys(ptr3)); TEST_ASSERT_EQUAL_PTR(ptr3, spi_flash_phys2cache(start, SPI_FLASH_MMAP_INST)); @@ -218,11 +222,8 @@ TEST_CASE("Can mmap into instruction address space", "[spi_flash][mmap]") printf("Unmapping handle3\n"); spi_flash_munmap(handle3); - } - -#endif //!DISABLED_FOR_TARGETS(ESP32S3, ESP32C3) - +#endif // #if !CONFIG_IDF_TARGET_ESP32C2 TEST_CASE("Can mmap unordered pages into contiguous memory", "[spi_flash][mmap]") { @@ -239,7 +240,7 @@ TEST_CASE("Can mmap unordered pages into contiguous memory", "[spi_flash][mmap]" //make inverse mapping: virt 0 -> page (nopages-1), virt 1 -> page (nopages-2), ... for (int i=0; i= 4MB, because max size of Dcache can mapped is 4MB setup_mmap_tests(); - printf("Mapping %x (+%x)\n", start, end - start); + printf("Mapping %"PRIx32" (+%"PRIx32")\n", start, end - start); const void *ptr1; TEST_ESP_OK( spi_flash_mmap(start, end - start, SPI_FLASH_MMAP_DATA, &ptr1, &handle1) ); - printf("mmap_res: handle=%d ptr=%p\n", handle1, ptr1); + printf("mmap_res: handle=%"PRIx32" ptr=%p\n", (uint32_t)handle1, ptr1); spi_flash_mmap_dump(); @@ -344,10 +344,10 @@ TEST_CASE("flash_mmap can mmap after get enough free MMU pages", "[spi_flash][mm uint32_t flash_pages = flash_size / SPI_FLASH_MMU_PAGE_SIZE; free_pages = (free_pages > flash_pages) ? flash_pages : free_pages; - printf("Mapping %x (+%x)\n", 0, free_pages * SPI_FLASH_MMU_PAGE_SIZE); + printf("Mapping %x (+%"PRIx32")\n", 0, free_pages * SPI_FLASH_MMU_PAGE_SIZE); const void *ptr2; TEST_ESP_OK( spi_flash_mmap(0, free_pages * SPI_FLASH_MMU_PAGE_SIZE, SPI_FLASH_MMAP_DATA, &ptr2, &handle2) ); - printf("mmap_res: handle=%d ptr=%p\n", handle2, ptr2); + printf("mmap_res: handle=%"PRIx32" ptr=%p\n", (uint32_t)handle2, ptr2); spi_flash_mmap_dump(); @@ -364,7 +364,6 @@ TEST_CASE("flash_mmap can mmap after get enough free MMU pages", "[spi_flash][mm TEST_ASSERT_EQUAL_PTR(NULL, spi_flash_phys2cache(start, SPI_FLASH_MMAP_DATA)); } -#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2) TEST_CASE("phys2cache/cache2phys basic checks", "[spi_flash][mmap]") { @@ -377,7 +376,9 @@ TEST_CASE("phys2cache/cache2phys basic checks", "[spi_flash][mmap]") uint32_t phys = spi_flash_cache2phys(esp_partition_find); TEST_ASSERT_NOT_EQUAL(SPI_FLASH_CACHE2PHYS_FAIL, phys); TEST_ASSERT_EQUAL_PTR(esp_partition_find, spi_flash_phys2cache(phys, SPI_FLASH_MMAP_INST)); +#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 TEST_ASSERT_EQUAL_PTR(NULL, spi_flash_phys2cache(phys, SPI_FLASH_MMAP_DATA)); +#endif //#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 /* Read the flash @ 'phys' and compare it to the data we get via regular cache access */ spi_flash_read_maybe_encrypted(phys, buf, sizeof(buf)); @@ -393,15 +394,15 @@ TEST_CASE("phys2cache/cache2phys basic checks", "[spi_flash][mmap]") TEST_ASSERT_NOT_EQUAL(SPI_FLASH_CACHE2PHYS_FAIL, phys); TEST_ASSERT_EQUAL_PTR(&constant_data, spi_flash_phys2cache(phys, SPI_FLASH_MMAP_DATA)); +#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 TEST_ASSERT_EQUAL_PTR(NULL, spi_flash_phys2cache(phys, SPI_FLASH_MMAP_INST)); +#endif //#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 /* Read the flash @ 'phys' and compare it to the data we get via normal cache access */ spi_flash_read_maybe_encrypted(phys, buf, sizeof(constant_data)); TEST_ASSERT_EQUAL_HEX8_ARRAY(constant_data, buf, sizeof(constant_data)); } -#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2) -//IDF-5138 TEST_CASE("mmap consistent with phys2cache/cache2phys", "[spi_flash][mmap]") { const void *ptr = NULL; @@ -470,4 +471,3 @@ TEST_CASE("no stale data read post mmap and write partition", "[spi_flash][mmap] spi_flash_munmap(handle); TEST_ASSERT_EQUAL(0, memcmp(buf, read_data, sizeof(buf))); } -#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2) diff --git a/components/spi_flash/test_apps/flash_mmap/partitions.csv b/components/spi_flash/test_apps/flash_mmap/partitions.csv new file mode 100644 index 0000000000..c941d8f4f1 --- /dev/null +++ b/components/spi_flash/test_apps/flash_mmap/partitions.csv @@ -0,0 +1,5 @@ +# Name, Type, SubType, Offset, Size, Flags +# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap +nvs, data, nvs, 0x9000, 0x6000, +factory, 0, 0, 0x10000, 1M +flash_test, data, fat, , 528K diff --git a/components/spi_flash/test_apps/flash_mmap/pytest_mmap.py b/components/spi_flash/test_apps/flash_mmap/pytest_mmap.py new file mode 100644 index 0000000000..53745d3332 --- /dev/null +++ b/components/spi_flash/test_apps/flash_mmap/pytest_mmap.py @@ -0,0 +1,20 @@ +# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Apache-2.0 + +import pytest +from pytest_embedded import Dut + + +@pytest.mark.supported_targets +@pytest.mark.generic +@pytest.mark.parametrize( + 'config', + [ + 'release', + ], + indirect=True, +) +def test_flash_mmap(dut: Dut) -> None: + dut.expect_exact('Press ENTER to see the list of tests') + dut.write('*') + dut.expect_unity_test_output(timeout=120) diff --git a/components/spi_flash/test_apps/flash_mmap/sdkconfig.ci.release b/components/spi_flash/test_apps/flash_mmap/sdkconfig.ci.release new file mode 100644 index 0000000000..6497a7f096 --- /dev/null +++ b/components/spi_flash/test_apps/flash_mmap/sdkconfig.ci.release @@ -0,0 +1,4 @@ +CONFIG_ESP_TASK_WDT=n +CONFIG_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y diff --git a/components/spi_flash/test_apps/flash_mmap/sdkconfig.defaults b/components/spi_flash/test_apps/flash_mmap/sdkconfig.defaults new file mode 100644 index 0000000000..e58745b57a --- /dev/null +++ b/components/spi_flash/test_apps/flash_mmap/sdkconfig.defaults @@ -0,0 +1,3 @@ +CONFIG_ESP_TASK_WDT=n +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" From db1bc05bc777e956026f457e376a2a110dfda320 Mon Sep 17 00:00:00 2001 From: Armando Date: Wed, 26 Oct 2022 11:59:02 +0800 Subject: [PATCH 2/3] flash_mmap: fix mmap unordered test on c2 --- .../test_apps/flash_mmap/main/test_mmap.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/components/spi_flash/test_apps/flash_mmap/main/test_mmap.c b/components/spi_flash/test_apps/flash_mmap/main/test_mmap.c index 4618e581fe..faf91ee755 100644 --- a/components/spi_flash/test_apps/flash_mmap/main/test_mmap.c +++ b/components/spi_flash/test_apps/flash_mmap/main/test_mmap.c @@ -251,13 +251,22 @@ TEST_CASE("Can mmap unordered pages into contiguous memory", "[spi_flash][mmap]" printf("mmap_res: handle=%"PRIx32" ptr=%p\n", (uint32_t)handle1, ptr1); spi_flash_mmap_dump(); +#if (CONFIG_MMU_PAGE_SIZE == 0x10000) + uint32_t words_per_sector = 1024; +#elif (CONFIG_MMU_PAGE_SIZE == 0x8000) + uint32_t words_per_sector = 512; +#elif (CONFIG_MMU_PAGE_SIZE == 0x4000) + uint32_t words_per_sector = 256; +#else + uint32_t words_per_sector = 128; +#endif srand(0); const uint32_t *data = (const uint32_t *) ptr1; - for (int block = 0; block < nopages; ++block) { + for (int block = 0; block < 1; ++block) { for (int sector = 0; sector < 16; ++sector) { - for (uint32_t word = 0; word < 1024; ++word) { - TEST_ASSERT_EQUAL_UINT32(rand(), data[(((nopages-1)-block) * 16 + sector) * 1024 + word]); + for (uint32_t word = 0; word < words_per_sector; ++word) { + TEST_ASSERT_EQUAL_UINT32(rand(), data[(((nopages-1)-block) * 16 + sector) * words_per_sector + word]); } } } From ba4d312d86564591bc71d31d9d716f58f6052c94 Mon Sep 17 00:00:00 2001 From: Armando Date: Wed, 26 Oct 2022 18:22:39 +0800 Subject: [PATCH 3/3] flash_mmap: format test_mmap.c --- .../test_apps/flash_mmap/main/test_mmap.c | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/components/spi_flash/test_apps/flash_mmap/main/test_mmap.c b/components/spi_flash/test_apps/flash_mmap/main/test_mmap.c index faf91ee755..0b7322c94e 100644 --- a/components/spi_flash/test_apps/flash_mmap/main/test_mmap.c +++ b/components/spi_flash/test_apps/flash_mmap/main/test_mmap.c @@ -55,7 +55,7 @@ static void setup_mmap_tests(void) printf("Test data partition @ 0x%"PRIx32" - 0x%"PRIx32"\n", start, end); } TEST_ASSERT(end > start); - TEST_ASSERT(end - start >= 512*1024); + TEST_ASSERT(end - start >= 512 * 1024); /* clean up any mmap handles left over from failed tests */ if (handle1) { @@ -232,15 +232,15 @@ TEST_CASE("Can mmap unordered pages into contiguous memory", "[spi_flash][mmap]" int startpage; setup_mmap_tests(); - nopages=(end-start)/SPI_FLASH_MMU_PAGE_SIZE; - pages=alloca(sizeof(int)*nopages); + nopages = (end - start) / SPI_FLASH_MMU_PAGE_SIZE; + pages = alloca(sizeof(int) * nopages); - startpage=start/SPI_FLASH_MMU_PAGE_SIZE; + startpage = start / SPI_FLASH_MMU_PAGE_SIZE; //make inverse mapping: virt 0 -> page (nopages-1), virt 1 -> page (nopages-2), ... - for (int i=0; i