]> Git Repo - qemu.git/blame - tests/qemu-iotests/common.filter
qemu-iotests: Initial import into the public repository.
[qemu.git] / tests / qemu-iotests / common.filter
CommitLineData
6bf19c94
CH
1#!/bin/sh
2#
3# Copyright (C) 2009 Red Hat, Inc.
4# Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
5#
6# This program is free software; you can redistribute it and/or
7# modify it under the terms of the GNU General Public License as
8# published by the Free Software Foundation.
9#
10# This program is distributed in the hope that it would be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write the Free Software Foundation,
17# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18#
19#
20# standard filters
21#
22
23# Checks that given_value is in range of correct_value +/- tolerance.
24# Tolerance can be an absolute value or a percentage of the correct value
25# (see examples with tolerances below).
26# Outputs suitable message to stdout if it's not in range.
27#
28# A verbose option, -v, may be used as the LAST argument
29#
30# e.g.
31# foo: 0.0298 = 0.03 +/- 5%
32# _within_tolerance "foo" 0.0298 0.03 5%
33#
34# foo: 0.0298 = 0.03 +/- 0.01
35# _within_tolerance "foo" 0.0298 0.03 0.01
36#
37# foo: 0.0298 = 0.03 -0.01 +0.002
38# _within_tolerance "foo" 0.0298 0.03 0.01 0.002
39#
40# foo: verbose output of 0.0298 = 0.03 +/- 5%
41# _within_tolerance "foo" 0.0298 0.03 5% -v
42_within_tolerance()
43{
44 _name=$1
45 _given_val=$2
46 _correct_val=$3
47 _mintol=$4
48 _maxtol=$_mintol
49 _verbose=0
50 _debug=false
51
52 # maxtol arg is optional
53 # verbose arg is optional
54 if [ $# -ge 5 ]
55 then
56 if [ "$5" = "-v" ]
57 then
58 _verbose=1
59 else
60 _maxtol=$5
61 fi
62 fi
63 if [ $# -ge 6 ]
64 then
65 [ "$6" = "-v" ] && _verbose=1
66 fi
67
68 # find min with or without %
69 _mintolerance=`echo $_mintol | sed -e 's/%//'`
70 if [ $_mintol = $_mintolerance ]
71 then
72 _min=`echo "scale=5; $_correct_val-$_mintolerance" | bc`
73 else
74 _min=`echo "scale=5; $_correct_val-$_mintolerance*0.01*$_correct_val" | bc`
75 fi
76
77 # find max with or without %
78 _maxtolerance=`echo $_maxtol | sed -e 's/%//'`
79 if [ $_maxtol = $_maxtolerance ]
80 then
81 _max=`echo "scale=5; $_correct_val+$_maxtolerance" | bc`
82 else
83 _max=`echo "scale=5; $_correct_val+$_maxtolerance*0.01*$_correct_val" | bc`
84 fi
85
86 $_debug && echo "min = $_min"
87 $_debug && echo "max = $_max"
88
89 cat <<EOF >$tmp.bc.1
90scale=5;
91if ($_min <= $_given_val) 1;
92if ($_min > $_given_val) 0;
93EOF
94
95 cat <<EOF >$tmp.bc.2
96scale=5;
97if ($_given_val <= $_max) 1;
98if ($_given_val > $_max) 0;
99EOF
100
101 _above_min=`bc <$tmp.bc.1`
102 _below_max=`bc <$tmp.bc.2`
103
104 rm -f $tmp.bc.[12]
105
106 _in_range=`expr $_above_min \& $_below_max`
107
108 # fix up min, max precision for output
109 # can vary for 5.3, 6.2
110 _min=`echo $_min | sed -e 's/0*$//'` # get rid of trailling zeroes
111 _max=`echo $_max | sed -e 's/0*$//'` # get rid of trailling zeroes
112
113 if [ $_in_range -eq 1 ]
114 then
115 [ $_verbose -eq 1 ] && echo $_name is in range
116 return 0
117 else
118 [ $_verbose -eq 1 ] && echo $_name has value of $_given_val
119 [ $_verbose -eq 1 ] && echo $_name is NOT in range $_min .. $_max
120 return 1
121 fi
122}
123
124# ctime(3) dates
125#
126_filter_date()
127{
128 sed \
129 -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/'
130}
131
132# replace occurances of the actual TEST_DIR value with TEST_DIR
133_filter_testdir()
134{
135 sed -e "s#$TEST_DIR#TEST_DIR#g"
136}
137
138# sanitize qemu-io output
139_filter_qemu_io()
140{
141 sed -e "s/[0-9]* ops\; [0-9/:. sec]* ([0-9/.]* [GMKiBbytes]*\/sec and [0-9/.]* ops\/sec)/X ops\; XX:XX:XX.X (XXX YYY\/sec and XXX ops\/sec)/"
142}
143
144# make sure this script returns success
145/bin/true
This page took 0.03539 seconds and 4 git commands to generate.