2010-04-26 11:44:05 +02:00
|
|
|
#!/bin/bash
|
2009-06-22 18:29:05 +02:00
|
|
|
#
|
|
|
|
# Copyright (C) 2009 Red Hat, Inc.
|
|
|
|
# Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it would be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2009-07-16 19:26:54 +02:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-06-22 18:29:05 +02:00
|
|
|
#
|
|
|
|
#
|
|
|
|
# standard filters
|
|
|
|
#
|
|
|
|
|
|
|
|
# Checks that given_value is in range of correct_value +/- tolerance.
|
|
|
|
# Tolerance can be an absolute value or a percentage of the correct value
|
|
|
|
# (see examples with tolerances below).
|
|
|
|
# Outputs suitable message to stdout if it's not in range.
|
|
|
|
#
|
|
|
|
# A verbose option, -v, may be used as the LAST argument
|
2013-09-04 13:16:04 +02:00
|
|
|
#
|
|
|
|
# e.g.
|
2009-06-22 18:29:05 +02:00
|
|
|
# foo: 0.0298 = 0.03 +/- 5%
|
2013-09-04 13:16:04 +02:00
|
|
|
# _within_tolerance "foo" 0.0298 0.03 5%
|
|
|
|
#
|
2009-06-22 18:29:05 +02:00
|
|
|
# foo: 0.0298 = 0.03 +/- 0.01
|
|
|
|
# _within_tolerance "foo" 0.0298 0.03 0.01
|
|
|
|
#
|
|
|
|
# foo: 0.0298 = 0.03 -0.01 +0.002
|
|
|
|
# _within_tolerance "foo" 0.0298 0.03 0.01 0.002
|
|
|
|
#
|
2013-09-04 13:16:04 +02:00
|
|
|
# foo: verbose output of 0.0298 = 0.03 +/- 5%
|
|
|
|
# _within_tolerance "foo" 0.0298 0.03 5% -v
|
2009-06-22 18:29:05 +02:00
|
|
|
_within_tolerance()
|
|
|
|
{
|
|
|
|
_name=$1
|
|
|
|
_given_val=$2
|
|
|
|
_correct_val=$3
|
|
|
|
_mintol=$4
|
|
|
|
_maxtol=$_mintol
|
|
|
|
_verbose=0
|
|
|
|
_debug=false
|
|
|
|
|
|
|
|
# maxtol arg is optional
|
|
|
|
# verbose arg is optional
|
|
|
|
if [ $# -ge 5 ]
|
2013-09-04 13:16:04 +02:00
|
|
|
then
|
2009-06-22 18:29:05 +02:00
|
|
|
if [ "$5" = "-v" ]
|
|
|
|
then
|
2013-09-04 13:16:04 +02:00
|
|
|
_verbose=1
|
2009-06-22 18:29:05 +02:00
|
|
|
else
|
|
|
|
_maxtol=$5
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ $# -ge 6 ]
|
|
|
|
then
|
|
|
|
[ "$6" = "-v" ] && _verbose=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# find min with or without %
|
2013-09-04 13:16:04 +02:00
|
|
|
_mintolerance=`echo $_mintol | sed -e 's/%//'`
|
2009-06-22 18:29:05 +02:00
|
|
|
if [ $_mintol = $_mintolerance ]
|
2013-09-04 13:16:04 +02:00
|
|
|
then
|
2009-06-22 18:29:05 +02:00
|
|
|
_min=`echo "scale=5; $_correct_val-$_mintolerance" | bc`
|
|
|
|
else
|
|
|
|
_min=`echo "scale=5; $_correct_val-$_mintolerance*0.01*$_correct_val" | bc`
|
|
|
|
fi
|
|
|
|
|
|
|
|
# find max with or without %
|
2013-09-04 13:16:04 +02:00
|
|
|
_maxtolerance=`echo $_maxtol | sed -e 's/%//'`
|
2009-06-22 18:29:05 +02:00
|
|
|
if [ $_maxtol = $_maxtolerance ]
|
2013-09-04 13:16:04 +02:00
|
|
|
then
|
2009-06-22 18:29:05 +02:00
|
|
|
_max=`echo "scale=5; $_correct_val+$_maxtolerance" | bc`
|
|
|
|
else
|
|
|
|
_max=`echo "scale=5; $_correct_val+$_maxtolerance*0.01*$_correct_val" | bc`
|
|
|
|
fi
|
|
|
|
|
|
|
|
$_debug && echo "min = $_min"
|
|
|
|
$_debug && echo "max = $_max"
|
|
|
|
|
|
|
|
cat <<EOF >$tmp.bc.1
|
|
|
|
scale=5;
|
|
|
|
if ($_min <= $_given_val) 1;
|
2013-09-04 13:16:04 +02:00
|
|
|
if ($_min > $_given_val) 0;
|
2009-06-22 18:29:05 +02:00
|
|
|
EOF
|
|
|
|
|
|
|
|
cat <<EOF >$tmp.bc.2
|
|
|
|
scale=5;
|
|
|
|
if ($_given_val <= $_max) 1;
|
|
|
|
if ($_given_val > $_max) 0;
|
|
|
|
EOF
|
|
|
|
|
|
|
|
_above_min=`bc <$tmp.bc.1`
|
|
|
|
_below_max=`bc <$tmp.bc.2`
|
|
|
|
|
|
|
|
rm -f $tmp.bc.[12]
|
|
|
|
|
2013-09-04 13:16:04 +02:00
|
|
|
_in_range=`expr $_above_min \& $_below_max`
|
2009-06-22 18:29:05 +02:00
|
|
|
|
|
|
|
# fix up min, max precision for output
|
|
|
|
# can vary for 5.3, 6.2
|
|
|
|
_min=`echo $_min | sed -e 's/0*$//'` # get rid of trailling zeroes
|
|
|
|
_max=`echo $_max | sed -e 's/0*$//'` # get rid of trailling zeroes
|
|
|
|
|
2013-09-04 13:16:04 +02:00
|
|
|
if [ $_in_range -eq 1 ]
|
2009-06-22 18:29:05 +02:00
|
|
|
then
|
2013-09-04 13:16:04 +02:00
|
|
|
[ $_verbose -eq 1 ] && echo $_name is in range
|
|
|
|
return 0
|
2009-06-22 18:29:05 +02:00
|
|
|
else
|
2013-09-04 13:16:04 +02:00
|
|
|
[ $_verbose -eq 1 ] && echo $_name has value of $_given_val
|
|
|
|
[ $_verbose -eq 1 ] && echo $_name is NOT in range $_min .. $_max
|
|
|
|
return 1
|
2009-06-22 18:29:05 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# ctime(3) dates
|
|
|
|
#
|
|
|
|
_filter_date()
|
|
|
|
{
|
|
|
|
sed \
|
2013-09-04 13:16:04 +02:00
|
|
|
-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/'
|
2009-06-22 18:29:05 +02:00
|
|
|
}
|
|
|
|
|
2015-10-13 01:36:50 +02:00
|
|
|
_filter_generated_node_ids()
|
|
|
|
{
|
|
|
|
sed -re 's/\#block[0-9]{3,}/NODE_NAME/'
|
|
|
|
}
|
|
|
|
|
2010-11-24 17:12:21 +01:00
|
|
|
# replace occurrences of the actual TEST_DIR value with TEST_DIR
|
2009-06-22 18:29:05 +02:00
|
|
|
_filter_testdir()
|
|
|
|
{
|
|
|
|
sed -e "s#$TEST_DIR#TEST_DIR#g"
|
|
|
|
}
|
|
|
|
|
2010-11-24 17:12:21 +01:00
|
|
|
# replace occurrences of the actual IMGFMT value with IMGFMT
|
|
|
|
_filter_imgfmt()
|
|
|
|
{
|
|
|
|
sed -e "s#$IMGFMT#IMGFMT#g"
|
|
|
|
}
|
|
|
|
|
2011-04-29 15:30:25 +02:00
|
|
|
# Removes \r from messages
|
|
|
|
_filter_win32()
|
|
|
|
{
|
|
|
|
sed -e 's/\r//g'
|
|
|
|
}
|
|
|
|
|
2009-06-22 18:29:05 +02:00
|
|
|
# sanitize qemu-io output
|
|
|
|
_filter_qemu_io()
|
|
|
|
{
|
2013-11-18 08:13:01 +01:00
|
|
|
_filter_win32 | sed -e "s/[0-9]* ops\; [0-9/:. sec]* ([0-9/.inf]* [EPTGMKiBbytes]*\/sec and [0-9/.inf]* ops\/sec)/X ops\; XX:XX:XX.X (XXX YYY\/sec and XXX ops\/sec)/" \
|
2014-12-08 10:48:11 +01:00
|
|
|
-e "s/: line [0-9][0-9]*: *[0-9][0-9]*\( Aborted\| Killed\)/:\1/" \
|
2013-11-18 08:13:01 +01:00
|
|
|
-e "s/qemu-io> //g"
|
2009-06-22 18:29:05 +02:00
|
|
|
}
|
|
|
|
|
2013-04-15 10:15:17 +02:00
|
|
|
# replace occurrences of QEMU_PROG with "qemu"
|
|
|
|
_filter_qemu()
|
|
|
|
{
|
2013-08-05 14:40:34 +02:00
|
|
|
sed -e "s#\\(^\\|(qemu) \\)$(basename $QEMU_PROG):#\1QEMU_PROG:#" \
|
2013-11-14 15:24:58 +01:00
|
|
|
-e 's#^QEMU [0-9]\+\.[0-9]\+\.[0-9]\+ monitor#QEMU X.Y.Z monitor#' \
|
2014-12-19 17:17:06 +01:00
|
|
|
-e '/main-loop: WARNING: I\/O thread spun for [0-9]\+ iterations/d' \
|
2013-11-14 15:24:58 +01:00
|
|
|
-e $'s#\r##' # QEMU monitor uses \r\n line endings
|
2013-04-15 10:15:17 +02:00
|
|
|
}
|
|
|
|
|
2013-09-18 16:47:41 +02:00
|
|
|
# replace problematic QMP output like timestamps
|
|
|
|
_filter_qmp()
|
|
|
|
{
|
|
|
|
_filter_win32 | \
|
|
|
|
sed -e 's#\("\(micro\)\?seconds": \)[0-9]\+#\1 TIMESTAMP#g' \
|
2014-11-17 13:31:05 +01:00
|
|
|
-e 's#^{"QMP":.*}$#QMP_VERSION#' \
|
|
|
|
-e '/^ "QMP": {\s*$/, /^ }\s*$/ c\' \
|
|
|
|
-e ' QMP_VERSION'
|
2013-09-18 16:47:41 +02:00
|
|
|
}
|
|
|
|
|
2014-08-19 19:28:58 +02:00
|
|
|
# replace driver-specific options in the "Formatting..." line
|
|
|
|
_filter_img_create()
|
|
|
|
{
|
|
|
|
sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
|
|
|
|
-e "s#$TEST_DIR#TEST_DIR#g" \
|
|
|
|
-e "s#$IMGFMT#IMGFMT#g" \
|
|
|
|
-e "s# encryption=off##g" \
|
|
|
|
-e "s# cluster_size=[0-9]\\+##g" \
|
|
|
|
-e "s# table_size=[0-9]\\+##g" \
|
2015-07-07 16:42:10 +02:00
|
|
|
-e "s# compat=[^ ]*##g" \
|
2014-08-19 19:28:58 +02:00
|
|
|
-e "s# compat6=\\(on\\|off\\)##g" \
|
|
|
|
-e "s# static=\\(on\\|off\\)##g" \
|
|
|
|
-e "s# zeroed_grain=\\(on\\|off\\)##g" \
|
|
|
|
-e "s# subformat='[^']*'##g" \
|
|
|
|
-e "s# adapter_type='[^']*'##g" \
|
|
|
|
-e "s# lazy_refcounts=\\(on\\|off\\)##g" \
|
|
|
|
-e "s# block_size=[0-9]\\+##g" \
|
|
|
|
-e "s# block_state_zero=\\(on\\|off\\)##g" \
|
|
|
|
-e "s# log_size=[0-9]\\+##g" \
|
2015-02-18 23:40:48 +01:00
|
|
|
-e "s/archipelago:a/TEST_DIR\//g" \
|
|
|
|
-e "s# refcount_bits=[0-9]\\+##g"
|
2014-08-19 19:28:58 +02:00
|
|
|
}
|
|
|
|
|
2014-09-10 11:05:45 +02:00
|
|
|
_filter_img_info()
|
|
|
|
{
|
|
|
|
sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
|
|
|
|
-e "s#$TEST_DIR#TEST_DIR#g" \
|
|
|
|
-e "s#$IMGFMT#IMGFMT#g" \
|
2015-01-27 03:02:58 +01:00
|
|
|
-e 's#nbd://127.0.0.1:10810$#TEST_DIR/t.IMGFMT#g' \
|
2014-09-10 11:05:45 +02:00
|
|
|
-e "/encrypted: yes/d" \
|
|
|
|
-e "/cluster_size: [0-9]\\+/d" \
|
|
|
|
-e "/table_size: [0-9]\\+/d" \
|
|
|
|
-e "/compat: '[^']*'/d" \
|
|
|
|
-e "/compat6: \\(on\\|off\\)/d" \
|
|
|
|
-e "/static: \\(on\\|off\\)/d" \
|
|
|
|
-e "/zeroed_grain: \\(on\\|off\\)/d" \
|
|
|
|
-e "/subformat: '[^']*'/d" \
|
|
|
|
-e "/adapter_type: '[^']*'/d" \
|
|
|
|
-e "/lazy_refcounts: \\(on\\|off\\)/d" \
|
|
|
|
-e "/block_size: [0-9]\\+/d" \
|
|
|
|
-e "/block_state_zero: \\(on\\|off\\)/d" \
|
|
|
|
-e "/log_size: [0-9]\\+/d" \
|
|
|
|
-e "s/archipelago:a/TEST_DIR\//g"
|
|
|
|
}
|
|
|
|
|
2014-10-24 15:57:41 +02:00
|
|
|
# filter out offsets and file names from qemu-img map
|
|
|
|
_filter_qemu_img_map()
|
|
|
|
{
|
|
|
|
sed -e 's/\([0-9a-fx]* *[0-9a-fx]* *\)[0-9a-fx]* */\1/g' \
|
|
|
|
-e 's/Mapped to *//' | _filter_testdir | _filter_imgfmt
|
|
|
|
}
|
|
|
|
|
2009-06-22 18:29:05 +02:00
|
|
|
# make sure this script returns success
|
2015-01-04 02:53:48 +01:00
|
|
|
true
|