Skip to content

Commit

Permalink
Tests: Add a generic test for reported file sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
sdomi committed Oct 6, 2024
1 parent 3462882 commit d2b9058
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions Tests/Kernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ set(LIBTEST_BASED_SOURCES
TestEmptySharedInodeVMObject.cpp
TestExt2FS.cpp
TestFileSystemDirentTypes.cpp
TestFileSystemReportedSize.cpp
TestInvalidUIDSet.cpp
TestSharedInodeVMObject.cpp
TestPosixFallocate.cpp
Expand Down
45 changes: 45 additions & 0 deletions Tests/Kernel/TestFileSystemReportedSize.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2024, sdomi <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <LibTest/TestCase.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>

static void test_write_path(const char* path)
{
struct stat st;

auto fd = open(path, O_RDWR | O_CREAT);
EXPECT_NE(fd, -1);

EXPECT_NE(fstat(fd, &st), -1);
EXPECT(st.st_blocks == 0);
EXPECT_EQ(st.st_size, 0);

auto rc = write(fd, "meow", 4);
EXPECT_NE(rc, 0);

EXPECT_NE(fstat(fd, &st), -1);

EXPECT(st.st_blocks > 0);
EXPECT(st.st_size > 0);
close(fd);
unlink(path);
}

TEST_CASE(reported_blocksize_ramfs)
{
test_write_path("/tmp/asdf");
}

TEST_CASE(reported_blocksize_ext2fs)
{
test_write_path("/home/anon/asdf");
}

// TODO: automate testing of FatFS/FUSE/...

0 comments on commit d2b9058

Please sign in to comment.