1 /*
2 * Copyright (c) 2022 Antmicro
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/ztest.h>
8 #include <zephyr/fs/littlefs.h>
9 #include "testfs_tests.h"
10 #include "testfs_lfs.h"
11
12 void test_fs_mkfs_ops(void);
13 void test_fs_mkfs_simple(void);
14 /* Using smallest partition for this tests as they do not write
15 * a lot of data, basically they just check flags.
16 */
17 struct fs_mount_t *fs_mkfs_mp = &testfs_small_mnt;
18 const int fs_mkfs_type = FS_LITTLEFS;
19 uintptr_t fs_mkfs_dev_id;
20 int fs_mkfs_flags;
21 const char *some_file_path = "/sml/some";
22 const char *other_dir_path = "/sml/other";
23
cleanup(struct fs_mount_t * mp)24 static void cleanup(struct fs_mount_t *mp)
25 {
26 TC_PRINT("Clean %s\n", mp->mnt_point);
27
28 zassert_equal(testfs_lfs_wipe_partition(mp), TC_PASS,
29 "Failed to clean partition");
30 }
31
ZTEST(littlefs,test_fs_mkfs_simple_lfs)32 ZTEST(littlefs, test_fs_mkfs_simple_lfs)
33 {
34 cleanup(fs_mkfs_mp);
35
36 fs_mkfs_dev_id = (uintptr_t) testfs_small_mnt.storage_dev;
37 test_fs_mkfs_simple();
38 }
39
ZTEST(littlefs,test_fs_mkfs_ops_lfs)40 ZTEST(littlefs, test_fs_mkfs_ops_lfs)
41 {
42 cleanup(fs_mkfs_mp);
43
44 fs_mkfs_dev_id = (uintptr_t) testfs_small_mnt.storage_dev;
45 test_fs_mkfs_ops();
46 }
47
48 /* Custom config with doubled the prog size */
49 FS_LITTLEFS_DECLARE_CUSTOM_CONFIG(custom_cfg,
50 CONFIG_FS_LITTLEFS_READ_SIZE,
51 CONFIG_FS_LITTLEFS_PROG_SIZE * 2,
52 CONFIG_FS_LITTLEFS_CACHE_SIZE,
53 CONFIG_FS_LITTLEFS_LOOKAHEAD_SIZE);
54
ZTEST(littlefs,test_fs_mkfs_custom)55 ZTEST(littlefs, test_fs_mkfs_custom)
56 {
57 int ret = 0;
58 struct fs_statvfs sbuf;
59 struct fs_mount_t mnt = testfs_small_mnt;
60
61 cleanup(fs_mkfs_mp);
62
63 ret = fs_mkfs(FS_LITTLEFS, (uintptr_t)testfs_small_mnt.storage_dev, &custom_cfg, 0);
64 zassert_equal(ret, 0, "Expected success (ret=%d)", ret);
65
66 mnt.flags = FS_MOUNT_FLAG_NO_FORMAT;
67 mnt.fs_data = &custom_cfg;
68 ret = fs_mount(&mnt);
69 zassert_equal(ret, 0, "Expected success (ret=%d)", ret);
70
71 ret = fs_statvfs(mnt.mnt_point, &sbuf);
72 zassert_equal(ret, 0, "Expected success (ret=%d)", ret);
73
74 TC_PRINT("f_bsize= %lu", sbuf.f_bsize);
75 /* Prog size is returned in f_bsize field. */
76 zassert_equal(sbuf.f_bsize, 2 * CONFIG_FS_LITTLEFS_PROG_SIZE);
77
78 ret = fs_unmount(&mnt);
79 zassert_equal(ret, 0, "Expected success (ret=%d)", ret);
80 }
81