1 /*
2 * Copyright (c) 2023 Antmicro
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/ztest.h>
8 #include <zephyr/fs/fs.h>
9 #include <zephyr/fs/ext2.h>
10
11 #include "utils.h"
12
13 void test_fs_open_flags(void);
14
15 /* Expected by test_fs_open_flags() */
16 const char *test_fs_open_flags_file_path = "/sml/open_flags_file";
17
ZTEST(ext2tests,test_open_flags)18 ZTEST(ext2tests, test_open_flags)
19 {
20 struct fs_mount_t *mp = &testfs_mnt;
21
22 zassert_equal(fs_mount(mp), 0, "Failed to mount partition");
23
24 test_fs_open_flags();
25
26 zassert_equal(fs_unmount(mp), 0, "Failed to unmount partition");
27 }
28
ZTEST(ext2tests,test_open_flags_2K)29 ZTEST(ext2tests, test_open_flags_2K)
30 {
31 int ret = 0;
32 struct fs_mount_t *mp = &testfs_mnt;
33 struct ext2_cfg ext2_config = {
34 .block_size = 2048,
35 .fs_size = 0x2000000,
36 .bytes_per_inode = 0,
37 .volume_name[0] = 0,
38 .set_uuid = false,
39 };
40
41 ret = fs_mkfs(FS_EXT2, (uintptr_t)mp->storage_dev, &ext2_config, 0);
42 zassert_equal(ret, 0, "Failed to mkfs with 2K blocks");
43
44 mp->flags = FS_MOUNT_FLAG_NO_FORMAT;
45 zassert_equal(fs_mount(mp), 0, "Failed to mount partition");
46
47 test_fs_open_flags();
48
49 zassert_equal(fs_unmount(mp), 0, "Failed to unmount partition");
50 }
51
52 #if defined(CONFIG_APP_TEST_BIG)
ZTEST(ext2tests,test_open_flags_4K)53 ZTEST(ext2tests, test_open_flags_4K)
54 {
55 int ret = 0;
56 struct fs_mount_t *mp = &testfs_mnt;
57 struct ext2_cfg ext2_config = {
58 .block_size = 4096,
59 .fs_size = 0x8000000,
60 .bytes_per_inode = 0,
61 .volume_name[0] = 0,
62 .set_uuid = false,
63 };
64
65 ret = fs_mkfs(FS_EXT2, (uintptr_t)mp->storage_dev, &ext2_config, 0);
66 zassert_equal(ret, 0, "Failed to mkfs with 2K blocks");
67
68 mp->flags = FS_MOUNT_FLAG_NO_FORMAT;
69 zassert_equal(fs_mount(mp), 0, "Failed to mount partition");
70
71 test_fs_open_flags();
72
73 zassert_equal(fs_unmount(mp), 0, "Failed to unmount partition");
74 }
75 #endif
76