6 # Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
8 # This program is free software; you can redistribute it and/or modify it
9 # under the terms of version 2 of the GNU General Public License as
10 # published by the Free Software Foundation.
12 # This program is distributed in the hope that it would be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 # Further, this software is distributed without any warranty that it is
17 # free of the rightful claim of any third person regarding infringement
18 # or the like. Any license provided herein, whether implied or
19 # otherwise, applies only to this software file. Patent licenses, if
20 # any, provided herein do not apply to combinations of this program with
21 # other software, or any other product whatsoever.
23 # You should have received a copy of the GNU General Public License along
24 # with this program; if not, write the Free Software Foundation, Inc., 59
25 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
27 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
28 # Mountain View, CA 94043, or:
32 # For further information regarding this notice, see:
34 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
38 # Checks that given_value is in range of correct_value +/- tolerance.
39 # Tolerance can be an absolute value or a percentage of the correct value
40 # (see examples with tolerances below).
41 # Outputs suitable message to stdout if it's not in range.
43 # A verbose option, -v, may be used as the LAST argument
46 # foo: 0.0298 = 0.03 +/- 5%
47 # _within_tolerance "foo" 0.0298 0.03 5%
49 # foo: 0.0298 = 0.03 +/- 0.01
50 # _within_tolerance "foo" 0.0298 0.03 0.01
52 # foo: 0.0298 = 0.03 -0.01 +0.002
53 # _within_tolerance "foo" 0.0298 0.03 0.01 0.002
55 # foo: verbose output of 0.0298 = 0.03 +/- 5%
56 # _within_tolerance "foo" 0.0298 0.03 5% -v
67 # maxtol arg is optional
68 # verbose arg is optional
80 [ "$6" = "-v" ] && _verbose=1
83 # find min with or without %
84 _mintolerance=`echo $_mintol | sed -e 's/%//'`
85 if [ $_mintol = $_mintolerance ]
87 _min=`echo "scale=5; $_correct_val-$_mintolerance" | bc`
89 _min=`echo "scale=5; $_correct_val-$_mintolerance*0.01*$_correct_val" | bc`
92 # find max with or without %
93 _maxtolerance=`echo $_maxtol | sed -e 's/%//'`
94 if [ $_maxtol = $_maxtolerance ]
96 _max=`echo "scale=5; $_correct_val+$_maxtolerance" | bc`
98 _max=`echo "scale=5; $_correct_val+$_maxtolerance*0.01*$_correct_val" | bc`
101 $_debug && echo "min = $_min"
102 $_debug && echo "max = $_max"
106 if ($_min <= $_given_val) 1;
107 if ($_min > $_given_val) 0;
112 if ($_given_val <= $_max) 1;
113 if ($_given_val > $_max) 0;
116 _above_min=`bc <$tmp.bc.1`
117 _below_max=`bc <$tmp.bc.2`
121 _in_range=`expr $_above_min \& $_below_max`
123 # fix up min, max precision for output
124 # can vary for 5.3, 6.2
125 _min=`echo $_min | sed -e 's/0*$//'` # get rid of trailling zeroes
126 _max=`echo $_max | sed -e 's/0*$//'` # get rid of trailling zeroes
128 if [ $_in_range -eq 1 ]
130 [ $_verbose -eq 1 ] && echo $_name is in range
133 [ $_verbose -eq 1 ] && echo $_name has value of $_given_val
134 [ $_verbose -eq 1 ] && echo $_name is NOT in range $_min .. $_max
144 -e 's/[A-Z][a-z][a-z] [A-z][a-z][a-z] *[0-9][0-9]* [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9][0-9][0-9][0-9]$/DATE/'
147 # prints filtered output on stdout, values (use eval) on stderr
153 if (/^meta-data=([\w|\/]+)\s+isize=(\d+)\s+agcount=(\d+), agsize=(\d+) blks/) {
154 print STDERR "ddev=$1\nisize=$2\nagcount=$3\nagsize=$4\n";
155 print STDOUT "meta-data=DDEV isize=XXX agcount=N, agsize=XXX blks\n";
157 if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+), imaxpct=(\d+)/) {
158 print STDERR "dbsize=$1\ndblocks=$2\nimaxpct=$3\n";
159 print STDOUT "data = bsize=XXX blocks=XXX, imaxpct=PCT\n";
161 if (/^\s+=\s+sunit=(\d+)\s+swidth=(\d+) blks, unwritten=(\d)/) {
162 print STDERR "sunit=$1\nswidth=$2\nunwritten=$3\n";
163 print STDOUT " = sunit=XXX swidth=XXX, unwritten=X\n";
165 if (/^naming\s+=version\s+(\d+)\s+bsize=(\d+)/) {
166 print STDERR "dirversion=$1\ndirbsize=$2\n";
167 print STDOUT "naming =VERN bsize=XXX\n";
169 if (/^log\s+=(internal log|[\w|\/]+)\s+bsize=(\d+)\s+blocks=(\d+)/) {
170 print STDERR "ldev=\"$1\"\nlbsize=$2\nlblocks=$3\n";
171 print STDOUT "log =LDEV bsize=XXX blocks=XXX\n";
173 if (/^realtime\s+=([\w|\/]+)\s+extsz=(\d+)\s+blocks=(\d+), rtextents=(\d+)/) {
174 print STDERR "rtdev=$1\nrtextsz=$2\nrtblocks=$3\nrtextents=$4\n";
175 print STDOUT "realtime =RDEV extsz=XXX blocks=XXX, rtextents=XXX\n";
179 # make sure this script returns success