mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'bugfix/partition_api_linux_test' into 'master'
spi_flash: convert Linux partition API test to Unity, bug fixes See merge request espressif/esp-idf!19567
This commit is contained in:
commit
985f44c158
@ -431,6 +431,14 @@ test_linux_example:
|
||||
- timeout 5 ./build/linux_host_app.elf >test.log || true
|
||||
- grep "Restarting" test.log
|
||||
|
||||
test_partition_api_host:
|
||||
extends: .host_test_template
|
||||
script:
|
||||
- cd ${IDF_PATH}/components/spi_flash/host_test/partition_api_test
|
||||
- idf.py build
|
||||
- timeout 5 ./build/partition_api_test.elf >test.log
|
||||
- grep " 0 Failures" test.log
|
||||
|
||||
test_gen_soc_caps_kconfig:
|
||||
extends: .host_test_template
|
||||
script:
|
||||
|
@ -7,3 +7,5 @@ set(COMPONENTS main)
|
||||
list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/freertos/")
|
||||
|
||||
project(partition_api_test)
|
||||
|
||||
add_dependencies(partition_api_test.elf partition-table)
|
||||
|
@ -1,2 +1,2 @@
|
||||
idf_component_register(SRCS "partition_api_test.cpp"
|
||||
REQUIRES spi_flash)
|
||||
idf_component_register(SRCS "partition_api_test.c"
|
||||
REQUIRES spi_flash unity)
|
||||
|
@ -10,64 +10,74 @@
|
||||
#include "esp_err.h"
|
||||
#include "esp_partition.h"
|
||||
#include "esp_private/partition_linux.h"
|
||||
#include "unity.h"
|
||||
#include "unity_fixture.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
||||
TEST_GROUP(partition_api);
|
||||
|
||||
TEST_SETUP(partition_api)
|
||||
{
|
||||
printf("Partition API Linux emulation test: ");
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
//PARTITION LOOKUP:
|
||||
TEST_TEAR_DOWN(partition_api)
|
||||
{
|
||||
}
|
||||
|
||||
//1. esp_partition_find (label=STORAGE)
|
||||
TEST(partition_api, test_partition_find_basic)
|
||||
{
|
||||
esp_partition_iterator_t iter = esp_partition_find(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, "storage");
|
||||
assert(iter);
|
||||
TEST_ASSERT_NOT_NULL(iter);
|
||||
|
||||
//2. esp_partition_get (label=STORAGE)
|
||||
const esp_partition_t *part = esp_partition_get(iter);
|
||||
assert(part);
|
||||
TEST_ASSERT_NOT_NULL(part);
|
||||
|
||||
//3. esp_partition_iterator_release (label STORAGE iter): assumed OK
|
||||
esp_partition_iterator_release(iter);
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
//ITERATORS, PARTITION PROPERTIES:
|
||||
|
||||
//4. esp_partition_find_first (type=APP, subtype=ANY)
|
||||
const esp_partition_t *partition_app = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, NULL);
|
||||
assert(partition_app);
|
||||
|
||||
//5. enumerate all APP partitions
|
||||
iter = esp_partition_find(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, NULL);
|
||||
assert(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++;
|
||||
assert(part_data);
|
||||
TEST_ASSERT_NOT_NULL(part_data);
|
||||
iter = esp_partition_next(iter);
|
||||
}
|
||||
esp_partition_iterator_release(iter);
|
||||
}
|
||||
|
||||
//6. enumerate all DATA partitions and print details for each
|
||||
iter = esp_partition_find(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, NULL);
|
||||
assert(iter);
|
||||
counter = 0;
|
||||
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++;
|
||||
assert(part_data);
|
||||
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);
|
||||
|
||||
//7. esp_partition_find_first (type=DATA, label=STORAGE)
|
||||
const esp_partition_t *partition_data = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, "storage");
|
||||
assert(partition_data);
|
||||
TEST_ASSERT_NOT_NULL(partition_data);
|
||||
}
|
||||
|
||||
/////////////////////////////////////
|
||||
//OPERATIONS
|
||||
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);
|
||||
@ -75,12 +85,12 @@ int main(int argc, char **argv)
|
||||
|
||||
//8. esp_partition_write/raw
|
||||
esp_err_t err = esp_partition_write(partition_data, off, (const void *)buff, bufsize);
|
||||
assert(err == ESP_OK);
|
||||
TEST_ESP_OK(err);
|
||||
|
||||
//9. esp_partition_read/raw
|
||||
uint8_t buffout[32] = {0};
|
||||
err = esp_partition_read(partition_data, off, (void *)buffout, bufsize);
|
||||
assert(err == ESP_OK);
|
||||
TEST_ESP_OK(err);
|
||||
|
||||
//10. esp_partition_erase_range
|
||||
uint8_t buferase[bufsize];
|
||||
@ -90,17 +100,30 @@ int main(int argc, char **argv)
|
||||
|
||||
err = esp_partition_erase_range(partition_data, sector_off, SPI_FLASH_SEC_SIZE);
|
||||
assert(esp_partition_read(partition_data, off, (void *)buffout, bufsize) == ESP_OK);
|
||||
assert(err == ESP_OK && memcmp(buffout, buferase, bufsize) == 0);
|
||||
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);
|
||||
assert(verified_partition != NULL);
|
||||
TEST_ASSERT_NOT_NULL(verified_partition);
|
||||
}
|
||||
|
||||
//12. release SPI FLASH emulation block from memory
|
||||
err = esp_partition_file_munmap();
|
||||
assert(err == ESP_OK);
|
||||
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);
|
||||
}
|
||||
|
||||
printf("OK\n");
|
||||
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;
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
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"
|
||||
|
@ -30,6 +30,13 @@
|
||||
#include "esp_private/partition_linux.h"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_IDF_TARGET_LINUX
|
||||
#define MMU_PAGE_SIZE CONFIG_MMU_PAGE_SIZE
|
||||
#else
|
||||
// No relation to the page size on Linux; assume the same value as on ESP32
|
||||
#define MMU_PAGE_SIZE 65536
|
||||
#endif // CONFIG_MMU_PAGE_SIZE
|
||||
|
||||
#ifndef NDEBUG
|
||||
// Enable built-in checks in queue.h in debug builds
|
||||
#define INVARIANTS
|
||||
@ -78,7 +85,7 @@ static esp_err_t load_partitions(void)
|
||||
esp_rom_md5_init(&context);
|
||||
#endif
|
||||
|
||||
uint32_t partition_align_pg_size = (ESP_PARTITION_TABLE_OFFSET) & ~(CONFIG_MMU_PAGE_SIZE - 1);
|
||||
uint32_t partition_align_pg_size = (ESP_PARTITION_TABLE_OFFSET) & ~(MMU_PAGE_SIZE - 1);
|
||||
uint32_t partition_pad = ESP_PARTITION_TABLE_OFFSET - partition_align_pg_size;
|
||||
|
||||
#if CONFIG_IDF_TARGET_LINUX
|
||||
|
@ -32,6 +32,7 @@ if(NOT "${target}" STREQUAL "linux")
|
||||
list(APPEND srcs "unity_port_esp32.c")
|
||||
list(APPEND srcs "port/esp/unity_utils_memory_esp.c")
|
||||
else()
|
||||
list(APPEND srcs "unity_port_linux.c")
|
||||
list(APPEND srcs "port/linux/unity_utils_memory_linux.c")
|
||||
endif()
|
||||
|
||||
@ -43,10 +44,8 @@ if(CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER)
|
||||
idf_component_optional_requires(PRIVATE spi_flash)
|
||||
endif()
|
||||
|
||||
if(NOT "${target}" STREQUAL "linux")
|
||||
target_compile_definitions(${COMPONENT_LIB} PUBLIC
|
||||
-DUNITY_INCLUDE_CONFIG_H
|
||||
)
|
||||
endif()
|
||||
|
||||
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-unused-const-variable)
|
||||
|
42
components/unity/unity_port_linux.c
Normal file
42
components/unity/unity_port_linux.c
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
#include "unity.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
|
||||
static struct timeval s_test_start, s_test_stop;
|
||||
|
||||
void unity_putc(int c)
|
||||
{
|
||||
putc(c, stdout);
|
||||
}
|
||||
|
||||
void unity_flush(void)
|
||||
{
|
||||
fflush(stdout);
|
||||
fsync(fileno(stdout));
|
||||
}
|
||||
|
||||
void unity_exec_time_start(void)
|
||||
{
|
||||
gettimeofday(&s_test_start, NULL);
|
||||
}
|
||||
|
||||
void unity_exec_time_stop(void)
|
||||
{
|
||||
gettimeofday(&s_test_stop, NULL);
|
||||
}
|
||||
|
||||
uint32_t unity_exec_time_get_ms(void)
|
||||
{
|
||||
return (uint32_t) (((s_test_stop.tv_sec * 1000000ULL + s_test_stop.tv_usec) -
|
||||
(s_test_start.tv_sec * 1000000ULL + s_test_start.tv_usec)) / 1000);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user