mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-09 12:35:28 +00:00
Storage: Partition APIs moved to the new component 'esp_partition'
All the partition handling API functions and data-types were moved from the 'spi_flash' component to the new one named 'esp_partition'. See Storage 5.x migration guide for more details
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
set(COMPONENTS main)
|
||||
# Freertos is included via common components, however, currently only the mock component is compatible with linux
|
||||
# target.
|
||||
list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/freertos/")
|
||||
|
||||
project(partition_api_test)
|
||||
|
||||
add_dependencies(partition_api_test.elf partition-table)
|
@@ -0,0 +1,18 @@
|
||||
| Supported Targets | Linux |
|
||||
| ----------------- | ----- |
|
||||
|
||||
This is a test project for partition-related APIs on Linux target (CONFIG_IDF_TARGET_LINUX).
|
||||
|
||||
# Build
|
||||
Source the IDF environment as usual.
|
||||
|
||||
Once this is done, build the application:
|
||||
```bash
|
||||
idf.py build partition-table
|
||||
```
|
||||
Note that for the time being, `partition-table` target needs to be built manually.
|
||||
|
||||
# Run
|
||||
```bash
|
||||
`build/partition_api_test.elf`
|
||||
```
|
@@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "partition_api_test.c"
|
||||
REQUIRES esp_partition unity)
|
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Linux host partition API test
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_partition.h"
|
||||
#include "esp_private/partition_linux.h"
|
||||
#include "unity.h"
|
||||
#include "unity_fixture.h"
|
||||
|
||||
|
||||
TEST_GROUP(partition_api);
|
||||
|
||||
TEST_SETUP(partition_api)
|
||||
{
|
||||
}
|
||||
|
||||
TEST_TEAR_DOWN(partition_api)
|
||||
{
|
||||
}
|
||||
|
||||
TEST(partition_api, test_partition_find_basic)
|
||||
{
|
||||
esp_partition_iterator_t iter = esp_partition_find(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, "storage");
|
||||
TEST_ASSERT_NOT_NULL(iter);
|
||||
|
||||
const esp_partition_t *part = esp_partition_get(iter);
|
||||
TEST_ASSERT_NOT_NULL(part);
|
||||
|
||||
esp_partition_iterator_release(iter);
|
||||
}
|
||||
|
||||
TEST(partition_api, test_partition_find_app)
|
||||
{
|
||||
esp_partition_iterator_t iter = esp_partition_find(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, NULL);
|
||||
TEST_ASSERT_NOT_NULL(iter);
|
||||
size_t counter = 0;
|
||||
|
||||
while (iter != NULL) {
|
||||
const esp_partition_t *part_data = esp_partition_get(iter);
|
||||
counter++;
|
||||
TEST_ASSERT_NOT_NULL(part_data);
|
||||
iter = esp_partition_next(iter);
|
||||
}
|
||||
esp_partition_iterator_release(iter);
|
||||
}
|
||||
|
||||
TEST(partition_api, test_partition_find_data)
|
||||
{
|
||||
esp_partition_iterator_t iter = esp_partition_find(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, NULL);
|
||||
TEST_ASSERT_NOT_NULL(iter);
|
||||
size_t counter = 0;
|
||||
|
||||
while (iter != NULL) {
|
||||
const esp_partition_t *part_data = esp_partition_get(iter);
|
||||
counter++;
|
||||
TEST_ASSERT_NOT_NULL(part_data);
|
||||
iter = esp_partition_next(iter);
|
||||
}
|
||||
esp_partition_iterator_release(iter);
|
||||
}
|
||||
|
||||
TEST(partition_api, test_partition_find_first)
|
||||
{
|
||||
const esp_partition_t *partition_app = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, NULL);
|
||||
TEST_ASSERT_NOT_NULL(partition_app);
|
||||
|
||||
const esp_partition_t *partition_data = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, "storage");
|
||||
TEST_ASSERT_NOT_NULL(partition_data);
|
||||
}
|
||||
|
||||
TEST(partition_api, test_partition_ops)
|
||||
{
|
||||
const esp_partition_t *partition_data = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, "storage");
|
||||
TEST_ASSERT_NOT_NULL(partition_data);
|
||||
|
||||
uint8_t buff[] = "ABCDEFGHIJKLMNOP";
|
||||
size_t bufsize = sizeof(buff);
|
||||
size_t off = 0x100;
|
||||
|
||||
//8. esp_partition_write/raw
|
||||
esp_err_t err = esp_partition_write(partition_data, off, (const void *)buff, bufsize);
|
||||
TEST_ESP_OK(err);
|
||||
|
||||
//9. esp_partition_read/raw
|
||||
uint8_t buffout[32] = {0};
|
||||
err = esp_partition_read(partition_data, off, (void *)buffout, bufsize);
|
||||
TEST_ESP_OK(err);
|
||||
|
||||
//10. esp_partition_erase_range
|
||||
uint8_t buferase[bufsize];
|
||||
memset(buferase, 0xFF, bufsize);
|
||||
memset(buffout, 0, sizeof(buffout));
|
||||
size_t sector_off = 0; //erase works per whole sector - offset must be aligned to 4kB boundaries
|
||||
|
||||
err = esp_partition_erase_range(partition_data, sector_off, partition_data->erase_size);
|
||||
assert(esp_partition_read(partition_data, off, (void *)buffout, bufsize) == ESP_OK);
|
||||
TEST_ESP_OK(err);
|
||||
TEST_ASSERT_EQUAL(0, memcmp(buffout, buferase, bufsize));
|
||||
|
||||
//11. esp_partition_verify (partition_data)
|
||||
const esp_partition_t *verified_partition = esp_partition_verify(partition_data);
|
||||
TEST_ASSERT_NOT_NULL(verified_partition);
|
||||
}
|
||||
|
||||
TEST_GROUP_RUNNER(partition_api)
|
||||
{
|
||||
RUN_TEST_CASE(partition_api, test_partition_find_basic);
|
||||
RUN_TEST_CASE(partition_api, test_partition_find_app);
|
||||
RUN_TEST_CASE(partition_api, test_partition_find_data);
|
||||
RUN_TEST_CASE(partition_api, test_partition_find_first);
|
||||
RUN_TEST_CASE(partition_api, test_partition_ops);
|
||||
}
|
||||
|
||||
static void run_all_tests(void)
|
||||
{
|
||||
RUN_TEST_GROUP(partition_api);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
UNITY_MAIN_FUNC(run_all_tests);
|
||||
return 0;
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
|
||||
nvs, data, nvs, 0x9000, 0x6000,
|
||||
phy_init, data, phy, 0xf000, 0x1000,
|
||||
factory, app, factory, 0x10000, 1M,
|
||||
storage, data, , , 0x40000,
|
|
@@ -0,0 +1,8 @@
|
||||
CONFIG_IDF_TARGET="linux"
|
||||
CONFIG_COMPILER_CXX_EXCEPTIONS=y
|
||||
CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=n
|
||||
CONFIG_UNITY_ENABLE_FIXTURE=y
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partition_table.csv"
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE="4MB"
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
Reference in New Issue
Block a user