mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
fatfs: host test migrated to CMake and esp_partition emulation for linux
This commit is contained in:
parent
96f2d215a2
commit
0078025d7b
@ -1,16 +1,34 @@
|
||||
idf_build_get_property(target IDF_TARGET)
|
||||
|
||||
set(srcs "diskio/diskio.c"
|
||||
"diskio/diskio_rawflash.c"
|
||||
"diskio/diskio_sdmmc.c"
|
||||
"diskio/diskio_wl.c"
|
||||
"src/ff.c"
|
||||
"port/freertos/ffsystem.c"
|
||||
"src/ffunicode.c"
|
||||
"vfs/vfs_fat.c"
|
||||
"vfs/vfs_fat_sdmmc.c"
|
||||
"vfs/vfs_fat_spiflash.c")
|
||||
"diskio/diskio_rawflash.c"
|
||||
"diskio/diskio_wl.c"
|
||||
"src/ff.c"
|
||||
"src/ffunicode.c")
|
||||
|
||||
set(include_dirs "diskio" "src")
|
||||
|
||||
set(requires "wear_levelling")
|
||||
|
||||
# for linux, we do not have support for vfs and sdmmc, for real targets, add respective sources
|
||||
if(${target} STREQUAL "linux")
|
||||
list(APPEND srcs "port/linux/ffsystem.c")
|
||||
else()
|
||||
list(APPEND srcs "port/freertos/ffsystem.c"
|
||||
"diskio/diskio_sdmmc.c"
|
||||
"vfs/vfs_fat.c"
|
||||
"vfs/vfs_fat_sdmmc.c"
|
||||
"vfs/vfs_fat_spiflash.c")
|
||||
|
||||
list(APPEND include_dirs "vfs")
|
||||
|
||||
list(APPEND requires "sdmmc")
|
||||
|
||||
list(APPEND priv_requires "vfs")
|
||||
endif()
|
||||
|
||||
idf_component_register(SRCS ${srcs}
|
||||
INCLUDE_DIRS diskio vfs src
|
||||
REQUIRES wear_levelling sdmmc
|
||||
PRIV_REQUIRES vfs
|
||||
INCLUDE_DIRS ${include_dirs}
|
||||
REQUIRES ${requires}
|
||||
PRIV_REQUIRES ${priv_requires}
|
||||
)
|
||||
|
10
components/fatfs/host_test/CMakeLists.txt
Normal file
10
components/fatfs/host_test/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
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(fatfs_host_test)
|
2
components/fatfs/host_test/README.md
Normal file
2
components/fatfs/host_test/README.md
Normal file
@ -0,0 +1,2 @@
|
||||
| Supported Targets | Linux |
|
||||
| ----------------- | ----- |
|
6
components/fatfs/host_test/main/CMakeLists.txt
Normal file
6
components/fatfs/host_test/main/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
||||
idf_component_register(SRCS "main.cpp"
|
||||
"test_fatfs.cpp"
|
||||
INCLUDE_DIRS "$ENV{IDF_PATH}/tools/catch"
|
||||
REQUIRES fatfs
|
||||
WHOLE_ARCHIVE
|
||||
)
|
7
components/fatfs/host_test/main/main.cpp
Normal file
7
components/fatfs/host_test/main/main.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
95
components/fatfs/host_test/main/test_fatfs.cpp
Normal file
95
components/fatfs/host_test/main/test_fatfs.cpp
Normal file
@ -0,0 +1,95 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ff.h"
|
||||
#include "esp_partition.h"
|
||||
#include "wear_levelling.h"
|
||||
#include "diskio_impl.h"
|
||||
#include "diskio_wl.h"
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
TEST_CASE("create volume, open file, write and read back data", "[fatfs]")
|
||||
{
|
||||
FRESULT fr_result;
|
||||
BYTE pdrv;
|
||||
FATFS fs;
|
||||
FIL file;
|
||||
UINT bw;
|
||||
|
||||
esp_err_t esp_result;
|
||||
|
||||
const esp_partition_t *partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, "storage");
|
||||
|
||||
// Mount wear-levelled partition
|
||||
wl_handle_t wl_handle;
|
||||
esp_result = wl_mount(partition, &wl_handle);
|
||||
REQUIRE(esp_result == ESP_OK);
|
||||
|
||||
// Get a physical drive
|
||||
esp_result = ff_diskio_get_drive(&pdrv);
|
||||
REQUIRE(esp_result == ESP_OK);
|
||||
|
||||
// Register physical drive as wear-levelled partition
|
||||
esp_result = ff_diskio_register_wl_partition(pdrv, wl_handle);
|
||||
|
||||
// Create FAT volume on the entire disk
|
||||
LBA_t part_list[] = {100, 0, 0, 0};
|
||||
BYTE work_area[FF_MAX_SS];
|
||||
|
||||
fr_result = f_fdisk(pdrv, part_list, work_area);
|
||||
REQUIRE(fr_result == FR_OK);
|
||||
const MKFS_PARM opt = {(BYTE)FM_ANY, 0, 0, 0, 0};
|
||||
fr_result = f_mkfs("", &opt, work_area, sizeof(work_area)); // Use default volume
|
||||
|
||||
// Mount the volume
|
||||
fr_result = f_mount(&fs, "", 0);
|
||||
REQUIRE(fr_result == FR_OK);
|
||||
|
||||
// Open, write and read data
|
||||
fr_result = f_open(&file, "test.txt", FA_OPEN_ALWAYS | FA_READ | FA_WRITE);
|
||||
REQUIRE(fr_result == FR_OK);
|
||||
|
||||
// Generate data
|
||||
uint32_t data_size = 100000;
|
||||
|
||||
char *data = (char*) malloc(data_size);
|
||||
char *read = (char*) malloc(data_size);
|
||||
|
||||
for(uint32_t i = 0; i < data_size; i += sizeof(i))
|
||||
{
|
||||
*((uint32_t*)(data + i)) = i;
|
||||
}
|
||||
|
||||
// Write generated data
|
||||
fr_result = f_write(&file, data, data_size, &bw);
|
||||
REQUIRE(fr_result == FR_OK);
|
||||
REQUIRE(bw == data_size);
|
||||
|
||||
// Move to beginning of file
|
||||
fr_result = f_lseek(&file, 0);
|
||||
REQUIRE(fr_result == FR_OK);
|
||||
|
||||
// Read written data
|
||||
fr_result = f_read(&file, read, data_size, &bw);
|
||||
REQUIRE(fr_result == FR_OK);
|
||||
REQUIRE(bw == data_size);
|
||||
|
||||
REQUIRE(memcmp(data, read, data_size) == 0);
|
||||
|
||||
// Close file
|
||||
fr_result = f_close(&file);
|
||||
REQUIRE(fr_result == FR_OK);
|
||||
|
||||
// Unmount default volume
|
||||
fr_result = f_mount(0, "", 0);
|
||||
REQUIRE(fr_result == FR_OK);
|
||||
|
||||
free(read);
|
||||
free(data);
|
||||
}
|
6
components/fatfs/host_test/partition_table.csv
Normal file
6
components/fatfs/host_test/partition_table.csv
Normal file
@ -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, fat, , 1M,
|
|
10
components/fatfs/host_test/pytest_fatfs_linux.py
Normal file
10
components/fatfs/host_test/pytest_fatfs_linux.py
Normal file
@ -0,0 +1,10 @@
|
||||
# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
import pytest
|
||||
from pytest_embedded import Dut
|
||||
|
||||
|
||||
@pytest.mark.linux
|
||||
@pytest.mark.host_test
|
||||
def test_fatfs_linux(dut: Dut) -> None:
|
||||
dut.expect_exact('All tests passed', timeout=120)
|
12
components/fatfs/host_test/sdkconfig.defaults
Normal file
12
components/fatfs/host_test/sdkconfig.defaults
Normal file
@ -0,0 +1,12 @@
|
||||
CONFIG_IDF_TARGET="linux"
|
||||
CONFIG_COMPILER_CXX_EXCEPTIONS=y
|
||||
CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=n
|
||||
CONFIG_WL_SECTOR_SIZE=4096
|
||||
CONFIG_LOG_DEFAULT_LEVEL=3
|
||||
CONFIG_PARTITION_TABLE_OFFSET=0x8000
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partition_table.csv"
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE="8MB"
|
||||
CONFIG_MMU_PAGE_SIZE=0X10000
|
||||
CONFIG_ESP_PARTITION_ENABLE_STATS=y
|
||||
CONFIG_FATFS_VOLUME_COUNT=2
|
Loading…
Reference in New Issue
Block a user