Test out some issues we have at the moment dealing with writing when out of space
[xfstests-dev.git] / common.filter
1 ##/bin/sh
2
3 #
4 # standard filters
5 #
6 # Copyright (c) 2000-2001 Silicon Graphics, Inc.  All Rights Reserved.
7
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.
11
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.
15
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.
22
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.
26
27 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
28 # Mountain View, CA  94043, or:
29
30 # http://www.sgi.com 
31
32 # For further information regarding this notice, see: 
33
34 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
35 #
36 #
37
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.
42 #
43 # A verbose option, -v, may be used as the LAST argument
44
45 # e.g. 
46 # foo: 0.0298 = 0.03 +/- 5%
47 # _within_tolerance "foo" 0.0298 0.03 5%  
48
49 # foo: 0.0298 = 0.03 +/- 0.01
50 # _within_tolerance "foo" 0.0298 0.03 0.01
51 #
52 # foo: 0.0298 = 0.03 -0.01 +0.002
53 # _within_tolerance "foo" 0.0298 0.03 0.01 0.002
54 #
55 # foo: verbose output of 0.0298 = 0.03 +/- 5% 
56 # _within_tolerance "foo" 0.0298 0.03 5% -v 
57 _within_tolerance()
58 {
59   _name=$1
60   _given_val=$2
61   _correct_val=$3
62   _mintol=$4
63   _maxtol=$_mintol
64   _verbose=0
65   _debug=false
66
67   # maxtol arg is optional
68   # verbose arg is optional
69   if [ $# -ge 5 ]
70   then 
71      if [ "$5" = "-v" ]
72      then
73         _verbose=1
74      else
75         _maxtol=$5
76      fi
77   fi
78   if [ $# -ge 6 ]
79   then
80      [ "$6" = "-v" ] && _verbose=1
81   fi
82
83   # find min with or without %
84   _mintolerance=`echo $_mintol | sed -e 's/%//'` 
85   if [ $_mintol = $_mintolerance ]
86   then 
87       _min=`echo "scale=5; $_correct_val-$_mintolerance" | bc`
88   else
89       _min=`echo "scale=5; $_correct_val-$_mintolerance*0.01*$_correct_val" | bc`
90   fi
91
92   # find max with or without %
93   _maxtolerance=`echo $_maxtol | sed -e 's/%//'` 
94   if [ $_maxtol = $_maxtolerance ]
95   then 
96       _max=`echo "scale=5; $_correct_val+$_maxtolerance" | bc`
97   else
98       _max=`echo "scale=5; $_correct_val+$_maxtolerance*0.01*$_correct_val" | bc`
99   fi
100
101   $_debug && echo "min = $_min"
102   $_debug && echo "max = $_max"
103
104   cat <<EOF >$tmp.bc.1
105 scale=5;
106 if ($_min <= $_given_val) 1;
107 if ($_min > $_given_val) 0; 
108 EOF
109
110   cat <<EOF >$tmp.bc.2
111 scale=5;
112 if ($_given_val <= $_max) 1;
113 if ($_given_val > $_max) 0;
114 EOF
115
116   _above_min=`bc <$tmp.bc.1`
117   _below_max=`bc <$tmp.bc.2`
118
119   rm -f $tmp.bc.[12]
120
121   _in_range=`expr $_above_min \& $_below_max` 
122
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
127
128   if [ $_in_range -eq 1 ] 
129   then
130         [ $_verbose -eq 1 ] && echo $_name is in range
131         return 0
132   else
133         [ $_verbose -eq 1 ] && echo $_name has value of $_given_val
134         [ $_verbose -eq 1 ] && echo $_name is NOT in range $_min .. $_max       
135         return 1
136   fi
137 }
138
139 # ctime(3) dates
140 #
141 _filter_date()
142 {
143     sed \
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/'
145 }
146
147 # prints filtered output on stdout, values (use eval) on stderr
148
149 _filter_mkfs()
150 {
151     set -
152     perl -ne '
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";
156     }
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";
160     }
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";
164     }
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";
168     }
169     if (/^log\s+=(internal log|[\w|\/.-]+)\s+bsize=(\d+)\s+blocks=(\d+),\s+version=(\d+)/) {
170         print STDERR "ldev=\"$1\"\nlbsize=$2\nlblocks=$3\nlversion=$4\n";
171         print STDOUT "log      =LDEV bsize=XXX blocks=XXX\n";
172     }
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";
176     }'
177 }
178
179 # make sure this script returns success
180 /bin/true