21 const size_t blk_count = DeviceManagerSingleton::instance().FindDevicesByType(
23 if (blk_count == 0 || blk_nodes[0]->block_device ==
nullptr) {
25 "fatfs_system_test: SKIP — no virtio-blk device "
32 "fatfs_system_test: virtio-blk has zero sectors");
38 EXPECT_TRUE(init_result.has_value(),
"fatfs_system_test: vfs init failed");
46 auto fat_mount = fat_fs.
Mount(blk);
48 "fatfs_system_test: FatFsFileSystem::Mount failed");
49 klog::Info(
"fatfs_system_test: FatFsFileSystem::Mount ok");
53 "fatfs_system_test: vfs mount at /mnt/fat failed");
54 klog::Info(
"fatfs_system_test: vfs mount at /mnt/fat ok");
62 "fatfs_system_test: open /mnt/fat/test.txt failed");
65 const char kMsg[] =
"Hello, FatFS!";
66 auto write_result =
vfs::Write(file, kMsg,
sizeof(kMsg) - 1);
68 "fatfs_system_test: write to /mnt/fat/test.txt failed");
69 EXPECT_EQ(write_result.value(),
sizeof(kMsg) - 1,
70 "fatfs_system_test: write byte count mismatch");
71 klog::Info(
"fatfs_system_test: wrote {} bytes to /mnt/fat/test.txt",
72 write_result.value());
82 "fatfs_system_test: re-open /mnt/fat/test.txt failed");
86 const char kMsg[] =
"Hello, FatFS!";
87 auto read_result =
vfs::Read(file, buf,
sizeof(buf) - 1);
89 "fatfs_system_test: read from /mnt/fat/test.txt failed");
90 EXPECT_EQ(read_result.value(),
sizeof(kMsg) - 1,
91 "fatfs_system_test: read byte count mismatch");
93 "fatfs_system_test: read content mismatch");
94 klog::Info(
"fatfs_system_test: verified read: {}", buf);
101 auto mkdir_result =
vfs::MkDir(
"/mnt/fat/subdir");
103 "fatfs_system_test: mkdir /mnt/fat/subdir failed");
104 klog::Info(
"fatfs_system_test: mkdir /mnt/fat/subdir ok");
111 "fatfs_system_test: create /mnt/fat/subdir/inner.txt failed");
112 if (inner.has_value()) {
120 "fatfs_system_test: open /mnt/fat as dir failed");
121 if (dir_file.has_value()) {
123 auto readdir_result =
vfs::ReadDir(dir_file.value(), entries, 16);
125 "fatfs_system_test: readdir /mnt/fat failed");
127 EXPECT_GT(readdir_result.value(),
static_cast<size_t>(1),
128 "fatfs_system_test: readdir /mnt/fat should return > 1 entry");
129 klog::Info(
"fatfs_system_test: readdir /mnt/fat returned {} entries",
130 readdir_result.value());
137 auto unmount_result = fat_fs.
Unmount();
139 "fatfs_system_test: FatFsFileSystem::Unmount failed");
140 klog::Info(
"fatfs_system_test: unmounted ok");
143 auto remount_result = fat_fs.
Mount(blk);
145 "fatfs_system_test: remount failed");
146 klog::Info(
"fatfs_system_test: remounted ok");
151 "fatfs_system_test: vfs remount failed");
157 "fatfs_system_test: test.txt not found after remount");
158 if (file_result.has_value()) {
160 const char kMsg[] =
"Hello, FatFS!";
161 auto read_result =
vfs::Read(file_result.value(), buf,
sizeof(buf) - 1);
163 "fatfs_system_test: read after remount failed");
165 "fatfs_system_test: data corrupted after remount");
166 klog::Info(
"fatfs_system_test: persistence verified: {}", buf);
171 klog::Info(
"fatfs_system_test: all tests passed");