Merge branch 'bugfix/nvs_flash_missing_tests' into 'release/v4.0'

nvs: Added nvs tests, minor corrections (backport v4.0)

See merge request espressif/esp-idf!6987
This commit is contained in:
Angus Gratton 2019-12-18 11:38:08 +08:00
commit 1b15e6cf56
3 changed files with 19 additions and 48 deletions

View file

@ -557,35 +557,6 @@ void nvs_entry_info(nvs_iterator_t iterator, nvs_entry_info_t *out_info);
*/ */
void nvs_release_iterator(nvs_iterator_t iterator); void nvs_release_iterator(nvs_iterator_t iterator);
/**
* @brief Returns next item matching the iterator criteria, NULL if no such item exists.
*
* Note that any copies of the iterator will be invalid after this call.
*
* @param[in] iterator Iterator obtained from nvs_entry_find function. Must be non-NULL.
*
* @return
* NULL if no entry was found, valid nvs_iterator_t otherwise.
*/
nvs_iterator_t nvs_entry_next(nvs_iterator_t iterator);
/**
* @brief Fills nvs_entry_info_t structure with information about entry pointed to by the iterator.
*
* @param[in] iterator Iterator obtained from nvs_entry_find or nvs_entry_next function. Must be non-NULL.
*
* @param[out] out_info Structure to which entry information is copied.
*/
void nvs_entry_info(nvs_iterator_t iterator, nvs_entry_info_t *out_info);
/**
* @brief Release iterator
*
* @param[in] iterator Release iterator obtained from nvs_entry_find function. NULL argument is allowed.
*
*/
void nvs_release_iterator(nvs_iterator_t iterator);
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"

View file

@ -1,3 +1,3 @@
idf_component_register(SRCS "." idf_component_register(SRC_DIRS "."
INCLUDE_DIRS "." INCLUDE_DIRS "."
REQUIRES unity test_utils nvs_flash bootloader_support) REQUIRES unity test_utils nvs_flash bootloader_support)

View file

@ -32,9 +32,9 @@ TEST_CASE("various nvs tests", "[nvs]")
} }
ESP_ERROR_CHECK( err ); ESP_ERROR_CHECK( err );
TEST_ESP_ERR(nvs_open("test_namespace1", NVS_READONLY, &handle_1), ESP_ERR_NVS_NOT_FOUND); TEST_ESP_ERR(ESP_ERR_NVS_NOT_FOUND, nvs_open("test_namespace1", NVS_READONLY, &handle_1));
TEST_ESP_ERR(nvs_set_i32(handle_1, "foo", 0x12345678), ESP_ERR_NVS_INVALID_HANDLE); TEST_ESP_ERR(ESP_ERR_NVS_INVALID_HANDLE, nvs_set_i32(handle_1, "foo", 0x12345678));
nvs_close(handle_1); nvs_close(handle_1);
TEST_ESP_OK(nvs_open("test_namespace2", NVS_READWRITE, &handle_1)); TEST_ESP_OK(nvs_open("test_namespace2", NVS_READWRITE, &handle_1));
@ -74,10 +74,10 @@ TEST_CASE("various nvs tests", "[nvs]")
TEST_CASE("calculate used and free space", "[nvs]") TEST_CASE("calculate used and free space", "[nvs]")
{ {
TEST_ESP_ERR(nvs_get_stats(NULL, NULL), ESP_ERR_INVALID_ARG); TEST_ESP_ERR(ESP_ERR_INVALID_ARG, nvs_get_stats(NULL, NULL));
nvs_stats_t stat1; nvs_stats_t stat1;
nvs_stats_t stat2; nvs_stats_t stat2;
TEST_ESP_ERR(nvs_get_stats(NULL, &stat1), ESP_ERR_NVS_NOT_INITIALIZED); TEST_ESP_ERR(ESP_ERR_NVS_NOT_INITIALIZED, nvs_get_stats(NULL, &stat1));
TEST_ASSERT_TRUE(stat1.free_entries == 0); TEST_ASSERT_TRUE(stat1.free_entries == 0);
TEST_ASSERT_TRUE(stat1.namespace_count == 0); TEST_ASSERT_TRUE(stat1.namespace_count == 0);
TEST_ASSERT_TRUE(stat1.total_entries == 0); TEST_ASSERT_TRUE(stat1.total_entries == 0);
@ -85,7 +85,7 @@ TEST_CASE("calculate used and free space", "[nvs]")
nvs_handle_t handle = 0; nvs_handle_t handle = 0;
size_t h_count_entries; size_t h_count_entries;
TEST_ESP_ERR(nvs_get_used_entry_count(handle, &h_count_entries), ESP_ERR_NVS_INVALID_HANDLE); TEST_ESP_ERR(ESP_ERR_NVS_INVALID_HANDLE, nvs_get_used_entry_count(handle, &h_count_entries));
TEST_ASSERT_TRUE(h_count_entries == 0); TEST_ASSERT_TRUE(h_count_entries == 0);
esp_err_t err = nvs_flash_init(); esp_err_t err = nvs_flash_init();
@ -184,10 +184,10 @@ TEST_CASE("calculate used and free space", "[nvs]")
nvs_close(handle_2); nvs_close(handle_2);
size_t temp = h2_count_entries; size_t temp = h2_count_entries;
TEST_ESP_ERR(nvs_get_used_entry_count(handle_1, &h2_count_entries), ESP_ERR_NVS_INVALID_HANDLE); TEST_ESP_ERR(ESP_ERR_NVS_INVALID_HANDLE, nvs_get_used_entry_count(handle_1, &h2_count_entries));
TEST_ASSERT_TRUE(h2_count_entries == 0); TEST_ASSERT_TRUE(h2_count_entries == 0);
h2_count_entries = temp; h2_count_entries = temp;
TEST_ESP_ERR(nvs_get_used_entry_count(handle_1, NULL), ESP_ERR_INVALID_ARG); TEST_ESP_ERR(ESP_ERR_INVALID_ARG, nvs_get_used_entry_count(handle_1, NULL));
nvs_handle_t handle_3; nvs_handle_t handle_3;
// create namespace test_k3 // create namespace test_k3
@ -233,7 +233,7 @@ TEST_CASE("check for memory leaks in nvs_set_blob", "[nvs]")
nvs_handle_t my_handle; nvs_handle_t my_handle;
uint8_t key[20] = {0}; uint8_t key[20] = {0};
TEST_ESP_OK( nvs_open("test_namespace1", NVS_READWRITE, &my_handle) ); TEST_ESP_OK( nvs_open("leak_check_ns", NVS_READWRITE, &my_handle) );
TEST_ESP_OK( nvs_set_blob(my_handle, "key", key, sizeof(key)) ); TEST_ESP_OK( nvs_set_blob(my_handle, "key", key, sizeof(key)) );
TEST_ESP_OK( nvs_commit(my_handle) ); TEST_ESP_OK( nvs_commit(my_handle) );
nvs_close(my_handle); nvs_close(my_handle);
@ -298,7 +298,7 @@ TEST_CASE("Check nvs key partition APIs (read and generate keys)", "[nvs]")
} }
TEST_ESP_OK(esp_partition_erase_range(key_part, 0, key_part->size)); TEST_ESP_OK(esp_partition_erase_range(key_part, 0, key_part->size));
TEST_ESP_ERR(nvs_flash_read_security_cfg(key_part, &cfg), ESP_ERR_NVS_KEYS_NOT_INITIALIZED); TEST_ESP_ERR(ESP_ERR_NVS_KEYS_NOT_INITIALIZED, nvs_flash_read_security_cfg(key_part, &cfg));
TEST_ESP_OK(nvs_flash_generate_keys(key_part, &cfg)); TEST_ESP_OK(nvs_flash_generate_keys(key_part, &cfg));
@ -336,7 +336,7 @@ TEST_CASE("test nvs apis with encryption enabled", "[nvs]")
uint8_t value[4096] = {[0 ... 4095] = 0xff}; uint8_t value[4096] = {[0 ... 4095] = 0xff};
TEST_ESP_OK(esp_partition_write(key_part, 0, value, sizeof(value))); TEST_ESP_OK(esp_partition_write(key_part, 0, value, sizeof(value)));
TEST_ESP_ERR(nvs_flash_read_security_cfg(key_part, &cfg), ESP_ERR_NVS_KEYS_NOT_INITIALIZED); TEST_ESP_ERR(ESP_ERR_NVS_KEYS_NOT_INITIALIZED, nvs_flash_read_security_cfg(key_part, &cfg));
TEST_ESP_OK(nvs_flash_generate_keys(key_part, &cfg)); TEST_ESP_OK(nvs_flash_generate_keys(key_part, &cfg));
} else { } else {
@ -348,7 +348,7 @@ TEST_CASE("test nvs apis with encryption enabled", "[nvs]")
nvs_handle_t handle_1; nvs_handle_t handle_1;
TEST_ESP_ERR(nvs_open("namespace1", NVS_READONLY, &handle_1), ESP_ERR_NVS_NOT_FOUND); TEST_ESP_ERR(ESP_ERR_NVS_NOT_FOUND, nvs_open("namespace1", NVS_READONLY, &handle_1));
TEST_ESP_OK(nvs_open("namespace1", NVS_READWRITE, &handle_1)); TEST_ESP_OK(nvs_open("namespace1", NVS_READWRITE, &handle_1));