nvs_flash/host_test: migrated to the CMake build system and nvs flash Linux implementation

Host tests of nvs_flash eligible to run in Linux implementation of nvs flash were migrated. Remaining test cases
were left in original folder. Migrated test cases use CMake instead of make.
pull/9962/head
radek.tandler 2022-10-18 15:06:10 +02:00
rodzic 73724b0d41
commit ca7f073e7b
28 zmienionych plików z 2988 dodań i 2766 usunięć

Wyświetl plik

@ -20,6 +20,13 @@ test_nvs_on_host:
- cd components/nvs_flash/test_nvs_host
- make test
test_nvs_on_host_cmake:
extends: .host_test_template
script:
- cd ${IDF_PATH}/components/nvs_flash/host_test/nvs_host_test
- idf.py build
- build/nvs_host_test.elf
test_nvs_coverage:
extends:
- .host_test_template

Wyświetl plik

@ -17,6 +17,7 @@ idf_component_register(SRCS "${srcs}"
REQUIRES "esp_partition"
PRIV_REQUIRES spi_flash
INCLUDE_DIRS "include"
"../spi_flash/include"
PRIV_INCLUDE_DIRS "private_include")
# If we use the linux target, we need to redirect the crc functions to the linux
@ -28,6 +29,13 @@ if(${target} STREQUAL "linux")
target_compile_options(${COMPONENT_LIB} PUBLIC "-DLINUX_TARGET")
target_compile_options(${COMPONENT_LIB} PUBLIC --coverage)
target_link_libraries(${COMPONENT_LIB} PUBLIC --coverage)
find_library(LIB_BSD bsd)
if(LIB_BSD)
target_link_libraries(${COMPONENT_LIB} PRIVATE ${LIB_BSD})
elseif(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
message(WARNING "Missing LIBBSD library. Install libbsd-dev package and/or check linker directories.")
endif()
endif()
if(CONFIG_NVS_ENCRYPTION)

Wyświetl plik

@ -1,16 +1,8 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "nvs_partition.hpp"
#include "nvs.h"
@ -29,8 +21,7 @@ extern "C" {
struct FixtureException : std::exception {
FixtureException(const std::string& msg) : msg(msg) { }
const char *what() {
const char *what() const noexcept {
return msg.c_str();
}

Wyświetl plik

@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
set(COMPONENTS main)
# Freertos is included via common components. However, CATCH isn't compatible with the FreeRTOS component yet, hence
# using the FreeRTOS mock component.
# target.
list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/freertos/")
project(nvs_host_test)
add_dependencies(nvs_host_test.elf partition-table)

Wyświetl plik

@ -0,0 +1,2 @@
| Supported Targets | Linux |
| ----------------- | ----- |

Wyświetl plik

@ -0,0 +1,14 @@
idf_component_register(SRCS "main.cpp"
"test_nvs.cpp"
"test_partition_manager.cpp"
"test_nvs_cxx_api.cpp"
"test_nvs_handle.cpp"
"test_nvs_initialization.cpp"
"test_nvs_storage.cpp"
INCLUDE_DIRS
"../../../src"
"../../../private_include"
"../../../../mbedtls/mbedtls/include"
"../../../../../tools/catch"
WHOLE_ARCHIVE
REQUIRES nvs_flash)

Wyświetl plik

@ -0,0 +1,7 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#define CATCH_CONFIG_MAIN
#include "catch.hpp"

Wyświetl plik

@ -0,0 +1,43 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "nvs_partition.hpp"
#include "esp_private/partition_linux.h"
#include "nvs.h"
class PartitionEmulationFixture {
public:
PartitionEmulationFixture( uint32_t start_sector = 0,
uint32_t sector_size = 1,
const char *partition_name = NVS_DEFAULT_PART_NAME) :
esp_partition()
{
if (esp_partition_file_mmap((const uint8_t **) &p_part_desc_addr_start) != ESP_OK) {
throw ("Failed to initialize esp_partition_file_mmap");
}
esp_partition.address = start_sector * SPI_FLASH_SEC_SIZE;
esp_partition.size = sector_size * SPI_FLASH_SEC_SIZE;
esp_partition.erase_size = ESP_PARTITION_EMULATED_SECTOR_SIZE;
strncpy(esp_partition.label, partition_name, PART_NAME_MAX_SIZE);
p_part = new nvs::NVSPartition(&esp_partition);
}
~PartitionEmulationFixture()
{
delete p_part;
esp_partition_file_munmap();
}
nvs::NVSPartition *part()
{
return p_part;
}
nvs::NVSPartition *p_part;
esp_partition_t esp_partition;
uint8_t *p_part_desc_addr_start;
};

Wyświetl plik

@ -1,30 +1,16 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "catch.hpp"
#include <algorithm>
#include <cstring>
#include "nvs_test_api.h"
#include "nvs_handle_simple.hpp"
#include "nvs_partition_manager.hpp"
#include "spi_flash_emulation.h"
#include "test_fixtures.hpp"
#include <iostream>
using namespace std;
TEST_CASE("NVSHandleSimple CXX api open invalid arguments", "[nvs cxx]")
{
const uint32_t NVS_FLASH_SECTOR = 6;
@ -34,7 +20,7 @@ TEST_CASE("NVSHandleSimple CXX api open invalid arguments", "[nvs cxx]")
shared_ptr<nvs::NVSHandle> handle;
REQUIRE(nvs::NVSPartitionManager::get_instance()->
init_custom(&f.part, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN) == ESP_OK);
init_custom(f.part(), NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN) == ESP_OK);
handle = nvs::open_nvs_handle_from_partition(nullptr, "ns_1", NVS_READWRITE, &result);
CHECK(result == ESP_ERR_INVALID_ARG);
@ -49,7 +35,9 @@ TEST_CASE("NVSHandleSimple CXX api open invalid arguments", "[nvs cxx]")
TEST_CASE("NVSHandleSimple CXX api open partition uninitialized", "[nvs cxx]")
{
SpiFlashEmulator emu(10);
uint8_t *p_part_desc_addr_start;
CHECK(esp_partition_file_mmap((const uint8_t **)&p_part_desc_addr_start) == ESP_OK);
esp_err_t result;
shared_ptr<nvs::NVSHandle> handle;
@ -67,7 +55,7 @@ TEST_CASE("NVSHandleSimple CXX api open successful", "[nvs cxx]")
esp_err_t result;
shared_ptr<nvs::NVSHandle> handle;
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(&f.part, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(f.part(), NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
CHECK(nvs::NVSPartitionManager::get_instance()->open_handles_size() == 0);
@ -93,7 +81,7 @@ TEST_CASE("NVSHandleSimple CXX api open default part successful", "[nvs cxx]")
esp_err_t result;
shared_ptr<nvs::NVSHandle> handle;
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(&f.part, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(f.part(), NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
CHECK(nvs::NVSPartitionManager::get_instance()->open_handles_size() == 0);
@ -119,7 +107,7 @@ TEST_CASE("NVSHandleSimple CXX api open default part ns NULL", "[nvs cxx]")
esp_err_t result;
shared_ptr<nvs::NVSHandle> handle;
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(&f.part, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(f.part(), NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
CHECK(nvs::NVSPartitionManager::get_instance()->open_handles_size() == 0);
@ -142,7 +130,7 @@ TEST_CASE("NVSHandleSimple CXX api read/write string", "[nvs cxx]")
esp_err_t result;
shared_ptr<nvs::NVSHandle> handle;
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(&f.part, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(f.part(), NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
CHECK(nvs::NVSPartitionManager::get_instance()->open_handles_size() == 0);
@ -172,7 +160,7 @@ TEST_CASE("NVSHandleSimple CXX api read/write blob", "[nvs cxx]")
esp_err_t result;
shared_ptr<nvs::NVSHandle> handle;
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(&f.part, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(f.part(), NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
CHECK(nvs::NVSPartitionManager::get_instance()->open_handles_size() == 0);

Wyświetl plik

@ -0,0 +1,268 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "catch.hpp"
#include <algorithm>
#include <cstring>
#include "nvs_handle_simple.hpp"
#include "nvs_partition_manager.hpp"
#include "test_fixtures.hpp"
#include <iostream>
#include <string>
#define TEMPORARILY_DISABLED(x)
TEST_CASE("NVSHandleSimple closes its reference in PartitionManager", "[partition_mgr]")
{
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
PartitionEmulationFixture f(0, 10, "test");
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(f.part(), NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
CHECK(nvs::NVSPartitionManager::get_instance()->open_handles_size() == 0);
nvs::NVSHandleSimple *handle;
REQUIRE(nvs::NVSPartitionManager::get_instance()->open_handle("test", "ns_1", NVS_READWRITE, &handle) == ESP_OK);
CHECK(nvs::NVSPartitionManager::get_instance()->open_handles_size() == 1);
delete handle;
CHECK(nvs::NVSPartitionManager::get_instance()->open_handles_size() == 0);
REQUIRE(nvs::NVSPartitionManager::get_instance()->deinit_partition("test") == ESP_OK);
}
TEST_CASE("NVSHandleSimple multiple open and closes with PartitionManager", "[partition_mgr]")
{
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
PartitionEmulationFixture f(0, 10, "test");
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(f.part(), NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
CHECK(nvs::NVSPartitionManager::get_instance()->open_handles_size() == 0);
nvs::NVSHandleSimple *handle1;
nvs::NVSHandleSimple *handle2;
REQUIRE(nvs::NVSPartitionManager::get_instance()->open_handle("test", "ns_1", NVS_READWRITE, &handle1) == ESP_OK);
CHECK(nvs::NVSPartitionManager::get_instance()->open_handles_size() == 1);
REQUIRE(nvs::NVSPartitionManager::get_instance()->open_handle("test", "ns_1", NVS_READWRITE, &handle2) == ESP_OK);
CHECK(nvs::NVSPartitionManager::get_instance()->open_handles_size() == 2);
delete handle1;
CHECK(nvs::NVSPartitionManager::get_instance()->open_handles_size() == 1);
delete handle2;
CHECK(nvs::NVSPartitionManager::get_instance()->open_handles_size() == 0);
REQUIRE(nvs::NVSPartitionManager::get_instance()->deinit_partition("test") == ESP_OK);
}
TEST_CASE("NVSHandleSimple readonly fails", "[partition_mgr]")
{
PartitionEmulationFixture f(0, 10);
nvs::NVSPartitionManager::get_instance()->deinit_partition(NVS_DEFAULT_PART_NAME);
nvs::NVSHandleSimple *handle_1;
nvs::NVSHandleSimple *handle_2;
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
TEMPORARILY_DISABLED(f.emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);)
CHECK(nvs::NVSPartitionManager::get_instance()->init_custom(f.part(), NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN) == ESP_OK);
CHECK(nvs::NVSPartitionManager::get_instance()->open_handles_size() == 0);
// first, creating namespace...
REQUIRE(nvs::NVSPartitionManager::get_instance()->open_handle(NVS_DEFAULT_PART_NAME, "ns_1", NVS_READWRITE, &handle_1) == ESP_OK);
CHECK(nvs::NVSPartitionManager::get_instance()->open_handles_size() == 1);
delete handle_1;
CHECK(nvs::NVSPartitionManager::get_instance()->open_handles_size() == 0);
REQUIRE(nvs::NVSPartitionManager::get_instance()->open_handle(NVS_DEFAULT_PART_NAME, "ns_1", NVS_READONLY, &handle_2) == ESP_OK);
CHECK(handle_2->set_item("key", 47) == ESP_ERR_NVS_READ_ONLY);
CHECK(nvs::NVSPartitionManager::get_instance()->open_handles_size() == 1);
delete handle_2;
CHECK(nvs::NVSPartitionManager::get_instance()->open_handles_size() == 0);
// without deinit it affects "nvs api tests"
CHECK(nvs_flash_deinit_partition(NVS_DEFAULT_PART_NAME) == ESP_OK);
}
TEST_CASE("NVSHandleSimple set/get char", "[partition_mgr]")
{
enum class TestEnum : char {
FOO = -1,
BEER,
BAR
};
PartitionEmulationFixture f(0, 10);
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
TEMPORARILY_DISABLED(f.emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);)
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(f.part(), NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
nvs::NVSHandleSimple *handle;
REQUIRE(nvs::NVSPartitionManager::get_instance()->open_handle(NVS_DEFAULT_PART_NAME, "ns_1", NVS_READWRITE, &handle) == ESP_OK);
char test_e = 'a';
char test_e_read = 'z';
CHECK(handle->set_item("key", test_e) == ESP_OK);
CHECK(handle->get_item("key", test_e_read) == ESP_OK);
CHECK(test_e == test_e_read);
delete handle;
REQUIRE(nvs::NVSPartitionManager::get_instance()->deinit_partition(NVS_DEFAULT_PART_NAME) == ESP_OK);
}
TEST_CASE("NVSHandleSimple correctly sets/gets int enum", "[partition_mgr]")
{
enum class TestEnum : int {
FOO,
BAR
};
PartitionEmulationFixture f(0, 10);
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
TEMPORARILY_DISABLED(f.emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);)
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(f.part(), NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
nvs::NVSHandleSimple *handle;
REQUIRE(nvs::NVSPartitionManager::get_instance()->open_handle(NVS_DEFAULT_PART_NAME, "ns_1", NVS_READWRITE, &handle) == ESP_OK);
TestEnum test_e = TestEnum::BAR;
TestEnum test_e_read = TestEnum::FOO;
CHECK(handle->set_item("key", test_e) == ESP_OK);
CHECK(handle->get_item("key", test_e_read) == ESP_OK);
CHECK(test_e == test_e_read);
delete handle;
REQUIRE(nvs::NVSPartitionManager::get_instance()->deinit_partition(NVS_DEFAULT_PART_NAME) == ESP_OK);
}
TEST_CASE("NVSHandleSimple correctly sets/gets int enum with negative values", "[partition_mgr]")
{
enum class TestEnum : int {
FOO = -1,
BEER,
BAR
};
PartitionEmulationFixture f(0, 10);
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
TEMPORARILY_DISABLED(f.emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);)
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(f.part(), NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
nvs::NVSHandleSimple *handle;
REQUIRE(nvs::NVSPartitionManager::get_instance()->open_handle(NVS_DEFAULT_PART_NAME, "ns_1", NVS_READWRITE, &handle) == ESP_OK);
TestEnum test_e = TestEnum::FOO;
TestEnum test_e_read = TestEnum::BEER;
CHECK(handle->set_item("key", test_e) == ESP_OK);
CHECK(handle->get_item("key", test_e_read) == ESP_OK);
CHECK(test_e == test_e_read);
delete handle;
REQUIRE(nvs::NVSPartitionManager::get_instance()->deinit_partition(NVS_DEFAULT_PART_NAME) == ESP_OK);
}
TEST_CASE("NVSHandleSimple correctly sets/gets uint8_t enum", "[partition_mgr]")
{
enum class TestEnum : uint8_t {
FOO,
BAR
};
PartitionEmulationFixture f(0, 10);
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
TEMPORARILY_DISABLED(f.emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);)
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(f.part(), NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
nvs::NVSHandleSimple *handle;
REQUIRE(nvs::NVSPartitionManager::get_instance()->open_handle(NVS_DEFAULT_PART_NAME, "ns_1", NVS_READWRITE, &handle) == ESP_OK);
TestEnum test_e = TestEnum::BAR;
TestEnum test_e_read = TestEnum::FOO;
CHECK(handle->set_item("key", test_e) == ESP_OK);
CHECK(handle->get_item("key", test_e_read) == ESP_OK);
CHECK(test_e == test_e_read);
delete handle;
REQUIRE(nvs::NVSPartitionManager::get_instance()->deinit_partition(NVS_DEFAULT_PART_NAME) == ESP_OK);
}
TEST_CASE("NVSHandleSimple correctly sets/gets char enum", "[partition_mgr]")
{
enum class TestEnum : char {
FOO = -1,
BEER,
BAR
};
PartitionEmulationFixture f(0, 10);
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
TEMPORARILY_DISABLED(f.emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);)
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(f.part(), NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
nvs::NVSHandleSimple *handle;
REQUIRE(nvs::NVSPartitionManager::get_instance()->open_handle(NVS_DEFAULT_PART_NAME, "ns_1", NVS_READWRITE, &handle) == ESP_OK);
TestEnum test_e = TestEnum::BAR;
TestEnum test_e_read = TestEnum::FOO;
CHECK(handle->set_item("key", test_e) == ESP_OK);
CHECK(handle->get_item("key", test_e_read) == ESP_OK);
CHECK(test_e == test_e_read);
delete handle;
REQUIRE(nvs::NVSPartitionManager::get_instance()->deinit_partition(NVS_DEFAULT_PART_NAME) == ESP_OK);
}

Wyświetl plik

@ -0,0 +1,38 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "catch.hpp"
#include "nvs.hpp"
#include "nvs_partition_manager.hpp"
#include "nvs_partition.hpp"
#include "test_fixtures.hpp"
#include <string.h>
TEST_CASE("nvs_flash_init_partition_ptr fails due to nullptr arg", "[nvs_custom_part]")
{
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
uint8_t *p_part_desc_addr_start;
CHECK(esp_partition_file_mmap((const uint8_t **)&p_part_desc_addr_start) == ESP_OK);
CHECK(nvs_flash_init_partition_ptr(nullptr) == ESP_ERR_INVALID_ARG);
}
TEST_CASE("nvs_flash_init_partition_ptr inits one partition", "[nvs_custom_part]")
{
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
uint8_t *p_part_desc_addr_start;
CHECK(esp_partition_file_mmap((const uint8_t **)&p_part_desc_addr_start) == ESP_OK);
esp_partition_t partition = {};
strcpy(partition.label, "test");
partition.address = NVS_FLASH_SECTOR * SPI_FLASH_SEC_SIZE;
partition.size = NVS_FLASH_SECTOR_COUNT_MIN * SPI_FLASH_SEC_SIZE;
CHECK(nvs_flash_init_partition_ptr(&partition) == ESP_OK);
CHECK(nvs::NVSPartitionManager::get_instance()->lookup_storage_from_name("test") != nullptr);
CHECK(nvs::NVSPartitionManager::get_instance()->deinit_partition("test") == ESP_OK);
}

Wyświetl plik

@ -0,0 +1,45 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "catch.hpp"
#include <cstring>
#include "nvs_storage.hpp"
#include "nvs_partition_manager.hpp"
#include "test_fixtures.hpp"
#include <iostream>
TEST_CASE("Storage iterator recognizes blob with VerOffset::VER_1_OFFSET", "[nvs_storage]")
{
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
PartitionEmulationFixture f(0, 10, "test");
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(f.part(), NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
uint8_t blob [] = {0x0, 0x1, 0x2, 0x3};
uint8_t blob_new [] = {0x3, 0x2, 0x1, 0x0};
nvs::Storage *storage = nvs::NVSPartitionManager::get_instance()->lookup_storage_from_name("test");
uint8_t ns_index;
storage->createOrOpenNamespace("test_ns", true, ns_index);
CHECK(storage->writeItem(ns_index, nvs::ItemType::BLOB, "test_blob", blob, sizeof(blob)) == ESP_OK);
// changing provokes a blob with version offset 1 (VerOffset::VER_1_OFFSET)
CHECK(storage->writeItem(ns_index, nvs::ItemType::BLOB, "test_blob", blob_new, sizeof(blob_new)) == ESP_OK);
nvs_opaque_iterator_t it;
it.storage = storage;
it.type = NVS_TYPE_ANY;
// Central check: does the iterator recognize the blob with version 1?
REQUIRE(storage->findEntry(&it, "test_ns"));
CHECK(string(it.entry_info.namespace_name) == string("test_ns"));
CHECK(string(it.entry_info.key) == string("test_blob"));
CHECK(it.entry_info.type == NVS_TYPE_BLOB);
REQUIRE(nvs::NVSPartitionManager::get_instance()->deinit_partition("test") == ESP_OK);
}

Wyświetl plik

@ -0,0 +1,70 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "catch.hpp"
#include <algorithm>
#include <cstring>
#include "nvs_handle_simple.hpp"
#include "nvs_partition_manager.hpp"
#include "nvs_test_api.h"
#include "test_fixtures.hpp"
TEST_CASE("Partition manager initializes storage", "[partition_mgr]")
{
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
PartitionEmulationFixture f(0, 10, "test");
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(f.part(), NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN) == ESP_OK);
CHECK(nvs::NVSPartitionManager::get_instance()->lookup_storage_from_name("test") != nullptr);
REQUIRE(nvs::NVSPartitionManager::get_instance()->deinit_partition(f.part()->get_partition_name()) == ESP_OK);
}
TEST_CASE("Partition manager de-initializes storage", "[partition_mgr]")
{
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
PartitionEmulationFixture f(0, 10, "test");
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(f.part(), NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN) == ESP_OK);
CHECK(nvs::NVSPartitionManager::get_instance()->lookup_storage_from_name("test") != nullptr);
CHECK(nvs::NVSPartitionManager::get_instance()->deinit_partition("test") == ESP_OK);
CHECK(nvs::NVSPartitionManager::get_instance()->lookup_storage_from_name("test") == nullptr);
}
TEST_CASE("Partition manager open fails on null handle", "[partition_mgr]")
{
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
PartitionEmulationFixture f(0, 10, "test");
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(f.part(), NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
CHECK(nvs::NVSPartitionManager::get_instance()->open_handle("test", "ns_1", NVS_READWRITE, nullptr)
== ESP_ERR_INVALID_ARG);
nvs::NVSPartitionManager::get_instance()->deinit_partition("test");
}
TEST_CASE("Partition manager invalidates handle on partition de-init", "[partition_mgr]")
{
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
PartitionEmulationFixture f(0, 10, "test");
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(f.part(), NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
nvs::NVSHandleSimple *handle;
REQUIRE(nvs::NVSPartitionManager::get_instance()->open_handle("test", "ns_1", NVS_READWRITE, &handle) == ESP_OK);
CHECK(handle->erase_all() == ESP_OK);
REQUIRE(nvs::NVSPartitionManager::get_instance()->deinit_partition("test") == ESP_OK);
CHECK(handle->erase_all() == ESP_ERR_NVS_INVALID_HANDLE);
delete handle;
}

Wyświetl plik

@ -0,0 +1,3 @@
CONFIG_IDF_TARGET="linux"
CONFIG_COMPILER_CXX_EXCEPTIONS=y
CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=n

Wyświetl plik

@ -21,12 +21,8 @@ SOURCE_FILES = \
test_spi_flash_emulation.cpp \
test_intrusive_list.cpp \
test_nvs.cpp \
test_partition_manager.cpp \
test_nvs_handle.cpp \
test_nvs_storage.cpp \
test_nvs_partition.cpp \
test_nvs_cxx_api.cpp \
test_nvs_initialization.cpp \
test_partition_manager.cpp \
main.cpp
SOURCE_FILES_C = ../../esp_rom/linux/esp_rom_crc.c ../../esp_common/src/esp_err_check_linux.c

Wyświetl plik

@ -1,20 +1,11 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "esp_partition.h"
#include "spi_flash_emulation.h"
static SpiFlashEmulator* s_emulator = nullptr;
void spi_flash_emulator_set(SpiFlashEmulator* e)

Wyświetl plik

@ -13,11 +13,6 @@
#include "spi_flash_mmap.h"
#include "catch.hpp"
using std::copy;
using std::begin;
using std::end;
using std::fill_n;
class SpiFlashEmulator;
void spi_flash_emulator_set(SpiFlashEmulator*);

Wyświetl plik

@ -7,7 +7,6 @@
#include "compressed_enum_table.hpp"
#include <cstring>
TEST_CASE("test if CompressedEnumTable works as expected", "[enumtable]")
{
@ -46,5 +45,4 @@ TEST_CASE("test if CompressedEnumTable works as expected", "[enumtable]")
// h 9 3 9 0 9 2 4 9
CHECK(table.data()[0] == 0x93909249);
}

Wyświetl plik

@ -1,314 +0,0 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "catch.hpp"
#include <algorithm>
#include <cstring>
#include "nvs_test_api.h"
#include "nvs_handle_simple.hpp"
#include "nvs_partition_manager.hpp"
#include "spi_flash_emulation.h"
#include "test_fixtures.hpp"
#include <iostream>
#include <string>
using namespace std;
using namespace nvs;
TEST_CASE("open_nvs_handle too long namespace name", "[partition_mgr]")
{
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
const char *TOO_LONG_NS_NAME = "0123456789abcdef";
char test_e = 'a';
NVSHandleSimple *handle;
PartitionEmulationFixture f(0, 10, "test");
CHECK(NVSPartitionManager::get_instance()->open_handles_size() == 0);
REQUIRE(NVSPartitionManager::get_instance()->init_custom(&f.part, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
REQUIRE(NVSPartitionManager::get_instance()->open_handle("test", TOO_LONG_NS_NAME, NVS_READWRITE, &handle) == ESP_ERR_NVS_KEY_TOO_LONG);
CHECK(NVSPartitionManager::get_instance()->open_handles_size() == 0);
REQUIRE(NVSPartitionManager::get_instance()->deinit_partition("test") == ESP_OK);
}
TEST_CASE("open_nvs_handle longest namespace name", "[partition_mgr]")
{
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
const char *LONGEST_NS_NAME = "0123456789abcde";
char test_e = 'a';
NVSHandleSimple *handle;
PartitionEmulationFixture f(0, 10, "test");
CHECK(NVSPartitionManager::get_instance()->open_handles_size() == 0);
REQUIRE(NVSPartitionManager::get_instance()->init_custom(&f.part, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
REQUIRE(NVSPartitionManager::get_instance()->open_handle("test", LONGEST_NS_NAME, NVS_READWRITE, &handle) == ESP_OK);
CHECK(NVSPartitionManager::get_instance()->open_handles_size() == 1);
delete handle;
REQUIRE(NVSPartitionManager::get_instance()->deinit_partition("test") == ESP_OK);
}
TEST_CASE("NVSHandleSimple closes its reference in PartitionManager", "[partition_mgr]")
{
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
PartitionEmulationFixture f(0, 10, "test");
REQUIRE(NVSPartitionManager::get_instance()->init_custom(&f.part, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
CHECK(NVSPartitionManager::get_instance()->open_handles_size() == 0);
NVSHandleSimple *handle;
REQUIRE(NVSPartitionManager::get_instance()->open_handle("test", "ns_1", NVS_READWRITE, &handle) == ESP_OK);
CHECK(NVSPartitionManager::get_instance()->open_handles_size() == 1);
delete handle;
CHECK(NVSPartitionManager::get_instance()->open_handles_size() == 0);
REQUIRE(NVSPartitionManager::get_instance()->deinit_partition("test") == ESP_OK);
}
TEST_CASE("NVSHandleSimple multiple open and closes with PartitionManager", "[partition_mgr]")
{
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
PartitionEmulationFixture f(0, 10, "test");
REQUIRE(NVSPartitionManager::get_instance()->init_custom(&f.part, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
CHECK(NVSPartitionManager::get_instance()->open_handles_size() == 0);
NVSHandleSimple *handle1;
NVSHandleSimple *handle2;
REQUIRE(NVSPartitionManager::get_instance()->open_handle("test", "ns_1", NVS_READWRITE, &handle1) == ESP_OK);
CHECK(NVSPartitionManager::get_instance()->open_handles_size() == 1);
REQUIRE(NVSPartitionManager::get_instance()->open_handle("test", "ns_1", NVS_READWRITE, &handle2) == ESP_OK);
CHECK(NVSPartitionManager::get_instance()->open_handles_size() == 2);
delete handle1;
CHECK(NVSPartitionManager::get_instance()->open_handles_size() == 1);
delete handle2;
CHECK(NVSPartitionManager::get_instance()->open_handles_size() == 0);
REQUIRE(NVSPartitionManager::get_instance()->deinit_partition("test") == ESP_OK);
}
TEST_CASE("NVSHandleSimple readonly fails", "[partition_mgr]")
{
PartitionEmulationFixture f(0, 10);
NVSPartitionManager::get_instance()->deinit_partition(NVS_DEFAULT_PART_NAME);
NVSHandleSimple *handle_1;
NVSHandleSimple *handle_2;
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
f.emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);
CHECK(NVSPartitionManager::get_instance()->init_custom(&f.part, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN) == ESP_OK);
CHECK(NVSPartitionManager::get_instance()->open_handles_size() == 0);
// first, creating namespace...
REQUIRE(NVSPartitionManager::get_instance()->open_handle(NVS_DEFAULT_PART_NAME, "ns_1", NVS_READWRITE, &handle_1) == ESP_OK);
CHECK(NVSPartitionManager::get_instance()->open_handles_size() == 1);
delete handle_1;
CHECK(NVSPartitionManager::get_instance()->open_handles_size() == 0);
REQUIRE(NVSPartitionManager::get_instance()->open_handle(NVS_DEFAULT_PART_NAME, "ns_1", NVS_READONLY, &handle_2) == ESP_OK);
CHECK(handle_2->set_item("key", 47) == ESP_ERR_NVS_READ_ONLY);
CHECK(NVSPartitionManager::get_instance()->open_handles_size() == 1);
delete handle_2;
CHECK(NVSPartitionManager::get_instance()->open_handles_size() == 0);
// without deinit it affects "nvs api tests"
CHECK(nvs_flash_deinit_partition(NVS_DEFAULT_PART_NAME) == ESP_OK);
}
TEST_CASE("NVSHandleSimple set/get char", "[partition_mgr]")
{
enum class TestEnum : char {
FOO = -1,
BEER,
BAR
};
PartitionEmulationFixture f(0, 10);
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
f.emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);
REQUIRE(NVSPartitionManager::get_instance()->init_custom(&f.part, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
NVSHandleSimple *handle;
REQUIRE(NVSPartitionManager::get_instance()->open_handle(NVS_DEFAULT_PART_NAME, "ns_1", NVS_READWRITE, &handle) == ESP_OK);
char test_e = 'a';
char test_e_read = 'z';
CHECK(handle->set_item("key", test_e) == ESP_OK);
CHECK(handle->get_item("key", test_e_read) == ESP_OK);
CHECK(test_e == test_e_read);
delete handle;
REQUIRE(NVSPartitionManager::get_instance()->deinit_partition(NVS_DEFAULT_PART_NAME) == ESP_OK);
}
TEST_CASE("NVSHandleSimple correctly sets/gets int enum", "[partition_mgr]")
{
enum class TestEnum : int {
FOO,
BAR
};
PartitionEmulationFixture f(0, 10);
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
f.emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);
REQUIRE(NVSPartitionManager::get_instance()->init_custom(&f.part, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
NVSHandleSimple *handle;
REQUIRE(NVSPartitionManager::get_instance()->open_handle(NVS_DEFAULT_PART_NAME, "ns_1", NVS_READWRITE, &handle) == ESP_OK);
TestEnum test_e = TestEnum::BAR;
TestEnum test_e_read = TestEnum::FOO;
CHECK(handle->set_item("key", test_e) == ESP_OK);
CHECK(handle->get_item("key", test_e_read) == ESP_OK);
CHECK(test_e == test_e_read);
delete handle;
REQUIRE(NVSPartitionManager::get_instance()->deinit_partition(NVS_DEFAULT_PART_NAME) == ESP_OK);
}
TEST_CASE("NVSHandleSimple correctly sets/gets int enum with negative values", "[partition_mgr]")
{
enum class TestEnum : int {
FOO = -1,
BEER,
BAR
};
PartitionEmulationFixture f(0, 10);
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
f.emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);
REQUIRE(NVSPartitionManager::get_instance()->init_custom(&f.part, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
NVSHandleSimple *handle;
REQUIRE(NVSPartitionManager::get_instance()->open_handle(NVS_DEFAULT_PART_NAME, "ns_1", NVS_READWRITE, &handle) == ESP_OK);
TestEnum test_e = TestEnum::FOO;
TestEnum test_e_read = TestEnum::BEER;
CHECK(handle->set_item("key", test_e) == ESP_OK);
CHECK(handle->get_item("key", test_e_read) == ESP_OK);
CHECK(test_e == test_e_read);
delete handle;
REQUIRE(NVSPartitionManager::get_instance()->deinit_partition(NVS_DEFAULT_PART_NAME) == ESP_OK);
}
TEST_CASE("NVSHandleSimple correctly sets/gets uint8_t enum", "[partition_mgr]")
{
enum class TestEnum : uint8_t {
FOO,
BAR
};
PartitionEmulationFixture f(0, 10);
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
f.emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);
REQUIRE(NVSPartitionManager::get_instance()->init_custom(&f.part, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
NVSHandleSimple *handle;
REQUIRE(NVSPartitionManager::get_instance()->open_handle(NVS_DEFAULT_PART_NAME, "ns_1", NVS_READWRITE, &handle) == ESP_OK);
TestEnum test_e = TestEnum::BAR;
TestEnum test_e_read = TestEnum::FOO;
CHECK(handle->set_item("key", test_e) == ESP_OK);
CHECK(handle->get_item("key", test_e_read) == ESP_OK);
CHECK(test_e == test_e_read);
delete handle;
REQUIRE(NVSPartitionManager::get_instance()->deinit_partition(NVS_DEFAULT_PART_NAME) == ESP_OK);
}
TEST_CASE("NVSHandleSimple correctly sets/gets char enum", "[partition_mgr]")
{
enum class TestEnum : char {
FOO = -1,
BEER,
BAR
};
PartitionEmulationFixture f(0, 10);
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
f.emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);
REQUIRE(NVSPartitionManager::get_instance()->init_custom(&f.part, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
NVSHandleSimple *handle;
REQUIRE(NVSPartitionManager::get_instance()->open_handle(NVS_DEFAULT_PART_NAME, "ns_1", NVS_READWRITE, &handle) == ESP_OK);
TestEnum test_e = TestEnum::BAR;
TestEnum test_e_read = TestEnum::FOO;
CHECK(handle->set_item("key", test_e) == ESP_OK);
CHECK(handle->get_item("key", test_e_read) == ESP_OK);
CHECK(test_e == test_e_read);
delete handle;
REQUIRE(NVSPartitionManager::get_instance()->deinit_partition(NVS_DEFAULT_PART_NAME) == ESP_OK);
}

Wyświetl plik

@ -1,46 +0,0 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "catch.hpp"
#include "nvs_partition_manager.hpp"
#include "spi_flash_emulation.h"
#include "esp_partition.h"
#include "nvs.h"
#include <string.h>
using namespace nvs;
TEST_CASE("nvs_flash_init_partition_ptr fails due to nullptr arg", "[nvs_custom_part]")
{
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
SpiFlashEmulator emu(10);
CHECK(nvs_flash_init_partition_ptr(nullptr) == ESP_ERR_INVALID_ARG);
}
TEST_CASE("nvs_flash_init_partition_ptr inits one partition", "[nvs_custom_part]")
{
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
SpiFlashEmulator emu(10);
esp_partition_t partition = {};
strcpy(partition.label, "test");
partition.address = NVS_FLASH_SECTOR * SPI_FLASH_SEC_SIZE;
partition.size = NVS_FLASH_SECTOR_COUNT_MIN * SPI_FLASH_SEC_SIZE;
CHECK(nvs_flash_init_partition_ptr(&partition) == ESP_OK);
CHECK(NVSPartitionManager::get_instance()->lookup_storage_from_name("test") != nullptr);
CHECK(NVSPartitionManager::get_instance()->deinit_partition("test") == ESP_OK);
}

Wyświetl plik

@ -1,16 +1,8 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "catch.hpp"
#include <algorithm>
#include <cstring>
@ -18,38 +10,33 @@
#include "nvs_handle_simple.hpp"
#include "nvs_partition.hpp"
#include "spi_flash_emulation.h"
#include "test_fixtures.hpp"
#include <iostream>
using namespace std;
using namespace nvs;
TEST_CASE("encrypted partition read size must be item size", "[nvs]")
{
char foo [32] = { };
nvs_sec_cfg_t xts_cfg;
for(int count = 0; count < NVS_KEY_SIZE; count++) {
for (int count = 0; count < NVS_KEY_SIZE; count++) {
xts_cfg.eky[count] = 0x11;
xts_cfg.tky[count] = 0x22;
}
EncryptedPartitionFixture fix(&xts_cfg);
CHECK(fix.part.read(0, foo, sizeof (foo) -1) == ESP_ERR_INVALID_SIZE);
CHECK(fix.part.read(0, foo, sizeof (foo) - 1) == ESP_ERR_INVALID_SIZE);
}
TEST_CASE("encrypted partition write size must be mod item size", "[nvs]")
{
char foo [64] = { };
nvs_sec_cfg_t xts_cfg;
for(int count = 0; count < NVS_KEY_SIZE; count++) {
for (int count = 0; count < NVS_KEY_SIZE; count++) {
xts_cfg.eky[count] = 0x11;
xts_cfg.tky[count] = 0x22;
}
EncryptedPartitionFixture fix(&xts_cfg);
CHECK(fix.part.write(0, foo, sizeof (foo) -1) == ESP_ERR_INVALID_SIZE);
CHECK(fix.part.write(0, foo, sizeof (foo)) == ESP_OK);
CHECK(fix.part.write(0, foo, sizeof (foo) * 2) == ESP_OK);
CHECK(fix.part.write(0, foo, sizeof (foo) - 1) == ESP_ERR_INVALID_SIZE);
CHECK(fix.part.write(0, foo, sizeof (foo) / 2) == ESP_OK);
CHECK(fix.part.write(sizeof(foo) / 2, foo, sizeof (foo)) == ESP_OK);
}

Wyświetl plik

@ -1,60 +0,0 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "catch.hpp"
#include <cstring>
#include "nvs_test_api.h"
#include "nvs_storage.hpp"
#include "nvs_partition_manager.hpp"
#include "spi_flash_emulation.h"
#include "test_fixtures.hpp"
#include <iostream>
using namespace std;
using namespace nvs;
TEST_CASE("Storage iterator recognizes blob with VerOffset::VER_1_OFFSET", "[nvs_storage]")
{
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
PartitionEmulationFixture f(0, 10, "test");
REQUIRE(NVSPartitionManager::get_instance()->init_custom(&f.part, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
uint8_t blob [] = {0x0, 0x1, 0x2, 0x3};
uint8_t blob_new [] = {0x3, 0x2, 0x1, 0x0};
Storage *storage = NVSPartitionManager::get_instance()->lookup_storage_from_name("test");
uint8_t ns_index;
storage->createOrOpenNamespace("test_ns", true, ns_index);
CHECK(storage->writeItem(ns_index, ItemType::BLOB, "test_blob", blob, sizeof(blob)) == ESP_OK);
// changing provokes a blob with version offset 1 (VerOffset::VER_1_OFFSET)
CHECK(storage->writeItem(ns_index, ItemType::BLOB, "test_blob", blob_new, sizeof(blob_new)) == ESP_OK);
nvs_opaque_iterator_t it;
it.storage = storage;
it.type = NVS_TYPE_ANY;
// Central check: does the iterator recognize the blob with version 1?
REQUIRE(storage->findEntry(&it, "test_ns"));
CHECK(string(it.entry_info.namespace_name) == string("test_ns"));
CHECK(string(it.entry_info.key) == string("test_blob"));
CHECK(it.entry_info.type == NVS_TYPE_BLOB);
REQUIRE(NVSPartitionManager::get_instance()->deinit_partition("test") == ESP_OK);
}

Wyświetl plik

@ -11,34 +11,8 @@
#include "nvs_partition_manager.hpp"
#include "spi_flash_emulation.h"
#include "nvs_test_api.h"
#include "test_fixtures.hpp"
using namespace nvs;
TEST_CASE("Partition manager initializes storage", "[partition_mgr]")
{
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
PartitionEmulationFixture f(0, 10, "test");
REQUIRE(NVSPartitionManager::get_instance()->init_custom(&f.part, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN) == ESP_OK);
CHECK(NVSPartitionManager::get_instance()->lookup_storage_from_name("test") != nullptr);
REQUIRE(NVSPartitionManager::get_instance()->deinit_partition(f.part.get_partition_name()) == ESP_OK);
}
TEST_CASE("Partition manager de-initializes storage", "[partition_mgr]")
{
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
PartitionEmulationFixture f(0, 10, "test");
REQUIRE(NVSPartitionManager::get_instance()->init_custom(&f.part, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN) == ESP_OK);
CHECK(NVSPartitionManager::get_instance()->lookup_storage_from_name("test") != nullptr);
CHECK(NVSPartitionManager::get_instance()->deinit_partition("test") == ESP_OK);
CHECK(NVSPartitionManager::get_instance()->lookup_storage_from_name("test") == nullptr);
}
TEST_CASE("Partition manager initializes multiple partitions", "[partition_mgr]")
{
const uint32_t NVS_FLASH_SECTOR = 6;
@ -47,52 +21,17 @@ TEST_CASE("Partition manager initializes multiple partitions", "[partition_mgr]"
PartitionEmulation part_0(&emu, NVS_FLASH_SECTOR * SPI_FLASH_SEC_SIZE, NVS_FLASH_SECTOR_COUNT_MIN * SPI_FLASH_SEC_SIZE, "test1");
PartitionEmulation part_1(&emu, NVS_FLASH_SECTOR * SPI_FLASH_SEC_SIZE, NVS_FLASH_SECTOR_COUNT_MIN * SPI_FLASH_SEC_SIZE, "test2");
REQUIRE(NVSPartitionManager::get_instance()->init_custom(&part_0, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(&part_0, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
// TODO: why does this work, actually? same sectors used as above
REQUIRE(NVSPartitionManager::get_instance()->init_custom(&part_1, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
REQUIRE(nvs::NVSPartitionManager::get_instance()->init_custom(&part_1, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
Storage *storage1 = NVSPartitionManager::get_instance()->lookup_storage_from_name("test1");
nvs::Storage *storage1 = nvs::NVSPartitionManager::get_instance()->lookup_storage_from_name("test1");
REQUIRE(storage1 != nullptr);
Storage *storage2 = NVSPartitionManager::get_instance()->lookup_storage_from_name("test2");
nvs::Storage *storage2 = nvs::NVSPartitionManager::get_instance()->lookup_storage_from_name("test2");
REQUIRE(storage2 != nullptr);
CHECK(storage1 != storage2);
REQUIRE(NVSPartitionManager::get_instance()->deinit_partition(part_0.get_partition_name()) == ESP_OK);
REQUIRE(NVSPartitionManager::get_instance()->deinit_partition(part_1.get_partition_name()) == ESP_OK);
}
TEST_CASE("Partition manager open fails on null handle", "[partition_mgr]")
{
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
PartitionEmulationFixture f(0, 10, "test");
REQUIRE(NVSPartitionManager::get_instance()->init_custom(&f.part, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
CHECK(NVSPartitionManager::get_instance()->open_handle("test", "ns_1", NVS_READWRITE, nullptr)
== ESP_ERR_INVALID_ARG);
NVSPartitionManager::get_instance()->deinit_partition("test");
}
TEST_CASE("Partition manager invalidates handle on partition de-init", "[partition_mgr]")
{
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
PartitionEmulationFixture f(0, 10, "test");
REQUIRE(NVSPartitionManager::get_instance()->init_custom(&f.part, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN)
== ESP_OK);
NVSHandleSimple *handle;
REQUIRE(NVSPartitionManager::get_instance()->open_handle("test", "ns_1", NVS_READWRITE, &handle) == ESP_OK);
CHECK(handle->erase_all() == ESP_OK);
REQUIRE(NVSPartitionManager::get_instance()->deinit_partition("test") == ESP_OK);
CHECK(handle->erase_all() == ESP_ERR_NVS_INVALID_HANDLE);
delete handle;
REQUIRE(nvs::NVSPartitionManager::get_instance()->deinit_partition(part_0.get_partition_name()) == ESP_OK);
REQUIRE(nvs::NVSPartitionManager::get_instance()->deinit_partition(part_1.get_partition_name()) == ESP_OK);
}

Wyświetl plik

@ -9,12 +9,10 @@
#include "spi_flash_emulation.h"
#include <functional>
using namespace std;
template <typename Tit>
bool range_empty_n(Tit it_begin, size_t n)
{
return all_of(it_begin, it_begin + n, bind(equal_to<uint32_t>(), placeholders::_1, 0xffffffff));
return std::all_of(it_begin, it_begin + n, bind(std::equal_to<uint32_t>(), std::placeholders::_1, 0xffffffff));
}
struct FlashEmuFixture {

Wyświetl plik

@ -804,7 +804,6 @@ components/mqtt/host_test/mocks/include/freertos/FreeRTOSConfig.h
components/mqtt/host_test/mocks/include/freertos/portmacro.h
components/mqtt/host_test/mocks/include/machine/endian.h
components/mqtt/host_test/mocks/include/sys/queue.h
components/nvs_flash/host_test/fixtures/test_fixtures.hpp
components/nvs_flash/host_test/nvs_page_test/main/nvs_page_test.cpp
components/nvs_flash/include/nvs_flash.h
components/nvs_flash/include/nvs_handle.hpp
@ -831,12 +830,10 @@ components/nvs_flash/test/test_nvs.c
components/nvs_flash/test_nvs_host/esp_error_check_stub.cpp
components/nvs_flash/test_nvs_host/main.cpp
components/nvs_flash/test_nvs_host/sdkconfig.h
components/nvs_flash/test_nvs_host/spi_flash_emulation.cpp
components/nvs_flash/test_nvs_host/test_fixtures.hpp
components/nvs_flash/test_nvs_host/test_intrusive_list.cpp
components/nvs_flash/test_nvs_host/test_nvs_cxx_api.cpp
components/nvs_flash/test_nvs_host/test_nvs_initialization.cpp
components/nvs_flash/test_nvs_host/test_nvs_partition.cpp
components/nvs_flash/test_nvs_host/test_nvs_storage.cpp
components/openthread/include/esp_openthread_lock.h
components/protocomm/include/transports/protocomm_console.h

Wyświetl plik

@ -509,11 +509,18 @@ macro(project project_name)
__component_get_target(build_component_target ${build_component})
__component_get_property(whole_archive ${build_component_target} WHOLE_ARCHIVE)
if(whole_archive)
message(STATUS "Component ${build_component} will be linked with -Wl,--whole-archive")
target_link_libraries(${project_elf} PRIVATE
"-Wl,--whole-archive"
${build_component}
"-Wl,--no-whole-archive")
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
message(STATUS "Component ${build_component} will be linked with -Wl,-force_load")
target_link_libraries(${project_elf} PRIVATE
"-Wl,-force_load"
${build_component})
else()
message(STATUS "Component ${build_component} will be linked with -Wl,--whole-archive")
target_link_libraries(${project_elf} PRIVATE
"-Wl,--whole-archive"
${build_component}
"-Wl,--no-whole-archive")
endif()
else()
target_link_libraries(${project_elf} PRIVATE ${build_component})
endif()