diff options
| author | Lukas Oesch <lukasoesch20@gmail.com> | 2026-06-09 11:40:45 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-07-14 22:08:22 +0200 |
| commit | 918e6eecfaefd94ccb2995cc526b2673263733b4 (patch) | |
| tree | 5e3ca0442ccff1edfd5bdc21ba43098e7603f785 /kernel/kapi | |
| parent | fcc3e7cef934f9a1532d4e2f6f011d60d41574ce (diff) | |
| download | kernel-918e6eecfaefd94ccb2995cc526b2673263733b4.tar.xz kernel-918e6eecfaefd94ccb2995cc526b2673263733b4.zip | |
add tests
Diffstat (limited to 'kernel/kapi')
| -rw-r--r-- | kernel/kapi/filesystem.tests.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/kernel/kapi/filesystem.tests.cpp b/kernel/kapi/filesystem.tests.cpp index b339f19f..595d73e8 100644 --- a/kernel/kapi/filesystem.tests.cpp +++ b/kernel/kapi/filesystem.tests.cpp @@ -211,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) < 0); + + REQUIRE(kapi::filesystem::create(new_file_path) == 0); + + auto fd = kapi::filesystem::open(new_file_path); + REQUIRE(fd >= 0); + + auto write_buffer = std::vector<std::byte>{std::byte{'T'}, std::byte{'e'}, std::byte{'s'}, std::byte{'t'}}; + kapi::filesystem::write(fd, write_buffer.data(), write_buffer.size()); + + REQUIRE(kapi::filesystem::close(fd) == 0); + + fd = kapi::filesystem::open(new_file_path); + REQUIRE(fd >= 0); + + 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) == 0); + } + + 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) < 0); + + REQUIRE(kapi::filesystem::mkdir(new_directory_path) == 0); + REQUIRE(kapi::filesystem::create(new_file_path) == 0); + + auto fd = kapi::filesystem::open(new_file_path); + REQUIRE(fd >= 0); + REQUIRE(kapi::filesystem::close(fd) == 0); + } + + THEN("a file can be created in a mounted filesystem, opened, and closed again") + { + kapi::filesystem::mount("/dev/ram16", "/information"); + + auto new_file_path = "/information/monkey_house/monkey_4.txt"; + REQUIRE(kapi::filesystem::open(new_file_path) < 0); + REQUIRE(kapi::filesystem::create(new_file_path) == 0); + + auto fd = kapi::filesystem::open(new_file_path); + REQUIRE(fd >= 0); + REQUIRE(kapi::filesystem::close(fd) == 0); + + REQUIRE(kapi::filesystem::umount("/information") == 0); + } } } |
