3 # Copyright (c) 2005, 2006 Marcel Moolenaar
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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.
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.
34 my $disk = "/tmp/disk-$$";
35 my $mntpt_prefix = "/tmp/mount-$$";
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%",
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",
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",
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",
77 "100" => "mdcfg destroy",
78 "110" => "mdcfg create corrupted",
79 "111" => "gctl verb=add geom=%dev%",
80 "120" => "mdcfg destroy",
84 "000" => "FAIL Verb missing",
85 "001" => "FAIL 22 verb 'bogus'",
86 "010" => "FAIL 87 provider",
87 "011" => "FAIL 22 provider 'bogus'",
89 "021" => "FAIL 22 entries -1",
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",
115 "053" => "FAIL 2 entry 1",
116 "054" => "b1856477950e5786898c8f01361196cf",
122 "065" => "b1856477950e5786898c8f01361196cf",
125 "111" => "FAIL 6 geom '%dev%'",
130 if (exists $ENV{'TEST_VERBOSE'}) {
134 # Compile the driver...
135 my $st = system("make obj && make all");
137 print "1..0 # SKIP error compiling test.c\n";
140 chomp(my $cmd = `make '-V\${.OBJDIR}/\${PROG}'`);
142 my $out = basename($cmd) . ".out";
144 # Make sure we have permission to use gctl...
145 if (`$cmd` =~ "^FAIL Permission denied") {
146 print "1..0 # SKIP insufficient permissions\n";
151 my $count = keys (%steps);
156 foreach 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;
163 if ($action =~ "^gctl") {
165 system("$cmd $verbose $args | tee $out 2>&1");
166 chomp($st = `tail -1 $out`);
168 $errmsg = "\"$st\" (actual) != \"$res\" (expected)\n";
170 printf("%sok $nr \# gctl($key)%s\n",
171 ($errmsg eq "" ? "" : "not "),
172 ($errmsg eq "" ? "" : " - $errmsg"));
174 } elsif ($action =~ "^mdcfg") {
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`);
181 if (system("gpart create -s GPT $dev") != 0) {
182 $errmsg = "gpart create failed";
185 $errmsg = "mdconfig -a failed";
188 $errmsg = "dd failed";
190 } elsif ($args =~ "^destroy") {
192 if (system("mdconfig -d $dev") != 0) {
193 $errmsg = "mdconfig -d failed";
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";
207 print "not ok $nr \# conf($key) - $st\n";
210 } elsif ($action =~ "^mount") {
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";
218 $errmsg = "newfs failed";
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";