fork the esp-idf fatfs for f_forward and exfat support
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
set(COMPONENTS main)
|
||||
set(EXTRA_COMPONENT_DIRS "${CMAKE_CURRENT_LIST_DIR}/../test_fatfs_common")
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
|
||||
project(test_fatfs_flash_wl)
|
||||
@@ -0,0 +1,8 @@
|
||||
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 |
|
||||
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- |
|
||||
|
||||
This test app runs a few FATFS test cases in a wear levelling FAT partition.
|
||||
|
||||
These tests should be possible to run on any ESP development board, not extra hardware is necessary.
|
||||
|
||||
See [../README.md](../README.md) for more information about FATFS test apps.
|
||||
@@ -0,0 +1,4 @@
|
||||
idf_component_register(SRCS "test_fatfs_flash_wl.c"
|
||||
INCLUDE_DIRS "."
|
||||
PRIV_REQUIRES unity spi_flash fatfs vfs test_fatfs_common
|
||||
WHOLE_ARCHIVE)
|
||||
@@ -0,0 +1,276 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/unistd.h>
|
||||
#include "unity.h"
|
||||
#include "esp_partition.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_random.h"
|
||||
#include "esp_vfs.h"
|
||||
#include "esp_vfs_fat.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "test_fatfs_common.h"
|
||||
#include "wear_levelling.h"
|
||||
#include "esp_partition.h"
|
||||
#include "esp_memory_utils.h"
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
unity_run_menu();
|
||||
}
|
||||
|
||||
static wl_handle_t s_test_wl_handle;
|
||||
static void test_setup(void)
|
||||
{
|
||||
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
||||
.format_if_mount_failed = true,
|
||||
.max_files = 5,
|
||||
};
|
||||
|
||||
TEST_ESP_OK(esp_vfs_fat_spiflash_mount_rw_wl("/spiflash", NULL, &mount_config, &s_test_wl_handle));
|
||||
}
|
||||
|
||||
static void test_teardown(void)
|
||||
{
|
||||
TEST_ESP_OK(esp_vfs_fat_spiflash_unmount_rw_wl("/spiflash", s_test_wl_handle));
|
||||
}
|
||||
|
||||
TEST_CASE("(WL) can format partition", "[fatfs][wear_levelling]")
|
||||
{
|
||||
TEST_ESP_OK(esp_vfs_fat_spiflash_format_rw_wl("/spiflash", NULL));
|
||||
test_setup();
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
TEST_CASE("(WL) can format when the FAT is mounted already", "[fatfs][wear_levelling]")
|
||||
{
|
||||
test_setup();
|
||||
TEST_ESP_OK(esp_vfs_fat_spiflash_format_rw_wl("/spiflash", NULL));
|
||||
test_fatfs_create_file_with_text("/spiflash/hello.txt", fatfs_test_hello_str);
|
||||
test_fatfs_pread_file("/spiflash/hello.txt");
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
TEST_CASE("(WL) can create and write file", "[fatfs][wear_levelling]")
|
||||
{
|
||||
test_setup();
|
||||
test_fatfs_create_file_with_text("/spiflash/hello.txt", fatfs_test_hello_str);
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
TEST_CASE("(WL) can create and open file with O_CREAT flag", "[fatfs][wear_levelling]")
|
||||
{
|
||||
test_setup();
|
||||
test_fatfs_create_file_with_o_creat_flag("/spiflash/hello.txt");
|
||||
test_fatfs_open_file_with_o_creat_flag("/spiflash/hello.txt");
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
TEST_CASE("(WL) can read file", "[fatfs][wear_levelling]")
|
||||
{
|
||||
test_setup();
|
||||
test_fatfs_create_file_with_text("/spiflash/hello.txt", fatfs_test_hello_str);
|
||||
test_fatfs_read_file("/spiflash/hello.txt");
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
TEST_CASE("(WL) can read file with pread", "[fatfs][wear_levelling]")
|
||||
{
|
||||
test_setup();
|
||||
test_fatfs_create_file_with_text("/spiflash/hello.txt", fatfs_test_hello_str);
|
||||
test_fatfs_pread_file("/spiflash/hello.txt");
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
TEST_CASE("(WL) pwrite() works well", "[fatfs][wear_levelling]")
|
||||
{
|
||||
test_setup();
|
||||
test_fatfs_pwrite_file("/spiflash/hello.txt");
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
TEST_CASE("(WL) can open maximum number of files", "[fatfs][wear_levelling]")
|
||||
{
|
||||
size_t max_files = FOPEN_MAX - 3; /* account for stdin, stdout, stderr */
|
||||
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
||||
.format_if_mount_failed = true,
|
||||
.max_files = max_files
|
||||
};
|
||||
TEST_ESP_OK(esp_vfs_fat_spiflash_mount_rw_wl("/spiflash", NULL, &mount_config, &s_test_wl_handle));
|
||||
test_fatfs_open_max_files("/spiflash/f", max_files);
|
||||
TEST_ESP_OK(esp_vfs_fat_spiflash_unmount_rw_wl("/spiflash", s_test_wl_handle));
|
||||
}
|
||||
|
||||
TEST_CASE("(WL) overwrite and append file", "[fatfs][wear_levelling]")
|
||||
{
|
||||
test_setup();
|
||||
test_fatfs_overwrite_append("/spiflash/hello.txt");
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
TEST_CASE("(WL) can lseek", "[fatfs][wear_levelling]")
|
||||
{
|
||||
test_setup();
|
||||
test_fatfs_lseek("/spiflash/seek.txt");
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
TEST_CASE("(WL) can truncate", "[fatfs][wear_levelling]")
|
||||
{
|
||||
test_setup();
|
||||
test_fatfs_truncate_file("/spiflash/truncate.txt");
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
TEST_CASE("(WL) stat returns correct values", "[fatfs][wear_levelling]")
|
||||
{
|
||||
test_setup();
|
||||
test_fatfs_stat("/spiflash/stat.txt", "/spiflash");
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
TEST_CASE("(WL) stat returns correct mtime if DST is enabled", "[fatfs][wear_levelling]")
|
||||
{
|
||||
test_setup();
|
||||
test_fatfs_mtime_dst("/spiflash/statdst.txt", "/spiflash");
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
TEST_CASE("(WL) utime sets modification time", "[fatfs][wear_levelling]")
|
||||
{
|
||||
test_setup();
|
||||
test_fatfs_utime("/spiflash/utime.txt", "/spiflash");
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
TEST_CASE("(WL) unlink removes a file", "[fatfs][wear_levelling]")
|
||||
{
|
||||
test_setup();
|
||||
test_fatfs_unlink("/spiflash/unlink.txt");
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
TEST_CASE("(WL) link copies a file, rename moves a file", "[fatfs][wear_levelling]")
|
||||
{
|
||||
test_setup();
|
||||
test_fatfs_link_rename("/spiflash/link");
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
TEST_CASE("(WL) can create and remove directories", "[fatfs][wear_levelling]")
|
||||
{
|
||||
test_setup();
|
||||
test_fatfs_mkdir_rmdir("/spiflash/dir");
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
TEST_CASE("(WL) can opendir root directory of FS", "[fatfs][wear_levelling]")
|
||||
{
|
||||
test_setup();
|
||||
test_fatfs_can_opendir("/spiflash");
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
TEST_CASE("(WL) opendir, readdir, rewinddir, seekdir work as expected", "[fatfs][wear_levelling]")
|
||||
{
|
||||
test_setup();
|
||||
test_fatfs_opendir_readdir_rewinddir("/spiflash/dir");
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
TEST_CASE("(WL) multiple tasks can use same volume", "[fatfs][wear_levelling]")
|
||||
{
|
||||
test_setup();
|
||||
test_fatfs_concurrent("/spiflash/f");
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
TEST_CASE("(WL) fatfs does not ignore leading spaces", "[fatfs][wear_levelling]")
|
||||
{
|
||||
// the functionality of ignoring leading and trailing whitespaces is not implemented yet
|
||||
// when the feature is implemented, this test will fail
|
||||
// please, remove the test and implement the functionality in fatfsgen.py to preserve the consistency
|
||||
test_setup();
|
||||
test_leading_spaces();
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("(WL) write/read speed test", "[fatfs][wear_levelling][timeout=60]")
|
||||
{
|
||||
/* Erase partition before running the test to get consistent results */
|
||||
const esp_partition_t* part = esp_partition_find_first(ESP_PARTITION_TYPE_DATA,
|
||||
ESP_PARTITION_SUBTYPE_DATA_FAT, NULL);
|
||||
esp_partition_erase_range(part, 0, part->size);
|
||||
|
||||
test_setup();
|
||||
|
||||
const size_t buf_size = 16 * 1024;
|
||||
uint32_t* buf = (uint32_t*) calloc(1, buf_size);
|
||||
esp_fill_random(buf, buf_size);
|
||||
const size_t file_size = 256 * 1024;
|
||||
const char* file = "/spiflash/256k.bin";
|
||||
|
||||
test_fatfs_rw_speed(file, buf, 4 * 1024, file_size, true);
|
||||
test_fatfs_rw_speed(file, buf, 8 * 1024, file_size, true);
|
||||
test_fatfs_rw_speed(file, buf, 16 * 1024, file_size, true);
|
||||
|
||||
test_fatfs_rw_speed(file, buf, 4 * 1024, file_size, false);
|
||||
test_fatfs_rw_speed(file, buf, 8 * 1024, file_size, false);
|
||||
test_fatfs_rw_speed(file, buf, 16 * 1024, file_size, false);
|
||||
|
||||
unlink(file);
|
||||
|
||||
free(buf);
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
TEST_CASE("(WL) can get partition info", "[fatfs][wear_levelling]")
|
||||
{
|
||||
test_setup();
|
||||
test_fatfs_info("/spiflash", "/spiflash/test.txt");
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
/*
|
||||
* In FatFs menuconfig, set CONFIG_FATFS_API_ENCODING to UTF-8 and set the
|
||||
* Codepage to CP936 (Simplified Chinese) in order to run the following tests.
|
||||
* Ensure that the text editor is UTF-8 compatible when compiling these tests.
|
||||
*/
|
||||
#if defined(CONFIG_FATFS_API_ENCODING_UTF_8) && (CONFIG_FATFS_CODEPAGE == 936)
|
||||
TEST_CASE("(WL) can read file with UTF-8 encoded strings", "[fatfs][wear_levelling]")
|
||||
{
|
||||
test_setup();
|
||||
test_fatfs_create_file_with_text("/spiflash/测试文件.txt", fatfs_test_hello_str_utf);
|
||||
test_fatfs_read_file_utf_8("/spiflash/测试文件.txt");
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
TEST_CASE("(WL) opendir, readdir, rewinddir, seekdir work as expected using UTF-8 encoded strings", "[fatfs][wear_levelling]")
|
||||
{
|
||||
test_setup();
|
||||
test_fatfs_opendir_readdir_rewinddir_utf_8("/spiflash/目录");
|
||||
test_teardown();
|
||||
}
|
||||
#endif //defined(CONFIG_FATFS_API_ENCODING_UTF_8) && (CONFIG_FATFS_CODEPAGE == 936)
|
||||
|
||||
#ifdef CONFIG_SPIRAM
|
||||
TEST_CASE("FATFS prefers SPI RAM for allocations", "[fatfs]")
|
||||
{
|
||||
test_setup();
|
||||
DIR* dir = opendir("/spiflash");
|
||||
TEST_ASSERT_NOT_NULL(dir);
|
||||
TEST_ASSERT(esp_ptr_external_ram(dir));
|
||||
closedir(dir);
|
||||
test_teardown();
|
||||
}
|
||||
#endif // CONFIG_SPIRAM
|
||||
@@ -0,0 +1,3 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
factory, app, factory, 0x10000, 1M,
|
||||
storage, data, fat, , 528k,
|
||||
|
@@ -0,0 +1,39 @@
|
||||
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
import pytest
|
||||
from pytest_embedded import Dut
|
||||
|
||||
|
||||
@pytest.mark.supported_targets
|
||||
@pytest.mark.generic
|
||||
@pytest.mark.parametrize(
|
||||
'config',
|
||||
[
|
||||
'default',
|
||||
'release',
|
||||
'fastseek',
|
||||
]
|
||||
)
|
||||
def test_fatfs_flash_wl_generic(dut: Dut) -> None:
|
||||
dut.expect_exact('Press ENTER to see the list of tests')
|
||||
dut.write('')
|
||||
dut.expect_exact('Enter test for running.')
|
||||
dut.write('*')
|
||||
dut.expect_unity_test_output(timeout=120)
|
||||
|
||||
|
||||
@pytest.mark.supported_targets
|
||||
@pytest.mark.psram
|
||||
@pytest.mark.parametrize(
|
||||
'config',
|
||||
[
|
||||
'psram',
|
||||
]
|
||||
)
|
||||
def test_fatfs_flash_wl_psram(dut: Dut) -> None:
|
||||
dut.expect_exact('Press ENTER to see the list of tests')
|
||||
dut.write('')
|
||||
dut.expect_exact('Enter test for running.')
|
||||
dut.write('*')
|
||||
dut.expect_unity_test_output(timeout=120)
|
||||
@@ -0,0 +1,2 @@
|
||||
CONFIG_FATFS_USE_FASTSEEK=y
|
||||
CONFIG_FATFS_FAST_SEEK_BUFFER_SIZE=64
|
||||
@@ -0,0 +1,3 @@
|
||||
CONFIG_SPIRAM=y
|
||||
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=0
|
||||
CONFIG_FATFS_ALLOC_PREFER_EXTRAM=y
|
||||
@@ -0,0 +1,2 @@
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y
|
||||
@@ -0,0 +1,18 @@
|
||||
# General options for additional checks
|
||||
CONFIG_HEAP_POISONING_COMPREHENSIVE=y
|
||||
CONFIG_COMPILER_WARN_WRITE_STRINGS=y
|
||||
CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y
|
||||
CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y
|
||||
CONFIG_COMPILER_STACK_CHECK_MODE_STRONG=y
|
||||
CONFIG_COMPILER_STACK_CHECK=y
|
||||
|
||||
# disable task watchdog since this app uses an interactive menu
|
||||
CONFIG_ESP_TASK_WDT_INIT=n
|
||||
|
||||
# use custom partition table
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
|
||||
|
||||
# some tests verify file name encoding
|
||||
CONFIG_FATFS_API_ENCODING_UTF_8=y
|
||||
CONFIG_FATFS_CODEPAGE_936=y
|
||||
Reference in New Issue
Block a user