1#include "fs/ext2/tests/test_internal.h"
2
3#define EXT2_INIT \
4 if (global.root_node->fs_type != FS_EXT2) { \
5 test_info("the mounted root is not ext2"); \
6 return TEST_SKIP(TEST_SKIP_NONE); \
7 } \
8 struct vfs_node *root = global.root_node;
9
10/*
11static void check_bcache(void) {
12 struct ext2_fs *fs = g_root_node->fs_data;
13 struct generic_disk *d = fs->drive;
14
15 uint64_t bcache_total_dirty = 42;
16 uint64_t bcache_total_present = 37;
17
18 bcache_stat(d, &bcache_total_dirty, &bcache_total_present);
19
20 char *msg = kmalloc(100);
21 snprintf(msg, 100, "Block cache has %d dirty entries and %d total entries",
22 bcache_total_dirty, bcache_total_present);
23
24 test_info(msg);
25
26 TEST_ASSERT_EQ(bcache_total_dirty, 0);
27}*/
28
29static void flush() {
30 struct ext2_fs *fs = global.root_node->fs_data;
31 struct block_device *d = fs->drive;
32
33 bio_sched_dispatch_all(disk: d);
34
35 /*
36 sleep_ms(500);
37 check_bcache();*/
38}
39
40TEST_DECLARE_INTEGRATION(ext2, file_lifecycle, TEST_INTENSITY(1, 4, 64)) {
41 EXT2_INIT;
42
43 size_t ops = ctx->intensity_val ? ctx->intensity_val : 4;
44 const char *lstr = large_test_string;
45 uint64_t len = strlen(str: lstr);
46 char *out_buf = kmalloc(len + 1, ALLOC_FLAGS_ZERO);
47 TEST_ASSERT_NONNULL(out_buf);
48
49 for (size_t iter = 0; iter < ops; iter++) {
50 char fname[32];
51 snprintf(buffer: fname, buffer_len: sizeof(fname), format: "ext2_test_%zu", iter);
52
53 TEST_ASSERT(
54 !ERR_IS_FATAL(root->ops->create(root, fname, VFS_MODE_FILE)));
55
56 struct vfs_dirent ent;
57 struct vfs_node *node;
58 TEST_ASSERT(!ERR_IS_FATAL(root->ops->finddir(root, fname, &ent)));
59
60 node = ent.node;
61 TEST_ASSERT_NONNULL(node);
62
63 TEST_ASSERT(!ERR_IS_FATAL(node->ops->write(node, lstr, len, 0)));
64 TEST_ASSERT_EQ(node->size, len);
65
66 memset(out_buf, 0, len + 1);
67 TEST_ASSERT(!ERR_IS_FATAL(node->ops->read(node, out_buf, len, 0)));
68 TEST_ASSERT_MEM_EQ(out_buf, lstr, len);
69
70 TEST_ASSERT(!ERR_IS_FATAL(node->ops->truncate(node, len / 2)));
71
72 memset(out_buf, 0, len + 1);
73 TEST_ASSERT(!ERR_IS_FATAL(node->ops->read(node, out_buf, len, 0)));
74 TEST_ASSERT_EQ(strlen(out_buf), len / 2);
75
76 TEST_ASSERT(!ERR_IS_FATAL(node->ops->unlink(root, fname)));
77
78 enum errno e = root->ops->finddir(root, fname, &ent);
79 TEST_ASSERT_EQ_S(e, ERR_NO_ENT);
80 }
81
82 kfree(out_buf);
83 flush();
84
85 return TEST_SUCCESS;
86}
87