3 # Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
8 # Checks that given_value is in range of correct_value +/- tolerance.
9 # Tolerance can be an absolute value or a percentage of the correct value
10 # (see examples with tolerances below).
11 # Outputs suitable message to stdout if it's not in range.
13 # A verbose option, -v, may be used as the LAST argument
16 # foo: 0.0298 = 0.03 +/- 5%
17 # _within_tolerance "foo" 0.0298 0.03 5%
19 # foo: 0.0298 = 0.03 +/- 0.01
20 # _within_tolerance "foo" 0.0298 0.03 0.01
22 # foo: 0.0298 = 0.03 -0.01 +0.002
23 # _within_tolerance "foo" 0.0298 0.03 0.01 0.002
25 # foo: verbose output of 0.0298 = 0.03 +/- 5%
26 # _within_tolerance "foo" 0.0298 0.03 5% -v
37 # maxtol arg is optional
38 # verbose arg is optional
50 [ "$6" = "-v" ] && _verbose=1
53 # find min with or without %
54 _mintolerance=`echo $_mintol | sed -e 's/%//'`
55 if [ $_mintol = $_mintolerance ]
57 _min=`echo "scale=5; $_correct_val-$_mintolerance" | bc`
59 _min=`echo "scale=5; $_correct_val-$_mintolerance*0.01*$_correct_val" | bc`
62 # find max with or without %
63 _maxtolerance=`echo $_maxtol | sed -e 's/%//'`
64 if [ $_maxtol = $_maxtolerance ]
66 _max=`echo "scale=5; $_correct_val+$_maxtolerance" | bc`
68 _max=`echo "scale=5; $_correct_val+$_maxtolerance*0.01*$_correct_val" | bc`
71 $_debug && echo "min = $_min"
72 $_debug && echo "max = $_max"
76 if ($_min <= $_given_val) 1;
77 if ($_min > $_given_val) 0;
82 if ($_given_val <= $_max) 1;
83 if ($_given_val > $_max) 0;
86 _above_min=`bc <$tmp.bc.1`
87 _below_max=`bc <$tmp.bc.2`
91 _in_range=`expr $_above_min \& $_below_max`
93 # fix up min, max precision for output
94 # can vary for 5.3, 6.2
95 _min=`echo $_min | sed -e 's/0*$//'` # get rid of trailling zeroes
96 _max=`echo $_max | sed -e 's/0*$//'` # get rid of trailling zeroes
98 if [ $_in_range -eq 1 ]
100 [ $_verbose -eq 1 ] && echo $_name is in range
103 [ $_verbose -eq 1 ] && echo $_name has value of $_given_val
104 [ $_verbose -eq 1 ] && echo $_name is NOT in range $_min .. $_max
114 -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/'
117 # prints filtered output on stdout, values (use eval) on stderr
123 if (/^meta-data=([\w,|\/.-]+)\s+isize=(\d+)\s+agcount=(\d+), agsize=(\d+) blks/) {
124 print STDERR "ddev=$1\nisize=$2\nagcount=$3\nagsize=$4\n";
125 print STDOUT "meta-data=DDEV isize=XXX agcount=N, agsize=XXX blks\n";
127 if (/^\s+=\s+sectsz=(\d+)\s+attr=(\d+)/) {
128 print STDERR "sectsz=$1\nattr=$2\n";
130 if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+), imaxpct=(\d+)/) {
131 print STDERR "dbsize=$1\ndblocks=$2\nimaxpct=$3\n";
132 print STDOUT "data = bsize=XXX blocks=XXX, imaxpct=PCT\n";
134 if (/^\s+=\s+sunit=(\d+)\s+swidth=(\d+) blks, unwritten=(\d)/) {
135 print STDERR "sunit=$1\nswidth=$2\nunwritten=$3\n";
136 print STDOUT " = sunit=XXX swidth=XXX, unwritten=X\n";
138 if (/^naming\s+=version\s+(\d+)\s+bsize=(\d+)/) {
139 print STDERR "dirversion=$1\ndirbsize=$2\n";
140 print STDOUT "naming =VERN bsize=XXX\n";
142 if (/^log\s+=(internal log|[\w|\/.-]+)\s+bsize=(\d+)\s+blocks=(\d+),\s+version=(\d+)/ ||
143 /^log\s+=(internal log|[\w|\/.-]+)\s+bsize=(\d+)\s+blocks=(\d+)/) {
144 print STDERR "ldev=\"$1\"\nlbsize=$2\nlblocks=$3\nlversion=$4\n";
145 print STDOUT "log =LDEV bsize=XXX blocks=XXX\n";
147 if (/^\s+=\s+sectsz=(\d+)\s+sunit=(\d+) blks/) {
148 print STDERR "logsectsz=$1\nlogsunit=$2\n\n";
150 if (/^realtime\s+=([\w|\/.-]+)\s+extsz=(\d+)\s+blocks=(\d+), rtextents=(\d+)/) {
151 print STDERR "rtdev=$1\nrtextsz=$2\nrtblocks=$3\nrtextents=$4\n";
152 print STDOUT "realtime =RDEV extsz=XXX blocks=XXX, rtextents=XXX\n";
156 # make sure this script returns success