* tests/df/sync.sh: New file. * tests/local.mk (all_tests): Add the test. --- tests/df/sync.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/local.mk | 1 + 2 files changed, 53 insertions(+) create mode 100755 tests/df/sync.sh
diff --git a/tests/df/sync.sh b/tests/df/sync.sh new file mode 100755 index 000000000..ba90e16d0 --- /dev/null +++ b/tests/df/sync.sh @@ -0,0 +1,52 @@ +#!/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 +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 diff --git a/tests/local.mk b/tests/local.mk index e3372354c..5a629e387 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -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 \ -- 2.52.0
