aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kapi/kapi/boot_module/boot_module.hpp2
-rw-r--r--kapi/kapi/boot_module/boot_module_registry.hpp2
-rw-r--r--kapi/kapi/boot_modules.hpp1
-rw-r--r--kernel/kernel/devices/storage/ram_disk/controller.tests.cpp82
4 files changed, 87 insertions, 0 deletions
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 <kapi/boot_modules.hpp>
+
#include <kapi/memory.hpp>
#include <cstddef>
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 <kapi/boot_modules.hpp>
+
#include <kapi/boot_module/boot_module.hpp>
#include <kstd/vector.hpp>
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 <kapi/boot_module/boot_module.hpp> // IWYU pragma: export
#include <kapi/boot_module/boot_module_registry.hpp> // 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 <kernel/devices/storage/ram_disk/controller.hpp>
+
+#include <kapi/boot_modules.hpp>
+#include <kapi/devices.hpp>
+#include <kapi/memory.hpp>
+
+#include <kstd/memory.hpp>
+
+#include <catch2/catch_test_macros.hpp>
+
+#include <cstddef>
+#include <vector>
+
+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<std::byte>{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<kernel::devices::storage::ram_disk::controller>(&registry);
+
+ 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<kernel::devices::storage::ram_disk::controller>(&registry);
+
+ 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