Collin Funk <[email protected]> writes:

> I guess for a simple test case we could check that /tmp is a seperate
> mountpoint and then call fts_open ("/", FTS_MOUNT, ...), and process all
> FTS_D entries returned from the root (skipping children so the test
> doesn't take forever). Then fail if we see /tmp returned.

Here is a more general test case. Just checking that each directory
directly under "/" has the same device ID as "/".

I'm considering moving the existing fts tests under a new
fts-extra-tests module so that this one is not marked as a
longrunning-test. Since I would like to see this one run more often. I
haven't looked into if Windows has an st_dev in 'struct stat' and if it
is set to a meaningful value.

Collin

>From d0f75507e8f41fe060e047387c014c52142a5ee8 Mon Sep 17 00:00:00 2001
Message-ID: <d0f75507e8f41fe060e047387c014c52142a5ee8.1761364704.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Fri, 24 Oct 2025 20:58:02 -0700
Subject: [PATCH] fts tests: Add a test for FTS_MOUNT.

* modules/fts-tests (Files): Add tests/macros.h.
* tests/test-fts.c: Include macros.h.
(test_fts_mount): New function.
(main): Call test_fts_mount.
---
 ChangeLog         |  8 ++++++++
 modules/fts-tests |  1 +
 tests/test-fts.c  | 37 +++++++++++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index a1228c2cd1..e6d594bee0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2025-10-24  Collin Funk  <[email protected]>
+
+	fts tests: Add a test for FTS_MOUNT.
+	* modules/fts-tests (Files): Add tests/macros.h.
+	* tests/test-fts.c: Include macros.h.
+	(test_fts_mount): New function.
+	(main): Call test_fts_mount.
+
 2025-10-23  Bruno Haible  <[email protected]>
 
 	stdioext: Add support for OpenBSD >= 7.8.
diff --git a/modules/fts-tests b/modules/fts-tests
index 5feb3c3c6e..0ff8a8cdde 100644
--- a/modules/fts-tests
+++ b/modules/fts-tests
@@ -3,6 +3,7 @@ longrunning-test
 
 Files:
 tests/test-fts.c
+tests/macros.h
 
 Depends-on:
 c99
diff --git a/tests/test-fts.c b/tests/test-fts.c
index f50df573b5..31c9898b80 100644
--- a/tests/test-fts.c
+++ b/tests/test-fts.c
@@ -26,6 +26,8 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
+#include "macros.h"
+
 #define BASE "t-fts.tmp"
 static char base[] = BASE; /* Not const, since argv needs non-const.  */
 static char const base_d[] = BASE "/d";
@@ -86,6 +88,39 @@ remove_tree (void)
     perror_exit (base, 3);
 }
 
+static void
+test_fts_mount (void)
+{
+  FTSENT *ent;
+  char *const root[] = { "/", NULL };
+  FTS *ftsp = fts_open (root, FTS_PHYSICAL | FTS_MOUNT | FTS_CWDFD, NULL);
+  dev_t root_dev;
+
+  ASSERT (ftsp != NULL);
+
+  /* Make sure each directory directly below the root directory has the same
+     device ID when we use FTS_MOUNT.  */
+  while ((ent = fts_read (ftsp)))
+    {
+      switch (ent->fts_info)
+        {
+        case FTS_D:
+          if (ent->fts_level == FTS_ROOTLEVEL)
+            root_dev = ent->fts_statp->st_dev;
+          else
+            {
+              ASSERT (ent->fts_statp->st_dev == root_dev);
+              ASSERT (fts_set (ftsp, ent, FTS_SKIP) == 0);
+            }
+          break;
+        default:
+          break;
+        }
+    }
+
+  ASSERT (fts_close (ftsp) == 0);
+}
+
 int
 main (void)
 {
@@ -168,5 +203,7 @@ main (void)
 
   fts_dealloc ();
 
+  test_fts_mount ();
+
   return 0;
 }
-- 
2.51.0

Reply via email to