aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-07-26 13:41:56 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-07-26 13:41:56 +0200
commit15d38c630052f43c980bdea60723ce388077437f (patch)
treee283de97a8d7fef1698be88d0efc26b085942c48
parent4cc05543d48a35908b0756e133bd668745bd95c3 (diff)
downloadkernel-15d38c630052f43c980bdea60723ce388077437f.tar.xz
kernel-15d38c630052f43c980bdea60723ce388077437f.zip
kernel: add devfs live-update tests
-rw-r--r--kapi/kapi/devices.hpp6
-rw-r--r--kernel/kapi/devices.cpp11
-rw-r--r--kernel/kernel/filesystem/devfs/filesystem.tests.cpp53
3 files changed, 69 insertions, 1 deletions
diff --git a/kapi/kapi/devices.hpp b/kapi/kapi/devices.hpp
index 59fcc568..124cd2bb 100644
--- a/kapi/kapi/devices.hpp
+++ b/kapi/kapi/devices.hpp
@@ -34,6 +34,12 @@ namespace kapi::devices
//! @return a shared pointer to the root bus.
auto get_root_bus() -> kstd::shared_ptr<bus>;
+ //! Remove a device from the device tree.
+ //!
+ //! @param device The device to remove.
+ //! @return true iff. the device had a parent an was remove, false otherwise.
+ auto remove_device(device & device) -> bool;
+
//! Publish the fact that a device supports a specific facet.
//!
//! @tparam Facet The facet type provided by the device.
diff --git a/kernel/kapi/devices.cpp b/kernel/kapi/devices.cpp
index f289bbf2..4480206a 100644
--- a/kernel/kapi/devices.cpp
+++ b/kernel/kapi/devices.cpp
@@ -42,6 +42,17 @@ namespace kapi::devices
return root_bus;
}
+ auto remove_device(device & device) -> bool
+ {
+ auto parent = device.parent();
+ if (!parent)
+ {
+ return false;
+ }
+
+ return parent->remove_child(device);
+ }
+
} // namespace kapi::devices
namespace kapi::test_support::devices
diff --git a/kernel/kernel/filesystem/devfs/filesystem.tests.cpp b/kernel/kernel/filesystem/devfs/filesystem.tests.cpp
index 29a33231..28da5275 100644
--- a/kernel/kernel/filesystem/devfs/filesystem.tests.cpp
+++ b/kernel/kernel/filesystem/devfs/filesystem.tests.cpp
@@ -2,14 +2,24 @@
#include <kernel/filesystem/filesystem.hpp>
#include <kernel/filesystem/vfs_types.hpp>
+#include <kernel/test_support/devices/block_device.hpp>
+#include <kernel/test_support/devices/driver.hpp>
#include <kernel/test_support/filesystem/storage_boot_module_fixture.hpp>
+#include <kapi/devices.hpp>
+#include <kapi/filesystem.hpp>
+
#include <kstd/memory.hpp>
+#include <kstd/units.hpp>
#include <catch2/catch_test_macros.hpp>
+#include <cstdint>
+
+using namespace kstd::units_literals;
+
SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_fixture,
- "Devfs filesystem lookup uses storage management devices", "[filesystem][devfs][filesystem]")
+ "Devfs filesystem lookup uses storage management devices", "[filesystem][devfs]")
{
GIVEN("a boot module registry with one module")
{
@@ -80,3 +90,44 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_fixture,
}
}
}
+
+SCENARIO("Devfs filesystem updates", "[filesystem][devfs]")
+{
+ GIVEN("A mounted devfs, and a bus attached to the root without a device attached")
+ {
+ auto fs = kstd::make_shared<kernel::filesystem::devfs::filesystem>();
+ REQUIRE(fs->mount(nullptr));
+
+ auto bus = kstd::make_shared<kapi::devices::bus>("devfs_live_update_bus");
+ kapi::devices::get_root_bus()->add_child(bus);
+
+ REQUIRE_FALSE(fs->lookup(fs->root_inode(), "devfs_live_update_device_node"));
+
+ WHEN("a device is attached, bound, and published")
+ {
+ auto device = kstd::make_shared<kernel::tests::devices::block_device>("devfs_live_update_device", 512_B);
+ bus->add_child(device);
+ CHECK(kernel::tests::devices::bind(*device, std::uint8_t{99}));
+
+ REQUIRE(
+ kapi::devices::publish_facet<kapi::filesystem::block_special_file>(device, "devfs_live_update_device_node"));
+
+ THEN("devfs finds it immediately")
+ {
+ REQUIRE(fs->lookup(fs->root_inode(), "devfs_live_update_device_node"));
+ }
+
+ WHEN("the device is detached")
+ {
+ REQUIRE(kapi::devices::remove_device(*device));
+
+ THEN("devfs does not find it anymore")
+ {
+ REQUIRE_FALSE(fs->lookup(fs->root_inode(), "devfs_live_update_device_node"));
+ }
+ }
+ }
+
+ REQUIRE(kapi::devices::remove_device(*bus));
+ }
+} \ No newline at end of file