aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Oesch <lukasoesch20@gmail.com>2026-04-14 08:44:41 +0200
committerLukas Oesch <lukasoesch20@gmail.com>2026-04-14 08:44:41 +0200
commit5354654a486296be674ecc7ba5e92ca01cc29107 (patch)
tree6bd1c2c7cdc4d4cf5ce30adad9a7ceab9b59de17
parent5e183b418b0e65dcdffa02a43702a0d6deb43b04 (diff)
downloadteachos-5354654a486296be674ecc7ba5e92ca01cc29107.tar.xz
teachos-5354654a486296be674ecc7ba5e92ca01cc29107.zip
add tests to mount filesystems backed by a file
-rw-r--r--arch/x86_64/support/modules/README.md26
-rw-r--r--arch/x86_64/support/modules/ext2_1KB_fs.img2
-rw-r--r--kernel/src/filesystem/vfs.tests.cpp67
-rw-r--r--kernel/src/test_support/filesystem/test_assets/ext2_1KB_fs.img2
4 files changed, 93 insertions, 4 deletions
diff --git a/arch/x86_64/support/modules/README.md b/arch/x86_64/support/modules/README.md
index f3955fa..fb64767 100644
--- a/arch/x86_64/support/modules/README.md
+++ b/arch/x86_64/support/modules/README.md
@@ -5,11 +5,37 @@ The ext2_4KB_fs image is intentionally fragmented, as some files were created an
## ext2_1KB_fs
.
./lost+found
+./archiv
+./archiv/2024.img
+./archiv/2025.img
./information
./information/info_1.txt
./information/info_2.txt
./closed.txt
+### 2024.img
+(2KB Block size)
+.
+./lost+found
+./sheep_1.txt
+./sheep_2.txt
+./stable/pig_1.txt
+./stable/pig_2.txt
+./stable/pig_3.txt
+
+### 2025.img
+(4KB Block size)
+.
+./lost+found
+./snake_1.txt
+./snake_2.txt
+./petting_zoo/goat_1.txt
+./petting_zoo/goat_2.txt
+./petting_zoo/chicken_coop
+./petting_zoo/chicken_coop/chicken_1.txt
+./petting_zoo/chicken_coop/chicken_2.txt
+./petting_zoo/chicken_coop/chicken_3.txt
+
## ext2_2KB_fs
.
./lost+found
diff --git a/arch/x86_64/support/modules/ext2_1KB_fs.img b/arch/x86_64/support/modules/ext2_1KB_fs.img
index 9f1ee4a..5bbb76d 100644
--- a/arch/x86_64/support/modules/ext2_1KB_fs.img
+++ b/arch/x86_64/support/modules/ext2_1KB_fs.img
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
-oid sha256:94d3988bc309eb9e81f06042c72bf4c4fb5991cd7fdd597eb00c518a96c792d8
+oid sha256:c2ef9536a439825520d9e230eedaa9ae327f9763350eddbc0f24bf5b9b5d2bf2
size 10485760
diff --git a/kernel/src/filesystem/vfs.tests.cpp b/kernel/src/filesystem/vfs.tests.cpp
index 8c963c6..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]")
@@ -165,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);
+ }
+ }
}
diff --git a/kernel/src/test_support/filesystem/test_assets/ext2_1KB_fs.img b/kernel/src/test_support/filesystem/test_assets/ext2_1KB_fs.img
index 9f1ee4a..5bbb76d 100644
--- a/kernel/src/test_support/filesystem/test_assets/ext2_1KB_fs.img
+++ b/kernel/src/test_support/filesystem/test_assets/ext2_1KB_fs.img
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
-oid sha256:94d3988bc309eb9e81f06042c72bf4c4fb5991cd7fdd597eb00c518a96c792d8
+oid sha256:c2ef9536a439825520d9e230eedaa9ae327f9763350eddbc0f24bf5b9b5d2bf2
size 10485760