aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/src/main.cpp69
1 files changed, 29 insertions, 40 deletions
diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp
index a2c531f..1893b84 100644
--- a/kernel/src/main.cpp
+++ b/kernel/src/main.cpp
@@ -111,51 +111,40 @@ auto test_device_with_vfs() -> void
auto test_file_lookup() -> void
{
- // TODO BA-FS26 implement a more complete test with multiple files and directories and mounts etc.
-
auto vfs = kernel::filesystem::vfs::get();
- auto storage_mgmt = kernel::devices::storage::management::get();
-
- auto ofd_hello = vfs.open("/hello.txt");
-
- kstd::vector<std::byte> buffer(64);
- auto number_of_read_bytes = ofd_hello->read(buffer.data(), buffer.size());
- kstd::println("read bytes: {}", number_of_read_bytes);
- kstd::println("buffer: {::#04x}", buffer);
-
- std::string_view hello_str{reinterpret_cast<char *>(buffer.data()), number_of_read_bytes};
- kstd::println("hello_str: {}", hello_str);
-
- auto ofd1 = vfs.open("/a/b/c");
- auto ofd2 = vfs.open("/dev/ram0");
- auto ofd3 = vfs.open("/a/d/e");
- if (!ofd1 || !ofd2 || !ofd3)
- {
- kstd::os::panic("test code failed");
- }
-
- if (auto ofd4 = vfs.open("/dev/xxx"))
- {
- kstd::os::panic("test code failed");
- }
+ auto read_and_write_file = [&vfs](std::string_view path) {
+ kstd::println("[TEST] Reading and writing file at path: {}", path);
+ auto ofd = vfs.open(path);
+ if (!ofd)
+ {
+ kstd::os::panic("test code failed");
+ }
+
+ kstd::vector<std::byte> buffer{32};
+ auto number_of_read_bytes = ofd->read(buffer.data(), buffer.size());
+ kstd::println("read bytes: {}", number_of_read_bytes);
+ kstd::println("buffer: {::#04x}", buffer);
+
+ std::string_view buffer_as_str{reinterpret_cast<char *>(buffer.data()), number_of_read_bytes};
+ kstd::println("buffer_as_str: {}", buffer_as_str);
+ };
+
+ read_and_write_file("/info.txt");
+ read_and_write_file("/enclosures/info.txt");
+ read_and_write_file("/enclosures/aquarium/tank_1/fish_4.txt");
+ read_and_write_file("/enclosures/elephant_house/elephant_1.txt");
+ read_and_write_file(
+ "/enclosures/aquarium/tank_2/"
+ "this_is_a_very_very_long_fish_filename_that_keeps_going_and_going_until_it_almost_breaks_linux_filesystem_"
+ "limits_for_testing_purposes_and_we_add_more_characters_to_make_it_even_longer_30.txt");
+ auto storage_mgmt = kernel::devices::storage::management::get();
auto device = storage_mgmt.device_by_major_minor(1, 16);
auto new_filesystem = kernel::filesystem::filesystem::probe_and_mount(device);
- if (vfs.do_mount("/a/b", new_filesystem) != 0)
- {
- kstd::os::panic("test code failed");
- }
- auto ofd5 = vfs.open("/a/b/c");
- if (!ofd5)
- {
- kstd::os::panic("test code failed");
- }
-
- if (auto ofd6 = vfs.open("x/y/z"))
- {
- kstd::os::panic("test code failed");
- }
+ vfs.do_mount("/enclosures/aquarium", new_filesystem);
+ read_and_write_file("/enclosures/aquarium/closed.txt");
+ read_and_write_file("/enclosures/aquarium/information/info_2.txt");
}
auto run_test_code() -> void