From c553430b0c74e1fdd2d3ae8648342871255a9ece Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 17 Dec 2020 19:30:19 +1100 Subject: [PATCH] nvs_flash: Fix host test regressions Regression in 09d2c5daa651c1034251cce433cb54ed765d8f95 - in some cases the test fixture was out of scope by the time nvs_flash_deinit_partition() was called in this test. --- .../nvs_flash/test_nvs_host/test_nvs.cpp | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/components/nvs_flash/test_nvs_host/test_nvs.cpp b/components/nvs_flash/test_nvs_host/test_nvs.cpp index d8467dfe57..bf2712e796 100644 --- a/components/nvs_flash/test_nvs_host/test_nvs.cpp +++ b/components/nvs_flash/test_nvs_host/test_nvs.cpp @@ -1220,9 +1220,9 @@ TEST_CASE("nvs api tests, starting with random data in flash", "[nvs][long]") nvs_close(handle_2); } nvs_close(handle_1); - } - TEST_ESP_OK(nvs_flash_deinit_partition(NVS_DEFAULT_PART_NAME)); + TEST_ESP_OK(nvs_flash_deinit_partition(f.part.get_partition_name())); + } } extern "C" void nvs_dump(const char *partName); @@ -1519,17 +1519,16 @@ TEST_CASE("test recovery from sudden poweroff", "[long][nvs][recovery][monkey]") gen.seed(seed); const size_t iter_count = 2000; - PartitionEmulationFixture f(0, 10); - - const uint32_t NVS_FLASH_SECTOR = 2; - const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 8; - - f.emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN); - size_t totalOps = 0; int lastPercent = -1; for (uint32_t errDelay = 0; ; ++errDelay) { INFO(errDelay); + + PartitionEmulationFixture f(0, 10); + const uint32_t NVS_FLASH_SECTOR = 2; + const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 8; + f.emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN); + f.emu.randomize(seed); f.emu.clearStats(); f.emu.failAfter(errDelay); @@ -1550,14 +1549,18 @@ TEST_CASE("test recovery from sudden poweroff", "[long][nvs][recovery][monkey]") if (NVSPartitionManager::get_instance()->init_custom(&f.part, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN) == ESP_OK) { + auto res = ESP_ERR_FLASH_OP_FAIL; if (nvs_open("namespace1", NVS_READWRITE, &handle) == ESP_OK) { - if(test.doRandomThings(handle, gen, count) != ESP_ERR_FLASH_OP_FAIL) { - nvs_close(handle); - break; - } + res = test.doRandomThings(handle, gen, count); nvs_close(handle); } + TEST_ESP_OK(nvs_flash_deinit_partition(NVS_DEFAULT_PART_NAME)); + if (res != ESP_ERR_FLASH_OP_FAIL) { + // This means we got to the end without an error due to f.emu.failAfter(), therefore errDelay + // is high enough that we're not triggering it any more, therefore we're done + break; + } } TEST_ESP_OK(NVSPartitionManager::get_instance()->init_custom(&f.part, @@ -1575,6 +1578,7 @@ TEST_CASE("test recovery from sudden poweroff", "[long][nvs][recovery][monkey]") TEST_ESP_OK(nvs_flash_deinit_partition(NVS_DEFAULT_PART_NAME)); } } + TEST_CASE("test for memory leaks in open/set", "[leaks]") { PartitionEmulationFixture f(0, 10);