From 8195165839877eece7984dd08613323e96424cea Mon Sep 17 00:00:00 2001 From: =?utf8?q?P=C3=A1draig=20Brady?= Date: Fri, 2 Mar 2012 10:53:48 +0000 Subject: [PATCH] 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. --- tests/dd/sparse | 14 ++++++++++++-- 1 file 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 -- 2.7.4