From 0248aab7d4a01d9a7ecd7a9ee433b1bc25edbeb0 Mon Sep 17 00:00:00 2001 From: Wildan M Date: Thu, 7 Aug 2025 07:19:56 +0700 Subject: [PATCH 1/3] Add basic test for statvfs --- tests/sys_statvfs/statvfs.c | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/sys_statvfs/statvfs.c diff --git a/tests/sys_statvfs/statvfs.c b/tests/sys_statvfs/statvfs.c new file mode 100644 index 0000000000..9bbc7af8e0 --- /dev/null +++ b/tests/sys_statvfs/statvfs.c @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include + +void test_statvfs(const char *path) { + struct statvfs buf; + + printf("Testing statvfs on: %s\n", path); + + if (statvfs(path, &buf) != 0) { + perror("statvfs failed"); + exit(EXIT_FAILURE); + } + + printf(" Filesystem block size: %lu\n", buf.f_bsize); + printf(" Fragment size: %lu\n", buf.f_frsize); + printf(" Total blocks: %lu\n", buf.f_blocks); + printf(" Free blocks: %lu\n", buf.f_bfree); + printf(" Available blocks: %lu\n", buf.f_bavail); + printf(" Total inodes: %lu\n", buf.f_files); + printf(" Free inodes: %lu\n", buf.f_ffree); + + if (buf.f_bsize == 0 || buf.f_frsize == 0) { + fprintf(stderr, "ERROR: Block size or fragment size is zero.\n"); + exit(EXIT_FAILURE); + } + + if (buf.f_blocks == 0) { + fprintf(stderr, "ERROR: Total number of blocks is zero.\n"); + exit(EXIT_FAILURE); + } + + printf("Test passed: statvfs returned valid values.\n"); +} + +int main(int argc, char *argv[]) { + const char *test_path = "/"; + + if (argc > 1) { + test_path = argv[1]; + } + + test_statvfs(test_path); + + return 0; +} From c7405e09bd85c3cf6d528eeac2972c7cd886776a Mon Sep 17 00:00:00 2001 From: Wildan M Date: Thu, 7 Aug 2025 07:35:40 +0700 Subject: [PATCH 2/3] Add statvfs tests to Makefile --- tests/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Makefile b/tests/Makefile index 89a0aa6c75..2d973ab0b1 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -239,6 +239,7 @@ NAMES=\ stdlib/realpath \ sys_epoll/epoll \ sys_resource/constants \ + sys_statvfs/statvfs \ sys_utsname/uname \ time/gettimeofday \ unistd/chdir \ From b3b806cafd6f614ecc282ae1cbc1e5816f3a9cfb Mon Sep 17 00:00:00 2001 From: Wildan M Date: Thu, 7 Aug 2025 08:46:54 +0700 Subject: [PATCH 3/3] Simplify test code --- tests/sys_statvfs/statvfs.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/tests/sys_statvfs/statvfs.c b/tests/sys_statvfs/statvfs.c index 9bbc7af8e0..62785f1bfa 100644 --- a/tests/sys_statvfs/statvfs.c +++ b/tests/sys_statvfs/statvfs.c @@ -4,14 +4,14 @@ #include #include -void test_statvfs(const char *path) { +int test_statvfs(const char *path) { struct statvfs buf; printf("Testing statvfs on: %s\n", path); if (statvfs(path, &buf) != 0) { perror("statvfs failed"); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } printf(" Filesystem block size: %lu\n", buf.f_bsize); @@ -24,25 +24,19 @@ void test_statvfs(const char *path) { if (buf.f_bsize == 0 || buf.f_frsize == 0) { fprintf(stderr, "ERROR: Block size or fragment size is zero.\n"); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } if (buf.f_blocks == 0) { fprintf(stderr, "ERROR: Total number of blocks is zero.\n"); - exit(EXIT_FAILURE); + return EXIT_FAILURE; } - printf("Test passed: statvfs returned valid values.\n"); -} - -int main(int argc, char *argv[]) { - const char *test_path = "/"; - - if (argc > 1) { - test_path = argv[1]; - } - - test_statvfs(test_path); - return 0; } + +int main(void) { + const char *test_path = "/"; + + return test_statvfs(test_path); +}