This better tests the SEEK_HOLE logic which replaced the original fiemap hole identification logic. Also it avoids a false failure in sparse-2.sh where we try to correlate the file sizes produced by cp and dd logic.
* tests/cp/sparse-2.sh: s/cp/cp --reflink=never/ * tests/cp/sparse-extents-2.sh: Likewise. * tests/cp/sparse-extents.sh: Likewise. * tests/cp/sparse-perf.sh: Likewise. * tests/cp/sparse.sh: Likewise. Fixes https://github.com/coreutils/coreutils/issues/54 --- tests/cp/sparse-2.sh | 4 ++-- tests/cp/sparse-extents-2.sh | 3 ++- tests/cp/sparse-extents.sh | 6 +++--- tests/cp/sparse-perf.sh | 2 +- tests/cp/sparse.sh | 20 ++++++++++++-------- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/tests/cp/sparse-2.sh b/tests/cp/sparse-2.sh index e75d232e3..da7503074 100755 --- a/tests/cp/sparse-2.sh +++ b/tests/cp/sparse-2.sh @@ -32,7 +32,7 @@ dd bs=1k seek=128 of=k < /dev/null || framework_failure_ for append in no yes; do test $append = yes && printf y >> k for i in always never; do - cp --sparse=$i k k2 || fail=1 + cp --reflink=never --sparse=$i k k2 || fail=1 cmp k k2 || fail=1 done done @@ -48,7 +48,7 @@ dd bs=1k seek=1 of=k count=255 < /dev/zero || framework_failure_ # 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 --sparse=always k k2 || fail=1 +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. diff --git a/tests/cp/sparse-extents-2.sh b/tests/cp/sparse-extents-2.sh index 544b959ef..24c7f6d9d 100755 --- a/tests/cp/sparse-extents-2.sh +++ b/tests/cp/sparse-extents-2.sh @@ -74,9 +74,10 @@ for i in $(seq 1 2 21); do # Note there is an implicit sync performed by cp on Linux kernels # before 2.6.39 to work around bugs in EXT4 and BTRFS. + # (this was removed in the release after coreutils-8.32). # Note also the -s parameter to the filefrag commands below # for the same reasons. - cp --sparse=always j1 j2 || fail=1 + cp --reflink=never --sparse=always j1 j2 || fail=1 cmp j1 j2 || fail_ "data loss i=$i j=$j" if ! filefrag -vs j1 | grep -F extent >/dev/null; then diff --git a/tests/cp/sparse-extents.sh b/tests/cp/sparse-extents.sh index 8f5b68653..eac44ba05 100755 --- a/tests/cp/sparse-extents.sh +++ b/tests/cp/sparse-extents.sh @@ -56,7 +56,7 @@ rm space.test # Ensure we read a large empty file quickly fallocate -l 300MiB empty.big || framework_failure_ -timeout 3 cp --sparse=always empty.big cp.test || fail=1 +timeout 3 cp --reflink=never --sparse=always empty.big cp.test || fail=1 test $(stat -c %s empty.big) = $(stat -c %s cp.test) || fail=1 rm empty.big cp.test fi @@ -68,12 +68,12 @@ fi # is smaller than the size, thus identifying the file as sparse. # Note the '-l 1' case is an effective noop, and just checks # a file with a trailing hole is copied correctly. -for sparse_mode in always auto never; do +for sparse_arg in always auto never; do for alloc in '-l 4194304' '-l 1048576 -o 4194304' '-l 1'; do dd count=10 if=/dev/urandom iflag=fullblock of=unwritten.withdata truncate -s 2MiB unwritten.withdata || framework_failure_ fallocate $alloc -n unwritten.withdata || framework_failure_ - cp --sparse=$sparse_mode unwritten.withdata cp.test || fail=1 + cp --reflink=never --sparse=$sparse_arg unwritten.withdata cp.test || fail=1 test $(stat -c %s unwritten.withdata) = $(stat -c %s cp.test) || fail=1 cmp unwritten.withdata cp.test || fail=1 rm unwritten.withdata cp.test || framework_failure_ diff --git a/tests/cp/sparse-perf.sh b/tests/cp/sparse-perf.sh index a71b854cf..d13415119 100755 --- a/tests/cp/sparse-perf.sh +++ b/tests/cp/sparse-perf.sh @@ -28,7 +28,7 @@ timeout 10 truncate -s1T f || skip_ "unable to create a 1 TiB sparse file" # Nothing can read (much less write) that many bytes in so little time. -timeout 10 cp f f2 || fail=1 +timeout 10 cp --reflink=never f f2 || fail=1 # Ensure that the sparse file copied through SEEK_DATA has the same size # in bytes as the original. diff --git a/tests/cp/sparse.sh b/tests/cp/sparse.sh index aa95422e2..9ce02fef6 100755 --- a/tests/cp/sparse.sh +++ b/tests/cp/sparse.sh @@ -27,8 +27,12 @@ require_sparse_support_ size=$(expr 128 \* 1024 + 1) dd bs=1 seek=$size of=sparse < /dev/null 2> /dev/null || framework_failure_ +# Avoid reflinking. We want to test hole navigation here. +cp_no_reflink() { + cp --reflink=never "$@" +} -cp --sparse=always sparse copy || fail=1 +cp_no_reflink --sparse=always sparse copy || fail=1 # Ensure that the copy has the same block count as the original. test $(stat --printf %b copy) -le $(stat --printf %b sparse) || fail=1 @@ -51,22 +55,22 @@ for pattern in 1 0; do for n in 1 2 4 11 32 $maxn; do parts=$(expr $maxn / $n) - rm -f sparse.in + rm -f file.in # Generate non sparse file for copying with alternating # hole/data patterns of size n * $hole_size for i in $(yes "$pattern" | head -n$parts); do - dd iflag=fullblock if=$i of=sparse.in conv=notrunc oflag=append \ + dd iflag=fullblock if=$i of=file.in conv=notrunc oflag=append \ bs=$hole_size count=$n status=none || framework_failure_ done - cp --sparse=always sparse.in sparse.out || fail=1 # non sparse input - cp --sparse=always sparse.out sparse.out2 || fail=1 # sparse input + cp_no_reflink --sparse=always file.in sparse.out || fail=1 # non sparse in + cp_no_reflink --sparse=always sparse.out sparse.out2 || fail=1 # sparse in - cmp sparse.in sparse.out || fail=1 - cmp sparse.in sparse.out2 || fail=1 + cmp file.in sparse.out || fail=1 + cmp file.in sparse.out2 || fail=1 - ls -lsh sparse.* + ls -lsh file.in sparse.* done done -- 2.26.2