test_nvs_initialization.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #include "catch.hpp"
  14. #include "nvs_partition_manager.hpp"
  15. #include "spi_flash_emulation.h"
  16. #include "esp_partition.h"
  17. #include "nvs.h"
  18. #include <string.h>
  19. using namespace nvs;
  20. TEST_CASE("nvs_flash_init_partition_ptr fails due to nullptr arg", "[nvs_custom_part]")
  21. {
  22. const uint32_t NVS_FLASH_SECTOR = 6;
  23. const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
  24. SpiFlashEmulator emu(10);
  25. CHECK(nvs_flash_init_partition_ptr(nullptr) == ESP_ERR_INVALID_ARG);
  26. }
  27. TEST_CASE("nvs_flash_init_partition_ptr inits one partition", "[nvs_custom_part]")
  28. {
  29. const uint32_t NVS_FLASH_SECTOR = 6;
  30. const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
  31. SpiFlashEmulator emu(10);
  32. esp_partition_t partition = {};
  33. strcpy(partition.label, "test");
  34. partition.address = NVS_FLASH_SECTOR * SPI_FLASH_SEC_SIZE;
  35. partition.size = NVS_FLASH_SECTOR_COUNT_MIN * SPI_FLASH_SEC_SIZE;
  36. CHECK(nvs_flash_init_partition_ptr(&partition) == ESP_OK);
  37. CHECK(NVSPartitionManager::get_instance()->lookup_storage_from_name("test") != nullptr);
  38. CHECK(NVSPartitionManager::get_instance()->deinit_partition("test") == ESP_OK);
  39. }