summaryrefslogtreecommitdiff
path: root/tests/dd
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2012-03-02 10:53:48 +0000
committerPádraig Brady <P@draigBrady.com>2012-03-02 10:57:56 +0000
commit8195165839877eece7984dd08613323e96424cea (patch)
tree49e78179f53d25946784b7ca5fd7f047325cef89 /tests/dd
parent4724cd8fe8c76039ef219f350e29179fa66fd2fc (diff)
downloadcoreutils-8195165839877eece7984dd08613323e96424cea.tar.xz
tests: work around a block alignment issue in dd/sparse
Prompted by the continuous integration build failure at: http://hydra.nixos.org/build/2188210 (which uses XFS). * tests/dd/sparse (alloc_equal): Add a block allocation comparison function that accounts for variations due to alignment.
Diffstat (limited to 'tests/dd')
-rwxr-xr-xtests/dd/sparse14
1 files changed, 12 insertions, 2 deletions
diff --git a/tests/dd/sparse b/tests/dd/sparse
index 8f558a1b0..17aa94b8b 100755
--- a/tests/dd/sparse
+++ b/tests/dd/sparse
@@ -47,14 +47,24 @@ dd if=/dev/urandom of=file.in bs=1M count=1
truncate -s+1M file.in
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.
+alloc_equal() {
+ : ${sectors_per_block:=$(expr $(stat -f -c "%S" .) / 512)}
+ 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
+}
+
# Ensure NUL blocks smaller than the block size are not made sparse
dd if=file.in of=file.out bs=2M conv=sparse
test $(stat -c %s file.in) = $(stat -c %s file.out) || fail=1
-test $(stat -c %b file.in) = $(stat -c %b file.out) && fail=1
+alloc_equal file.in file.out && fail=1
# Ensure NUL blocks >= block size are made sparse
dd if=file.in of=file.out bs=1M conv=sparse
test $(stat -c %s file.in) = $(stat -c %s file.out) || fail=1
-test $(stat -c %b file.in) = $(stat -c %b file.out) || fail=1
+alloc_equal file.in file.out || fail=1
Exit $fail