tests: fs: fat_fs_api: Add support for non-"flash map" devices
Test will now use disk_access_ functions to erase FAT FS disk before some operations when target disk is not set with CONFIG_DISK_DRIVER_FLASH. Fixes #53151 Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
This commit is contained in:
parent
850b8fcbc2
commit
a20f5edcd8
6 changed files with 86 additions and 13 deletions
|
@ -23,7 +23,7 @@
|
|||
};
|
||||
|
||||
/ {
|
||||
storage_disk {
|
||||
test_disk: storage_disk {
|
||||
compatible = "zephyr,flash-disk";
|
||||
partition = <&flashdisk_partition>;
|
||||
disk-name = "NAND";
|
||||
|
|
9
tests/subsys/fs/fat_fs_api/prj_native_posix_ram.conf
Normal file
9
tests/subsys/fs/fat_fs_api/prj_native_posix_ram.conf
Normal file
|
@ -0,0 +1,9 @@
|
|||
CONFIG_FILE_SYSTEM=y
|
||||
CONFIG_FILE_SYSTEM_MKFS=y
|
||||
CONFIG_LOG=y
|
||||
CONFIG_FAT_FILESYSTEM_ELM=y
|
||||
CONFIG_DISK_DRIVER_RAM=y
|
||||
CONFIG_ZTEST=y
|
||||
CONFIG_ZTEST_NEW_API=y
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_FLASH_MAP=y
|
|
@ -9,7 +9,19 @@
|
|||
#include <zephyr/ztest.h>
|
||||
#include <zephyr/fs/fs.h>
|
||||
|
||||
#define FATFS_MNTP "/NAND:"
|
||||
#ifdef CONFIG_DISK_DRIVER_RAM
|
||||
#define DISK_NAME CONFIG_DISK_RAM_VOLUME_NAME
|
||||
#elif defined(CONFIG_DISK_DRIVER_FLASH)
|
||||
#define DISK_NAME DT_PROP(DT_NODELABEL(test_disk), disk_name)
|
||||
#elif defined(CONFIG_DISK_DRIVER_SDMMC)
|
||||
#define DISK_NAME CONFIG_SDMMC_VOLUME_NAME
|
||||
#elif defined(CONFIG_DISK_DRIVER_MMC)
|
||||
#define DISK_NAME CONFIG_MMC_VOLUME_NAME
|
||||
#else
|
||||
#error "Failed to select DISK access type"
|
||||
#endif
|
||||
|
||||
#define FATFS_MNTP "/"DISK_NAME":"
|
||||
#if defined(CONFIG_FS_FATFS_LFN)
|
||||
#define TEST_FILE FATFS_MNTP \
|
||||
"/testlongfilenamethatsmuchlongerthan8.3chars.text"
|
||||
|
|
|
@ -7,7 +7,11 @@
|
|||
|
||||
#include "test_fat.h"
|
||||
#include <ff.h>
|
||||
#ifdef CONFIG_DISK_DRIVER_FLASH
|
||||
#include <zephyr/storage/flash_map.h>
|
||||
#else
|
||||
#include <zephyr/storage/disk_access.h>
|
||||
#endif
|
||||
|
||||
/* FatFs work area */
|
||||
static FATFS fat_fs;
|
||||
|
@ -15,7 +19,7 @@ static FATFS fat_fs;
|
|||
/* mounting info */
|
||||
static struct fs_mount_t fatfs_mnt = {
|
||||
.type = FS_FATFS,
|
||||
.mnt_point = "/NAND:",
|
||||
.mnt_point = "/"DISK_NAME":",
|
||||
.fs_data = &fat_fs,
|
||||
};
|
||||
|
||||
|
@ -24,11 +28,12 @@ void test_fs_mkfs_ops(void);
|
|||
|
||||
struct fs_mount_t *fs_mkfs_mp = &fatfs_mnt;
|
||||
const int fs_mkfs_type = FS_FATFS;
|
||||
uintptr_t fs_mkfs_dev_id = (uintptr_t) "NAND:";
|
||||
uintptr_t fs_mkfs_dev_id = (uintptr_t) DISK_NAME":";
|
||||
int fs_mkfs_flags;
|
||||
const char *some_file_path = "/NAND:/SOME";
|
||||
const char *other_dir_path = "/NAND:/OTHER";
|
||||
const char *some_file_path = "/"DISK_NAME":/SOME";
|
||||
const char *other_dir_path = "/"DISK_NAME":/OTHER";
|
||||
|
||||
#ifdef CONFIG_DISK_DRIVER_FLASH
|
||||
static int wipe_partition(void)
|
||||
{
|
||||
/* In this test the first partition on flash device is used for FAT */
|
||||
|
@ -54,6 +59,50 @@ static int wipe_partition(void)
|
|||
|
||||
return TC_PASS;
|
||||
}
|
||||
#else
|
||||
static uint8_t erase_buffer[4096] = { 0 };
|
||||
|
||||
static int wipe_partition(void)
|
||||
{
|
||||
uint32_t sector_size;
|
||||
uint32_t sector_count;
|
||||
uint32_t sector_wr_jmp;
|
||||
uint32_t sector_wr_size;
|
||||
|
||||
if (disk_access_init(DISK_NAME)) {
|
||||
TC_PRINT("Failed to init disk "DISK_NAME"\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
if (disk_access_ioctl(DISK_NAME, DISK_IOCTL_GET_SECTOR_COUNT, §or_count)) {
|
||||
TC_PRINT("Failed to get disk "DISK_NAME" sector count\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
if (disk_access_ioctl(DISK_NAME, DISK_IOCTL_GET_SECTOR_SIZE, §or_size)) {
|
||||
TC_PRINT("Failed to get disk "DISK_NAME" sector size\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
if (sector_size > ARRAY_SIZE(erase_buffer)) {
|
||||
TC_PRINT("Predefined \"erase_buffer\" to small to handle single sector\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
sector_wr_size = MIN(sector_size, ARRAY_SIZE(erase_buffer));
|
||||
sector_wr_jmp = sector_wr_size / sector_wr_size;
|
||||
TC_PRINT("For "DISK_NAME" using sector write size "PRIu32" to write "PRIu32" at once\n",
|
||||
sector_wr_size, sector_wr_jmp);
|
||||
|
||||
for (uint32_t sector_idx = 0; sector_idx < sector_count; sector_idx += sector_wr_jmp) {
|
||||
if (disk_access_write(DISK_NAME, erase_buffer, sector_idx, 1)) {
|
||||
TC_PRINT("Faield to \"erase\" sector "PRIu32" to "DISK_NAME"\n",
|
||||
sector_idx);
|
||||
return TC_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
return TC_PASS;
|
||||
}
|
||||
#endif
|
||||
|
||||
ZTEST(fat_fs_mkfs, test_mkfs_simple)
|
||||
{
|
||||
|
|
|
@ -24,7 +24,7 @@ static void test_prepare(void)
|
|||
|
||||
fs_file_t_init(&fs);
|
||||
zassert_equal(fs_mount(&fatfs_mnt), 0);
|
||||
zassert_equal(fs_open(&fs, "/NAND:/testfile.txt", FS_O_CREATE),
|
||||
zassert_equal(fs_open(&fs, FATFS_MNTP"/testfile.txt", FS_O_CREATE),
|
||||
0, NULL);
|
||||
zassert_equal(fs_close(&fs), 0);
|
||||
zassert_equal(fs_unmount(&fatfs_mnt), 0);
|
||||
|
@ -48,17 +48,17 @@ static void test_ops_on_rd(void)
|
|||
zassert_equal(ret, 0, "Expected success", ret);
|
||||
|
||||
/* Attempt creating new file */
|
||||
ret = fs_open(&fs, "/NAND:/nosome", FS_O_CREATE);
|
||||
ret = fs_open(&fs, FATFS_MNTP"/nosome", FS_O_CREATE);
|
||||
zassert_equal(ret, -EROFS, "Expected EROFS", ret);
|
||||
ret = fs_mkdir("/NAND:/another");
|
||||
ret = fs_mkdir(FATFS_MNTP"/another");
|
||||
zassert_equal(ret, -EROFS, "Expected EROFS", ret);
|
||||
ret = fs_rename("/NAND:/testfile.txt", "/NAND:/bestfile.txt");
|
||||
ret = fs_rename(FATFS_MNTP"/testfile.txt", FATFS_MNTP"/bestfile.txt");
|
||||
zassert_equal(ret, -EROFS, "Expected EROFS", ret);
|
||||
ret = fs_unlink("/NAND:/testfile.txt");
|
||||
ret = fs_unlink(FATFS_MNTP"/testfile.txt");
|
||||
zassert_equal(ret, -EROFS, "Expected EROFS", ret);
|
||||
ret = fs_open(&fs, "/NAND:/testfile.txt", FS_O_RDWR);
|
||||
ret = fs_open(&fs, FATFS_MNTP"/testfile.txt", FS_O_RDWR);
|
||||
zassert_equal(ret, -EROFS, "Expected EROFS", ret);
|
||||
ret = fs_open(&fs, "/NAND:/testfile.txt", FS_O_READ);
|
||||
ret = fs_open(&fs, FATFS_MNTP"/testfile.txt", FS_O_READ);
|
||||
zassert_equal(ret, 0, "Expected success", ret);
|
||||
fs_close(&fs);
|
||||
}
|
||||
|
|
|
@ -11,3 +11,6 @@ tests:
|
|||
filesystem.fat.api.mmc:
|
||||
extra_args: CONF_FILE="prj_mmc.conf"
|
||||
filter: dt_compat_enabled("zephyr,mmc-disk")
|
||||
filesystem.fat.ram.api:
|
||||
platform_allow: native_posix
|
||||
extra_args: CONF_FILE="prj_native_posix_ram.conf"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue