1#!/usr/bin/env perl 2# 3# Copyright (c) 2005, 2006 Marcel Moolenaar 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 10# 1. Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer. 12# 2. Redistributions in binary form must reproduce the above copyright 13# notice, this list of conditions and the following disclaimer in the 14# documentation and/or other materials provided with the distribution. 15# 16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26# 27# $FreeBSD$ 28 29use strict; 30use warnings; 31 32use File::Basename; 33 34my $disk = "/tmp/disk-$$"; 35my $mntpt_prefix = "/tmp/mount-$$"; 36 37my %steps = ( 38 "000" => "gctl", 39 "001" => "gctl verb=bogus", 40 "010" => "gctl verb=create", 41 "011" => "gctl verb=create provider=bogus", 42 "020" => "mdcfg create pristine", 43 "021" => "gctl verb=create provider=%dev% entries=-1", 44 "022" => "gctl verb=create provider=%dev% entries=128", 45 "023" => "gctl verb=create provider=%dev%", 46 "024" => "gctl verb=modify geom=%dev%", 47 "025" => "conf", 48 "030" => "gctl verb=add", 49 "031" => "gctl verb=add geom=bogus", 50 "032" => "gctl verb=add geom=%dev%", 51 "033" => "gctl verb=add geom=%dev% type=bogus", 52 "034" => "gctl verb=add geom=%dev% type=ed0101b0-2a71-11da-ba81-003048416ace", 53 "035" => "gctl verb=add geom=%dev% type=ed0101b0-2a71-11da-ba81-003048416ace start=1", 54 "036" => "gctl verb=add geom=%dev% type=ed0101b0-2a71-11da-ba81-003048416ace start=34", 55 "037" => "gctl verb=add geom=%dev% type=ed0101b0-2a71-11da-ba81-003048416ace start=34 end=12345678", 56 "038" => "gctl verb=add geom=%dev% type=ed0101b0-2a71-11da-ba81-003048416ace start=162 end=417 entry=129", 57 "039" => "gctl verb=add geom=%dev% type=ed0101b0-2a71-11da-ba81-003048416ace start=162 end=417 entry:8=5", 58 "040" => "gctl verb=add geom=%dev% type=83d34ed5-c4ff-11da-b65b-000347c5d7f3 start=34 end=161 entry=5", 59 "041" => "gctl verb=add geom=%dev% type=83d34ed5-c4ff-11da-b65b-000347c5d7f3 start=34 end=546", 60 "042" => "gctl verb=add geom=%dev% type=83d34ed5-c4ff-11da-b65b-000347c5d7f3 start=162 end=417", 61 "043" => "gctl verb=add geom=%dev% type=83d34ed5-c4ff-11da-b65b-000347c5d7f3 start=100 end=300", 62 "044" => "gctl verb=add geom=%dev% type=83d34ed5-c4ff-11da-b65b-000347c5d7f3 start=300 end=500", 63 "045" => "gctl verb=add geom=%dev% type=83d34ed5-c4ff-11da-b65b-000347c5d7f3 start=34 end=161 entry:8", 64 "046" => "gctl verb=add geom=%dev% type=d2bd4509-c4ff-11da-b4cc-00306e39b62f start=418 end=546 entry:8", 65 "047" => "conf", 66 "050" => "gctl verb=remove geom=%dev% entry=5", 67 "051" => "gctl verb=remove geom=%dev% entry=2", 68 "052" => "gctl verb=remove geom=%dev% entry=1", 69 "053" => "gctl verb=remove geom=%dev% entry=1", 70 "054" => "conf", 71 "060" => "gctl verb=add geom=%dev% type=516e7cb6-6ecf-11d6-8ff8-00022d09712b start=34 end=546 entry:8=1", 72 "061" => "mount %dev%p1", 73 "062" => "gctl verb=delete geom=%dev% entry=1", 74 "063" => "umount %dev%p1", 75 "064" => "gctl verb=delete geom=%dev% entry=1", 76 "065" => "conf", 77 "100" => "mdcfg destroy", 78 "110" => "mdcfg create corrupted", 79 "111" => "gctl verb=add geom=%dev%", 80 "120" => "mdcfg destroy", 81); 82 83my %result = ( 84 "000" => "FAIL Verb missing", 85 "001" => "FAIL 22 verb 'bogus'", 86 "010" => "FAIL 87 provider", 87 "011" => "FAIL 22 provider 'bogus'", 88 "020" => "", 89 "021" => "FAIL 22 entries -1", 90 "022" => "PASS", 91 "023" => "FAIL 17 geom '%dev%'", 92 "024" => "FAIL 87 entry", 93 "025" => "b1856477950e5786898c8f01361196cf", 94 "030" => "FAIL 87 geom", 95 "031" => "FAIL 22 geom 'bogus'", 96 "032" => "FAIL 87 type", 97 "033" => "FAIL 22 type 'bogus'", 98 "034" => "FAIL 87 start", 99 "035" => "FAIL 22 start 1", 100 "036" => "FAIL 87 end", 101 "037" => "FAIL 22 end 12345678", 102 "038" => "FAIL 22 entry 129", 103 "039" => "PASS entry=5", 104 "040" => "FAIL 17 entry 5", 105 "041" => "FAIL 28 start/end 34/546", 106 "042" => "FAIL 28 start/end 162/417", 107 "043" => "FAIL 28 start/end 100/300", 108 "044" => "FAIL 28 start/end 300/500", 109 "045" => "PASS entry=1", 110 "046" => "PASS entry=2", 111 "047" => "50783a39eecfc62a29db24381e12b9d8", 112 "050" => "PASS", 113 "051" => "PASS", 114 "052" => "PASS", 115 "053" => "FAIL 2 entry 1", 116 "054" => "b1856477950e5786898c8f01361196cf", 117 "060" => "PASS", 118 "061" => "PASS", 119 "062" => "FAIL 16", 120 "063" => "PASS", 121 "064" => "PASS", 122 "065" => "b1856477950e5786898c8f01361196cf", 123 "100" => "", 124 "110" => "", 125 "111" => "FAIL 6 geom '%dev%'", 126 "120" => "", 127); 128 129my $verbose = ""; 130if (exists $ENV{'TEST_VERBOSE'}) { 131 $verbose = "-v"; 132} 133 134# Compile the driver... 135my $st = system("make obj && make all"); 136if ($st != 0) { 137 print "1..0 # SKIP error compiling test.c\n"; 138 exit 0; 139} 140chomp(my $cmd = `make '-V\${.OBJDIR}/\${PROG}'`); 141 142my $out = basename($cmd) . ".out"; 143 144# Make sure we have permission to use gctl... 145if (`$cmd` =~ "^FAIL Permission denied") { 146 print "1..0 # SKIP insufficient permissions\n"; 147 unlink $cmd; 148 exit 0; 149} 150 151my $count = keys (%steps); 152print "1..$count\n"; 153 154my $nr = 1; 155my $dev = "n/a"; 156foreach my $key (sort keys %steps) { 157 my ($action, $args) = split(/ /, $steps{$key}, 2); 158 my $res = $result{$key}; 159 $args = "" if (not defined $args); 160 $args =~ s/%dev%/$dev/g; 161 $res =~ s/%dev%/$dev/g; 162 163 if ($action =~ "^gctl") { 164 my $errmsg = ""; 165 system("$cmd $verbose $args | tee $out 2>&1"); 166 chomp($st = `tail -1 $out`); 167 if ($st ne $res) { 168 $errmsg = "\"$st\" (actual) != \"$res\" (expected)\n"; 169 } 170 printf("%sok $nr \# gctl($key)%s\n", 171 ($errmsg eq "" ? "" : "not "), 172 ($errmsg eq "" ? "" : " - $errmsg")); 173 unlink $out; 174 } elsif ($action =~ "^mdcfg") { 175 my $errmsg = ""; 176 if ($args =~ "^create") { 177 # NOTE: `count=1024` affects $key => {"025" "054", "065"}. 178 if (system("dd if=/dev/zero of=$disk count=1024 2>&1") == 0) { 179 chomp($dev = `mdconfig -a -t vnode -f $disk`); 180 if ($? == 0) { 181 if (system("gpart create -s GPT $dev") != 0) { 182 $errmsg = "gpart create failed"; 183 } 184 } else { 185 $errmsg = "mdconfig -a failed"; 186 } 187 } else { 188 $errmsg = "dd failed"; 189 } 190 } elsif ($args =~ "^destroy") { 191 $dev =~ s/md/-u /g; 192 if (system("mdconfig -d $dev") != 0) { 193 $errmsg = "mdconfig -d failed"; 194 } 195 unlink $disk; 196 $dev = "n/a"; 197 } 198 printf("%sok $nr # mdcfg($key)%s\n", 199 ($errmsg eq "" ? "" : "not "), 200 ($errmsg eq "" ? "" : " - $errmsg")); 201 } elsif ($action =~ "^conf") { 202 system("sysctl -b kern.geom.conftxt | grep -a $dev | sed -e s:$disk:DISK:g -e s:$dev:DEV:g | sort | md5 -p | tee $out 2>&1"); 203 $st = `tail -1 $out`; 204 if ($st =~ "^$res") { 205 print "ok $nr \# conf($key)\n"; 206 } else { 207 print "not ok $nr \# conf($key) - $st\n"; 208 } 209 unlink $out; 210 } elsif ($action =~ "^mount") { 211 my $errmsg = ""; 212 mkdir("$mntpt_prefix-$args"); 213 if (system("newfs /dev/$args") == 0) { 214 if (system("mount /dev/$args $mntpt_prefix-$args") != 0) { 215 $errmsg = "mount failed"; 216 } 217 } else { 218 $errmsg = "newfs failed"; 219 } 220 printf("%sok $nr # mount($key)%s\n", 221 ($errmsg eq "" ? "" : "not "), 222 ($errmsg eq "" ? "" : " - $errmsg")); 223 } elsif ($action =~ "^umount") { 224 system("umount $mntpt_prefix-$args"); 225 system("rmdir $mntpt_prefix-$args"); 226 print "ok $nr \# umount($key)\n"; 227 } 228 $nr += 1; 229} 230exit 0; 231