This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new 271cb4b9d testing/testsuites: Add an fstatfs() case for a directory 
descriptor.
271cb4b9d is described below

commit 271cb4b9d9420a053155b40e007319b916b72729
Author: Marco Casaroli <[email protected]>
AuthorDate: Mon Nov 16 17:17:49 2026 +0100

    testing/testsuites: Add an fstatfs() case for a directory descriptor.
    
    fstatfs() and fstatvfs() of a descriptor that open() gives for a
    directory must give the file system of the directory, as statfs() and
    statvfs() of its path do.  The new case test_nuttx_fs_fstatfs02 opens
    the test directory with O_DIRECTORY and compares the two results.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 .../testsuites/kernel/fs/cases/fs_fstatfs_test.c   | 42 ++++++++++++++++++++++
 testing/testsuites/kernel/fs/cmocka_fs_test.c      |  3 ++
 testing/testsuites/kernel/fs/include/fstest.h      |  1 +
 3 files changed, 46 insertions(+)

diff --git a/testing/testsuites/kernel/fs/cases/fs_fstatfs_test.c 
b/testing/testsuites/kernel/fs/cases/fs_fstatfs_test.c
index 240e74d90..282bfb317 100644
--- a/testing/testsuites/kernel/fs/cases/fs_fstatfs_test.c
+++ b/testing/testsuites/kernel/fs/cases/fs_fstatfs_test.c
@@ -26,6 +26,7 @@
 #include <nuttx/config.h>
 #include <sys/stat.h>
 #include <sys/statfs.h>
+#include <sys/statvfs.h>
 #include <stdio.h>
 #include <fcntl.h>
 #include <syslog.h>
@@ -109,3 +110,44 @@ void test_nuttx_fs_fstatfs01(FAR void **state)
   assert_int_equal(ret, 0);
   close(fd);
 }
+
+/****************************************************************************
+ * Name: test_nuttx_fs_fstatfs02
+ ****************************************************************************/
+
+void test_nuttx_fs_fstatfs02(FAR void **state)
+{
+  struct statfs fstatfsbuf;
+  struct statfs statfsbuf;
+  struct statvfs fstatvfsbuf;
+  struct statvfs statvfsbuf;
+  struct fs_testsuites_state_s *test_state;
+  int ret;
+  int fd;
+
+  test_state = *state;
+
+  /* A descriptor of a directory gives the file system of the directory.
+   * The teardown closes fd1, also when an assert fails.
+   */
+
+  fd = open(".", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+  assert_true(fd > 0);
+  test_state->fd1 = fd;
+
+  ret = fstatfs(fd, &fstatfsbuf);
+  assert_int_equal(ret, 0);
+  ret = statfs(".", &statfsbuf);
+  assert_int_equal(ret, 0);
+  assert_int_equal(fstatfsbuf.f_type, statfsbuf.f_type);
+  assert_int_equal(fstatfsbuf.f_bsize, statfsbuf.f_bsize);
+  assert_int_equal(fstatfsbuf.f_namelen, statfsbuf.f_namelen);
+
+  ret = fstatvfs(fd, &fstatvfsbuf);
+  assert_int_equal(ret, 0);
+  ret = statvfs(".", &statvfsbuf);
+  assert_int_equal(ret, 0);
+  assert_int_equal(fstatvfsbuf.f_bsize, statvfsbuf.f_bsize);
+  assert_int_equal(fstatvfsbuf.f_namemax, statvfsbuf.f_namemax);
+  assert_int_equal(fstatvfsbuf.f_flag, statvfsbuf.f_flag);
+}
diff --git a/testing/testsuites/kernel/fs/cmocka_fs_test.c 
b/testing/testsuites/kernel/fs/cmocka_fs_test.c
index f90d12d59..e46709ab7 100644
--- a/testing/testsuites/kernel/fs/cmocka_fs_test.c
+++ b/testing/testsuites/kernel/fs/cmocka_fs_test.c
@@ -78,6 +78,9 @@ int main(int argc, char *argv[])
       cmocka_unit_test_setup_teardown(test_nuttx_fs_fstatfs01,
                                       test_nuttx_fs_test_group_setup,
                                       test_nuttx_fs_test_group_teardown),
+      cmocka_unit_test_setup_teardown(test_nuttx_fs_fstatfs02,
+                                      test_nuttx_fs_test_group_setup,
+                                      test_nuttx_fs_test_group_teardown),
       cmocka_unit_test_setup_teardown(test_nuttx_fs_fsync01,
                                       test_nuttx_fs_test_group_setup,
                                       test_nuttx_fs_test_group_teardown),
diff --git a/testing/testsuites/kernel/fs/include/fstest.h 
b/testing/testsuites/kernel/fs/include/fstest.h
index 11d26f251..b1a21ac22 100644
--- a/testing/testsuites/kernel/fs/include/fstest.h
+++ b/testing/testsuites/kernel/fs/include/fstest.h
@@ -105,6 +105,7 @@ void test_nuttx_fs_fstat02(FAR void **state);
  * ************************************************/
 
 void test_nuttx_fs_fstatfs01(FAR void **state);
+void test_nuttx_fs_fstatfs02(FAR void **state);
 
 /* cases/fs_fsync_test.c
  * ************************************************/

Reply via email to