diff options
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/kernel/devices/storage.tests.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/kernel/kernel/devices/storage.tests.cpp b/kernel/kernel/devices/storage.tests.cpp new file mode 100644 index 00000000..603321c2 --- /dev/null +++ b/kernel/kernel/devices/storage.tests.cpp @@ -0,0 +1,48 @@ +#include <kernel/devices/storage.hpp> + +#include <kernel/test_support/boot_modules.hpp> + +#include <kapi/boot_modules.hpp> +#include <kapi/devices.hpp> +#include <kapi/memory.hpp> + +#include <catch2/catch_test_macros.hpp> + +#include <cstddef> +#include <vector> + +TEST_CASE("Storage devices attached with init() are reachable from the root bus", "[devices][storage]") +{ + auto storage = std::vector<std::byte>{4096, std::byte{}}; + 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(), + }); + + kapi::boot_modules::set_boot_module_registry(registry); + + kernel::devices::storage::init(); + + CHECK(kapi::devices::find_device("ram0")); + + auto root = kapi::devices::get_root_bus(); + auto ram_disk_controller_found = false; + + for (auto const & child : root->children()) + { + if (child->name() == "ram_disk") + { + ram_disk_controller_found = true; + } + } + CHECK(ram_disk_controller_found); + + auto boot_device = kernel::devices::storage::determine_boot_device(); + REQUIRE(boot_device); + CHECK(boot_device->name() == "ram0"); + + kernel::tests::boot_modules::deinit(); +}
\ No newline at end of file |
