1#include "fs/ext2/tests/test_internal.h"
2
3TEST_GROUP_DECLARE(ext2, .intensity_desc = {
4 .curve = SCALE_PIECEWISE_LOG,
5 .unit = "ops",
6 });
7
8#define EXT2_INIT \
9 if (global.root_node->fs_type != FS_EXT2) { \
10 test_info("the mounted root is not ext2"); \
11 return TEST_SKIP(TEST_SKIP_NONE); \
12 } \
13 struct vfs_node *root = global.root_node;
14
15static void flush() {
16 struct ext2_fs *fs = global.root_node->fs_data;
17 struct block_device *d = fs->drive;
18
19 bio_sched_dispatch_all(disk: d);
20}
21
22TEST_DECLARE_INTEGRATION(ext2, stat, TEST_INTENSITY(1, 1, 16)) {
23 EXT2_INIT;
24
25 TEST_ASSERT(!ERR_IS_FATAL(
26 root->ops->create(root, "ext2_stat_test", VFS_MODE_FILE)));
27
28 struct vfs_node *node;
29 struct vfs_dirent out;
30
31 TEST_ASSERT(
32 !ERR_IS_FATAL(root->ops->finddir(root, "ext2_stat_test", &out)));
33
34 node = out.node;
35 TEST_ASSERT_NONNULL(node);
36
37 struct vfs_stat empty_stat = {0};
38 struct vfs_stat stat_out = {0};
39 node->ops->stat(node, &stat_out);
40
41 /* this should return something */
42 TEST_ASSERT_NE(memcmp(&stat_out, &empty_stat, sizeof(struct vfs_stat)), 0);
43
44 flush();
45 return TEST_SUCCESS;
46}
47
48TEST_DECLARE_INTEGRATION(ext2, rename, TEST_INTENSITY(1, 1, 16)) {
49 EXT2_INIT;
50
51 TEST_ASSERT(!ERR_IS_FATAL(
52 root->ops->create(root, "ext2_rename_test", VFS_MODE_FILE)));
53
54 struct vfs_dirent out;
55 struct vfs_node *node;
56
57 TEST_ASSERT(
58 !ERR_IS_FATAL(root->ops->finddir(root, "ext2_rename_test", &out)));
59
60 node = out.node;
61 TEST_ASSERT_NONNULL(node);
62
63 TEST_ASSERT(!ERR_IS_FATAL(node->ops->rename(root, "ext2_rename_test", root,
64 "ext2_rename_test2")));
65
66 enum errno e = root->ops->finddir(root, "ext2_rename_test", &out);
67 TEST_ASSERT_EQ_S(e, ERR_NO_ENT);
68
69 TEST_ASSERT(
70 !ERR_IS_FATAL(root->ops->finddir(root, "ext2_rename_test2", &out)));
71
72 node = out.node;
73 TEST_ASSERT_NONNULL(node);
74
75 flush();
76 return TEST_SUCCESS;
77}
78
79TEST_DECLARE_INTEGRATION(ext2, chmod, TEST_INTENSITY(1, 1, 16)) {
80 EXT2_INIT;
81
82 TEST_ASSERT(!ERR_IS_FATAL(
83 root->ops->create(root, "ext2_chmod_test", VFS_MODE_FILE)));
84
85 struct vfs_node *node;
86 struct vfs_dirent ent;
87
88 TEST_ASSERT(
89 !ERR_IS_FATAL(root->ops->finddir(root, "ext2_chmod_test", &ent)));
90
91 node = ent.node;
92 TEST_ASSERT_NONNULL(node);
93
94 TEST_ASSERT(
95 !ERR_IS_FATAL(root->ops->chmod(node, (uint16_t) VFS_MODE_O_EXEC)));
96 TEST_ASSERT(node->mode & VFS_MODE_O_EXEC);
97
98 TEST_ASSERT(
99 !ERR_IS_FATAL(root->ops->finddir(root, "ext2_chmod_test", &ent)));
100
101 node = ent.node;
102 TEST_ASSERT_NONNULL(node);
103 TEST_ASSERT(node->mode & VFS_MODE_O_EXEC);
104
105 flush();
106 return TEST_SUCCESS;
107}
108
109TEST_DECLARE_INTEGRATION(ext2, symlink, TEST_INTENSITY(1, 1, 16)) {
110 EXT2_INIT;
111
112 TEST_ASSERT(
113 !ERR_IS_FATAL(root->ops->symlink(root, "/tmp", "ext2_symlink_test")));
114
115 struct vfs_dirent ent;
116 struct vfs_node *node;
117
118 TEST_ASSERT(
119 !ERR_IS_FATAL(root->ops->finddir(root, "ext2_symlink_test", &ent)));
120
121 node = ent.node;
122 TEST_ASSERT_NONNULL(node);
123
124 char *buf = kmalloc(5, ALLOC_FLAGS_ZERO);
125 TEST_ASSERT_NONNULL(buf);
126
127 TEST_ASSERT(!ERR_IS_FATAL(node->ops->readlink(node, buf, 4)));
128
129 TEST_ASSERT_STR_EQ(buf, "/tmp");
130
131 flush();
132 return TEST_SUCCESS;
133}
134
135TEST_DECLARE_INTEGRATION(ext2, mkdir_rmdir, TEST_INTENSITY(1, 1, 16)) {
136 EXT2_INIT;
137
138 TEST_ASSERT(
139 !ERR_IS_FATAL(root->ops->mkdir(root, "ext2_dir_test", VFS_MODE_DIR)));
140
141 struct vfs_dirent ent;
142 struct vfs_node *node;
143
144 TEST_ASSERT(!ERR_IS_FATAL(root->ops->finddir(root, "ext2_dir_test", &ent)));
145
146 node = ent.node;
147 TEST_ASSERT_NONNULL(node);
148
149 TEST_ASSERT(!ERR_IS_FATAL(root->ops->rmdir(root, "ext2_dir_test")));
150
151 flush();
152 return TEST_SUCCESS;
153}
154