From: antti Date: Wed, 23 Nov 2016 03:29:36 +0000 (+0800) Subject: add updated nvs flash test X-Git-Tag: v1.0~29^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=83a3ce882f568692400914b410863b45877f4562;p=esp-idf add updated nvs flash test --- diff --git a/components/nvs_flash/test/test_nvs.c b/components/nvs_flash/test/test_nvs.c index c523026432..db97879bc2 100644 --- a/components/nvs_flash/test/test_nvs.c +++ b/components/nvs_flash/test/test_nvs.c @@ -9,32 +9,26 @@ #include "esp_spi_flash.h" #include -#define NVS_FLASH_SECTOR 6 -#define NVS_FLASH_SECTOR_COUNT_MIN 3 -#define NVS_FLASH_SECTOR_COUNT_MAX 10 TEST_CASE("various nvs tests", "[nvs]") { nvs_handle handle_1; - TEST_ESP_ERR(nvs_open("namespace1", NVS_READWRITE, &handle_1), ESP_ERR_NVS_NOT_INITIALIZED); - 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_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)); + TEST_ESP_OK(nvs_flash_init()); + TEST_ESP_ERR(nvs_open("test_namespace1", NVS_READONLY, &handle_1), ESP_ERR_NVS_NOT_FOUND); - TEST_ESP_ERR(nvs_open("namespace1", NVS_READONLY, &handle_1), ESP_ERR_NVS_NOT_FOUND); + TEST_ESP_ERR(nvs_set_i32(handle_1, "foo", 0x12345678), ESP_ERR_NVS_INVALID_HANDLE); + nvs_close(handle_1); - // TEST_ESP_ERR(nvs_set_i32(handle_1, "foo", 0x12345678), ESP_ERR_NVS_READ_ONLY); - // nvs_close(handle_1); - - TEST_ESP_OK(nvs_open("namespace1", NVS_READWRITE, &handle_1)); + TEST_ESP_OK(nvs_open("test_namespace2", NVS_READWRITE, &handle_1)); + TEST_ESP_OK(nvs_erase_all(handle_1)); TEST_ESP_OK(nvs_set_i32(handle_1, "foo", 0x12345678)); TEST_ESP_OK(nvs_set_i32(handle_1, "foo", 0x23456789)); nvs_handle handle_2; - TEST_ESP_OK(nvs_open("namespace2", NVS_READWRITE, &handle_2)); + TEST_ESP_OK(nvs_open("test_namespace3", NVS_READWRITE, &handle_2)); + TEST_ESP_OK(nvs_erase_all(handle_2)); TEST_ESP_OK(nvs_set_i32(handle_2, "foo", 0x3456789a)); - const char *str = "value 0123456789abcdef0123456789abcdef"; + const char* str = "value 0123456789abcdef0123456789abcdef"; TEST_ESP_OK(nvs_set_str(handle_2, "key", str)); int32_t v1; @@ -51,4 +45,7 @@ TEST_CASE("various nvs tests", "[nvs]") TEST_ESP_OK(nvs_get_str(handle_2, "key", buf, &buf_len)); TEST_ASSERT_EQUAL_INT32(0, strcmp(buf, str)); + + nvs_close(handle_1); + nvs_close(handle_2); }