test_partition_manager.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "catch.hpp"
  7. #include <algorithm>
  8. #include <cstring>
  9. #include "nvs_test_api.h"
  10. #include "nvs_handle_simple.hpp"
  11. #include "nvs_partition_manager.hpp"
  12. #include "spi_flash_emulation.h"
  13. #include "nvs_test_api.h"
  14. #include "test_fixtures.hpp"
  15. TEST_CASE("Partition manager initializes multiple partitions", "[partition_mgr]")
  16. {
  17. const uint32_t NVS_FLASH_SECTOR = 6;
  18. const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
  19. SpiFlashEmulator emu(10);
  20. PartitionEmulation part_0(&emu, NVS_FLASH_SECTOR * SPI_FLASH_SEC_SIZE, NVS_FLASH_SECTOR_COUNT_MIN * SPI_FLASH_SEC_SIZE, "test1");
  21. PartitionEmulation part_1(&emu, NVS_FLASH_SECTOR * SPI_FLASH_SEC_SIZE, NVS_FLASH_SECTOR_COUNT_MIN * SPI_FLASH_SEC_SIZE, "test2");
  22. REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(&part_0, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
  23. == ESP_OK);
  24. // TODO: why does this work, actually? same sectors used as above
  25. REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(&part_1, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
  26. == ESP_OK);
  27. nvs::Storage *storage1 = nvs::NVSPartitionManager::get_instance()->lookup_storage_from_name("test1");
  28. REQUIRE(storage1 != nullptr);
  29. nvs::Storage *storage2 = nvs::NVSPartitionManager::get_instance()->lookup_storage_from_name("test2");
  30. REQUIRE(storage2 != nullptr);
  31. CHECK(storage1 != storage2);
  32. REQUIRE(nvs::NVSPartitionManager::get_instance()->deinit_partition(part_0.get_partition_name()) == ESP_OK);
  33. REQUIRE(nvs::NVSPartitionManager::get_instance()->deinit_partition(part_1.get_partition_name()) == ESP_OK);
  34. }