aboutsummaryrefslogtreecommitdiff
path: root/kernel/src/filesystem/mount.tests.cpp
diff options
context:
space:
mode:
authorMarcel Braun <marcel.braun@ost.ch>2026-05-25 14:13:11 +0200
committerMarcel Braun <marcel.braun@ost.ch>2026-05-25 14:13:11 +0200
commit0ab7525951b0116241f393090987bedc07a18c33 (patch)
treefdd1d16c7de4f35dfc6d527cb9caa554e0db2c0c /kernel/src/filesystem/mount.tests.cpp
parent093074d5209f2d0062be79059f5881ee051c07d0 (diff)
parentadb1b5f2d6858097227fa610e86d1152b79d0bfa (diff)
downloadkernel-0ab7525951b0116241f393090987bedc07a18c33.tar.xz
kernel-0ab7525951b0116241f393090987bedc07a18c33.zip
Merge branch 'improve-mount-reference-count' into 'develop-BA-FS26'
Increase reference count of source_mount when one of its files is mounted somewhere See merge request teachos/kernel!42
Diffstat (limited to 'kernel/src/filesystem/mount.tests.cpp')
-rw-r--r--kernel/src/filesystem/mount.tests.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/kernel/src/filesystem/mount.tests.cpp b/kernel/src/filesystem/mount.tests.cpp
index 6b66571..c9ff82e 100644
--- a/kernel/src/filesystem/mount.tests.cpp
+++ b/kernel/src/filesystem/mount.tests.cpp
@@ -11,6 +11,8 @@
#include <catch2/catch_test_macros.hpp>
+#include <stdexcept>
+
SCENARIO("Mount construction", "[filesystem][mount]")
{
GIVEN("a filesystem and a root dentry")
@@ -21,7 +23,7 @@ SCENARIO("Mount construction", "[filesystem][mount]")
WHEN("constructing a mount with the filesystem and root dentry")
{
- auto mount = kernel::filesystem::mount{root_dentry, root_dentry, fs, nullptr};
+ 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")
{
@@ -32,9 +34,10 @@ SCENARIO("Mount construction", "[filesystem][mount]")
REQUIRE(mount.is_ready_to_unmount());
}
- THEN("the mount has no parent mount")
+ THEN("the mount has no parent mount and no source mount")
{
REQUIRE(mount.parent_mount() == nullptr);
+ REQUIRE(mount.source_mount() == nullptr);
}
}
@@ -42,7 +45,7 @@ SCENARIO("Mount construction", "[filesystem][mount]")
{
THEN("the constructor panics")
{
- REQUIRE_THROWS_AS((kernel::filesystem::mount{root_dentry, root_dentry, nullptr, nullptr}),
+ REQUIRE_THROWS_AS((kernel::filesystem::mount{root_dentry, root_dentry, nullptr, nullptr, nullptr}),
kernel::tests::cpu::halt);
}
}
@@ -60,7 +63,7 @@ SCENARIO("Mount reference counting", "[filesystem][mount]")
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};
+ auto mount = kernel::filesystem::mount{root_dentry, root_dentry, fs, nullptr, nullptr};
mount.increment_ref_count();
REQUIRE(mount.ref_count() == 1);
@@ -70,20 +73,20 @@ SCENARIO("Mount reference counting", "[filesystem][mount]")
REQUIRE(mount.ref_count() == 2);
REQUIRE_FALSE(mount.is_ready_to_unmount());
- REQUIRE(mount.decrement_ref_count());
+ mount.decrement_ref_count();
REQUIRE(mount.ref_count() == 1);
REQUIRE_FALSE(mount.is_ready_to_unmount());
- REQUIRE(mount.decrement_ref_count());
+ 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};
+ auto mount = kernel::filesystem::mount{root_dentry, root_dentry, fs, nullptr, nullptr};
- REQUIRE_FALSE(mount.decrement_ref_count());
+ REQUIRE_THROWS_AS(mount.decrement_ref_count(), std::runtime_error);
REQUIRE(mount.ref_count() == 0);
REQUIRE(mount.is_ready_to_unmount());
}