diff options
Diffstat (limited to 'lib/fatfs/host_test/main/test_fatfs.cpp')
| -rw-r--r-- | lib/fatfs/host_test/main/test_fatfs.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
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 |
