From e0242199421b104743ca1112d29f5ea905fc3912 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 23 Jul 2026 10:29:15 +0200 Subject: kernel/dev: add basic ram disk controller tests --- kapi/kapi/boot_module/boot_module.hpp | 2 + kapi/kapi/boot_module/boot_module_registry.hpp | 2 + kapi/kapi/boot_modules.hpp | 1 + .../devices/storage/ram_disk/controller.tests.cpp | 82 ++++++++++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 kernel/kernel/devices/storage/ram_disk/controller.tests.cpp diff --git a/kapi/kapi/boot_module/boot_module.hpp b/kapi/kapi/boot_module/boot_module.hpp index 9b4b1650..608e5341 100644 --- a/kapi/kapi/boot_module/boot_module.hpp +++ b/kapi/kapi/boot_module/boot_module.hpp @@ -1,6 +1,8 @@ #ifndef TEACHOS_KAPI_BOOT_MODULE_BOOT_MODULE_HPP #define TEACHOS_KAPI_BOOT_MODULE_BOOT_MODULE_HPP +// IWYU pragma: private, include + #include #include diff --git a/kapi/kapi/boot_module/boot_module_registry.hpp b/kapi/kapi/boot_module/boot_module_registry.hpp index fdba0740..fdffa757 100644 --- a/kapi/kapi/boot_module/boot_module_registry.hpp +++ b/kapi/kapi/boot_module/boot_module_registry.hpp @@ -1,6 +1,8 @@ #ifndef TEACHOS_KAPI_BOOT_MODULE_BOOT_MODULE_REGISTRY_HPP #define TEACHOS_KAPI_BOOT_MODULE_BOOT_MODULE_REGISTRY_HPP +// IWYU pragma: private, include + #include #include diff --git a/kapi/kapi/boot_modules.hpp b/kapi/kapi/boot_modules.hpp index 2a88f747..678195c0 100644 --- a/kapi/kapi/boot_modules.hpp +++ b/kapi/kapi/boot_modules.hpp @@ -1,6 +1,7 @@ #ifndef TEACHOS_KAPI_BOOT_MODULES_HPP #define TEACHOS_KAPI_BOOT_MODULES_HPP +#include // IWYU pragma: export #include // IWYU pragma: export namespace kapi::boot_modules diff --git a/kernel/kernel/devices/storage/ram_disk/controller.tests.cpp b/kernel/kernel/devices/storage/ram_disk/controller.tests.cpp new file mode 100644 index 00000000..6393043b --- /dev/null +++ b/kernel/kernel/devices/storage/ram_disk/controller.tests.cpp @@ -0,0 +1,82 @@ +#include + +#include +#include +#include + +#include + +#include + +#include +#include + +SCENARIO("The RAM disk controller attaches its devices to the device tree", "[devices][storage][ram_disk]") +{ + GIVEN("A boot modules registry with one valid module") + { + auto storage = std::vector{4096, std::byte{0x0}}; + auto registry = kapi::boot_modules::boot_module_registry{}; + registry.add_boot_module({ + .name = "test_module", + .start_address = kapi::memory::linear_address{storage.data()}, + .size = storage.size(), + }); + + auto controller = kstd::make_shared(®istry); + + WHEN("the controller is initialized") + { + auto succeeded = controller->init(); + + THEN("initialization succeeds") + { + REQUIRE(succeeded); + } + + THEN("the RAM disk is reachable as a child of the controller") + { + REQUIRE(controller->children().size() == 1); + REQUIRE(controller->children()[0]->name() == "ram0"); + } + + THEN("the RAM disk is reachable through the global device tree") + { + REQUIRE(kapi::devices::find_device("ram0")); + } + } + } + + GIVEN("A boot modules registry with one invalid module") + { + auto registry = kapi::boot_modules::boot_module_registry{}; + registry.add_boot_module({ + .name = "invalid module", + .start_address = kapi::memory::linear_address{nullptr}, + .size = 0, + }); + + auto controller = kstd::make_shared(®istry); + + WHEN("the controller is initialized") + { + auto succeeded = controller->init(); + + THEN("initialization fails") + { + REQUIRE_FALSE(succeeded); + } + + THEN("the invalid RAM disk i still attache to the tree") + { + REQUIRE(controller->children().size() == 1); + REQUIRE(controller->children()[0]->name() == "ram0"); + } + + THEN("the invalid RAM disk reachable through the global device tree") + { + REQUIRE(kapi::devices::find_device("ram0")); + } + } + } +} \ No newline at end of file -- cgit v1.2.3