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 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 #include "catch.hpp" 15 #include "nvs_partition_manager.hpp" 16 #include "spi_flash_emulation.h" 17 #include "esp_partition.h" 18 #include "nvs.h" 19 #include <string.h> 20 21 using namespace nvs; 22 23 TEST_CASE("nvs_flash_init_partition_ptr fails due to nullptr arg", "[nvs_custom_part]") 24 { 25 const uint32_t NVS_FLASH_SECTOR = 6; 26 const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3; 27 SpiFlashEmulator emu(10); 28 29 CHECK(nvs_flash_init_partition_ptr(nullptr) == ESP_ERR_INVALID_ARG); 30 } 31 32 TEST_CASE("nvs_flash_init_partition_ptr inits one partition", "[nvs_custom_part]") 33 { 34 const uint32_t NVS_FLASH_SECTOR = 6; 35 const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3; 36 SpiFlashEmulator emu(10); 37 38 esp_partition_t partition = {}; 39 strcpy(partition.label, "test"); 40 partition.address = NVS_FLASH_SECTOR * SPI_FLASH_SEC_SIZE; 41 partition.size = NVS_FLASH_SECTOR_COUNT_MIN * SPI_FLASH_SEC_SIZE; 42 43 CHECK(nvs_flash_init_partition_ptr(&partition) == ESP_OK); 44 CHECK(NVSPartitionManager::get_instance()->lookup_storage_from_name("test") != nullptr); 45 CHECK(NVSPartitionManager::get_instance()->deinit_partition("test") == ESP_OK); 46 } 47