nvs_flash: fixed deinit other partition's handles

* When deinitializing or erasing a partition,
  nvs used to close all handles instead of only
  the current partition's handles.
  This is fixed now
* Added a unit test for that case

Closes FCS-533
This commit is contained in:
Jakob Hasse
2020-10-22 10:27:42 +08:00
parent 079247b42a
commit 09d2c5daa6
4 changed files with 48 additions and 2 deletions
@@ -705,6 +705,37 @@ TEST_CASE("nvs api tests", "[nvs]")
TEST_ESP_OK(nvs_flash_deinit_partition(NVS_DEFAULT_PART_NAME));
}
TEST_CASE("deinit partition doesn't affect other partition's open handles", "[nvs]")
{
const char *OTHER_PARTITION_NAME = "other_part";
PartitionEmulationFixture f(0, 10);
PartitionEmulationFixture f_other(0, 10, OTHER_PARTITION_NAME);
const char* str = "value 0123456789abcdef0123456789abcdef";
const uint8_t blob[8] = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7};
nvs_handle_t handle_1;
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
f.emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);
f_other.emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);
TEST_ESP_OK(NVSPartitionManager::get_instance()->init_custom(&f.part,
NVS_FLASH_SECTOR,
NVS_FLASH_SECTOR_COUNT_MIN));
TEST_ESP_OK(NVSPartitionManager::get_instance()->init_custom(&f_other.part,
NVS_FLASH_SECTOR,
NVS_FLASH_SECTOR_COUNT_MIN));
TEST_ESP_OK(nvs_open_from_partition(OTHER_PARTITION_NAME, "ns", NVS_READWRITE, &handle_1));
// Deinitializing must not interfere with the open handle from the other partition.
TEST_ESP_OK(nvs_flash_deinit_partition(NVS_DEFAULT_PART_NAME));
TEST_ESP_OK(nvs_set_i32(handle_1, "foo", 0x3456789a));
nvs_close(handle_1);
TEST_ESP_OK(nvs_flash_deinit_partition(OTHER_PARTITION_NAME));
}
TEST_CASE("nvs iterators tests", "[nvs]")
{