aboutsummaryrefslogtreecommitdiff
path: root/kernel/src/filesystem/mount.tests.cpp
diff options
context:
space:
mode:
authorLukas Oesch <lukas.oesch@ost.ch>2026-06-10 10:40:46 +0200
committerLukas Oesch <lukas.oesch@ost.ch>2026-06-10 10:40:46 +0200
commit33abd5cf264cb9e34121082105b0bc17b3cf7a36 (patch)
tree36b15d53fea04f4f9d9af817100f7ad013bd9b5c /kernel/src/filesystem/mount.tests.cpp
parentd01caf1c4aef3c89c68b9d1cc9fe56445f0860b5 (diff)
parent7e27130c342b7299a1d2188a7192a7f17b5ac2ad (diff)
downloadkernel-33abd5cf264cb9e34121082105b0bc17b3cf7a36.tar.xz
kernel-33abd5cf264cb9e34121082105b0bc17b3cf7a36.zip
Merge branch 'develop-BA-FS26' into 'develop'HEADdevelop
Merge of BA-FS26 branch into develop See merge request teachos/kernel!49
Diffstat (limited to 'kernel/src/filesystem/mount.tests.cpp')
-rw-r--r--kernel/src/filesystem/mount.tests.cpp94
1 files changed, 94 insertions, 0 deletions
diff --git a/kernel/src/filesystem/mount.tests.cpp b/kernel/src/filesystem/mount.tests.cpp
new file mode 100644
index 0000000..c9ff82e
--- /dev/null
+++ b/kernel/src/filesystem/mount.tests.cpp
@@ -0,0 +1,94 @@
+#include <kernel/filesystem/mount.hpp>
+
+#include <kernel/filesystem/dentry.hpp>
+#include <kernel/test_support/cpu.hpp>
+#include <kernel/test_support/filesystem/filesystem.hpp>
+#include <kernel/test_support/filesystem/inode.hpp>
+
+#include <kstd/memory>
+#include <kstd/print>
+#include <kstd/vector>
+
+#include <catch2/catch_test_macros.hpp>
+
+#include <stdexcept>
+
+SCENARIO("Mount construction", "[filesystem][mount]")
+{
+ GIVEN("a filesystem and a root dentry")
+ {
+ auto fs = kstd::make_shared<kernel::tests::filesystem::filesystem>();
+ auto root_inode = kstd::make_shared<kernel::tests::filesystem::inode>();
+ auto root_dentry = kstd::make_shared<kernel::filesystem::dentry>(nullptr, root_inode, "/");
+
+ WHEN("constructing a mount with the filesystem and root dentry")
+ {
+ auto mount = kernel::filesystem::mount{root_dentry, root_dentry, fs, nullptr, nullptr};
+
+ THEN("the mount has the correct filesystem, root dentry, mount dentry, and mount path")
+ {
+ REQUIRE(mount.get_filesystem() == fs);
+ REQUIRE(mount.root_dentry() == root_dentry);
+ REQUIRE(mount.mount_dentry() == root_dentry);
+ REQUIRE(mount.mount_path() == "/");
+ REQUIRE(mount.is_ready_to_unmount());
+ }
+
+ THEN("the mount has no parent mount and no source mount")
+ {
+ REQUIRE(mount.parent_mount() == nullptr);
+ REQUIRE(mount.source_mount() == nullptr);
+ }
+ }
+
+ WHEN("constructing a mount with a null filesystem")
+ {
+ THEN("the constructor panics")
+ {
+ REQUIRE_THROWS_AS((kernel::filesystem::mount{root_dentry, root_dentry, nullptr, nullptr, nullptr}),
+ kernel::tests::cpu::halt);
+ }
+ }
+ }
+}
+
+SCENARIO("Mount reference counting", "[filesystem][mount]")
+{
+ GIVEN("a filesystem and a root dentry")
+ {
+ auto fs = kstd::make_shared<kernel::tests::filesystem::filesystem>();
+ auto root_inode = kstd::make_shared<kernel::tests::filesystem::inode>();
+ auto root_dentry = kstd::make_shared<kernel::filesystem::dentry>(nullptr, root_inode, "/");
+
+ THEN("reference count can be incremented and decremented, the mount is ready to unmount when the reference "
+ "count == 0")
+ {
+ auto mount = kernel::filesystem::mount{root_dentry, root_dentry, fs, nullptr, nullptr};
+
+ mount.increment_ref_count();
+ REQUIRE(mount.ref_count() == 1);
+ REQUIRE_FALSE(mount.is_ready_to_unmount());
+
+ mount.increment_ref_count();
+ REQUIRE(mount.ref_count() == 2);
+ REQUIRE_FALSE(mount.is_ready_to_unmount());
+
+ mount.decrement_ref_count();
+ REQUIRE(mount.ref_count() == 1);
+ REQUIRE_FALSE(mount.is_ready_to_unmount());
+
+ mount.decrement_ref_count();
+ REQUIRE(mount.ref_count() == 0);
+ REQUIRE(mount.is_ready_to_unmount());
+ }
+
+ THEN("decrementing reference count when it is already zero does not decrement it below zero")
+ {
+ auto mount = kernel::filesystem::mount{root_dentry, root_dentry, fs, nullptr, nullptr};
+
+ REQUIRE_THROWS_AS(mount.decrement_ref_count(), std::runtime_error);
+ REQUIRE(mount.ref_count() == 0);
+ REQUIRE(mount.is_ready_to_unmount());
+ }
+ }
+} \ No newline at end of file