tests: fix a false positive fiemap test on some file systems
authorPádraig Brady <P@draigBrady.com>
Wed, 13 Apr 2011 06:58:02 +0000 (07:58 +0100)
committerPádraig Brady <P@draigBrady.com>
Wed, 13 Apr 2011 10:18:48 +0000 (11:18 +0100)
* tests/filefrag-extent-compare: Don't check the length of the
last extent, as this was seen to vary on XFS, where it leaves
trailing blocks allocated for performance reasons.
* tests/cp/fiemap-empty: Though not seen as an issue in practise,
try to avoid possible issues with the allocator in file systems,
by requesting to allocate a power of 2.

tests/cp/fiemap-empty
tests/filefrag-extent-compare

index 42d816b..64c3254 100755 (executable)
@@ -38,8 +38,8 @@ rm falloc.test
 # which would cause failure of unrelated tests run in parallel.
 require_file_system_bytes_free_ 800000000
 
-fallocate -l 600000000 space.test ||
-  skip_test_ 'this test needs at least 600MB free space'
+fallocate -l 600MiB space.test ||
+  skip_test_ 'this test needs at least 600MiB free space'
 
 # Disable this test on old BTRFS (e.g. Fedora 14)
 # which reports ordinary extents for unwritten ones.
@@ -50,7 +50,7 @@ filefrag -v space.test | grep -F 'unwritten' > /dev/null ||
 rm space.test
 
 # Ensure we read a large empty file quickly
-fallocate -l 300000000 empty.big || framework_failure
+fallocate -l 300MiB empty.big || framework_failure
 timeout 3 cp --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
@@ -58,7 +58,7 @@ rm empty.big cp.test
 # Ensure we handle extents beyond file size correctly.
 # Note until we support fallocate, we will not maintain
 # the file allocation.  FIXME: amend this test when fallocate is supported.
-fallocate -l 10000000 -n unwritten.withdata || framework_failure
+fallocate -l 10MiB -n unwritten.withdata || framework_failure
 dd count=10 if=/dev/urandom conv=notrunc iflag=fullblock of=unwritten.withdata
 cp unwritten.withdata cp.test || fail=1
 test $(stat -c %s unwritten.withdata) = $(stat -c %s cp.test) || fail=1
@@ -68,16 +68,16 @@ rm unwritten.withdata cp.test
 # The following to generate unaccounted extents followed by a hole, is not
 # supported by ext4 at least. The ftruncate discards all extents not
 # accounted for in the size.
-#  fallocate -l 10000000 -n unacc.withholes
+#  fallocate -l 10MiB -n unacc.withholes
 #  dd count=10 if=/dev/urandom conv=notrunc iflag=fullblock of=unacc.withholes
-#  truncate -s20000000 unacc.withholes
+#  truncate -s20M unacc.withholes
 
 # Ensure we handle a hole after empty extents correctly.
 # Since all extents are accounted for in the size,
 # we can maintain the allocation independently from
 # fallocate() support.
-fallocate -l 10000000 empty.withholes
-truncate -s 20000000 empty.withholes
+fallocate -l 10MiB empty.withholes
+truncate -s 20M empty.withholes
 sectors_per_block=$(expr $(stat -c %o .) / 512)
 cp empty.withholes cp.test || fail=1
 test $(stat -c %s empty.withholes) = $(stat -c %s cp.test) || fail=1
index 2c33584..155e7ff 100644 (file)
@@ -56,10 +56,18 @@ merge_extents \@b;
 my $i = 0;
 while (defined $a[$i])
   {
-    $a[$i]->{L_BLK} == $b[$i]->{L_BLK} && $a[$i]->{LEN} == $b[$i]->{LEN}
-      or die "$ME: differing extent:\n"
-        . "  [$i]=$a[$i]->{L_BLK} $a[$i]->{LEN}\n"
-          . "  [$i]=$b[$i]->{L_BLK} $b[$i]->{LEN}\n";
+    my $start_match = $a[$i]->{L_BLK} == $b[$i]->{L_BLK};
+    my $len_match = $a[$i]->{LEN} == $b[$i]->{LEN};
+    if ( ! ($start_match && ($len_match || $i == (@a - 1))))
+      {
+        # On XFS on Linux kernel 2.6.38, it was seen that the size of the
+        # last extent can vary, and can extend beyond the length of the file.
+        # So we ignore the length of the last extent, because if the
+        # file is the wrong length we'll get failures elsewhere.
+        die "$ME: differing extent:\n"
+          . "  [$i]=$a[$i]->{L_BLK} $a[$i]->{LEN}\n"
+            . "  [$i]=$b[$i]->{L_BLK} $b[$i]->{LEN}\n";
+      }
     $i++;
   }