aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/kapi/devices.cpp11
-rw-r--r--kernel/kernel/filesystem/devfs/filesystem.tests.cpp53
2 files changed, 63 insertions, 1 deletions
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