|
|
@@ -549,6 +549,34 @@ TEST_CASE("can erase items", "[nvs]")
|
|
|
CHECK(storage.readItem(3, "key00222", val) == ESP_ERR_NVS_NOT_FOUND);
|
|
|
}
|
|
|
|
|
|
+TEST_CASE("readonly handle fails on writing", "[nvs]")
|
|
|
+{
|
|
|
+ SpiFlashEmulator emu(10);
|
|
|
+ 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;
|
|
|
+ emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);
|
|
|
+
|
|
|
+ TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
|
|
|
+
|
|
|
+ // first, creating namespace...
|
|
|
+ TEST_ESP_OK(nvs_open("ro_ns", NVS_READWRITE, &handle_1));
|
|
|
+ nvs_close(handle_1);
|
|
|
+
|
|
|
+ TEST_ESP_OK(nvs_open("ro_ns", NVS_READONLY, &handle_1));
|
|
|
+ TEST_ESP_ERR(nvs_set_i32(handle_1, "key", 47), ESP_ERR_NVS_READ_ONLY);
|
|
|
+ TEST_ESP_ERR(nvs_set_str(handle_1, "key", str), ESP_ERR_NVS_READ_ONLY);
|
|
|
+ TEST_ESP_ERR(nvs_set_blob(handle_1, "key", blob, 8), ESP_ERR_NVS_READ_ONLY);
|
|
|
+
|
|
|
+ nvs_close(handle_1);
|
|
|
+
|
|
|
+ // without deinit it affects "nvs api tests"
|
|
|
+ TEST_ESP_OK(nvs_flash_deinit_partition(NVS_DEFAULT_PART_NAME));
|
|
|
+}
|
|
|
+
|
|
|
TEST_CASE("nvs api tests", "[nvs]")
|
|
|
{
|
|
|
SpiFlashEmulator emu(10);
|
|
|
@@ -772,6 +800,39 @@ TEST_CASE("nvs iterators tests", "[nvs]")
|
|
|
nvs_close(handle_2);
|
|
|
}
|
|
|
|
|
|
+TEST_CASE("Iterator with not matching type iterates correctly", "[nvs]")
|
|
|
+{
|
|
|
+ SpiFlashEmulator emu(5);
|
|
|
+ nvs_iterator_t it;
|
|
|
+ nvs_handle_t my_handle;
|
|
|
+ const char* NAMESPACE = "test_ns_4";
|
|
|
+
|
|
|
+ const uint32_t NVS_FLASH_SECTOR = 0;
|
|
|
+ const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 5;
|
|
|
+ emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);
|
|
|
+
|
|
|
+ for (uint16_t i = NVS_FLASH_SECTOR; i < NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN; ++i) {
|
|
|
+ spi_flash_erase_sector(i);
|
|
|
+ }
|
|
|
+ TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
|
|
|
+
|
|
|
+ // writing string to namespace (a type which spans multiple entries)
|
|
|
+ TEST_ESP_OK(nvs_open(NAMESPACE, NVS_READWRITE, &my_handle));
|
|
|
+ TEST_ESP_OK(nvs_set_str(my_handle, "test-string", "InitString0"));
|
|
|
+ TEST_ESP_OK(nvs_commit(my_handle));
|
|
|
+ nvs_close(my_handle);
|
|
|
+
|
|
|
+ it = nvs_entry_find(NVS_DEFAULT_PART_NAME, NAMESPACE, NVS_TYPE_I32);
|
|
|
+ CHECK(it == NULL);
|
|
|
+
|
|
|
+ // re-init to trigger cleaning up of broken items -> a corrupted string will be erased
|
|
|
+ nvs_flash_deinit();
|
|
|
+ TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
|
|
|
+
|
|
|
+ it = nvs_entry_find(NVS_DEFAULT_PART_NAME, NAMESPACE, NVS_TYPE_STR);
|
|
|
+ CHECK(it != NULL);
|
|
|
+ nvs_release_iterator(it);
|
|
|
+}
|
|
|
|
|
|
TEST_CASE("wifi test", "[nvs]")
|
|
|
{
|
|
|
@@ -1955,7 +2016,7 @@ TEST_CASE("Multi-page blob erased using nvs_erase_key should not be found when p
|
|
|
TEST_ESP_OK(nvs_open("Test", NVS_READWRITE, &handle));
|
|
|
TEST_ESP_OK(nvs_set_blob(handle, "abc", blob, blob_size));
|
|
|
TEST_ESP_OK(nvs_erase_key(handle, "abc"));
|
|
|
- TEST_ESP_ERR(nvs_get_blob(handle, "abc", NULL, &read_size), ESP_ERR_NVS_NOT_FOUND);
|
|
|
+ TEST_ESP_ERR(nvs_get_blob(handle, "abc", NULL, &read_size), ESP_ERR_NVS_NOT_FOUND);
|
|
|
TEST_ESP_OK(nvs_commit(handle));
|
|
|
nvs_close(handle);
|
|
|
}
|
|
|
@@ -2054,7 +2115,7 @@ TEST_CASE("Check that NVS supports old blob format without blob index", "[nvs]")
|
|
|
nvs_handle_t handle;
|
|
|
|
|
|
TEST_ESP_OK( nvs_flash_init_custom("test", 0, 2) );
|
|
|
- TEST_ESP_OK( nvs_open_from_partition("test", "dummyNamespace", NVS_READONLY, &handle));
|
|
|
+ TEST_ESP_OK( nvs_open_from_partition("test", "dummyNamespace", NVS_READWRITE, &handle));
|
|
|
|
|
|
char buf[64] = {0};
|
|
|
size_t buflen = 64;
|