From 15d38c630052f43c980bdea60723ce388077437f Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sun, 26 Jul 2026 13:41:56 +0200 Subject: kernel: add devfs live-update tests --- kernel/kapi/devices.cpp | 11 +++++ .../kernel/filesystem/devfs/filesystem.tests.cpp | 53 +++++++++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) (limited to 'kernel') 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 #include +#include +#include #include +#include +#include + #include +#include #include +#include + +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(); + REQUIRE(fs->mount(nullptr)); + + auto bus = kstd::make_shared("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("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(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 -- cgit v1.2.3