>From 7e27d28b799f0399bbf79074854fa9967ff7752e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Sat, 19 Mar 2011 01:22:37 +0000 Subject: [PATCH] tests: fix the sparse-fiemap test * tests/filefrag-extent-compare: Merge adjacent extents in each list before processing, so we correctly account for split extents in either list. * tests/cp/sparse-fiemap: Remove the explicit syncing, which was only changing way extents were arranged, and thus working around the extent comparison issue that was seen on ext4 loop back. --- tests/cp/sparse-fiemap | 11 +++++------ tests/filefrag-extent-compare | 41 ++++++++++++++++++++++++++++++----------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/tests/cp/sparse-fiemap b/tests/cp/sparse-fiemap index a2460a0..5f0beb7 100755 --- a/tests/cp/sparse-fiemap +++ b/tests/cp/sparse-fiemap @@ -69,12 +69,11 @@ for i in $(seq 1 2 21); do -e 'for (1..'$j') { sysseek (*F, $n, 1)' \ -e '&& syswrite (*F, chr($_)x$n) or die "$!"}' > j1 || fail=1 - # Note the explicit fdatasync is used here as - # it was seen that `filefrag -s` (FIEMAP_FLAG_SYNC) was - # ineffective on ext4 loopback on Linux 2.6.35.10-72.fc14.i686 - dd if=/dev/null of=j1 conv=notrunc,fdatasync + # Note there is an implicit sync performed by cp to + # work arounds bugs in EXT4 and BTRFS before Linux 2.6.38 + # Note also the -s parameter to the second filefrag below + # for the same reasons. cp --sparse=always j1 j2 || fail=1 - dd if=/dev/null of=j2 conv=notrunc,fdatasync cmp j1 j2 || fail=1 if ! filefrag -v j1 | grep -F extent >/dev/null; then @@ -98,7 +97,7 @@ for i in $(seq 1 2 21); do # exclude the physical block numbers; they always differ filefrag -v j1 > ff1 || framework_failure - filefrag -v j2 > ff2 || framework_failure + filefrag -vs j2 > ff2 || framework_failure { f ff1; f ff2; } | $PERL $abs_top_srcdir/tests/filefrag-extent-compare || fail=1 fi diff --git a/tests/filefrag-extent-compare b/tests/filefrag-extent-compare index 3c095d5..fa04d9e 100644 --- a/tests/filefrag-extent-compare +++ b/tests/filefrag-extent-compare @@ -28,31 +28,50 @@ my @b; foreach my $i (0..@A/2-1) { $a[$i] = { L_BLK => $A[2*$i], LEN => $A[2*$i+1] } }; foreach my $i (0..@B/2-1) { $b[$i] = { L_BLK => $B[2*$i], LEN => $B[2*$i+1] } }; +# Merge adjacent extents in passed array +# Discounted extents have length set to 0 +sub merge_extents($) +{ + my @e = @{ $_[0] }; + + my $a = 1; + my $b = 0; + while (1) + { + (!defined $e[$a] || !defined $e[$b]) + and last; + ($e[$b]->{L_BLK} + $e[$b]->{LEN} == $e[$a]->{L_BLK}) + and $e[$b]->{LEN} += $e[$a]->{LEN}, $e[$a]->{LEN} = 0, next; + $b=$a; + } + continue + { + ++$a; + } +} + +merge_extents(\@a); +merge_extents(\@b); + my $i = 0; my $j = 0; while (1) { + # skip discounted extents + defined $a[$i] && $a[$i]->{LEN} == 0 and ++$i, next; + defined $b[$j] && $b[$j]->{LEN} == 0 and ++$j, next; + !defined $a[$i] && !defined $b[$j] and exit 0; defined $a[$i] && defined $b[$j] or die "\@a and \@b have different lengths, even after adjustment\n"; ($a[$i]->{L_BLK} == $b[$j]->{L_BLK} && $a[$i]->{LEN} == $b[$j]->{LEN}) - and next; - ($a[$i]->{LEN} < $b[$j]->{LEN} - && exists $a[$i+1] && $a[$i]->{LEN} + $a[$i+1]->{LEN} == $b[$j]->{LEN}) - and ++$i, next; - exists $b[$j+1] && $a[$i]->{LEN} == $b[$i]->{LEN} + $b[$i+1]->{LEN} - and ++$j, next; + and $i++, $j++, next; die "differing extent:\n" . " [$i]=$a[$i]->{L_BLK} $a[$i]->{LEN}\n" . " [$j]=$b[$j]->{L_BLK} $b[$j]->{LEN}\n" } -continue - { - ++$i; - ++$j; - } ### Setup "GNU" style for perl-mode and cperl-mode. ## Local Variables: -- 1.7.4