aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-06-02 13:43:49 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-06-02 16:30:20 +0200
commit772861fc5fae1c126fcc63a8809b0a9c729bd152 (patch)
tree34560fabed4b1deff4a737872d84ca65aded107e
parentb34db5a8acd0639fde9a81b38e96776f7c2ef61e (diff)
downloadkernel-772861fc5fae1c126fcc63a8809b0a9c729bd152.tar.xz
kernel-772861fc5fae1c126fcc63a8809b0a9c729bd152.zip
kernel/vfs: add type registry tests
-rw-r--r--kernel/CMakeLists.txt1
-rw-r--r--kernel/include/kernel/filesystem/type_registry.hpp8
-rw-r--r--kernel/src/filesystem/type_registry.cpp11
-rw-r--r--kernel/src/filesystem/type_registry.tests.cpp77
-rw-r--r--kernel/src/filesystem/vfs.cpp1
-rw-r--r--libs/kstd/kstd/flat_map16
-rw-r--r--libs/kstd/kstd/flat_map.test.cpp10
7 files changed, 119 insertions, 5 deletions
diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt
index 3dd84ba..2388370 100644
--- a/kernel/CMakeLists.txt
+++ b/kernel/CMakeLists.txt
@@ -201,6 +201,7 @@ if(BUILD_TESTING)
"src/filesystem/mount.tests.cpp"
"src/filesystem/open_file_descriptor.tests.cpp"
"src/filesystem/open_file_table.tests.cpp"
+ "src/filesystem/type_registry.tests.cpp"
"src/filesystem/vfs.tests.cpp"
# Storage Subsystem Tests
diff --git a/kernel/include/kernel/filesystem/type_registry.hpp b/kernel/include/kernel/filesystem/type_registry.hpp
index 2f5e708..3be7295 100644
--- a/kernel/include/kernel/filesystem/type_registry.hpp
+++ b/kernel/include/kernel/filesystem/type_registry.hpp
@@ -7,6 +7,7 @@
#include <kstd/memory>
#include <kstd/string>
+#include <cstddef>
#include <span>
#include <string_view>
@@ -35,7 +36,12 @@ namespace kernel::filesystem
//! Get all currently registered type descriptors.
//!
//! @return A span containing all currently registered filesystem type descriptors.
- [[nodiscard]] auto all() const noexcept -> std::span<pointer>;
+ [[nodiscard]] auto all() const noexcept -> std::span<pointer const>;
+
+ //! Get the number of registered filesystem types.
+ //!
+ //! @return The number of filesystem descriptors currently registered with this registry.
+ [[nodiscard]] auto size() const noexcept -> std::size_t;
private:
//! A map from filesystem names (identifiers) to filesystem type descriptors.
diff --git a/kernel/src/filesystem/type_registry.cpp b/kernel/src/filesystem/type_registry.cpp
index 033b879..d917c81 100644
--- a/kernel/src/filesystem/type_registry.cpp
+++ b/kernel/src/filesystem/type_registry.cpp
@@ -6,6 +6,7 @@
#include <kstd/print>
#include <algorithm>
+#include <cstddef>
#include <optional>
#include <ranges>
#include <span>
@@ -58,10 +59,14 @@ namespace kernel::filesystem
return result.second;
}
- [[nodiscard]] auto type_registry::all() const noexcept -> std::span<pointer>
+ auto type_registry::all() const noexcept -> std::span<pointer const>
{
- // TODO: implement value accessor for flat_map
- return {};
+ return {m_descriptors.values().begin(), m_descriptors.values().end()};
+ }
+
+ auto type_registry::size() const noexcept -> std::size_t
+ {
+ return m_descriptors.size();
}
} // namespace kernel::filesystem
diff --git a/kernel/src/filesystem/type_registry.tests.cpp b/kernel/src/filesystem/type_registry.tests.cpp
new file mode 100644
index 0000000..8382579
--- /dev/null
+++ b/kernel/src/filesystem/type_registry.tests.cpp
@@ -0,0 +1,77 @@
+#include <kernel/filesystem/type_registry.hpp>
+
+#include <kernel/filesystem/filesystem.hpp>
+#include <kernel/filesystem/type.hpp>
+
+#include <kstd/memory>
+
+#include <catch2/catch_test_macros.hpp>
+
+#include <iterator>
+#include <string_view>
+
+struct test_type final : kernel::filesystem::type
+{
+ [[nodiscard]] auto name() const noexcept -> std::string_view override
+ {
+ return "bht_testfs";
+ }
+
+ [[nodiscard]] auto requires_device() const noexcept -> bool override
+ {
+ return false;
+ }
+
+ [[nodiscard]] auto make_instance() const -> kstd::shared_ptr<kernel::filesystem::filesystem> override
+ {
+ return nullptr;
+ }
+};
+
+SCENARIO("Filesystem type registry initialization and construction", "[filesystem]")
+{
+ GIVEN("A default constructed type_registry")
+ {
+ auto instance = kernel::filesystem::type_registry{};
+
+ WHEN("getting the span of filesystem descriptors")
+ {
+ auto descriptors = instance.all();
+
+ THEN("the span is empty")
+ {
+ REQUIRE(descriptors.empty());
+ }
+ }
+ }
+}
+
+SCENARIO("Filesystem type registry modifiers", "[filesystem]")
+{
+ GIVEN("A default constructed type_registry")
+ {
+ auto instance = kernel::filesystem::type_registry{};
+
+ WHEN("adding a type descriptor")
+ {
+ auto descriptor = test_type{};
+
+ instance.add(kstd::make_observer(&descriptor));
+
+ THEN("the size of the registry is one")
+ {
+ REQUIRE(instance.size() == 1);
+ }
+
+ THEN("the span is not empty")
+ {
+ REQUIRE_FALSE(instance.all().empty());
+ }
+
+ THEN("the span's size is equal to the registry size")
+ {
+ REQUIRE(std::size(instance.all()) == std::size(instance));
+ }
+ }
+ }
+}
diff --git a/kernel/src/filesystem/vfs.cpp b/kernel/src/filesystem/vfs.cpp
index 8d1fd23..e5dff8c 100644
--- a/kernel/src/filesystem/vfs.cpp
+++ b/kernel/src/filesystem/vfs.cpp
@@ -12,7 +12,6 @@
#include <kapi/system.hpp>
#include <kstd/memory>
-#include <kstd/print>
#include <kstd/vector>
#include <algorithm>
diff --git a/libs/kstd/kstd/flat_map b/libs/kstd/kstd/flat_map
index f12b1b5..943e9fc 100644
--- a/libs/kstd/kstd/flat_map
+++ b/libs/kstd/kstd/flat_map
@@ -356,6 +356,22 @@ namespace kstd
return find(key) != cend();
}
+ //! Get a reference to the keys container.
+ //!
+ //! @return a reference to the keys container.
+ [[nodiscard]] constexpr auto keys() const noexcept -> key_container_type const &
+ {
+ return m_containers.keys;
+ }
+
+ //! Get a reference to the values container.
+ //!
+ //! @return a reference to the values container.
+ [[nodiscard]] constexpr auto values() const noexcept -> mapped_container_type const &
+ {
+ return m_containers.values;
+ }
+
private:
containers m_containers;
key_compare m_comparator;
diff --git a/libs/kstd/kstd/flat_map.test.cpp b/libs/kstd/kstd/flat_map.test.cpp
index 2e5a47c..6c57173 100644
--- a/libs/kstd/kstd/flat_map.test.cpp
+++ b/libs/kstd/kstd/flat_map.test.cpp
@@ -20,6 +20,16 @@ SCENARIO("Flat Map initialization and construction", "[flat_map]")
{
REQUIRE_FALSE(map.contains(1));
}
+
+ THEN("the keys container is empty")
+ {
+ REQUIRE(map.keys().empty());
+ }
+
+ THEN("the values container is empty")
+ {
+ REQUIRE(map.values().empty());
+ }
}
}
}