aboutsummaryrefslogtreecommitdiff
path: root/kernel/src/filesystem/vfs.tests.cpp
diff options
context:
space:
mode:
authorMarcel Braun <marcel.braun@ost.ch>2026-04-16 22:04:32 +0200
committerMarcel Braun <marcel.braun@ost.ch>2026-04-16 22:04:32 +0200
commitf642efb5cf199d3bbb8e3b01c451c71a1fbeabf8 (patch)
tree7e680dd885a59678d7075d352ee623f659d64d48 /kernel/src/filesystem/vfs.tests.cpp
parent3c210c07c60fbe9378cfb720847e8c1d3c763ead (diff)
parente70ea2357a80386b0a12138201b353d942910296 (diff)
downloadteachos-f642efb5cf199d3bbb8e3b01c451c71a1fbeabf8.tar.xz
teachos-f642efb5cf199d3bbb8e3b01c451c71a1fbeabf8.zip
Merge branch 'syscall-interface' into 'develop-BA-FS26'
Add fs syscall handler See merge request teachos/kernel!23
Diffstat (limited to 'kernel/src/filesystem/vfs.tests.cpp')
-rw-r--r--kernel/src/filesystem/vfs.tests.cpp99
1 files changed, 82 insertions, 17 deletions
diff --git a/kernel/src/filesystem/vfs.tests.cpp b/kernel/src/filesystem/vfs.tests.cpp
index f363041..12dce84 100644
--- a/kernel/src/filesystem/vfs.tests.cpp
+++ b/kernel/src/filesystem/vfs.tests.cpp
@@ -1,12 +1,14 @@
#include "kernel/filesystem/vfs.hpp"
-#include "kernel/devices/storage/management.hpp"
-#include "kernel/filesystem/filesystem.hpp"
#include "kernel/test_support/filesystem/storage_boot_module_vfs_fixture.hpp"
+#include <kstd/vector>
+
#include <catch2/catch_test_macros.hpp>
+#include <cstddef>
#include <filesystem>
+#include <string_view>
SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS with dummy modules",
"[filesystem][vfs]")
@@ -67,11 +69,6 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS
{image_path_1, image_path_2, image_path_3}));
auto & vfs = kernel::filesystem::vfs::get();
- auto storage_mgmt = kernel::devices::storage::management::get();
- auto device_1 = storage_mgmt.device_by_major_minor(1, 16);
- auto fs_1 = kernel::filesystem::filesystem::probe_and_mount(device_1);
- auto device_2 = storage_mgmt.device_by_major_minor(1, 32);
- auto fs_2 = kernel::filesystem::filesystem::probe_and_mount(device_2);
THEN("vfs initializes first module as root")
{
@@ -85,7 +82,7 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS
THEN("second image can be mounted, data retrieved and unmounted again")
{
- REQUIRE(vfs.do_mount("/information", fs_1) == kernel::filesystem::vfs::operation_result::success);
+ REQUIRE(vfs.do_mount("/dev/ram16", "/information") == kernel::filesystem::vfs::operation_result::success);
auto mounted_monkey_1 = vfs.open("/information/monkey_house/monkey_1.txt");
REQUIRE(mounted_monkey_1 != nullptr);
@@ -100,8 +97,8 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS
THEN("third image can be mounted in a mounted file system, unmount only if no child mount exists")
{
- REQUIRE(vfs.do_mount("/information", fs_1) == kernel::filesystem::vfs::operation_result::success);
- REQUIRE(vfs.do_mount("/information/monkey_house/infrastructure", fs_2) ==
+ REQUIRE(vfs.do_mount("/dev/ram16", "/information") == kernel::filesystem::vfs::operation_result::success);
+ REQUIRE(vfs.do_mount("/dev/ram32", "/information/monkey_house/infrastructure") ==
kernel::filesystem::vfs::operation_result::success);
auto mounted_monkey_1 = vfs.open("/information/monkey_house/monkey_1.txt");
@@ -118,8 +115,8 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS
THEN("images can be stacked mounted and correct file system is unmounted again")
{
- REQUIRE(vfs.do_mount("/information", fs_1) == kernel::filesystem::vfs::operation_result::success);
- REQUIRE(vfs.do_mount("/information", fs_2) == kernel::filesystem::vfs::operation_result::success);
+ REQUIRE(vfs.do_mount("/dev/ram16", "/information") == kernel::filesystem::vfs::operation_result::success);
+ REQUIRE(vfs.do_mount("/dev/ram32", "/information") == kernel::filesystem::vfs::operation_result::success);
auto mounted_tickets = vfs.open("/information/entrance/tickets.txt");
REQUIRE(mounted_tickets != nullptr);
@@ -134,19 +131,26 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS
THEN("mount with null file system fails")
{
- REQUIRE(vfs.do_mount("/information", nullptr) == kernel::filesystem::vfs::operation_result::filesystem_null);
+ REQUIRE(vfs.do_mount("/closed.txt", "/information") ==
+ kernel::filesystem::vfs::operation_result::invalid_filesystem);
}
THEN("mount with invalid path fails")
{
- REQUIRE(vfs.do_mount("", fs_1) == kernel::filesystem::vfs::operation_result::invalid_path);
- REQUIRE(vfs.do_mount("information", fs_1) == kernel::filesystem::vfs::operation_result::invalid_path);
- REQUIRE(vfs.do_mount("/information/", fs_1) == kernel::filesystem::vfs::operation_result::invalid_path);
+ REQUIRE(vfs.do_mount("/dev/ram16", "") == kernel::filesystem::vfs::operation_result::invalid_path);
+ REQUIRE(vfs.do_mount("/dev/ram16", "information") == kernel::filesystem::vfs::operation_result::invalid_path);
+ REQUIRE(vfs.do_mount("/dev/ram16", "/information/") == kernel::filesystem::vfs::operation_result::invalid_path);
+ }
+
+ THEN("mount with non-existent source path fails")
+ {
+ REQUIRE(vfs.do_mount("/dev/nonexistent", "/information") ==
+ kernel::filesystem::vfs::operation_result::non_existent_path);
}
THEN("mount with non-existent mount point fails")
{
- REQUIRE(vfs.do_mount("/information/nonexistent", fs_1) ==
+ REQUIRE(vfs.do_mount("/dev/ram16", "/information/nonexistent") ==
kernel::filesystem::vfs::operation_result::mount_point_not_found);
}
@@ -163,4 +167,65 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS
kernel::filesystem::vfs::operation_result::mount_point_not_found);
}
}
+
+ GIVEN("A real image file containing as filesystem formatted files")
+ {
+ REQUIRE(std::filesystem::exists(image_path_1));
+ REQUIRE_NOTHROW(setup_modules_from_img_and_init_vfs({"test_img_module_1"}, {image_path_1}));
+
+ THEN("the file-filesystem in the image can be mounted, files can be read and unmounted again")
+ {
+ auto & vfs = kernel::filesystem::vfs::get();
+ REQUIRE(vfs.do_mount("/archiv/2024.img", "/information") == kernel::filesystem::vfs::operation_result::success);
+
+ auto sheep_1 = vfs.open("/information/sheep_1.txt");
+ REQUIRE(sheep_1 != nullptr);
+
+ kstd::vector<std::byte> buffer(7);
+ auto bytes_read = sheep_1->read(buffer.data(), buffer.size());
+ std::string_view buffer_as_str{reinterpret_cast<char *>(buffer.data()), bytes_read};
+ REQUIRE(buffer_as_str == "sheep_1");
+
+ REQUIRE(vfs.unmount("/information") == kernel::filesystem::vfs::operation_result::success);
+ auto unmounted_sheep_1 = vfs.open("/information/sheep_1.txt");
+ REQUIRE(unmounted_sheep_1 == nullptr);
+ }
+
+ THEN("the file-filesystem in the image can be mounted and in this filesystem can another file-filesystem be "
+ "mounted, files can be read and unmounted again")
+ {
+ auto & vfs = kernel::filesystem::vfs::get();
+ REQUIRE(vfs.do_mount("/archiv/2024.img", "/information") == kernel::filesystem::vfs::operation_result::success);
+ REQUIRE(vfs.do_mount("/archiv/2025.img", "/information/stable") ==
+ kernel::filesystem::vfs::operation_result::success);
+
+ auto sheep_1 = vfs.open("/information/sheep_1.txt");
+ auto goat_1 = vfs.open("/information/stable/petting_zoo/goat_1.txt");
+ REQUIRE(sheep_1 != nullptr);
+ REQUIRE(goat_1 != nullptr);
+
+ kstd::vector<std::byte> sheep_buffer(7);
+ auto bytes_read = sheep_1->read(sheep_buffer.data(), sheep_buffer.size());
+ std::string_view buffer_as_str{reinterpret_cast<char *>(sheep_buffer.data()), bytes_read};
+ REQUIRE(buffer_as_str == "sheep_1");
+
+ kstd::vector<std::byte> goat_buffer(6);
+ bytes_read = goat_1->read(goat_buffer.data(), goat_buffer.size());
+ buffer_as_str = std::string_view{reinterpret_cast<char *>(goat_buffer.data()), bytes_read};
+ REQUIRE(buffer_as_str == "goat_1");
+
+ REQUIRE(vfs.unmount("/information") == kernel::filesystem::vfs::operation_result::unmount_failed);
+
+ REQUIRE(vfs.unmount("/information/stable") == kernel::filesystem::vfs::operation_result::success);
+ auto unmounted_goat_1 = vfs.open("/information/stable/petting_zoo/goat_1.txt");
+ REQUIRE(unmounted_goat_1 == nullptr);
+
+ auto still_mounted_sheep_1 = vfs.open("/information/sheep_1.txt");
+ REQUIRE(still_mounted_sheep_1 != nullptr);
+
+ REQUIRE(vfs.unmount("/information") == kernel::filesystem::vfs::operation_result::success);
+ auto unmounted_sheep_1 = vfs.open("/information/sheep_1.txt");
+ REQUIRE(unmounted_sheep_1 == nullptr);
+ }
+ }
}