coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] tests: work around a block alignment issue in dd/sparse


From: Pádraig Brady
Subject: [PATCH] tests: work around a block alignment issue in dd/sparse
Date: Fri, 2 Mar 2012 11:00:14 +0000

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.
---
 tests/dd/sparse |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/tests/dd/sparse b/tests/dd/sparse
index 8f558a1..17aa94b 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
-- 
1.7.6.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]