aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Oesch <lukasoesch20@gmail.com>2026-05-30 22:47:16 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-07-14 20:18:24 +0200
commitefdb44b9ca98ccea925a4fbf51b0b1a9960570b2 (patch)
tree55371aaf114a058d7d996e95b8b0128bc3320b6f
parent08e84e373004e46ed00173b63ba16be123faf4b8 (diff)
downloadkernel-efdb44b9ca98ccea925a4fbf51b0b1a9960570b2.tar.xz
kernel-efdb44b9ca98ccea925a4fbf51b0b1a9960570b2.zip
add inode write tests with real filesystem image
-rw-r--r--kernel/kernel/filesystem/ext2/inode.tests.cpp27
1 files changed, 26 insertions, 1 deletions
diff --git a/kernel/kernel/filesystem/ext2/inode.tests.cpp b/kernel/kernel/filesystem/ext2/inode.tests.cpp
index 7b00dae1..8341dbbf 100644
--- a/kernel/kernel/filesystem/ext2/inode.tests.cpp
+++ b/kernel/kernel/filesystem/ext2/inode.tests.cpp
@@ -303,7 +303,7 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_fixture, "Ext2 in
REQUIRE(file);
REQUIRE(file.value()->is_regular());
- THEN("writing to the inode updates backing device")
+ THEN("writing to the inode updates backing device and the inode size")
{
auto write_buffer = kstd::vector<std::byte>{std::byte{'H'}, std::byte{'e'}, std::byte{'l'}, std::byte{'l'},
std::byte{'o'}, std::byte{' '}, std::byte{'W'}, std::byte{'o'},
@@ -318,6 +318,31 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_fixture, "Ext2 in
auto const text = std::string_view{reinterpret_cast<char const *>(read_buffer.data()), *bytes_read};
REQUIRE(text == "Hello World!");
+
+ auto inode_data = static_cast<kernel::filesystem::ext2::inode *>(file.get())->data();
+ REQUIRE(inode_data.size == bytes_read);
+ }
+
+ THEN("writing allocates new blocks and updates the inode size")
+ {
+ auto inode_data = static_cast<kernel::filesystem::ext2::inode *>(file.get())->data();
+
+ auto const block_size = fs.block_size();
+ auto const expected_allocated_blocks = 32 * fs.inode_block_count(inode_data);
+
+ auto write_buffer = kstd::vector<std::byte>(block_size * expected_allocated_blocks, std::byte{'A'});
+
+ auto const bytes_written = file->write(write_buffer.data(), 0, write_buffer.size());
+ REQUIRE(bytes_written == block_size * expected_allocated_blocks);
+
+ auto read_buffer = kstd::vector<std::byte>(block_size * expected_allocated_blocks, std::byte{0x00});
+ auto const bytes_read = file->read(read_buffer.data(), 0, read_buffer.size());
+ REQUIRE(bytes_read == block_size * expected_allocated_blocks);
+ REQUIRE(std::ranges::all_of(read_buffer, [](std::byte c) { return c == std::byte{'A'}; }));
+
+ auto new_inode_data = static_cast<kernel::filesystem::ext2::inode *>(file.get())->data();
+ REQUIRE(new_inode_data.size == write_buffer.size());
+ REQUIRE(fs.inode_block_count(new_inode_data) == expected_allocated_blocks);
}
THEN("writing to a an inode of type directory panics")