aboutsummaryrefslogtreecommitdiff
path: root/kernel/kapi/filesystem.tests.cpp
diff options
context:
space:
mode:
authormanuel <manuel.bott@eps.ch>2026-11-22 01:06:22 +0000
committermanuel <manuel.bott@eps.ch>2026-11-22 01:06:22 +0000
commitd260c7339080e8c72224b68b93781139c297861f (patch)
tree1c40512c6b4257c0fdc7c1ec6a7168f0c2808758 /kernel/kapi/filesystem.tests.cpp
parentea79ee8e74f28f05803f458294f17fc873df2153 (diff)
downloadkernel-d260c7339080e8c72224b68b93781139c297861f.tar.xz
kernel-d260c7339080e8c72224b68b93781139c297861f.zip
kernel/filesystem: add bigger fat32 image to test and adjust teststest/fat32-real-imagefa26/develop
Diffstat (limited to 'kernel/kapi/filesystem.tests.cpp')
-rw-r--r--kernel/kapi/filesystem.tests.cpp55
1 files changed, 49 insertions, 6 deletions
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 <kapi/filesystem.hpp>
+#include <kernel/test_support/filesystems/fat32_image.hpp>
#include <kernel/test_support/vfs/storage_boot_module_vfs_fixture.hpp>
#include <kstd/system_error.hpp>
@@ -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<kapi::filesystem::directory_entry>{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<std::string>{};
+ auto buffer = std::vector<kapi::filesystem::directory_entry>{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");