2010-04-26 13:44:05 +04:00
|
|
|
#!/bin/bash
|
2009-06-22 20:29:05 +04:00
|
|
|
#
|
|
|
|
# Copyright (C) 2009 Red Hat, Inc.
|
|
|
|
# Copyright (c) 2000-2006 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; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will 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 21:26:54 +04:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-06-22 20:29:05 +04:00
|
|
|
#
|
|
|
|
|
|
|
|
dd()
|
|
|
|
{
|
|
|
|
if [ "$HOSTOS" == "Linux" ]
|
2013-09-04 15:16:04 +04:00
|
|
|
then
|
|
|
|
command dd --help | grep noxfer > /dev/null 2>&1
|
|
|
|
|
|
|
|
if [ "$?" -eq 0 ]
|
|
|
|
then
|
|
|
|
command dd status=noxfer $@
|
|
|
|
else
|
|
|
|
command dd $@
|
|
|
|
fi
|
2009-06-22 20:29:05 +04:00
|
|
|
else
|
2013-09-04 15:16:04 +04:00
|
|
|
command dd $@
|
2009-06-22 20:29:05 +04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-08-06 11:44:49 +04:00
|
|
|
# poke_file 'test.img' 512 '\xff\xfe'
|
|
|
|
poke_file()
|
|
|
|
{
|
|
|
|
printf "$3" | dd "of=$1" bs=1 "seek=$2" conv=notrunc &>/dev/null
|
|
|
|
}
|
|
|
|
|
2017-09-12 17:44:55 +03:00
|
|
|
|
|
|
|
if ! . ./common.config
|
|
|
|
then
|
2017-09-12 17:44:58 +03:00
|
|
|
echo "$0: failed to source common.config"
|
2017-09-12 17:44:55 +03:00
|
|
|
exit 1
|
2009-06-22 20:29:05 +04:00
|
|
|
fi
|
|
|
|
|
2017-09-12 17:44:54 +03:00
|
|
|
_qemu_wrapper()
|
|
|
|
{
|
|
|
|
(
|
|
|
|
if [ -n "${QEMU_NEED_PID}" ]; then
|
|
|
|
echo $BASHPID > "${QEMU_TEST_DIR}/qemu-${_QEMU_HANDLE}.pid"
|
|
|
|
fi
|
|
|
|
exec "$QEMU_PROG" $QEMU_OPTIONS "$@"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
_qemu_img_wrapper()
|
|
|
|
{
|
|
|
|
(exec "$QEMU_IMG_PROG" $QEMU_IMG_OPTIONS "$@")
|
|
|
|
}
|
|
|
|
|
|
|
|
_qemu_io_wrapper()
|
|
|
|
{
|
|
|
|
local VALGRIND_LOGFILE="${TEST_DIR}"/$$.valgrind
|
|
|
|
local QEMU_IO_ARGS="$QEMU_IO_OPTIONS"
|
|
|
|
if [ "$IMGOPTSSYNTAX" = "true" ]; then
|
|
|
|
QEMU_IO_ARGS="--image-opts $QEMU_IO_ARGS"
|
|
|
|
if [ -n "$IMGKEYSECRET" ]; then
|
|
|
|
QEMU_IO_ARGS="--object secret,id=keysec0,data=$IMGKEYSECRET $QEMU_IO_ARGS"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
local RETVAL
|
|
|
|
(
|
|
|
|
if [ "${VALGRIND_QEMU}" == "y" ]; then
|
|
|
|
exec valgrind --log-file="${VALGRIND_LOGFILE}" --error-exitcode=99 "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@"
|
|
|
|
else
|
|
|
|
exec "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@"
|
|
|
|
fi
|
|
|
|
)
|
|
|
|
RETVAL=$?
|
|
|
|
if [ "${VALGRIND_QEMU}" == "y" ]; then
|
|
|
|
if [ $RETVAL == 99 ]; then
|
|
|
|
cat "${VALGRIND_LOGFILE}"
|
|
|
|
fi
|
|
|
|
rm -f "${VALGRIND_LOGFILE}"
|
|
|
|
fi
|
|
|
|
(exit $RETVAL)
|
|
|
|
}
|
|
|
|
|
|
|
|
_qemu_nbd_wrapper()
|
|
|
|
{
|
|
|
|
(
|
|
|
|
echo $BASHPID > "${QEMU_TEST_DIR}/qemu-nbd.pid"
|
|
|
|
exec "$QEMU_NBD_PROG" $QEMU_NBD_OPTIONS "$@"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
_qemu_vxhs_wrapper()
|
|
|
|
{
|
|
|
|
(
|
|
|
|
echo $BASHPID > "${TEST_DIR}/qemu-vxhs.pid"
|
|
|
|
exec "$QEMU_VXHS_PROG" $QEMU_VXHS_OPTIONS "$@"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export QEMU=_qemu_wrapper
|
|
|
|
export QEMU_IMG=_qemu_img_wrapper
|
|
|
|
export QEMU_IO=_qemu_io_wrapper
|
|
|
|
export QEMU_NBD=_qemu_nbd_wrapper
|
|
|
|
export QEMU_VXHS=_qemu_vxhs_wrapper
|
|
|
|
|
2016-05-10 19:11:27 +03:00
|
|
|
if [ "$IMGOPTSSYNTAX" = "true" ]; then
|
|
|
|
DRIVER="driver=$IMGFMT"
|
2017-09-12 17:44:56 +03:00
|
|
|
QEMU_IMG_EXTRA_ARGS="--image-opts $QEMU_IMG_EXTRA_ARGS"
|
|
|
|
if [ -n "$IMGKEYSECRET" ]; then
|
|
|
|
QEMU_IMG_EXTRA_ARGS="--object secret,id=keysec0,data=$IMGKEYSECRET $QEMU_IMG_EXTRA_ARGS"
|
|
|
|
fi
|
2016-05-10 19:11:29 +03:00
|
|
|
if [ "$IMGFMT" = "luks" ]; then
|
|
|
|
DRIVER="$DRIVER,key-secret=keysec0"
|
|
|
|
fi
|
2016-05-10 19:11:27 +03:00
|
|
|
if [ "$IMGPROTO" = "file" ]; then
|
|
|
|
TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT
|
|
|
|
TEST_IMG="$DRIVER,file.filename=$TEST_DIR/t.$IMGFMT"
|
|
|
|
elif [ "$IMGPROTO" = "nbd" ]; then
|
|
|
|
TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT
|
|
|
|
TEST_IMG="$DRIVER,file.driver=nbd,file.host=127.0.0.1,file.port=10810"
|
|
|
|
elif [ "$IMGPROTO" = "ssh" ]; then
|
|
|
|
TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT
|
|
|
|
TEST_IMG="$DRIVER,file.driver=ssh,file.host=127.0.0.1,file.path=$TEST_IMG_FILE"
|
|
|
|
elif [ "$IMGPROTO" = "nfs" ]; then
|
|
|
|
TEST_DIR="$DRIVER,file.driver=nfs,file.filename=nfs://127.0.0.1/$TEST_DIR"
|
2016-10-27 14:16:56 +03:00
|
|
|
TEST_IMG=$TEST_DIR/t.$IMGFMT
|
2016-05-10 19:11:27 +03:00
|
|
|
else
|
|
|
|
TEST_IMG="$DRIVER,file.driver=$IMGPROTO,file.filename=$TEST_DIR/t.$IMGFMT"
|
|
|
|
fi
|
2011-01-17 20:01:17 +03:00
|
|
|
else
|
2017-09-12 17:44:56 +03:00
|
|
|
QEMU_IMG_EXTRA_ARGS=
|
2016-05-10 19:11:27 +03:00
|
|
|
if [ "$IMGPROTO" = "file" ]; then
|
|
|
|
TEST_IMG=$TEST_DIR/t.$IMGFMT
|
|
|
|
elif [ "$IMGPROTO" = "nbd" ]; then
|
|
|
|
TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT
|
|
|
|
TEST_IMG="nbd:127.0.0.1:10810"
|
|
|
|
elif [ "$IMGPROTO" = "ssh" ]; then
|
|
|
|
TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT
|
|
|
|
TEST_IMG="ssh://127.0.0.1$TEST_IMG_FILE"
|
|
|
|
elif [ "$IMGPROTO" = "nfs" ]; then
|
2018-05-17 18:26:14 +03:00
|
|
|
TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT
|
2018-05-17 19:33:52 +03:00
|
|
|
REMOTE_TEST_DIR="nfs://127.0.0.1$TEST_DIR"
|
2018-05-17 18:26:14 +03:00
|
|
|
TEST_IMG="nfs://127.0.0.1$TEST_IMG_FILE"
|
2017-04-04 06:48:09 +03:00
|
|
|
elif [ "$IMGPROTO" = "vxhs" ]; then
|
|
|
|
TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT
|
|
|
|
TEST_IMG="vxhs://127.0.0.1:9999/t.$IMGFMT"
|
2016-05-10 19:11:27 +03:00
|
|
|
else
|
|
|
|
TEST_IMG=$IMGPROTO:$TEST_DIR/t.$IMGFMT
|
|
|
|
fi
|
2011-01-17 20:01:17 +03:00
|
|
|
fi
|
2017-07-27 16:13:20 +03:00
|
|
|
ORIG_TEST_IMG="$TEST_IMG"
|
2009-06-22 20:29:05 +04:00
|
|
|
|
2017-09-12 17:44:56 +03:00
|
|
|
if [ -z "$TEST_DIR" ]; then
|
|
|
|
TEST_DIR=`pwd`/scratch
|
|
|
|
fi
|
|
|
|
|
|
|
|
QEMU_TEST_DIR="${TEST_DIR}"
|
|
|
|
|
|
|
|
if [ ! -e "$TEST_DIR" ]; then
|
|
|
|
mkdir "$TEST_DIR"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d "$TEST_DIR" ]; then
|
|
|
|
echo "common.config: Error: \$TEST_DIR ($TEST_DIR) is not a directory"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-05-17 19:33:52 +03:00
|
|
|
if [ -z "$REMOTE_TEST_DIR" ]; then
|
|
|
|
REMOTE_TEST_DIR="$TEST_DIR"
|
|
|
|
fi
|
|
|
|
|
2017-09-12 17:44:56 +03:00
|
|
|
if [ ! -d "$SAMPLE_IMG_DIR" ]; then
|
|
|
|
echo "common.config: Error: \$SAMPLE_IMG_DIR ($SAMPLE_IMG_DIR) is not a directory"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2013-09-25 16:12:20 +04:00
|
|
|
_use_sample_img()
|
|
|
|
{
|
|
|
|
SAMPLE_IMG_FILE="${1%\.bz2}"
|
|
|
|
TEST_IMG="$TEST_DIR/$SAMPLE_IMG_FILE"
|
|
|
|
bzcat "$SAMPLE_IMG_DIR/$1" > "$TEST_IMG"
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
then
|
|
|
|
echo "_use_sample_img error, cannot extract '$SAMPLE_IMG_DIR/$1'"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-07-11 09:40:46 +03:00
|
|
|
_stop_nbd_server()
|
|
|
|
{
|
|
|
|
if [ -f "${QEMU_TEST_DIR}/qemu-nbd.pid" ]; then
|
|
|
|
local QEMU_NBD_PID
|
|
|
|
read QEMU_NBD_PID < "${QEMU_TEST_DIR}/qemu-nbd.pid"
|
|
|
|
kill ${QEMU_NBD_PID}
|
|
|
|
rm -f "${QEMU_TEST_DIR}/qemu-nbd.pid"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2009-06-22 20:29:05 +04:00
|
|
|
_make_test_img()
|
|
|
|
{
|
|
|
|
# extra qemu-img options can be added by tests
|
|
|
|
# at least one argument (the image size) needs to be added
|
2012-03-14 22:57:23 +04:00
|
|
|
local extra_img_options=""
|
|
|
|
local image_size=$*
|
2012-03-27 15:45:14 +04:00
|
|
|
local optstr=""
|
2012-11-02 17:01:23 +04:00
|
|
|
local img_name=""
|
2013-10-31 19:57:37 +04:00
|
|
|
local use_backing=0
|
|
|
|
local backing_file=""
|
2016-05-10 19:11:28 +03:00
|
|
|
local object_options=""
|
2012-11-02 17:01:23 +04:00
|
|
|
|
|
|
|
if [ -n "$TEST_IMG_FILE" ]; then
|
|
|
|
img_name=$TEST_IMG_FILE
|
|
|
|
else
|
|
|
|
img_name=$TEST_IMG
|
|
|
|
fi
|
2012-03-27 15:45:14 +04:00
|
|
|
|
|
|
|
if [ -n "$IMGOPTS" ]; then
|
|
|
|
optstr=$(_optstr_add "$optstr" "$IMGOPTS")
|
|
|
|
fi
|
2016-05-10 19:11:28 +03:00
|
|
|
if [ -n "$IMGKEYSECRET" ]; then
|
|
|
|
object_options="--object secret,id=keysec0,data=$IMGKEYSECRET"
|
|
|
|
optstr=$(_optstr_add "$optstr" "key-secret=keysec0")
|
|
|
|
fi
|
2009-06-22 20:29:05 +04:00
|
|
|
|
2012-03-14 22:57:23 +04:00
|
|
|
if [ "$1" = "-b" ]; then
|
2013-10-31 19:57:37 +04:00
|
|
|
use_backing=1
|
|
|
|
backing_file=$2
|
2012-03-14 22:57:23 +04:00
|
|
|
image_size=$3
|
|
|
|
fi
|
2010-10-31 23:10:20 +03:00
|
|
|
if [ \( "$IMGFMT" = "qcow2" -o "$IMGFMT" = "qed" \) -a -n "$CLUSTER_SIZE" ]; then
|
2012-03-27 15:45:14 +04:00
|
|
|
optstr=$(_optstr_add "$optstr" "cluster_size=$CLUSTER_SIZE")
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$optstr" ]; then
|
|
|
|
extra_img_options="-o $optstr $extra_img_options"
|
2009-10-01 21:29:59 +04:00
|
|
|
fi
|
|
|
|
|
2018-07-11 09:40:46 +03:00
|
|
|
if [ $IMGPROTO = "nbd" ]; then
|
|
|
|
_stop_nbd_server
|
|
|
|
fi
|
|
|
|
|
2009-06-22 20:29:05 +04:00
|
|
|
# XXX(hch): have global image options?
|
2013-10-31 19:57:37 +04:00
|
|
|
(
|
|
|
|
if [ $use_backing = 1 ]; then
|
2016-05-10 19:11:28 +03:00
|
|
|
$QEMU_IMG create $object_options -f $IMGFMT $extra_img_options -b "$backing_file" "$img_name" $image_size 2>&1
|
2013-10-31 19:57:37 +04:00
|
|
|
else
|
2016-05-10 19:11:28 +03:00
|
|
|
$QEMU_IMG create $object_options -f $IMGFMT $extra_img_options "$img_name" $image_size 2>&1
|
2013-10-31 19:57:37 +04:00
|
|
|
fi
|
2014-08-19 21:28:58 +04:00
|
|
|
) | _filter_img_create
|
2012-11-02 17:01:23 +04:00
|
|
|
|
|
|
|
# Start an NBD server on the image file, which is what we'll be talking to
|
|
|
|
if [ $IMGPROTO = "nbd" ]; then
|
2017-04-26 17:14:07 +03:00
|
|
|
# Pass a sufficiently high number to -e that should be enough for all
|
|
|
|
# tests
|
2017-11-10 01:12:16 +03:00
|
|
|
eval "$QEMU_NBD -v -t -b 127.0.0.1 -p 10810 -f $IMGFMT -e 42 -x '' $TEST_IMG_FILE >/dev/null &"
|
2012-11-02 17:01:23 +04:00
|
|
|
sleep 1 # FIXME: qemu-nbd needs to be listening before we continue
|
|
|
|
fi
|
2017-04-04 06:48:09 +03:00
|
|
|
|
|
|
|
# Start QNIO server on image directory for vxhs protocol
|
|
|
|
if [ $IMGPROTO = "vxhs" ]; then
|
|
|
|
eval "$QEMU_VXHS -d $TEST_DIR > /dev/null &"
|
|
|
|
sleep 1 # Wait for server to come up.
|
|
|
|
fi
|
2009-06-22 20:29:05 +04:00
|
|
|
}
|
|
|
|
|
2013-11-26 10:40:34 +04:00
|
|
|
_rm_test_img()
|
|
|
|
{
|
|
|
|
local img=$1
|
|
|
|
if [ "$IMGFMT" = "vmdk" ]; then
|
|
|
|
# Remove all the extents for vmdk
|
2014-04-11 00:47:39 +04:00
|
|
|
"$QEMU_IMG" info "$img" 2>/dev/null | grep 'filename:' | cut -f 2 -d: \
|
2013-11-26 10:40:34 +04:00
|
|
|
| xargs -I {} rm -f "{}"
|
|
|
|
fi
|
2014-04-11 00:47:39 +04:00
|
|
|
rm -f "$img"
|
2013-11-26 10:40:34 +04:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:29:05 +04:00
|
|
|
_cleanup_test_img()
|
|
|
|
{
|
2011-01-17 20:01:17 +03:00
|
|
|
case "$IMGPROTO" in
|
|
|
|
|
2012-11-02 17:01:23 +04:00
|
|
|
nbd)
|
2018-07-11 09:40:46 +03:00
|
|
|
_stop_nbd_server
|
2013-09-25 16:12:22 +04:00
|
|
|
rm -f "$TEST_IMG_FILE"
|
2012-11-02 17:01:23 +04:00
|
|
|
;;
|
2017-04-04 06:48:09 +03:00
|
|
|
vxhs)
|
|
|
|
if [ -f "${TEST_DIR}/qemu-vxhs.pid" ]; then
|
|
|
|
local QEMU_VXHS_PID
|
|
|
|
read QEMU_VXHS_PID < "${TEST_DIR}/qemu-vxhs.pid"
|
|
|
|
kill ${QEMU_VXHS_PID} >/dev/null 2>&1
|
|
|
|
rm -f "${TEST_DIR}/qemu-vxhs.pid"
|
|
|
|
fi
|
|
|
|
rm -f "$TEST_IMG_FILE"
|
|
|
|
;;
|
|
|
|
|
2011-01-17 20:01:17 +03:00
|
|
|
file)
|
2013-11-26 10:40:34 +04:00
|
|
|
_rm_test_img "$TEST_DIR/t.$IMGFMT"
|
|
|
|
_rm_test_img "$TEST_DIR/t.$IMGFMT.orig"
|
|
|
|
_rm_test_img "$TEST_DIR/t.$IMGFMT.base"
|
2013-09-25 16:12:20 +04:00
|
|
|
if [ -n "$SAMPLE_IMG_FILE" ]
|
|
|
|
then
|
|
|
|
rm -f "$TEST_DIR/$SAMPLE_IMG_FILE"
|
2017-07-27 16:13:20 +03:00
|
|
|
SAMPLE_IMG_FILE=
|
|
|
|
TEST_IMG="$ORIG_TEST_IMG"
|
2013-09-25 16:12:20 +04:00
|
|
|
fi
|
2011-01-17 20:01:17 +03:00
|
|
|
;;
|
|
|
|
|
|
|
|
rbd)
|
2014-01-09 00:05:38 +04:00
|
|
|
rbd --no-progress rm "$TEST_DIR/t.$IMGFMT" > /dev/null
|
2011-01-17 20:01:17 +03:00
|
|
|
;;
|
|
|
|
|
|
|
|
sheepdog)
|
2013-09-25 16:12:22 +04:00
|
|
|
collie vdi delete "$TEST_DIR/t.$IMGFMT"
|
2011-01-17 20:01:17 +03:00
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|
2009-06-22 20:29:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
_check_test_img()
|
|
|
|
{
|
2016-05-10 19:11:27 +03:00
|
|
|
(
|
|
|
|
if [ "$IMGOPTSSYNTAX" = "true" ]; then
|
|
|
|
$QEMU_IMG check $QEMU_IMG_EXTRA_ARGS "$@" "$TEST_IMG" 2>&1
|
|
|
|
else
|
|
|
|
$QEMU_IMG check "$@" -f $IMGFMT "$TEST_IMG" 2>&1
|
|
|
|
fi
|
2016-08-10 05:43:12 +03:00
|
|
|
) | _filter_testdir | _filter_qemu_img_check
|
2009-06-22 20:29:05 +04:00
|
|
|
}
|
|
|
|
|
2012-10-17 16:02:32 +04:00
|
|
|
_img_info()
|
|
|
|
{
|
2014-11-27 17:03:53 +03:00
|
|
|
if [[ "$1" == "--format-specific" ]]; then
|
|
|
|
local format_specific=1
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
local format_specific=0
|
|
|
|
fi
|
|
|
|
|
qemu-iotests: Discard specific info in _img_info
In _img_info, filter out additional information specific to the image
format provided by qemu-img info, since tests designed for multiple
image formats would produce different outputs for every image format
otherwise.
In a human-readable dump, that new information will always be last for
each "image information block" (multiple blocks are emitted when
inspecting the backing file chain). Every block is separated by an empty
line. Therefore, in this case, everything starting with the line "Format
specific information:" up to that empty line (or EOF, if it is the last
block) has to be stripped.
The JSON dump will always emit pretty JSON data. Therefore, the opening
and closing braces of every object will be on lines which are indented
by exactly the same amount, and all lines in between will have more
indentation. Thus, in this case, everything starting with a line
matching the regular expression /^ *"format-specific": {/ until /^ *},?/
has to be stripped, where the number of spaces at the beginning of the
respective lines is equal.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2013-10-09 12:46:19 +04:00
|
|
|
discard=0
|
|
|
|
regex_json_spec_start='^ *"format-specific": \{'
|
2018-03-02 20:38:14 +03:00
|
|
|
$QEMU_IMG info $QEMU_IMG_EXTRA_ARGS "$@" "$TEST_IMG" 2>&1 | \
|
2018-05-17 19:33:52 +03:00
|
|
|
sed -e "s#$REMOTE_TEST_DIR#TEST_DIR#g" \
|
|
|
|
-e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
|
2012-10-17 16:02:32 +04:00
|
|
|
-e "s#$TEST_DIR#TEST_DIR#g" \
|
|
|
|
-e "s#$IMGFMT#IMGFMT#g" \
|
|
|
|
-e "/^disk size:/ D" \
|
qemu-iotests: Discard specific info in _img_info
In _img_info, filter out additional information specific to the image
format provided by qemu-img info, since tests designed for multiple
image formats would produce different outputs for every image format
otherwise.
In a human-readable dump, that new information will always be last for
each "image information block" (multiple blocks are emitted when
inspecting the backing file chain). Every block is separated by an empty
line. Therefore, in this case, everything starting with the line "Format
specific information:" up to that empty line (or EOF, if it is the last
block) has to be stripped.
The JSON dump will always emit pretty JSON data. Therefore, the opening
and closing braces of every object will be on lines which are indented
by exactly the same amount, and all lines in between will have more
indentation. Thus, in this case, everything starting with a line
matching the regular expression /^ *"format-specific": {/ until /^ *},?/
has to be stripped, where the number of spaces at the beginning of the
respective lines is equal.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2013-10-09 12:46:19 +04:00
|
|
|
-e "/actual-size/ D" | \
|
2017-11-23 05:08:20 +03:00
|
|
|
while IFS='' read -r line; do
|
2014-11-27 17:03:53 +03:00
|
|
|
if [[ $format_specific == 1 ]]; then
|
|
|
|
discard=0
|
|
|
|
elif [[ $line == "Format specific information:" ]]; then
|
qemu-iotests: Discard specific info in _img_info
In _img_info, filter out additional information specific to the image
format provided by qemu-img info, since tests designed for multiple
image formats would produce different outputs for every image format
otherwise.
In a human-readable dump, that new information will always be last for
each "image information block" (multiple blocks are emitted when
inspecting the backing file chain). Every block is separated by an empty
line. Therefore, in this case, everything starting with the line "Format
specific information:" up to that empty line (or EOF, if it is the last
block) has to be stripped.
The JSON dump will always emit pretty JSON data. Therefore, the opening
and closing braces of every object will be on lines which are indented
by exactly the same amount, and all lines in between will have more
indentation. Thus, in this case, everything starting with a line
matching the regular expression /^ *"format-specific": {/ until /^ *},?/
has to be stripped, where the number of spaces at the beginning of the
respective lines is equal.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2013-10-09 12:46:19 +04:00
|
|
|
discard=1
|
|
|
|
elif [[ $line =~ $regex_json_spec_start ]]; then
|
|
|
|
discard=2
|
|
|
|
regex_json_spec_end="^${line%%[^ ]*}\\},? *$"
|
|
|
|
fi
|
|
|
|
if [[ $discard == 0 ]]; then
|
|
|
|
echo "$line"
|
|
|
|
elif [[ $discard == 1 && ! $line ]]; then
|
|
|
|
echo
|
|
|
|
discard=0
|
|
|
|
elif [[ $discard == 2 && $line =~ $regex_json_spec_end ]]; then
|
|
|
|
discard=0
|
|
|
|
fi
|
|
|
|
done
|
2012-10-17 16:02:32 +04:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:29:05 +04:00
|
|
|
# bail out, setting up .notrun file
|
|
|
|
#
|
|
|
|
_notrun()
|
|
|
|
{
|
2014-05-25 01:24:55 +04:00
|
|
|
echo "$*" >"$OUTPUT_DIR/$seq.notrun"
|
2009-06-22 20:29:05 +04:00
|
|
|
echo "$seq not run: $*"
|
|
|
|
status=0
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
|
|
|
# just plain bail out
|
|
|
|
#
|
|
|
|
_fail()
|
|
|
|
{
|
2014-05-25 01:24:55 +04:00
|
|
|
echo "$*" | tee -a "$OUTPUT_DIR/$seq.full"
|
2009-06-22 20:29:05 +04:00
|
|
|
echo "(see $seq.full for details)"
|
|
|
|
status=1
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# tests whether $IMGFMT is one of the supported image formats for a test
|
|
|
|
#
|
|
|
|
_supported_fmt()
|
|
|
|
{
|
2014-03-26 16:05:23 +04:00
|
|
|
# "generic" is suitable for most image formats. For some formats it doesn't
|
|
|
|
# work, however (most notably read-only formats), so they can opt out by
|
|
|
|
# setting IMGFMT_GENERIC to false.
|
2009-06-22 20:29:05 +04:00
|
|
|
for f; do
|
2013-09-27 16:48:15 +04:00
|
|
|
if [ "$f" = "$IMGFMT" -o "$f" = "generic" -a "$IMGFMT_GENERIC" = "true" ]; then
|
2013-09-04 15:16:04 +04:00
|
|
|
return
|
|
|
|
fi
|
2009-06-22 20:29:05 +04:00
|
|
|
done
|
|
|
|
|
|
|
|
_notrun "not suitable for this image format: $IMGFMT"
|
|
|
|
}
|
|
|
|
|
2017-02-01 03:31:19 +03:00
|
|
|
# tests whether $IMGFMT is one of the unsupported image format for a test
|
|
|
|
#
|
|
|
|
_unsupported_fmt()
|
|
|
|
{
|
|
|
|
for f; do
|
|
|
|
if [ "$f" = "$IMGFMT" ]; then
|
|
|
|
_notrun "not suitable for this image format: $IMGFMT"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2011-01-17 20:01:17 +03:00
|
|
|
# tests whether $IMGPROTO is one of the supported image protocols for a test
|
|
|
|
#
|
|
|
|
_supported_proto()
|
|
|
|
{
|
|
|
|
for f; do
|
2013-09-04 15:16:04 +04:00
|
|
|
if [ "$f" = "$IMGPROTO" -o "$f" = "generic" ]; then
|
|
|
|
return
|
|
|
|
fi
|
2011-01-17 20:01:17 +03:00
|
|
|
done
|
|
|
|
|
|
|
|
_notrun "not suitable for this image protocol: $IMGPROTO"
|
|
|
|
}
|
|
|
|
|
2017-02-14 19:21:17 +03:00
|
|
|
# tests whether $IMGPROTO is specified as an unsupported image protocol for a test
|
|
|
|
#
|
|
|
|
_unsupported_proto()
|
|
|
|
{
|
|
|
|
for f; do
|
|
|
|
if [ "$f" = "$IMGPROTO" ]; then
|
|
|
|
_notrun "not suitable for this image protocol: $IMGPROTO"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2009-06-22 20:29:05 +04:00
|
|
|
# tests whether the host OS is one of the supported OSes for a test
|
|
|
|
#
|
|
|
|
_supported_os()
|
|
|
|
{
|
|
|
|
for h
|
|
|
|
do
|
2013-09-04 15:16:04 +04:00
|
|
|
if [ "$h" = "$HOSTOS" ]
|
|
|
|
then
|
|
|
|
return
|
|
|
|
fi
|
2009-06-22 20:29:05 +04:00
|
|
|
done
|
|
|
|
|
|
|
|
_notrun "not suitable for this OS: $HOSTOS"
|
|
|
|
}
|
|
|
|
|
2013-12-04 05:07:00 +04:00
|
|
|
_supported_cache_modes()
|
2012-08-09 16:05:57 +04:00
|
|
|
{
|
2013-12-04 05:07:00 +04:00
|
|
|
for mode; do
|
|
|
|
if [ "$mode" = "$CACHEMODE" ]; then
|
|
|
|
return
|
|
|
|
fi
|
2012-08-09 16:05:57 +04:00
|
|
|
done
|
2013-12-04 05:07:00 +04:00
|
|
|
_notrun "not suitable for cache mode: $CACHEMODE"
|
|
|
|
}
|
|
|
|
|
|
|
|
_default_cache_mode()
|
|
|
|
{
|
|
|
|
if $CACHEMODE_IS_DEFAULT; then
|
|
|
|
CACHEMODE="$1"
|
|
|
|
QEMU_IO="$QEMU_IO --cache $1"
|
|
|
|
return
|
|
|
|
fi
|
2012-08-09 16:05:57 +04:00
|
|
|
}
|
|
|
|
|
2013-11-26 10:40:32 +04:00
|
|
|
_unsupported_imgopts()
|
|
|
|
{
|
|
|
|
for bad_opt
|
|
|
|
do
|
|
|
|
if echo "$IMGOPTS" | grep -q 2>/dev/null "$bad_opt"
|
|
|
|
then
|
|
|
|
_notrun "not suitable for image option: $bad_opt"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2009-06-22 20:29:05 +04:00
|
|
|
# this test requires that a specified command (executable) exists
|
|
|
|
#
|
|
|
|
_require_command()
|
|
|
|
{
|
2015-09-02 21:52:27 +03:00
|
|
|
if [ "$1" = "QEMU" ]; then
|
|
|
|
c=$QEMU_PROG
|
|
|
|
elif [ "$1" = "QEMU_IMG" ]; then
|
|
|
|
c=$QEMU_IMG_PROG
|
|
|
|
elif [ "$1" = "QEMU_IO" ]; then
|
|
|
|
c=$QEMU_IO_PROG
|
|
|
|
elif [ "$1" = "QEMU_NBD" ]; then
|
|
|
|
c=$QEMU_NBD_PROG
|
|
|
|
else
|
|
|
|
eval c=\$$1
|
|
|
|
fi
|
2013-12-04 13:10:56 +04:00
|
|
|
[ -x "$c" ] || _notrun "$1 utility required, skipped this test"
|
2009-06-22 20:29:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# make sure this script returns success
|
2015-01-04 04:53:48 +03:00
|
|
|
true
|