git: 8cbd3949297d - main - stat: Nits in stat tests

From: Dag-Erling Smørgrav <des_at_FreeBSD.org>
Date: Wed, 08 Apr 2026 15:36:06 UTC
The branch main has been updated by des:

URL: https://cgit.FreeBSD.org/src/commit/?id=8cbd3949297d56e3960dcde73bd7e2277ac4bee8

commit 8cbd3949297d56e3960dcde73bd7e2277ac4bee8
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-04-08 15:35:35 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-04-08 15:35:35 +0000

    stat: Nits in stat tests
    
    * Use ourselves as test file instead of /COPYRIGHT, which may or may not
      be present in the test environment.
    
    * atf-check understands \n in strings, use it.
    
    * Some file systems don't like creating small holes, so create large ones
      instead.  This means we need two variables: ps (page size) is the
      minimum size of a data region and the alignment for a hole, while hs
      (hole size) is the minimum size of the holes we create.  This makes no
      difference on FreeBSD but makes it easier to port the test to other
      platforms.
    
    MFC after:      1 week
    Sponsored by:   Klara, Inc.
    Reviewed by:    kevans
    Differential Revision:  https://reviews.freebsd.org/D56304
---
 usr.bin/stat/tests/stat_test.sh | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/usr.bin/stat/tests/stat_test.sh b/usr.bin/stat/tests/stat_test.sh
index afe698575034..6043686396be 100755
--- a/usr.bin/stat/tests/stat_test.sh
+++ b/usr.bin/stat/tests/stat_test.sh
@@ -54,6 +54,7 @@ h_flag_head()
 }
 h_flag_body()
 {
+	file=$(realpath $0)
 	# POSIX defines a hole as “[a] contiguous region of bytes
 	# within a file, all having the value of zero” and requires
 	# that “all seekable files shall have a virtual hole starting
@@ -82,27 +83,27 @@ h_flag_body()
 	atf_check -o inline:"$((ps)) .\n" stat -h .
 	atf_check -o inline:"$((ps)) ." stat -hn .
 
-	# For a file, prints a list of holes.
+	# For a file, prints a list of holes.  Some file systems don't
+	# like creating small holes, so we create large ones instead.
+	hs=$((16*1024*1024))
 	atf_check truncate -s 0 foo
 	atf_check -o inline:"0 foo" \
 	    stat -hn foo
-	atf_check truncate -s "$((ps))" foo
-	atf_check -o inline:"0-$((ps-1)) foo" \
+	atf_check truncate -s "$((hs))" foo
+	atf_check -o inline:"0-$((hs-1)) foo" \
 	    stat -hn foo
-	atf_check dd status=none if=/COPYRIGHT of=foo \
-	    oseek="$((ps))" bs=1 count=1
-	atf_check -o inline:"0-$((ps-1)),$((ps+1)) foo" \
+	atf_check dd status=none if="${file}" of=foo \
+	    oseek="$((hs))" bs=1 count=1
+	atf_check -o inline:"0-$((hs-1)),$((hs+1)) foo" \
 	    stat -hn foo
-	atf_check truncate -s "$((ps*3))" foo
-	atf_check -o inline:"0-$((ps-1)),$((ps*2))-$((ps*3-1)) foo" \
+	atf_check truncate -s "$((hs*3))" foo
+	atf_check -o inline:"0-$((hs-1)),$((hs+ps))-$((hs*3-1)) foo" \
 	    stat -hn foo
 
 	# Test multiple files.
-	atf_check dd status=none if=/COPYRIGHT of=bar
+	atf_check dd status=none if="${file}" of=bar
 	sz=$(stat -f%z bar)
-	atf_check -o inline:"0-$((ps-1)),$((ps*2))-$((ps*3-1)) foo
-$((sz)) bar
-" \
+	atf_check -o inline:"0-$((hs-1)),$((hs+ps))-$((hs*3-1)) foo\n$((sz)) bar\n" \
 	    stat -h foo bar
 
 	# For a device, fail.