aboutsummaryrefslogtreecommitdiff
path: root/kernel/tests/src
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/tests/src')
-rw-r--r--kernel/tests/src/main.cpp4
-rw-r--r--kernel/tests/src/simulated_memory.cpp33
2 files changed, 37 insertions, 0 deletions
diff --git a/kernel/tests/src/main.cpp b/kernel/tests/src/main.cpp
index c0ec12f..69fd633 100644
--- a/kernel/tests/src/main.cpp
+++ b/kernel/tests/src/main.cpp
@@ -12,6 +12,10 @@ auto main(int argc, char ** argv) -> int
kapi::interrupts::enable();
kapi::memory::init();
+ // note: no kernel heap is created, since we are in the test environment. Nonetheless, we still initialize the memory
+ // subsystem, so that components that rely on it can be tested. No component must ever rely on the heap allocator
+ // directly, rather they have to go through the new and delete. However, some components may use the frame allocator
+ // and page mapper in order to perform their tasks.
return Catch::Session().run(argc, argv);
}
diff --git a/kernel/tests/src/simulated_memory.cpp b/kernel/tests/src/simulated_memory.cpp
new file mode 100644
index 0000000..9a9b354
--- /dev/null
+++ b/kernel/tests/src/simulated_memory.cpp
@@ -0,0 +1,33 @@
+#include "kernel/tests/simulated_memory.hpp"
+
+#include <kstd/units>
+
+#include <cstddef>
+#include <vector>
+
+namespace kernel::tests::simulated_memory
+{
+
+ namespace
+ {
+ auto constinit ram_storage = std::vector<std::byte>{};
+ auto constinit pmm_storage = std::vector<std::byte>{};
+ } // namespace
+
+ auto init(kstd::units::bytes size) -> void
+ {
+ ram_storage.resize(size / kstd::units::bytes{1});
+ pmm_storage.resize(size / kstd::units::bytes{1});
+ }
+
+ auto pmm_metadata_base() -> std::byte *
+ {
+ return pmm_storage.data();
+ }
+
+ auto ram_base() -> std::byte *
+ {
+ return ram_storage.data();
+ }
+
+} // namespace kernel::tests::simulated_memory \ No newline at end of file