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