From daa1e4f55702e03e9bcf06d2d0906652fb1619b0 Mon Sep 17 00:00:00 2001
From: =?utf8?q?P=C3=A1draig=20Brady?=
Date: Wed, 12 Apr 2023 14:37:00 +0100
Subject: [PATCH] tests: avoid dependence on file layout for cp sparse check
* tests/cp/sparse-2.sh: Don't depend on the copy taking
<= allocation of the source. Instead leverage --debug
to check that zero detection is being enabled.
---
tests/cp/sparse-2.sh | 18 ++++--------------
1 file changed, 4 insertions(+), 14 deletions(-)
diff --git a/tests/cp/sparse-2.sh b/tests/cp/sparse-2.sh
index 3024055e65..65607648ac 100755
--- a/tests/cp/sparse-2.sh
+++ b/tests/cp/sparse-2.sh
@@ -17,7 +17,7 @@
# along with this program. If not, see .
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
-print_ver_ cp stat dd
+print_ver_ cp dd
touch sparse_chk
seek_data_capable_ sparse_chk \
@@ -44,18 +44,8 @@ printf x > k || framework_failure_
dd bs=1k seek=1 of=k count=255 < /dev/zero || framework_failure_
# cp should detect the all-zero blocks and convert some of them to holes.
-# How many it detects/converts currently depends on io_blksize.
-# Currently, on my F14/ext4 desktop, this K file starts off with size 256KiB,
-# (note that the K in the preceding test starts off with size 4KiB).
-# cp from coreutils-8.9 with --sparse=always reduces the size to 32KiB.
-cp --reflink=never --sparse=always k k2 || fail=1
-if test $(stat -c %b k2) -ge $(stat -c %b k); then
- # If not sparse, then double check by creating with dd
- # as we're not guaranteed that seek will create a hole.
- # apfs on darwin 19.2.0 for example was seen to not to create holes < 16MiB.
- hole_size=$(stat -c %o k2) || framework_failure_
- dd if=k of=k2.dd bs=$hole_size conv=sparse || framework_failure_
- test $(stat -c %b k2) -eq $(stat -c %b k2.dd) || fail=1
-fi
+cp --debug --reflink=never --sparse=always k k2 >cp.out || fail=1
+cmp k k2 || fail=1
+grep 'sparse detection: .*zeros' cp.out || { cat cp.out; fail=1; }
Exit $fail
--
2.47.2