nvs: nvs_get_stats fixed test, improved comment

This commit is contained in:
radek.tandler 2023-08-07 12:01:13 +02:00
parent ac6c03fad1
commit 3ffb8f8ffd
2 changed files with 2 additions and 1 deletions

View File

@ -235,6 +235,7 @@ esp_err_t PageManager::fillStats(nvs_stats_t& nvsStats)
nvsStats.free_entries += mFreePageList.size() * Page::ENTRY_COUNT; nvsStats.free_entries += mFreePageList.size() * Page::ENTRY_COUNT;
// calculate available entries from free entries by applying reserved page size // calculate available entries from free entries by applying reserved page size
// avoid overflow of size_t declared available_entries in case of free_entries being too low
nvsStats.available_entries = (nvsStats.free_entries >= Page::ENTRY_COUNT) ? nvsStats.free_entries - Page::ENTRY_COUNT : 0; nvsStats.available_entries = (nvsStats.free_entries >= Page::ENTRY_COUNT) ? nvsStats.free_entries - Page::ENTRY_COUNT : 0;
return err; return err;

View File

@ -314,7 +314,7 @@ TEST_CASE("calculate used and free space", "[nvs]")
TEST_ASSERT_TRUE(stat1.total_entries == stat2.total_entries); TEST_ASSERT_TRUE(stat1.total_entries == stat2.total_entries);
TEST_ASSERT_TRUE(stat1.used_entries == 7); TEST_ASSERT_TRUE(stat1.used_entries == 7);
TEST_ASSERT_TRUE(stat1.total_entries == (stat1.used_entries + stat1.free_entries + 126)); // one Page::ENTRY_COUNT is reserved TEST_ASSERT_TRUE(stat1.total_entries == (stat1.used_entries + stat1.free_entries));
// amount valid pair in namespace 2 // amount valid pair in namespace 2
size_t h2_count_entries; size_t h2_count_entries;