tests: avoid spurious dd/sparse failure
authorPádraig Brady <P@draigBrady.com>
Sat, 17 Mar 2012 16:04:21 +0000 (17:04 +0100)
committerPádraig Brady <P@draigBrady.com>
Tue, 20 Mar 2012 10:30:39 +0000 (10:30 +0000)
* tests/dd/sparse: Allow for greater variation in sparse-block counts.
Reported by Nelson H. F. Beebe and Bruno Haible.

tests/dd/sparse

index 17aa94b..feb9447 100755 (executable)
@@ -49,12 +49,18 @@ dd if=/dev/urandom of=file.in bs=1M count=1 conv=notrunc oflag=append
 
 # Note the block allocations below are usually equal,
 # but can vary by a file system block due to alignment,
-# which was seen on XFS at least.
+# which was seen on XFS at least.  Also on various BSDs
+# the sparse granularity was up to 8 file system blocks
+# (16KiB for the tested systems), causing this to be the
+# minimum accuracy we can support.
 alloc_equal() {
-  : ${sectors_per_block:=$(expr $(stat -f -c "%S" .) / 512)}
+  # 8 and 512 below are related, so hardcode sector_size for now
+  # : ${sector_size:=$(stat -c "%B" "$1")}
+  : ${sectors_per_block:=$(expr $(stat -f -c '%S' "$1") / 512)}
+  : ${min_sectors_per_sparse_block:=$(expr $sectors_per_block '*' 8)}
   alloc_diff=$(expr $(stat -c %b "$1") - $(stat -c %b "$2"))
   alloc_diff=$(echo $alloc_diff | tr -d -- -) # abs()
-  test $alloc_diff -le $sectors_per_block
+  test $alloc_diff -le $min_sectors_per_sparse_block
 }
 
 # Ensure NUL blocks smaller than the block size are not made sparse