summaryrefslogtreecommitdiff
path: root/lib/fatfs/host_test
diff options
context:
space:
mode:
Diffstat (limited to 'lib/fatfs/host_test')
-rw-r--r--lib/fatfs/host_test/.build-test-rules.yml7
-rw-r--r--lib/fatfs/host_test/CMakeLists.txt4
-rw-r--r--lib/fatfs/host_test/main/CMakeLists.txt8
-rw-r--r--lib/fatfs/host_test/main/idf_component.yml2
-rw-r--r--lib/fatfs/host_test/main/main.cpp7
-rw-r--r--lib/fatfs/host_test/main/test_fatfs.cpp22
-rw-r--r--lib/fatfs/host_test/partition_table.csv4
-rw-r--r--lib/fatfs/host_test/pytest_fatfs_linux.py5
-rw-r--r--lib/fatfs/host_test/sdkconfig.defaults1
9 files changed, 32 insertions, 28 deletions
diff --git a/lib/fatfs/host_test/.build-test-rules.yml b/lib/fatfs/host_test/.build-test-rules.yml
new file mode 100644
index 00000000..17714e9c
--- /dev/null
+++ b/lib/fatfs/host_test/.build-test-rules.yml
@@ -0,0 +1,7 @@
+components/fatfs/host_test:
+ enable:
+ - if: IDF_TARGET == "linux"
+ disable_test:
+ - if: IDF_TARGET == "esp32p4"
+ temporary: true
+ reason: test not pass, should be re-enable # TODO: IDF-8980
diff --git a/lib/fatfs/host_test/CMakeLists.txt b/lib/fatfs/host_test/CMakeLists.txt
index 48267da8..7bf861b1 100644
--- a/lib/fatfs/host_test/CMakeLists.txt
+++ b/lib/fatfs/host_test/CMakeLists.txt
@@ -2,9 +2,7 @@ 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.
+# This test doesn't require FreeRTOS, uses a mock instead
list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/freertos/")
project(fatfs_host_test)
diff --git a/lib/fatfs/host_test/main/CMakeLists.txt b/lib/fatfs/host_test/main/CMakeLists.txt
index ef8aeb43..046433c1 100644
--- a/lib/fatfs/host_test/main/CMakeLists.txt
+++ b/lib/fatfs/host_test/main/CMakeLists.txt
@@ -1,6 +1,8 @@
-idf_component_register(SRCS "main.cpp"
- "test_fatfs.cpp"
- INCLUDE_DIRS "$ENV{IDF_PATH}/tools/catch"
+idf_component_register(SRCS "test_fatfs.cpp"
REQUIRES fatfs
WHOLE_ARCHIVE
)
+
+# Currently 'main' for IDF_TARGET=linux is defined in freertos component.
+# Since we are using a freertos mock here, need to let Catch2 provide 'main'.
+target_link_libraries(${COMPONENT_LIB} PRIVATE Catch2WithMain)
diff --git a/lib/fatfs/host_test/main/idf_component.yml b/lib/fatfs/host_test/main/idf_component.yml
new file mode 100644
index 00000000..f7982136
--- /dev/null
+++ b/lib/fatfs/host_test/main/idf_component.yml
@@ -0,0 +1,2 @@
+dependencies:
+ espressif/catch2: "^3.4.0"
diff --git a/lib/fatfs/host_test/main/main.cpp b/lib/fatfs/host_test/main/main.cpp
deleted file mode 100644
index cd66dc30..00000000
--- a/lib/fatfs/host_test/main/main.cpp
+++ /dev/null
@@ -1,7 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
- *
- * SPDX-License-Identifier: Apache-2.0
- */
-#define CATCH_CONFIG_MAIN
-#include "catch.hpp"
diff --git a/lib/fatfs/host_test/main/test_fatfs.cpp b/lib/fatfs/host_test/main/test_fatfs.cpp
index 77af2e70..88aa16e1 100644
--- a/lib/fatfs/host_test/main/test_fatfs.cpp
+++ b/lib/fatfs/host_test/main/test_fatfs.cpp
@@ -1,5 +1,5 @@
/*
- * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
+ * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -12,7 +12,7 @@
#include "diskio_impl.h"
#include "diskio_wl.h"
-#include "catch.hpp"
+#include <catch2/catch_test_macros.hpp>
TEST_CASE("Create volume, open file, write and read back data", "[fatfs]")
{
@@ -44,7 +44,10 @@ TEST_CASE("Create volume, open file, write and read back data", "[fatfs]")
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};
+
+ // For host tests, include FM_SFD flag when formatting partitions smaller than 128KB.
+ // if n_root field of MKFS_PARM is set to 128 => 1 root directory sec and if set to 0(default 512) => 4 root directory sectors.
+ const MKFS_PARM opt = {(BYTE)(FM_ANY | FM_SFD), 0, 0, 128, 0};
fr_result = f_mkfs("", &opt, work_area, sizeof(work_area)); // Use default volume
// Mount the volume
@@ -56,7 +59,7 @@ TEST_CASE("Create volume, open file, write and read back data", "[fatfs]")
REQUIRE(fr_result == FR_OK);
// Generate data
- uint32_t data_size = 100000;
+ uint32_t data_size = 1000;
char *data = (char*) malloc(data_size);
char *read = (char*) malloc(data_size);
@@ -130,7 +133,7 @@ static void prepare_fatfs(const char* partition_label, const esp_partition_t** p
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};
+ const MKFS_PARM opt = {(BYTE)(FM_ANY | FM_SFD), 0, 0, 128, 0};
fr_result = f_mkfs(drv, &opt, work_area, sizeof(work_area)); // Use default volume
REQUIRE(fr_result == FR_OK);
}
@@ -141,7 +144,7 @@ static void prepare_fatfs(const char* partition_label, const esp_partition_t** p
* at the time of writing this - therefore there also is a device test_apps test in
* `components/fatfs/test_apps/flash_wl/main/test_fatfs_flash_wl.c` which tests our VFS FATFS SPIFLASH API.
*/
-TEST_CASE("Test mounting 2 volumes, writing data and formating the 2nd one, reading data", "[fatfs]")
+TEST_CASE("Test mounting 2 volumes, writing data and formatting the 2nd one, reading data", "[fatfs]")
{
FRESULT fr_result;
esp_err_t esp_result;
@@ -158,7 +161,6 @@ TEST_CASE("Test mounting 2 volumes, writing data and formating the 2nd one, read
FATFS fs1;
wl_handle_t wl_handle1 = WL_INVALID_HANDLE;
- size_t allocation_unit_size = CONFIG_WL_SECTOR_SIZE;
size_t data_size = 10;
@@ -223,7 +225,7 @@ TEST_CASE("Test mounting 2 volumes, writing data and formating the 2nd one, read
const size_t workbuf_size = 4096;
void *workbuf = ff_memalloc(workbuf_size);
REQUIRE(workbuf != NULL);
- const MKFS_PARM opt = {(BYTE)(FM_ANY | FM_SFD), 0, 0, 0, CONFIG_WL_SECTOR_SIZE};
+ const MKFS_PARM opt = {(BYTE)(FM_ANY | FM_SFD), 0, 0, 128, CONFIG_WL_SECTOR_SIZE};
fr_result = f_mkfs(drv1, &opt, workbuf, workbuf_size);
free(workbuf);
workbuf = NULL;
@@ -241,7 +243,7 @@ TEST_CASE("Test mounting 2 volumes, writing data and formating the 2nd one, read
fr_result = f_read(&file1, read1, data_size, &bw1);
REQUIRE(fr_result == FR_OK);
REQUIRE(bw1 != data_size);
- // Comapre data
+ // Compare data
printf("data1=%s, read1=%s\n", data1, read1);
REQUIRE(strncmp(data1, read1, data_size-1) != 0); // 987654321 should be ersead due to formatting
// Close file from file1
@@ -259,7 +261,7 @@ TEST_CASE("Test mounting 2 volumes, writing data and formating the 2nd one, read
fr_result = f_read(&file0, read0, data_size, &bw0);
REQUIRE(fr_result == FR_OK);
REQUIRE(bw0 == data_size);
- // Comapre data
+ // Compare data
printf("data0=%s, read0=%s\n", data0, read0);
REQUIRE(strncmp(data0, read0, data_size-1) == 0); // should match since the partition was not formatted
// Close file from file0
diff --git a/lib/fatfs/host_test/partition_table.csv b/lib/fatfs/host_test/partition_table.csv
index 30d2d909..777a3e67 100644
--- a/lib/fatfs/host_test/partition_table.csv
+++ b/lib/fatfs/host_test/partition_table.csv
@@ -3,5 +3,5 @@
nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000,
factory, app, factory, 0x10000, 1M,
-storage, data, fat, , 1M,
-storage2, data, fat, , 1M,
+storage, data, fat, , 32k,
+storage2, data, fat, , 32k,
diff --git a/lib/fatfs/host_test/pytest_fatfs_linux.py b/lib/fatfs/host_test/pytest_fatfs_linux.py
index 7b12c361..e14e927a 100644
--- a/lib/fatfs/host_test/pytest_fatfs_linux.py
+++ b/lib/fatfs/host_test/pytest_fatfs_linux.py
@@ -1,10 +1,11 @@
-# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
+# SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Unlicense OR CC0-1.0
import pytest
from pytest_embedded import Dut
+from pytest_embedded_idf.utils import idf_parametrize
-@pytest.mark.linux
@pytest.mark.host_test
+@idf_parametrize('target', ['linux'], indirect=['target'])
def test_fatfs_linux(dut: Dut) -> None:
dut.expect_exact('All tests passed', timeout=120)
diff --git a/lib/fatfs/host_test/sdkconfig.defaults b/lib/fatfs/host_test/sdkconfig.defaults
index e0d9a692..53e7687b 100644
--- a/lib/fatfs/host_test/sdkconfig.defaults
+++ b/lib/fatfs/host_test/sdkconfig.defaults
@@ -6,7 +6,6 @@ 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=3