diff options
Diffstat (limited to 'kernel/src/filesystem/mount.tests.cpp')
| -rw-r--r-- | kernel/src/filesystem/mount.tests.cpp | 94 |
1 files changed, 0 insertions, 94 deletions
diff --git a/kernel/src/filesystem/mount.tests.cpp b/kernel/src/filesystem/mount.tests.cpp deleted file mode 100644 index c9ff82e9..00000000 --- a/kernel/src/filesystem/mount.tests.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#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 |
