From d260c7339080e8c72224b68b93781139c297861f Mon Sep 17 00:00:00 2001 From: manuel Date: Sun, 22 Nov 2026 01:06:22 +0000 Subject: kernel/filesystem: add bigger fat32 image to test and adjust tests --- kernel/kapi/filesystem.tests.cpp | 55 +++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 6 deletions(-) (limited to 'kernel/kapi/filesystem.tests.cpp') diff --git a/kernel/kapi/filesystem.tests.cpp b/kernel/kapi/filesystem.tests.cpp index f71eead0..baa587e5 100644 --- a/kernel/kapi/filesystem.tests.cpp +++ b/kernel/kapi/filesystem.tests.cpp @@ -1,5 +1,6 @@ #include +#include #include #include @@ -347,6 +348,7 @@ SCENARIO_METHOD(kernel::tests::vfs::storage_boot_module_vfs_fixture, "Kapi files { auto const ext2_image_path = std::filesystem::path{KERNEL_TEST_ASSETS_DIR} / "ext2_1KB_fs.img"; auto const fat32_image_path = std::filesystem::path{KERNEL_TEST_ASSETS_DIR} / "fat32.img"; + namespace image = kernel::tests::filesystems::fat32::image; GIVEN("an ext2 root filesystem with a fat32 image mounted on /information") { @@ -375,7 +377,7 @@ SCENARIO_METHOD(kernel::tests::vfs::storage_boot_module_vfs_fixture, "Kapi files { auto const fd = kapi::filesystem::open("/information/hello.txt"); REQUIRE(fd); - REQUIRE(read_text(*fd, 64) == "Hello World!"); + REQUIRE(read_text(*fd, 64) == image::hello_content); REQUIRE(kapi::filesystem::close(*fd)); } @@ -383,7 +385,7 @@ SCENARIO_METHOD(kernel::tests::vfs::storage_boot_module_vfs_fixture, "Kapi files { auto const fd = kapi::filesystem::open("/information/hello.txt"); REQUIRE(fd); - REQUIRE(read_text(*fd, 5) == "Hello World!"); + REQUIRE(read_text(*fd, 5) == image::hello_content); REQUIRE(kapi::filesystem::close(*fd)); } @@ -392,7 +394,7 @@ SCENARIO_METHOD(kernel::tests::vfs::storage_boot_module_vfs_fixture, "Kapi files auto const fd = kapi::filesystem::open("/information/hello.txt"); REQUIRE(fd); REQUIRE(kapi::filesystem::seek(*fd, 6_B_off, kapi::filesystem::seek_origin::beginning) == 6_B); - REQUIRE(read_text(*fd, 16) == "World!"); + REQUIRE(read_text(*fd, 16) == "World!\n"); REQUIRE(kapi::filesystem::close(*fd)); } @@ -401,7 +403,7 @@ SCENARIO_METHOD(kernel::tests::vfs::storage_boot_module_vfs_fixture, "Kapi files auto const status = kapi::filesystem::status("/information/hello.txt"); REQUIRE(status); REQUIRE(status->mode == std::to_underlying(kapi::filesystem::file_type::regular)); - REQUIRE(status->size == 12_B); + REQUIRE(status->size == image::hello_size); } THEN("the mounted root directory can be listed") @@ -410,11 +412,52 @@ SCENARIO_METHOD(kernel::tests::vfs::storage_boot_module_vfs_fixture, "Kapi files REQUIRE(directory); auto buffer = std::vector{10}; - REQUIRE(kapi::filesystem::read_directory(*directory, buffer) == 1); - REQUIRE(buffer[0].name == "HELLO.TXT"); + REQUIRE(kapi::filesystem::read_directory(*directory, buffer) == image::root_names().size()); + for (auto index = 0uz; index < image::root_names().size(); ++index) + { + REQUIRE(buffer[index].name == image::root_names()[index]); + } REQUIRE(kapi::filesystem::read_directory(*directory, buffer) == 0); } + THEN("a directory spanning two clusters can be listed in small pages") + { + auto const directory = kapi::filesystem::open("/information/docs"); + REQUIRE(directory); + + auto names = std::vector{}; + auto buffer = std::vector{4}; + while (true) + { + auto const count = kapi::filesystem::read_directory(*directory, buffer); + REQUIRE(count); + if (*count == 0) + { + break; + } + for (auto index = 0uz; index < *count; ++index) + { + names.emplace_back(buffer[index].name.data(), buffer[index].name.size()); + } + } + REQUIRE(names == image::docs_names()); + } + + THEN("a multi cluster file in a nested directory can be read in chunks") + { + auto const fd = kapi::filesystem::open("/information/docs/sub/file2.txt"); + REQUIRE(fd); + REQUIRE(read_text(*fd, 100) == image::text_content(image::multi_cluster_file_size)); + REQUIRE(kapi::filesystem::close(*fd)); + } + + THEN("a path through \"..\" leads back to the mounted root directory") + { + auto const status = kapi::filesystem::status("/information/docs/../hello.txt"); + REQUIRE(status); + REQUIRE(status->size == image::hello_size); + } + THEN("a file can be overwritten and extended through its file descriptor") { auto const fd = kapi::filesystem::open("/information/hello.txt"); -- cgit v1.2.3