diff options
| author | Lukas Oesch <lukasoesch20@gmail.com> | 2026-05-16 13:53:34 +0200 |
|---|---|---|
| committer | Lukas Oesch <lukasoesch20@gmail.com> | 2026-05-16 13:53:34 +0200 |
| commit | 7ecf092ca7ff91dd59e81eda7ef2b05fe837844d (patch) | |
| tree | 3f243707cd66fea90e2d610506baeadbe99a74dc /kernel/src | |
| parent | ba2f62972823df320e05dea7080adf658c2977b3 (diff) | |
| download | kernel-7ecf092ca7ff91dd59e81eda7ef2b05fe837844d.tar.xz kernel-7ecf092ca7ff91dd59e81eda7ef2b05fe837844d.zip | |
add mount tests
Diffstat (limited to 'kernel/src')
| -rw-r--r-- | kernel/src/filesystem/mount.cpp | 6 | ||||
| -rw-r--r-- | kernel/src/filesystem/mount.tests.cpp | 42 |
2 files changed, 48 insertions, 0 deletions
diff --git a/kernel/src/filesystem/mount.cpp b/kernel/src/filesystem/mount.cpp index 3016509..1e04083 100644 --- a/kernel/src/filesystem/mount.cpp +++ b/kernel/src/filesystem/mount.cpp @@ -8,6 +8,7 @@ #include <kstd/memory> #include <kstd/string> +#include <cstddef> #include <string_view> namespace kernel::filesystem @@ -75,4 +76,9 @@ namespace kernel::filesystem { return m_ref_count == 0; } + + auto mount::get_ref_count() const -> size_t + { + return m_ref_count; + } } // namespace kernel::filesystem
\ No newline at end of file diff --git a/kernel/src/filesystem/mount.tests.cpp b/kernel/src/filesystem/mount.tests.cpp index 58e9bab..e7dd709 100644 --- a/kernel/src/filesystem/mount.tests.cpp +++ b/kernel/src/filesystem/mount.tests.cpp @@ -29,6 +29,7 @@ SCENARIO("Mount construction", "[filesystem][mount]") REQUIRE(mount.get_root_dentry() == root_dentry); REQUIRE(mount.get_mount_dentry() == root_dentry); REQUIRE(mount.get_mount_path() == "/"); + REQUIRE(mount.is_ready_to_unmount()); } THEN("the mount has no parent mount") @@ -47,3 +48,44 @@ SCENARIO("Mount construction", "[filesystem][mount]") } } } + +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}; + + mount.increment_ref_count(); + REQUIRE(mount.get_ref_count() == 1); + REQUIRE_FALSE(mount.is_ready_to_unmount()); + + mount.increment_ref_count(); + REQUIRE(mount.get_ref_count() == 2); + REQUIRE_FALSE(mount.is_ready_to_unmount()); + + REQUIRE(mount.decrement_ref_count()); + REQUIRE(mount.get_ref_count() == 1); + REQUIRE_FALSE(mount.is_ready_to_unmount()); + + REQUIRE(mount.decrement_ref_count()); + REQUIRE(mount.get_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}; + + REQUIRE_FALSE(mount.decrement_ref_count()); + REQUIRE(mount.get_ref_count() == 0); + REQUIRE(mount.is_ready_to_unmount()); + } + } +}
\ No newline at end of file |
