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 4,
51 CONFIG_FS_LITTLEFS_READ_SIZE,
52 CONFIG_FS_LITTLEFS_PROG_SIZE * 2,
53 CONFIG_FS_LITTLEFS_CACHE_SIZE,
54 CONFIG_FS_LITTLEFS_LOOKAHEAD_SIZE);
55
ZTEST(littlefs,test_fs_mkfs_custom)56 ZTEST(littlefs, test_fs_mkfs_custom)
57 {
58 int ret = 0;
59 struct fs_statvfs sbuf;
60 struct fs_mount_t mnt = testfs_small_mnt;
61
62 cleanup(fs_mkfs_mp);
63
64 ret = fs_mkfs(FS_LITTLEFS, (uintptr_t)testfs_small_mnt.storage_dev, &custom_cfg, 0);
65 zassert_equal(ret, 0, "Expected success (ret=%d)", ret);
66
67 mnt.flags = FS_MOUNT_FLAG_NO_FORMAT;
68 mnt.fs_data = &custom_cfg;
69 ret = fs_mount(&mnt);
70 zassert_equal(ret, 0, "Expected success (ret=%d)", ret);
71
72 ret = fs_statvfs(mnt.mnt_point, &sbuf);
73 zassert_equal(ret, 0, "Expected success (ret=%d)", ret);
74
75 TC_PRINT("f_bsize= %lu", sbuf.f_bsize);
76 /* Prog size is returned in f_bsize field. */
77 zassert_equal(sbuf.f_bsize, 2 * CONFIG_FS_LITTLEFS_PROG_SIZE);
78
79 ret = fs_unmount(&mnt);
80 zassert_equal(ret, 0, "Expected success (ret=%d)", ret);
81 }
82