]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: df: check that --sync always calls sync before statfs
authorCollin Funk <collin.funk1@gmail.com>
Mon, 2 Feb 2026 05:32:03 +0000 (21:32 -0800)
committerCollin Funk <collin.funk1@gmail.com>
Thu, 5 Feb 2026 00:49:12 +0000 (16:49 -0800)
* tests/df/sync.sh: New file.
* tests/local.mk (all_tests): Add the test.

tests/df/sync.sh [new file with mode: 0755]
tests/local.mk

diff --git a/tests/df/sync.sh b/tests/df/sync.sh
new file mode 100755 (executable)
index 0000000..6bef029
--- /dev/null
@@ -0,0 +1,55 @@
+#!/bin/sh
+# Ensure 'df --sync' works.
+
+# Copyright (C) 2026 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ df
+
+# This test is marked "very expensive" since calling sync() can take a long
+# time on a busy system.
+very_expensive_
+require_strace_ 'sync,statfs,fstatfs'
+
+# Check that sync was called before statfs or statvfs.
+check_sync ()
+{
+  seen_sync=0
+  while IFS= read line; do
+    case "$line" in
+      sync\(*) seen_sync=1 ;;
+      statfs\(*|fstatfs\(*)
+        if test "$seen_sync" -eq 1; then
+          return 0
+        else
+          return 1
+        fi
+        ;;
+    esac
+  done < "$1"
+  # Fail if we don't see statfs or fstatfs.
+  return 1
+}
+
+# Make sure that 'df --sync' calls sync() before gathering usage information.
+strace -o strace.out -e trace=sync,statfs,fstatfs df --sync || fail=1
+check_sync strace.out || fail=1
+
+# Also check it with a file given as the argument.
+strace -o strace.out -e trace=sync,statfs,fstatfs df --sync . || fail=1
+check_sync strace.out || fail=1
+
+Exit $fail
index e3372354c8f4d08e146fba33d54496be9fc565ca..5a629e3876d116cc9fa6de4b492bba144a3b09c2 100644 (file)
@@ -584,6 +584,7 @@ all_tests =                                 \
   tests/df/df-P.sh                             \
   tests/df/df-output.sh                                \
   tests/df/df-symlink.sh                       \
+  tests/df/sync.sh                             \
   tests/df/unreadable.sh                       \
   tests/df/total-unprocessed.sh                        \
   tests/df/no-mtab-status.sh                   \