summaryrefslogtreecommitdiff
path: root/lib/fatfs/host_test/main
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2025-07-25 13:33:07 +1000
committerjacqueline <me@jacqueline.id.au>2025-07-25 13:33:07 +1000
commitc8e79a926620e48830778714cfe4b2ea2453fcaf (patch)
tree8c756e08e01b8e147cf72bec128026f46bd854c5 /lib/fatfs/host_test/main
parent237136f3e93cb6b5be24670d7520adb17cc0fa36 (diff)
downloadtangara-fw-c8e79a926620e48830778714cfe4b2ea2453fcaf.tar.gz
Update forked idf components
Diffstat (limited to 'lib/fatfs/host_test/main')
-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
4 files changed, 19 insertions, 20 deletions
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