From fde90dcc551b35ea03fef1231fafac9faea2c5b5 Mon Sep 17 00:00:00 2001 From: Lukas Oesch Date: Sun, 22 Mar 2026 09:31:03 +0100 Subject: add tests, use better println for vectors --- kernel/src/main.cpp | 57 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 24 deletions(-) (limited to 'kernel') diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp index 1043c81..3ba240d 100644 --- a/kernel/src/main.cpp +++ b/kernel/src/main.cpp @@ -19,7 +19,6 @@ #include #include -#include auto test_device_names() -> void { @@ -51,17 +50,8 @@ auto test_file_description_manually() -> void kstd::vector buffer{2}; auto number_of_read_bytes = fd->read(buffer.data(), buffer.size()); - - for (size_t i = 0; i < number_of_read_bytes; ++i) - { - kstd::print("{:02x} ", static_cast(buffer[i])); - - if ((i + 1) % 16 == 0) - { - kstd::println(""); - } - } - kstd::println("---"); + kstd::println("read bytes: {}", number_of_read_bytes); + kstd::println("buffer: {::#04x}", buffer); // write half of the file new auto const value1 = std::byte{0xAA}; @@ -85,17 +75,8 @@ auto test_file_description_manually() -> void kstd::vector buffer1{4}; number_of_read_bytes = fd1->read(buffer1.data(), buffer1.size()); - - for (size_t i = 0; i < number_of_read_bytes; ++i) - { - kstd::print("{:02x} ", static_cast(buffer1[i])); - - if ((i + 1) % 16 == 0) - { - kstd::println(""); - } - } - kstd::println("---"); + kstd::println("read bytes: {}", number_of_read_bytes); + kstd::println("buffer: {::#04x}", buffer1); } auto test_device_with_vfs() -> void @@ -103,14 +84,41 @@ auto test_device_with_vfs() -> void // TODO BA-FS26 auto vfs = filesystem::vfs::get(); - vfs.open("/"); + auto ofd = vfs.open("/dev/ram0"); + if (!ofd) + { + kstd::os::panic("test code failed"); + } + + auto fd_table = filesystem::file_descriptor_table::get(); + auto fd = fd_table.add_file(ofd); + kstd::vector buffer{2}; + auto file = fd_table.get_file(fd); + if (!file) + { + kstd::os::panic("test code failed"); + } + + auto number_of_read_bytes = file->read(buffer.data(), buffer.size()); + kstd::println("read bytes: {}", number_of_read_bytes); + kstd::println("buffer: {::#04x}", buffer); } auto run_test_code() -> void { + kstd::println("[TEST] Running test code..."); + + kstd::println("[TEST] device names"); test_device_names(); + kstd::println("---------------------------------"); + + kstd::println("[TEST] file description manually"); test_file_description_manually(); + kstd::println("---------------------------------"); + + kstd::println("[TEST] device with VFS"); test_device_with_vfs(); + kstd::println("---------------------------------"); } auto main() -> int @@ -136,6 +144,7 @@ auto main() -> int kstd::println("[OS] Virtual filesystem initialized."); run_test_code(); + kstd::println("[TEST] All tests completed."); kapi::system::panic("Returning from kernel main!"); } -- cgit v1.2.3