summaryrefslogtreecommitdiff
path: root/lib/fatfs/test_apps/flash_wl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/fatfs/test_apps/flash_wl')
-rw-r--r--lib/fatfs/test_apps/flash_wl/README.md4
-rw-r--r--lib/fatfs/test_apps/flash_wl/main/CMakeLists.txt2
-rw-r--r--lib/fatfs/test_apps/flash_wl/main/Kconfig.projbuild10
-rw-r--r--lib/fatfs/test_apps/flash_wl/main/test_fatfs_flash_wl.c92
-rw-r--r--lib/fatfs/test_apps/flash_wl/main/test_fatfs_small_partition.c76
-rw-r--r--lib/fatfs/test_apps/flash_wl/partitions.csv1
-rw-r--r--lib/fatfs/test_apps/flash_wl/pytest_fatfs_flash_wl.py27
-rw-r--r--lib/fatfs/test_apps/flash_wl/sdkconfig.ci.auto_fsync2
-rw-r--r--lib/fatfs/test_apps/flash_wl/sdkconfig.ci.dyn_buffers1
-rw-r--r--lib/fatfs/test_apps/flash_wl/sdkconfig.ci.psram.esp32 (renamed from lib/fatfs/test_apps/flash_wl/sdkconfig.ci.psram)1
10 files changed, 189 insertions, 27 deletions
diff --git a/lib/fatfs/test_apps/flash_wl/README.md b/lib/fatfs/test_apps/flash_wl/README.md
index 9112db39..a90777a3 100644
--- a/lib/fatfs/test_apps/flash_wl/README.md
+++ b/lib/fatfs/test_apps/flash_wl/README.md
@@ -1,5 +1,5 @@
-| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
-| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
+| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H21 | ESP32-H4 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
+| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | --------- | -------- | -------- | -------- | -------- |
This test app runs a few FATFS test cases in a wear levelling FAT partition.
diff --git a/lib/fatfs/test_apps/flash_wl/main/CMakeLists.txt b/lib/fatfs/test_apps/flash_wl/main/CMakeLists.txt
index 20b600fc..f6501bda 100644
--- a/lib/fatfs/test_apps/flash_wl/main/CMakeLists.txt
+++ b/lib/fatfs/test_apps/flash_wl/main/CMakeLists.txt
@@ -1,4 +1,4 @@
-idf_component_register(SRCS "test_fatfs_flash_wl.c"
+idf_component_register(SRCS "test_fatfs_flash_wl.c" "test_fatfs_small_partition.c"
INCLUDE_DIRS "."
PRIV_REQUIRES unity spi_flash fatfs vfs test_fatfs_common
WHOLE_ARCHIVE)
diff --git a/lib/fatfs/test_apps/flash_wl/main/Kconfig.projbuild b/lib/fatfs/test_apps/flash_wl/main/Kconfig.projbuild
new file mode 100644
index 00000000..c7292513
--- /dev/null
+++ b/lib/fatfs/test_apps/flash_wl/main/Kconfig.projbuild
@@ -0,0 +1,10 @@
+menu "Test configuration"
+ config SPI_WL_TEST_ERASE_PARTITION
+ bool "Erase partition"
+ default y if IDF_TARGET_LINUX
+ help
+ Erase the partition before each format operation.
+ This will destroy the flash fairly quickly in CI, but is necessary to
+ ensure that the test is not affected by previous test runs.
+ Run with caution.
+endmenu
diff --git a/lib/fatfs/test_apps/flash_wl/main/test_fatfs_flash_wl.c b/lib/fatfs/test_apps/flash_wl/main/test_fatfs_flash_wl.c
index 1af50fe6..fa383803 100644
--- a/lib/fatfs/test_apps/flash_wl/main/test_fatfs_flash_wl.c
+++ b/lib/fatfs/test_apps/flash_wl/main/test_fatfs_flash_wl.c
@@ -1,5 +1,5 @@
/*
- * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
+ * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -23,6 +23,7 @@
#include "wear_levelling.h"
#include "esp_partition.h"
#include "esp_memory_utils.h"
+#include "vfs_fat_internal.h"
void app_main(void)
{
@@ -32,7 +33,7 @@ void app_main(void)
static wl_handle_t s_test_wl_handle;
static void test_setup(void)
{
- esp_vfs_fat_sdmmc_mount_config_t mount_config = {
+ esp_vfs_fat_mount_config_t mount_config = {
.format_if_mount_failed = true,
.max_files = 5,
};
@@ -45,14 +46,47 @@ 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][timeout=180]")
+#ifdef CONFIG_SPI_WL_TEST_ERASE_PARTITION
+static void corrupt_wl_data(void)
{
+ const esp_partition_t* part = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, NULL);
+ TEST_ASSERT_NOT_NULL(part);
+ TEST_ESP_OK(esp_partition_erase_range(part, 0, part->size));
+}
+#endif
+
+TEST_CASE("(WL) can format partition", "[fatfs][wear_levelling][timeout=120]")
+{
+#ifdef CONFIG_SPI_WL_TEST_ERASE_PARTITION
+ corrupt_wl_data();
+#endif
TEST_ESP_OK(esp_vfs_fat_spiflash_format_rw_wl("/spiflash", NULL));
test_setup();
+ vfs_fat_spiflash_ctx_t* ctx = get_vfs_fat_spiflash_ctx(s_test_wl_handle);
+ TEST_ASSERT_NOT_NULL(ctx);
+ TEST_ASSERT_TRUE(ctx->fs->n_fats == 2); // 2 FATs are created by default
+ test_teardown();
+}
+
+TEST_CASE("(WL) can format partition with config", "[fatfs][wear_levelling][timeout=120]")
+{
+#ifdef CONFIG_SPI_WL_TEST_ERASE_PARTITION
+ corrupt_wl_data();
+#endif
+ esp_vfs_fat_mount_config_t format_config = {
+ .format_if_mount_failed = true,
+ .max_files = 5,
+ .use_one_fat = true,
+ };
+ TEST_ESP_OK(esp_vfs_fat_spiflash_format_cfg_rw_wl("/spiflash", NULL, &format_config));
+ test_setup();
+ vfs_fat_spiflash_ctx_t* ctx = get_vfs_fat_spiflash_ctx(s_test_wl_handle);
+ TEST_ASSERT_NOT_NULL(ctx);
+ TEST_ASSERT_TRUE(ctx->fs->n_fats == 1);
test_teardown();
}
-TEST_CASE("(WL) can format when the FAT is mounted already", "[fatfs][wear_levelling][timeout=180]")
+TEST_CASE("(WL) can format when the FAT is mounted already", "[fatfs][wear_levelling][timeout=120]")
{
test_setup();
TEST_ESP_OK(esp_vfs_fat_spiflash_format_rw_wl("/spiflash", NULL));
@@ -61,9 +95,28 @@ TEST_CASE("(WL) can format when the FAT is mounted already", "[fatfs][wear_level
test_teardown();
}
-TEST_CASE("(WL) can format specified FAT when more are mounted", "[fatfs][wear_levelling][timeout=180]")
+TEST_CASE("(WL) can format when the FAT is mounted already with config", "[fatfs][wear_levelling][timeout=120]")
+{
+ TEST_ESP_OK(esp_vfs_fat_spiflash_format_rw_wl("/spiflash", NULL)); // To reset the FAT number to 2
+ test_setup();
+ vfs_fat_spiflash_ctx_t* ctx = get_vfs_fat_spiflash_ctx(s_test_wl_handle);
+ TEST_ASSERT_NOT_NULL(ctx);
+ TEST_ASSERT_TRUE(ctx->fs->n_fats == 2);
+ esp_vfs_fat_mount_config_t format_config = {
+ .format_if_mount_failed = true,
+ .max_files = 5,
+ .use_one_fat = true,
+ };
+ TEST_ESP_OK(esp_vfs_fat_spiflash_format_cfg_rw_wl("/spiflash", NULL, &format_config));
+ TEST_ASSERT_TRUE(ctx->fs->n_fats == 1);
+ 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 format specified FAT when more are mounted", "[fatfs][wear_levelling][timeout=120]")
{
- esp_vfs_fat_sdmmc_mount_config_t mount_config = {
+ esp_vfs_fat_mount_config_t mount_config = {
.format_if_mount_failed = true,
.max_files = 5,
};
@@ -126,7 +179,7 @@ TEST_CASE("(WL) pwrite() works well", "[fatfs][wear_levelling]")
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 = {
+ esp_vfs_fat_mount_config_t mount_config = {
.format_if_mount_failed = true,
.max_files = max_files
};
@@ -152,9 +205,25 @@ TEST_CASE("(WL) can lseek", "[fatfs][wear_levelling]")
TEST_CASE("(WL) can truncate", "[fatfs][wear_levelling]")
{
test_setup();
- test_fatfs_truncate_file("/spiflash/truncate.txt");
+ test_fatfs_truncate_file("/spiflash/truncate.txt", true);
+ test_teardown();
+}
+
+TEST_CASE("(WL) can ftruncate", "[fatfs][wear_levelling]")
+{
+ test_setup();
+ test_fatfs_ftruncate_file("/spiflash/ftrunc.txt", true);
+ test_teardown();
+}
+
+#if FF_USE_EXPAND
+TEST_CASE("(WL) can esp_vfs_fat_create_contiguous_file", "[fatfs][wear_levelling]")
+{
+ test_setup();
+ test_fatfs_create_contiguous_file("/spiflash", "/spiflash/expand.txt");
test_teardown();
}
+#endif
TEST_CASE("(WL) stat returns correct values", "[fatfs][wear_levelling]")
{
@@ -205,6 +274,13 @@ TEST_CASE("(WL) can opendir root directory of FS", "[fatfs][wear_levelling]")
test_teardown();
}
+TEST_CASE("(WL) readdir, stat work as expected", "[fatfs][wear_levelling]")
+{
+ test_setup();
+ test_fatfs_readdir_stat("/spiflash/dir");
+ test_teardown();
+}
+
TEST_CASE("(WL) opendir, readdir, rewinddir, seekdir work as expected", "[fatfs][wear_levelling]")
{
test_setup();
diff --git a/lib/fatfs/test_apps/flash_wl/main/test_fatfs_small_partition.c b/lib/fatfs/test_apps/flash_wl/main/test_fatfs_small_partition.c
new file mode 100644
index 00000000..fd65a4db
--- /dev/null
+++ b/lib/fatfs/test_apps/flash_wl/main/test_fatfs_small_partition.c
@@ -0,0 +1,76 @@
+/*
+ * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/unistd.h>
+#include "unity.h"
+#include "esp_vfs_fat.h"
+
+static wl_handle_t s_test_wl_handle;
+static void test_setup(void)
+{
+ // With this configuration, for 32k partition size,
+ // 4 sectors will be used for WL and 4 sectors for FATFS
+ // (1 FAT, 1 root directory, 1 reserved and 1 data sector)
+ esp_vfs_fat_mount_config_t mount_config = {
+ .format_if_mount_failed = true,
+ .max_files = 5,
+ .use_one_fat = true,
+ };
+
+ TEST_ESP_OK(esp_vfs_fat_spiflash_format_cfg_rw_wl("/spiflash", "storage1", &mount_config));
+ TEST_ESP_OK(esp_vfs_fat_spiflash_mount_rw_wl("/spiflash", "storage1", &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));
+}
+
+static void test_write_data_sec(int num_data_sec)
+{
+ int fd = open("/spiflash/test.txt", O_CREAT | O_WRONLY);
+ TEST_ASSERT_NOT_EQUAL(-1, fd);
+
+ // Generate data
+ uint32_t data_size = 4096*num_data_sec;
+
+ char *data = (char*) malloc(data_size);
+ char *read_data = (char*) malloc(data_size);
+
+ for(uint32_t i = 0; i < (data_size); i += sizeof(i))
+ {
+ *((uint32_t*)(data + i)) = i;
+ }
+ ssize_t wr = write(fd, data, data_size);
+ if (num_data_sec == 1) {
+ TEST_ASSERT_EQUAL(data_size, wr);
+ } else {
+ TEST_ASSERT_NOT_EQUAL(data_size, wr);
+ }
+ TEST_ASSERT_EQUAL(0, close(fd));
+
+ fd = open("/spiflash/test.txt", O_RDONLY);
+ int r = read(fd, read_data, data_size);
+ if (num_data_sec == 1) {
+ TEST_ASSERT_EQUAL(data_size, r);
+ } else {
+ TEST_ASSERT_NOT_EQUAL(data_size, r);
+ }
+ TEST_ASSERT_EQUAL(0, strcmp(data, read_data));
+ TEST_ASSERT_EQUAL(0, close(fd));
+}
+
+TEST_CASE("(WL) can format small partition and read-write data", "[fatfs][wear_levelling][timeout=120]")
+{
+ test_setup();
+ test_write_data_sec(1); //for 1 data sectors, write and read func should work
+ test_write_data_sec(2); //for 2 data sectors, write and read func should fail
+ test_teardown();
+}
diff --git a/lib/fatfs/test_apps/flash_wl/partitions.csv b/lib/fatfs/test_apps/flash_wl/partitions.csv
index d1dcbae6..d68a9de0 100644
--- a/lib/fatfs/test_apps/flash_wl/partitions.csv
+++ b/lib/fatfs/test_apps/flash_wl/partitions.csv
@@ -2,3 +2,4 @@
factory, app, factory, 0x10000, 768k,
storage, data, fat, , 528k,
storage2, data, fat, , 528k,
+storage1, data, fat, , 32k,
diff --git a/lib/fatfs/test_apps/flash_wl/pytest_fatfs_flash_wl.py b/lib/fatfs/test_apps/flash_wl/pytest_fatfs_flash_wl.py
index af8c5db6..a9863635 100644
--- a/lib/fatfs/test_apps/flash_wl/pytest_fatfs_flash_wl.py
+++ b/lib/fatfs/test_apps/flash_wl/pytest_fatfs_flash_wl.py
@@ -1,11 +1,10 @@
-# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
+# SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: CC0-1.0
-
import pytest
from pytest_embedded import Dut
+from pytest_embedded_idf.utils import idf_parametrize
-@pytest.mark.supported_targets
@pytest.mark.generic
@pytest.mark.parametrize(
'config',
@@ -13,27 +12,23 @@ from pytest_embedded import Dut
'default',
'release',
'fastseek',
- ]
+ 'auto_fsync',
+ 'dyn_buffers',
+ ],
)
+@idf_parametrize('target', ['esp32', 'esp32c3'], indirect=['target'])
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=180)
+ dut.run_all_single_board_cases(timeout=240)
-@pytest.mark.supported_targets
+@pytest.mark.generic
@pytest.mark.psram
@pytest.mark.parametrize(
'config',
[
'psram',
- ]
+ ],
)
+@idf_parametrize('target', ['esp32'], indirect=['target'])
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=180)
+ dut.run_all_single_board_cases(timeout=180)
diff --git a/lib/fatfs/test_apps/flash_wl/sdkconfig.ci.auto_fsync b/lib/fatfs/test_apps/flash_wl/sdkconfig.ci.auto_fsync
index b74d5124..9ab32baa 100644
--- a/lib/fatfs/test_apps/flash_wl/sdkconfig.ci.auto_fsync
+++ b/lib/fatfs/test_apps/flash_wl/sdkconfig.ci.auto_fsync
@@ -1 +1,3 @@
CONFIG_FATFS_IMMEDIATE_FSYNC=y
+CONFIG_ESP_MAIN_TASK_STACK_SIZE=4096
+CONFIG_FATFS_VFS_FSTAT_BLKSIZE=2048
diff --git a/lib/fatfs/test_apps/flash_wl/sdkconfig.ci.dyn_buffers b/lib/fatfs/test_apps/flash_wl/sdkconfig.ci.dyn_buffers
new file mode 100644
index 00000000..380dafbf
--- /dev/null
+++ b/lib/fatfs/test_apps/flash_wl/sdkconfig.ci.dyn_buffers
@@ -0,0 +1 @@
+CONFIG_FATFS_USE_DYN_BUFFERS=y
diff --git a/lib/fatfs/test_apps/flash_wl/sdkconfig.ci.psram b/lib/fatfs/test_apps/flash_wl/sdkconfig.ci.psram.esp32
index b3b45db9..5becfb94 100644
--- a/lib/fatfs/test_apps/flash_wl/sdkconfig.ci.psram
+++ b/lib/fatfs/test_apps/flash_wl/sdkconfig.ci.psram.esp32
@@ -1,3 +1,4 @@
+CONFIG_IDF_TARGET="esp32"
CONFIG_SPIRAM=y
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=0
CONFIG_FATFS_ALLOC_PREFER_EXTRAM=y