gctl.t revision 150308
1#!/usr/bin/env perl -w 2# 3# Copyright (c) 2005 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: head/tools/regression/geom_gpt/gctl.t 150308 2005-09-19 06:51:57Z marcel $ 28 29my $srcdir = `dirname $0`; 30chomp $srcdir; 31 32my $cmd = "/tmp/gctl-$$"; 33my $out = "$cmd.out"; 34my $disk = "/tmp/disk-$$"; 35my $unit = ""; 36 37my %steps = ( 38 "1" => "gctl", 39 "2" => "gctl", 40 "3" => "gctl", 41 "4" => "gctl", 42 "5" => "mdcfg", 43 "6" => "gctl", 44 "7" => "gctl", 45 "8" => "gctl", 46 "9" => "mdcfg", 47); 48 49my %args = ( 50 "1" => "", 51 "2" => "verb=invalid", 52 "3" => "verb=create", 53 "4" => "verb=create provider=invalid", 54 "5" => "create", 55 "6" => "verb=create provider=md%unit% entries=-1", 56 "7" => "verb=create provider=md%unit%", 57 "8" => "verb=create provider=md%unit%", 58 "9" => "destroy", 59); 60 61my %result = ( 62 "1" => "FAIL Verb missing", 63 "2" => "FAIL 22 verb 'invalid'", 64 "3" => "FAIL 87 provider", 65 "4" => "FAIL 22 provider 'invalid'", 66 # 67 "6" => "FAIL 22 entries -1", 68 "7" => "PASS", 69 "8" => "FAIL 17 geom 'md0'", 70 # 71); 72 73my $verbose = ""; 74if (exists $ENV{'TEST_VERBOSE'}) { 75 $verbose = "-v"; 76} 77 78# Compile the driver... 79my $st = system("cc -o $cmd -g $srcdir/test.c -lgeom"); 80if ($st != 0) { 81 print "1..0 # SKIP error compiling test.c\n"; 82 exit 0; 83} 84 85# Make sure we have permission to use gctl... 86if (`$cmd` =~ "^FAIL Permission denied") { 87 print "1..0 # SKIP not enough permission\n"; 88 unlink $cmd; 89 exit 0; 90} 91 92$count = keys (%steps); 93print "1..$count\n"; 94 95foreach my $nr (sort keys %steps) { 96 my $action = $steps{$nr}; 97 my $arg = $args{$nr}; 98 99 if ($action =~ "gctl") { 100 $arg =~ s/%unit%/$unit/g; 101 system("$cmd $verbose $arg | tee $out 2>&1"); 102 $st = `tail -1 $out`; 103 if ($st =~ "^$result{$nr}") { 104 print "ok $nr\n"; 105 } else { 106 print "not ok $nr \# $st\n"; 107 } 108 unlink $out; 109 } elsif ($action =~ "mdcfg") { 110 if ($arg =~ "create") { 111 system("dd if=/dev/zero of=$disk count=1024 2>&1"); 112 $unit = `mdconfig -a -t vnode -f $disk`; 113 chomp $unit; 114 $unit =~ s/md//g; 115 } elsif ($arg =~ "destroy") { 116 system("mdconfig -d -u $unit"); 117 unlink $disk; 118 $unit = ""; 119 } 120 print "ok $nr\n"; 121 } 122} 123 124unlink $cmd; 125exit 0; 126