From: Collin Funk Date: Mon, 2 Feb 2026 05:32:03 +0000 (-0800) Subject: tests: df: check that --sync always calls sync before statfs X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e0b2db00ad21968e3631eeed77140ad4c85b7b23;p=thirdparty%2Fcoreutils.git tests: df: check that --sync always calls sync before statfs * tests/df/sync.sh: New file. * tests/local.mk (all_tests): Add the test. --- diff --git a/tests/df/sync.sh b/tests/df/sync.sh new file mode 100755 index 0000000000..6bef029809 --- /dev/null +++ b/tests/df/sync.sh @@ -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 . + +. "${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 diff --git a/tests/local.mk b/tests/local.mk index e3372354c8..5a629e3876 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 \