legacy_test.pl revision 212839
1#! /usr/bin/perl 2# 3# $FreeBSD: head/tools/regression/sbin/growfs/regress.t 212839 2010-09-19 08:18:56Z brian $ 4 5use strict; 6use warnings; 7use Test::More tests => 19; 8use Fcntl qw(:DEFAULT :seek); 9 10use constant BLK => 512; 11use constant BLKS_PER_MB => 2048; 12 13my $unit; 14END { system "mdconfig -du$unit" if defined $unit }; 15 16sub setsize { 17 my ($partszMB, $unitszMB) = @_; 18 19 open my $fd, "|-", "disklabel -R md$unit /dev/stdin" or die; 20 print $fd "a: ", ($partszMB * BLKS_PER_MB), " 0 4.2BSD 1024 8192\n"; 21 print $fd "c: ", ($unitszMB * BLKS_PER_MB), " 0 unused 0 0\n"; 22 close $fd; 23} 24 25sub fill { 26 my ($start, $size, $content) = @_; 27 28 my $content512 = $content x (int(512 / length $content) + 1); 29 substr($content512, 512) = ""; 30 sysopen my $fd, "/dev/md$unit", O_RDWR or die "/dev/md$unit: $!"; 31 seek($fd, $start * BLK, SEEK_SET); 32 while ($size) { 33 syswrite($fd, $content512) == 512 or die "write: $!"; 34 $size--; 35 } 36} 37 38SKIP: { 39 skip "Cannot test without UID 0", 19 if $<; 40 41 chomp(my $md = `mdconfig -s40m`); 42 like($md, qr/^md\d+$/, "Created $md with size 40m") or die; 43 $unit = substr $md, 2; 44 45 for my $type (1..2) { 46 47 initialise: { 48 ok(setsize(10, 40), "Sized ${md}a to 10m"); 49 system "newfs -O $type -U ${md}a >/dev/null"; 50 is($?, 0, "Initialised the filesystem on ${md}a as UFS$type"); 51 chomp(my @out = `fsck -tufs -y ${md}a`); 52 ok(!grep(/MODIFIED/, @out), "fsck says ${md}a is clean, " . 53 scalar(@out) . " lines of output"); 54 } 55 56 extend20_zeroed: { 57 ok(setsize(20, 40), "Sized ${md}a to 20m"); 58 diag "Filling the extent with zeros"; 59 fill(10 * BLKS_PER_MB, 10 * BLKS_PER_MB, chr(0)); 60 my $out = `growfs -y ${md}a`; 61 is($?, 0, "Extended the filesystem on ${md}a") or print $out; 62 63 my ($unallocated) = $out =~ m{\d+ sectors cannot be allocated}; 64 fill(30 * BLKS_PER_MB - $unallocated, $unallocated, chr(0)) 65 if $unallocated; 66 67 chomp(my @out = `fsck -tufs -y ${md}a`); 68 ok(!grep(/MODIFIED/, @out), "fsck says ${md}a is clean, " . 69 scalar(@out) . " lines of output"); 70 } 71 72 extend30_garbaged: { 73 ok(setsize(30, 40), "Sized ${md}a to 30m"); 74 diag "Filling the extent with garbage"; 75 fill(20 * BLKS_PER_MB, 10 * BLKS_PER_MB, chr(0xaa) . chr(0x55)); 76 my $out = `growfs -y ${md}a`; 77 is($?, 0, "Extended the filesystem on ${md}a") or print $out; 78 79 my ($unallocated) = $out =~ m{\d+ sectors cannot be allocated}; 80 fill(30 * BLKS_PER_MB - $unallocated, $unallocated, chr(0)) 81 if $unallocated; 82 83 chomp(my @out = `fsck -tufs -y ${md}a`); 84 ok(!grep(/MODIFIED/, @out), "fsck says ${md}a is clean, " . 85 scalar(@out) . " lines of output"); 86 } 87 } 88 89 system "mdconfig -du$unit"; 90 undef $unit; 91} 92