diff options
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/kernel/devices/storage/ram_disk/controller.tests.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
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>(®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<kernel::devices::storage::ram_disk::controller>(®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 |
