Merge branch 'bugfix/nvs_stat_test' into 'master'

NVS: fix nvs_get_stats unit test

See merge request idf/esp-idf!2248
This commit is contained in:
Ivan Grokhotkov 2018-04-16 14:45:43 +08:00
commit fc1e944f59
2 changed files with 34 additions and 27 deletions

View File

@ -133,6 +133,23 @@ extern "C" esp_err_t nvs_flash_init(void)
return nvs_flash_init_partition(NVS_DEFAULT_PART_NAME);
}
extern "C" esp_err_t nvs_flash_erase_partition(const char *part_name)
{
const esp_partition_t* partition = esp_partition_find_first(
ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, part_name);
if (partition == NULL) {
return ESP_ERR_NOT_FOUND;
}
return esp_partition_erase_range(partition, 0, partition->size);
}
extern "C" esp_err_t nvs_flash_erase()
{
return nvs_flash_erase_partition(NVS_DEFAULT_PART_NAME);
}
#endif // ESP_PLATFORM
extern "C" esp_err_t nvs_flash_deinit_partition(const char* partition_name)
{
Lock::init();
@ -150,7 +167,7 @@ extern "C" esp_err_t nvs_flash_deinit_partition(const char* partition_name)
next++;
if (it->mStoragePtr == storage) {
ESP_LOGD(TAG, "Deleting handle %d (ns=%d) related to partition \"%s\" (missing call to nvs_close?)",
it->mHandle, it->mNsIndex, partition_name);
it->mHandle, it->mNsIndex, partition_name);
s_nvs_handles.erase(it);
delete static_cast<HandleEntry*>(it);
}
@ -169,23 +186,6 @@ extern "C" esp_err_t nvs_flash_deinit(void)
return nvs_flash_deinit_partition(NVS_DEFAULT_PART_NAME);
}
extern "C" esp_err_t nvs_flash_erase_partition(const char *part_name)
{
const esp_partition_t* partition = esp_partition_find_first(
ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, part_name);
if (partition == NULL) {
return ESP_ERR_NOT_FOUND;
}
return esp_partition_erase_range(partition, 0, partition->size);
}
extern "C" esp_err_t nvs_flash_erase()
{
return nvs_flash_erase_partition(NVS_DEFAULT_PART_NAME);
}
#endif
static esp_err_t nvs_find_ns_handle(nvs_handle handle, HandleEntry& entry)
{
auto it = find_if(begin(s_nvs_handles), end(s_nvs_handles), [=](HandleEntry& e) -> bool {
@ -473,11 +473,11 @@ extern "C" esp_err_t nvs_get_stats(const char* part_name, nvs_stats_t* nvs_stats
pStorage = lookup_storage_from_name((part_name == NULL) ? NVS_DEFAULT_PART_NAME : part_name);
if (pStorage == NULL) {
return ESP_ERR_NVS_PART_NOT_FOUND;
return ESP_ERR_NVS_NOT_INITIALIZED;
}
if(!pStorage->isValid()){
return ESP_ERR_NVS_NOT_INITIALIZED;
return ESP_ERR_NVS_INVALID_STATE;
}
return pStorage->fillStats(*nvs_stats);

View File

@ -1267,16 +1267,10 @@ TEST_CASE("nvs page selection takes into account free entries also not just eras
nvs_close(handle);
}
TEST_CASE("dump all performance data", "[nvs]")
{
std::cout << "====================" << std::endl << "Dumping benchmarks" << std::endl;
std::cout << s_perf.str() << std::endl;
std::cout << "====================" << std::endl;
}
TEST_CASE("calculate used and free space", "[nvs]")
{
SpiFlashEmulator emu(6);
nvs_flash_deinit();
TEST_ESP_ERR(nvs_get_stats(NULL, NULL), ESP_ERR_INVALID_ARG);
nvs_stats_t stat1;
nvs_stats_t stat2;
@ -1407,3 +1401,16 @@ TEST_CASE("calculate used and free space", "[nvs]")
nvs_close(handle_3);
}
/* Add new tests above */
/* This test has to be the final one */
TEST_CASE("dump all performance data", "[nvs]")
{
std::cout << "====================" << std::endl << "Dumping benchmarks" << std::endl;
std::cout << s_perf.str() << std::endl;
std::cout << "====================" << std::endl;
}