Index: stable/11/sbin/growfs/tests/legacy_test.pl =================================================================== --- stable/11/sbin/growfs/tests/legacy_test.pl (revision 324690) +++ stable/11/sbin/growfs/tests/legacy_test.pl (revision 324691) @@ -1,89 +1,101 @@ # $FreeBSD$ use strict; use warnings; +use POSIX; use Test::More tests => 19; use Fcntl qw(:DEFAULT :seek); use constant BLK => 512; use constant BLKS_PER_MB => 2048; my $unit; END { system "mdconfig -du$unit" if defined $unit }; +sub fsck_md { + my ($is_clean, $md); + + $md = shift; + + chomp(my @fsck_output = `fsck_ffs -Ffy ${md}a`); + $is_clean = WIFEXITED($?) && + (WEXITSTATUS($?) == 0 || WEXITSTATUS($?) == 7); + ok($is_clean, "checking ${md}a's filesystem"); + if ($is_clean) { + diag "filesystem reported clean"; + } else { + diag "filesystem not reported clean: " . join("\n", @fsck_output); + } +} + sub setsize { my ($partszMB, $unitszMB) = @_; open my $fd, "|-", "disklabel -R md$unit /dev/stdin" or die; print $fd "a: ", ($partszMB * BLKS_PER_MB), " 0 4.2BSD 1024 8192\n"; print $fd "c: ", ($unitszMB * BLKS_PER_MB), " 0 unused 0 0\n"; close $fd; } sub fill { my ($start, $size, $content) = @_; my $content512 = $content x (int(512 / length $content) + 1); substr($content512, 512) = ""; sysopen my $fd, "/dev/md$unit", O_RDWR or die "/dev/md$unit: $!"; seek($fd, $start * BLK, SEEK_SET); while ($size) { syswrite($fd, $content512) == 512 or die "write: $!"; $size--; } } SKIP: { skip "Cannot test without UID 0", 19 if $<; chomp(my $md = `mdconfig -s40m`); like($md, qr/^md\d+$/, "Created $md with size 40m") or die; $unit = substr $md, 2; for my $type (1..2) { initialise: { ok(setsize(10, 40), "Sized ${md}a to 10m"); system "newfs -O $type -U ${md}a >/dev/null"; is($?, 0, "Initialised the filesystem on ${md}a as UFS$type"); - chomp(my @out = `fsck -tufs -y ${md}a`); - ok(!grep(/MODIFIED/, @out), "fsck says ${md}a is clean, " . - scalar(@out) . " lines of output"); + + fsck_md($md); } extend20_zeroed: { ok(setsize(20, 40), "Sized ${md}a to 20m"); diag "Filling the extent with zeros"; fill(10 * BLKS_PER_MB, 10 * BLKS_PER_MB, chr(0)); my $out = `growfs -y ${md}a`; is($?, 0, "Extended the filesystem on ${md}a") or print $out; my ($unallocated) = $out =~ m{\d+ sectors cannot be allocated}; fill(30 * BLKS_PER_MB - $unallocated, $unallocated, chr(0)) if $unallocated; - chomp(my @out = `fsck -tufs -y ${md}a`); - ok(!grep(/MODIFIED/, @out), "fsck says ${md}a is clean, " . - scalar(@out) . " lines of output"); + fsck_md($md); } extend30_garbaged: { ok(setsize(30, 40), "Sized ${md}a to 30m"); diag "Filling the extent with garbage"; fill(20 * BLKS_PER_MB, 10 * BLKS_PER_MB, chr(0xaa) . chr(0x55)); my $out = `growfs -y ${md}a`; is($?, 0, "Extended the filesystem on ${md}a") or print $out; my ($unallocated) = $out =~ m{\d+ sectors cannot be allocated}; fill(30 * BLKS_PER_MB - $unallocated, $unallocated, chr(0)) if $unallocated; - chomp(my @out = `fsck -tufs -y ${md}a`); - ok(!grep(/MODIFIED/, @out), "fsck says ${md}a is clean, " . - scalar(@out) . " lines of output"); + fsck_md($md); } } system "mdconfig -du$unit"; undef $unit; } Index: stable/11/tests/sys/geom/class/eli/resize_test.sh =================================================================== --- stable/11/tests/sys/geom/class/eli/resize_test.sh (revision 324690) +++ stable/11/tests/sys/geom/class/eli/resize_test.sh (revision 324691) @@ -1,148 +1,147 @@ #!/bin/sh # $FreeBSD$ . $(dirname $0)/conf.sh echo 1..27 BLK=512 BLKS_PER_MB=2048 md=$(mdconfig -s40m) || exit 1 unit=${md#md} i=1 +fsck_md() +{ + local is_clean + + out=$(fsck_ffs -Ffy ${md}a.eli) + if [ $? -eq 0 -o $? -eq 7 ]; then + echo "ok $i - fsck says ${md}a.eli is clean" + else + echo "not ok $i - fsck says ${md}a.eli is dirty" + fi + i=$((i + 1)) +} + setsize() { partszMB=$1 unitszMB=$2 { echo a: $(($partszMB * $BLKS_PER_MB)) 0 4.2BSD 1024 8192 echo c: $(($unitszMB * $BLKS_PER_MB)) 0 unused 0 0 } | disklabel -R $md /dev/stdin } # Initialise setsize 10 40 || echo -n "not " echo ok $i - "Sized ${md}a to 10m" i=$((i + 1)) echo secret >tmp.key geli init -Bnone -PKtmp.key ${md}a || echo -n "not " echo ok $i - "Initialised geli on ${md}a" i=$((i + 1)) geli attach -pk tmp.key ${md}a || echo -n "not " echo ok $i - "Attached ${md}a as ${md}a.eli" i=$((i + 1)) newfs -U ${md}a.eli >/dev/null || echo -n "not " echo ok $i - "Initialised the filesystem on ${md}a.eli" i=$((i + 1)) -out=$(fsck -tufs -y ${md}a.eli) -echo "$out" | fgrep -q MODIFIED && echo -n "not " -echo ok $i - "fsck says ${md}a.eli is clean," $(echo $(echo "$out" | wc -l)) \ - "lines of output" -i=$((i + 1)) +fsck_md - # Doing a backup, resize & restore must be forced (with -f) as geli # verifies that the provider size in the metadata matches the consumer. geli backup ${md}a tmp.meta || echo -n "not " echo ok $i - "Backed up ${md}a metadata" i=$((i + 1)) geli detach ${md}a.eli || echo -n "not " echo ok $i - "Detached ${md}a.eli" i=$((i + 1)) setsize 20 40 || echo -n "not " echo ok $i - "Sized ${md}a to 20m" i=$((i + 1)) geli attach -pktmp.key ${md}a && echo -n "not " echo ok $i - "Attaching ${md}a fails after resizing the consumer" i=$((i + 1)) geli restore tmp.meta ${md}a && echo -n "not " echo ok $i - "Restoring metadata on ${md}a.eli fails without -f" i=$((i + 1)) geli restore -f tmp.meta ${md}a || echo -n "not " echo ok $i - "Restoring metadata on ${md}a.eli can be forced" i=$((i + 1)) geli attach -pktmp.key ${md}a || echo -n "not " echo ok $i - "Attaching ${md}a is now possible" i=$((i + 1)) growfs -y ${md}a.eli >/dev/null || echo -n "not " echo ok $i - "Extended the filesystem on ${md}a.eli" i=$((i + 1)) -out=$(fsck -tufs -y ${md}a.eli) -echo "$out" | fgrep -q MODIFIED && echo -n "not " -echo ok $i - "fsck says ${md}a.eli is clean," $(echo $(echo "$out" | wc -l)) \ - "lines of output" -i=$((i + 1)) +fsck_md - # Now do the resize properly geli detach ${md}a.eli || echo -n "not " echo ok $i - "Detached ${md}a.eli" i=$((i + 1)) setsize 30 40 || echo -n "not " echo ok $i - "Sized ${md}a to 30m" i=$((i + 1)) geli resize -s20m ${md}a || echo -n "not " echo ok $i - "Resizing works ok" i=$((i + 1)) geli resize -s20m ${md}a && echo -n "not " echo ok $i - "Resizing doesn't work a 2nd time (no old metadata)" i=$((i + 1)) geli attach -pktmp.key ${md}a || echo -n "not " echo ok $i - "Attaching ${md}a works ok" i=$((i + 1)) growfs -y ${md}a.eli >/dev/null || echo -n "not " echo ok $i - "Extended the filesystem on ${md}a.eli" i=$((i + 1)) -out=$(fsck -tufs -y ${md}a.eli) -echo "$out" | fgrep -q MODIFIED && echo -n "not " -echo ok $i - "fsck says ${md}a.eli is clean," $(echo $(echo "$out" | wc -l)) \ - "lines of output" -i=$((i + 1)) +fsck_md geli detach ${md}a.eli gpart destroy -F $md >/dev/null # Verify that the man page example works, changing ada0 to $md, # 1g to 20m, 2g to 30m and keyfile to tmp.key, and adding -B none # to geli init. gpart create -s GPT $md || echo -n "not " echo ok $i - "Installed a GPT on ${md}" i=$((i + 1)) gpart add -s 20m -t freebsd-ufs -i 1 $md || echo -n "not " echo ok $i - "Added a 20m partition in slot 1" i=$((i + 1)) geli init -B none -K tmp.key -P ${md}p1 || echo -n "not " echo ok $i - "Initialised geli on ${md}p1" i=$((i + 1)) gpart resize -s 30m -i 1 $md || echo -n "not " echo ok $i - "Resized partition ${md}p1 to 30m" i=$((i + 1)) geli resize -s 20m ${md}p1 || echo -n "not " echo ok $i - "Resized geli on ${md}p1 to 30m" i=$((i + 1)) geli attach -k tmp.key -p ${md}p1 || echo -n "not " echo ok $i - "Attached ${md}p1.eli" i=$((i + 1)) geli detach ${md}p1.eli rm tmp.* Index: stable/11 =================================================================== --- stable/11 (revision 324690) +++ stable/11 (revision 324691) Property changes on: stable/11 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head:r324478