1 /*
2 * Copyright (c) 2022 Antmicro
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7
8 #include "test_fat.h"
9 #include <ff.h>
10
11 /* mounting info */
12 static struct fs_mount_t fatfs_mnt = {
13 .type = FS_FATFS,
14 .mnt_point = "/"DISK_NAME":",
15 .fs_data = &fat_fs,
16 };
17
18 void test_fs_mkfs_simple(void);
19 void test_fs_mkfs_ops(void);
20
21 struct fs_mount_t *fs_mkfs_mp = &fatfs_mnt;
22 const int fs_mkfs_type = FS_FATFS;
23 uintptr_t fs_mkfs_dev_id = (uintptr_t) DISK_NAME":";
24 int fs_mkfs_flags;
25 const char *some_file_path = "/"DISK_NAME":/SOME";
26 const char *other_dir_path = "/"DISK_NAME":/OTHER";
27
ZTEST(fat_fs_mkfs,test_mkfs_simple)28 ZTEST(fat_fs_mkfs, test_mkfs_simple)
29 {
30 int ret;
31
32 ret = wipe_partition();
33 zassert_equal(ret, TC_PASS, "wipe partition failed %d", ret);
34
35 test_fs_mkfs_simple();
36 }
37
ZTEST(fat_fs_mkfs,test_mkfs_ops)38 ZTEST(fat_fs_mkfs, test_mkfs_ops)
39 {
40 int ret;
41
42 ret = wipe_partition();
43 zassert_equal(ret, TC_PASS, "wipe partition failed %d", ret);
44
45 test_fs_mkfs_ops();
46 }
47
48 static MKFS_PARM custom_cfg = {
49 .fmt = FM_ANY | FM_SFD, /* Any suitable FAT */
50 .n_fat = 1, /* One FAT fs table */
51 .align = 0, /* Get sector size via diskio query */
52 .n_root = CONFIG_FS_FATFS_MAX_ROOT_ENTRIES,
53 .au_size = 0 /* Auto calculate cluster size */
54 };
55
ZTEST(fat_fs_mkfs,test_mkfs_custom)56 ZTEST(fat_fs_mkfs, test_mkfs_custom)
57 {
58 int ret;
59 struct fs_mount_t mp = fatfs_mnt;
60 struct fs_statvfs sbuf;
61
62 ret = wipe_partition();
63 zassert_equal(ret, 0, "wipe partition failed %d", ret);
64
65 ret = fs_mkfs(FS_FATFS, fs_mkfs_dev_id, &custom_cfg, 0);
66 zassert_equal(ret, 0, "mkfs failed %d", ret);
67
68
69 mp.flags = FS_MOUNT_FLAG_NO_FORMAT;
70 ret = fs_mount(&mp);
71 zassert_equal(ret, 0, "mount failed %d", ret);
72
73 ret = fs_statvfs(mp.mnt_point, &sbuf);
74 zassert_equal(ret, 0, "statvfs failed %d", ret);
75
76 TC_PRINT("statvfs: %lu %lu %lu %lu",
77 sbuf.f_bsize, sbuf.f_frsize, sbuf.f_blocks, sbuf.f_bfree);
78
79 ret = fs_unmount(&mp);
80 zassert_equal(ret, 0, "unmount failed %d", ret);
81 }
82
83 ZTEST_SUITE(fat_fs_mkfs, NULL, NULL, NULL, NULL, NULL);
84