aboutsummaryrefslogtreecommitdiff
path: root/kernel/kapi/filesystem.tests.cpp
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-07-15 09:27:43 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-07-15 09:27:43 +0200
commitd7ad126367675fb50276f96db760dd1af8332352 (patch)
treeffa17592e4eff7ad60d3d8e05c54496590ce98c6 /kernel/kapi/filesystem.tests.cpp
parentd6735726d9cc6e98142e94001250076592279d36 (diff)
parent8170017c8fcea4b9047c7a1d586bb82473c1eed5 (diff)
downloadkernel-d7ad126367675fb50276f96db760dd1af8332352.tar.xz
kernel-d7ad126367675fb50276f96db760dd1af8332352.zip
Merge branch 'experimental/ext2-write-support' into 'develop'
ext2: add basic write support See merge request teachos/kernel!55
Diffstat (limited to 'kernel/kapi/filesystem.tests.cpp')
-rw-r--r--kernel/kapi/filesystem.tests.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/kernel/kapi/filesystem.tests.cpp b/kernel/kapi/filesystem.tests.cpp
index d1e01db6..f2a6a988 100644
--- a/kernel/kapi/filesystem.tests.cpp
+++ b/kernel/kapi/filesystem.tests.cpp
@@ -39,6 +39,30 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "Kap
REQUIRE(kapi::filesystem::close(fd));
}
+ THEN("files can be opened, written to, read from and closed again")
+ {
+ auto write_fd = kapi::filesystem::open("/information/info_1.txt");
+ REQUIRE(write_fd);
+
+ auto write_buffer = std::vector<std::byte>{std::byte{'H'}, std::byte{'e'}};
+
+ auto const bytes_written = kapi::filesystem::write(*write_fd, write_buffer.data(), write_buffer.size());
+ REQUIRE(bytes_written == 2);
+
+ auto read_fd = kapi::filesystem::open("/information/info_1.txt");
+ REQUIRE(read_fd);
+
+ auto read_buffer = std::vector<std::byte>(6);
+ auto const bytes_read = kapi::filesystem::read(*read_fd, read_buffer.data(), read_buffer.size());
+ REQUIRE(bytes_read);
+
+ std::string_view buffer_as_str{reinterpret_cast<char *>(read_buffer.data()), static_cast<size_t>(*bytes_read)};
+ REQUIRE(buffer_as_str == "Hefo_1");
+
+ REQUIRE(kapi::filesystem::close(*write_fd));
+ REQUIRE(kapi::filesystem::close(*read_fd));
+ }
+
THEN("files can be opened through absolute symbolic link, read and closed again")
{
auto fd = kapi::filesystem::open("/symlinks/information_directory_absolute/info_1.txt").value();
@@ -187,5 +211,63 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "Kap
auto bytes_written = kapi::filesystem::write(invalid_fd, buffer.data(), buffer.size());
REQUIRE(!bytes_written);
}
+
+ THEN("a new file can be created, written to, read from, and closed again")
+ {
+ auto new_file_path = "/information/new_information.txt";
+
+ REQUIRE(!kapi::filesystem::open(new_file_path));
+
+ REQUIRE(kapi::filesystem::create(new_file_path));
+
+ auto fd = kapi::filesystem::open(new_file_path);
+ REQUIRE(fd);
+
+ auto write_buffer = std::vector<std::byte>{std::byte{'T'}, std::byte{'e'}, std::byte{'s'}, std::byte{'t'}};
+ CHECK(kapi::filesystem::write(*fd, write_buffer.data(), write_buffer.size()));
+
+ REQUIRE(kapi::filesystem::close(*fd));
+
+ fd = kapi::filesystem::open(new_file_path);
+ REQUIRE(fd);
+
+ auto read_buffer = std::vector<std::byte>(4);
+ auto bytes_read = kapi::filesystem::read(*fd, read_buffer.data(), read_buffer.size());
+
+ std::string_view buffer_as_str{reinterpret_cast<char *>(read_buffer.data()), static_cast<size_t>(*bytes_read)};
+ REQUIRE(buffer_as_str == "Test");
+
+ REQUIRE(kapi::filesystem::close(*fd));
+ }
+
+ THEN("a new directory can be created and a file within can be created, opened, and closed again")
+ {
+ auto new_directory_path = "/information/new_directory";
+ auto new_file_path = "/information/new_directory/new_information.txt";
+
+ REQUIRE(!kapi::filesystem::open(new_file_path));
+
+ REQUIRE(kapi::filesystem::mkdir(new_directory_path));
+ REQUIRE(kapi::filesystem::create(new_file_path));
+
+ auto fd = kapi::filesystem::open(new_file_path);
+ REQUIRE(fd);
+ REQUIRE(kapi::filesystem::close(*fd));
+ }
+
+ THEN("a file can be created in a mounted filesystem, opened, and closed again")
+ {
+ CHECK(kapi::filesystem::mount("/dev/ram16", "/information"));
+
+ auto new_file_path = "/information/monkey_house/monkey_4.txt";
+ REQUIRE(!kapi::filesystem::open(new_file_path));
+ REQUIRE(kapi::filesystem::create(new_file_path));
+
+ auto fd = kapi::filesystem::open(new_file_path);
+ REQUIRE(fd);
+ REQUIRE(kapi::filesystem::close(*fd));
+
+ REQUIRE(kapi::filesystem::umount("/information"));
+ }
}
}