2019-03-07 15:58:38 +01:00
|
|
|
#!/usr/bin/env bash
|
2009-06-22 18:29:05 +02: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 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
|
|
|
#
|
|
|
|
|
2019-03-07 15:58:39 +01:00
|
|
|
SED=
|
|
|
|
for sed in sed gsed; do
|
|
|
|
($sed --version | grep 'GNU sed') > /dev/null 2>&1
|
|
|
|
if [ "$?" -eq 0 ]; then
|
|
|
|
SED=$sed
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ -z "$SED" ]; then
|
|
|
|
echo "$0: GNU sed not found"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2009-06-22 18:29:05 +02:00
|
|
|
dd()
|
|
|
|
{
|
|
|
|
if [ "$HOSTOS" == "Linux" ]
|
2013-09-04 13:16:04 +02: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 18:29:05 +02:00
|
|
|
else
|
2013-09-04 13:16:04 +02:00
|
|
|
command dd $@
|
2009-06-22 18:29:05 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-08-06 09:44:49 +02:00
|
|
|
# poke_file 'test.img' 512 '\xff\xfe'
|
|
|
|
poke_file()
|
|
|
|
{
|
|
|
|
printf "$3" | dd "of=$1" bs=1 "seek=$2" conv=notrunc &>/dev/null
|
|
|
|
}
|
2020-03-24 18:27:56 +01:00
|
|
|
|
|
|
|
# poke_file_le $img_filename $offset $byte_width $value
|
|
|
|
# Example: poke_file_le "$TEST_IMG" 512 2 65534
|
|
|
|
poke_file_le()
|
|
|
|
{
|
|
|
|
local img=$1 ofs=$2 len=$3 val=$4 str=''
|
|
|
|
|
|
|
|
while ((len--)); do
|
|
|
|
str+=$(printf '\\x%02x' $((val & 0xff)))
|
|
|
|
val=$((val >> 8))
|
|
|
|
done
|
|
|
|
|
|
|
|
poke_file "$img" "$ofs" "$str"
|
|
|
|
}
|
|
|
|
|
|
|
|
# poke_file_be $img_filename $offset $byte_width $value
|
|
|
|
# Example: poke_file_be "$TEST_IMG" 512 2 65279
|
|
|
|
poke_file_be()
|
|
|
|
{
|
|
|
|
local img=$1 ofs=$2 len=$3 val=$4
|
|
|
|
local str=$(printf "%0$((len * 2))x\n" $val | sed 's/\(..\)/\\x\1/g')
|
|
|
|
|
|
|
|
poke_file "$img" "$ofs" "$str"
|
|
|
|
}
|
2013-08-06 09:44:49 +02:00
|
|
|
|
2019-10-11 17:28:13 +02:00
|
|
|
# peek_file_le 'test.img' 512 2 => 65534
|
|
|
|
peek_file_le()
|
|
|
|
{
|
2020-02-26 13:54:24 +01:00
|
|
|
local val=0 shift=0 byte
|
|
|
|
|
|
|
|
# coreutils' od --endian is not portable, so manually assemble bytes.
|
|
|
|
for byte in $(od -j"$2" -N"$3" -An -v -tu1 "$1"); do
|
|
|
|
val=$(( val | (byte << shift) ))
|
|
|
|
shift=$((shift + 8))
|
|
|
|
done
|
|
|
|
printf %llu $val
|
2019-10-11 17:28:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# peek_file_be 'test.img' 512 2 => 65279
|
|
|
|
peek_file_be()
|
|
|
|
{
|
2020-02-26 13:54:24 +01:00
|
|
|
local val=0 byte
|
|
|
|
|
|
|
|
# coreutils' od --endian is not portable, so manually assemble bytes.
|
|
|
|
for byte in $(od -j"$2" -N"$3" -An -v -tu1 "$1"); do
|
|
|
|
val=$(( (val << 8) | byte ))
|
|
|
|
done
|
|
|
|
printf %llu $val
|
2019-10-11 17:28:13 +02:00
|
|
|
}
|
|
|
|
|
2020-02-26 13:54:24 +01:00
|
|
|
# peek_file_raw 'test.img' 512 2 => '\xff\xfe'. Do not use if the raw data
|
|
|
|
# is likely to contain \0 or trailing \n.
|
2019-10-11 17:28:13 +02:00
|
|
|
peek_file_raw()
|
|
|
|
{
|
|
|
|
dd if="$1" bs=1 skip="$2" count="$3" status=none
|
|
|
|
}
|
|
|
|
|
2017-09-12 16:44:55 +02:00
|
|
|
|
|
|
|
if ! . ./common.config
|
|
|
|
then
|
2017-09-12 16:44:58 +02:00
|
|
|
echo "$0: failed to source common.config"
|
2017-09-12 16:44:55 +02:00
|
|
|
exit 1
|
2009-06-22 18:29:05 +02:00
|
|
|
fi
|
|
|
|
|
2019-09-04 11:11:19 +02:00
|
|
|
# Set the variables to the empty string to turn Valgrind off
|
|
|
|
# for specific processes, e.g.
|
|
|
|
# $ VALGRIND_QEMU_IO= ./check -qcow2 -valgrind 015
|
|
|
|
|
|
|
|
: ${VALGRIND_QEMU_VM=$VALGRIND_QEMU}
|
|
|
|
: ${VALGRIND_QEMU_IMG=$VALGRIND_QEMU}
|
|
|
|
: ${VALGRIND_QEMU_IO=$VALGRIND_QEMU}
|
|
|
|
: ${VALGRIND_QEMU_NBD=$VALGRIND_QEMU}
|
|
|
|
|
|
|
|
# The Valgrind own parameters may be set with
|
|
|
|
# its environment variable VALGRIND_OPTS, e.g.
|
|
|
|
# $ VALGRIND_OPTS="--leak-check=yes" ./check -qcow2 -valgrind 015
|
|
|
|
|
|
|
|
_qemu_proc_exec()
|
|
|
|
{
|
|
|
|
local VALGRIND_LOGFILE="$1"
|
|
|
|
shift
|
2019-09-04 11:11:20 +02:00
|
|
|
if [[ "${VALGRIND_QEMU}" == "y" && "${NO_VALGRIND}" != "y" ]]; then
|
2019-09-04 11:11:19 +02:00
|
|
|
exec valgrind --log-file="${VALGRIND_LOGFILE}" --error-exitcode=99 "$@"
|
|
|
|
else
|
|
|
|
exec "$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
_qemu_proc_valgrind_log()
|
|
|
|
{
|
|
|
|
local VALGRIND_LOGFILE="$1"
|
|
|
|
local RETVAL="$2"
|
2019-09-04 11:11:20 +02:00
|
|
|
if [[ "${VALGRIND_QEMU}" == "y" && "${NO_VALGRIND}" != "y" ]]; then
|
2019-09-04 11:11:19 +02:00
|
|
|
if [ $RETVAL == 99 ]; then
|
|
|
|
cat "${VALGRIND_LOGFILE}"
|
|
|
|
fi
|
|
|
|
rm -f "${VALGRIND_LOGFILE}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-09-12 16:44:54 +02:00
|
|
|
_qemu_wrapper()
|
|
|
|
{
|
2019-09-04 11:11:19 +02:00
|
|
|
local VALGRIND_LOGFILE="${TEST_DIR}"/$$.valgrind
|
2017-09-12 16:44:54 +02:00
|
|
|
(
|
|
|
|
if [ -n "${QEMU_NEED_PID}" ]; then
|
|
|
|
echo $BASHPID > "${QEMU_TEST_DIR}/qemu-${_QEMU_HANDLE}.pid"
|
|
|
|
fi
|
2019-09-04 11:11:19 +02:00
|
|
|
VALGRIND_QEMU="${VALGRIND_QEMU_VM}" _qemu_proc_exec "${VALGRIND_LOGFILE}" \
|
|
|
|
"$QEMU_PROG" $QEMU_OPTIONS "$@"
|
2017-09-12 16:44:54 +02:00
|
|
|
)
|
2019-09-04 11:11:19 +02:00
|
|
|
RETVAL=$?
|
|
|
|
_qemu_proc_valgrind_log "${VALGRIND_LOGFILE}" $RETVAL
|
|
|
|
return $RETVAL
|
2017-09-12 16:44:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_qemu_img_wrapper()
|
|
|
|
{
|
2019-09-04 11:11:19 +02:00
|
|
|
local VALGRIND_LOGFILE="${TEST_DIR}"/$$.valgrind
|
|
|
|
(
|
|
|
|
VALGRIND_QEMU="${VALGRIND_QEMU_IMG}" _qemu_proc_exec "${VALGRIND_LOGFILE}" \
|
|
|
|
"$QEMU_IMG_PROG" $QEMU_IMG_OPTIONS "$@"
|
|
|
|
)
|
|
|
|
RETVAL=$?
|
|
|
|
_qemu_proc_valgrind_log "${VALGRIND_LOGFILE}" $RETVAL
|
|
|
|
return $RETVAL
|
2017-09-12 16:44:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_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
|
|
|
|
(
|
2019-09-04 11:11:19 +02:00
|
|
|
VALGRIND_QEMU="${VALGRIND_QEMU_IO}" _qemu_proc_exec "${VALGRIND_LOGFILE}" \
|
|
|
|
"$QEMU_IO_PROG" $QEMU_IO_ARGS "$@"
|
2017-09-12 16:44:54 +02:00
|
|
|
)
|
|
|
|
RETVAL=$?
|
2019-09-04 11:11:19 +02:00
|
|
|
_qemu_proc_valgrind_log "${VALGRIND_LOGFILE}" $RETVAL
|
|
|
|
return $RETVAL
|
2017-09-12 16:44:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_qemu_nbd_wrapper()
|
|
|
|
{
|
2019-09-04 11:11:19 +02:00
|
|
|
local VALGRIND_LOGFILE="${TEST_DIR}"/$$.valgrind
|
|
|
|
(
|
|
|
|
VALGRIND_QEMU="${VALGRIND_QEMU_NBD}" _qemu_proc_exec "${VALGRIND_LOGFILE}" \
|
|
|
|
"$QEMU_NBD_PROG" --pid-file="${QEMU_TEST_DIR}/qemu-nbd.pid" \
|
|
|
|
$QEMU_NBD_OPTIONS "$@"
|
|
|
|
)
|
|
|
|
RETVAL=$?
|
|
|
|
_qemu_proc_valgrind_log "${VALGRIND_LOGFILE}" $RETVAL
|
|
|
|
return $RETVAL
|
2017-09-12 16:44:54 +02:00
|
|
|
}
|
|
|
|
|
2019-09-04 11:11:20 +02:00
|
|
|
# Valgrind bug #409141 https://bugs.kde.org/show_bug.cgi?id=409141
|
|
|
|
# Until valgrind 3.16+ is ubiquitous, we must work around a hang in
|
|
|
|
# valgrind when issuing sigkill. Disable valgrind for this invocation.
|
|
|
|
_NO_VALGRIND()
|
|
|
|
{
|
|
|
|
NO_VALGRIND="y" "$@"
|
|
|
|
}
|
|
|
|
|
2017-09-12 16:44:54 +02:00
|
|
|
export QEMU=_qemu_wrapper
|
|
|
|
export QEMU_IMG=_qemu_img_wrapper
|
|
|
|
export QEMU_IO=_qemu_io_wrapper
|
|
|
|
export QEMU_NBD=_qemu_nbd_wrapper
|
|
|
|
|
2016-05-10 18:11:27 +02:00
|
|
|
if [ "$IMGOPTSSYNTAX" = "true" ]; then
|
|
|
|
DRIVER="driver=$IMGFMT"
|
2017-09-12 16:44:56 +02: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 18:11:29 +02:00
|
|
|
if [ "$IMGFMT" = "luks" ]; then
|
|
|
|
DRIVER="$DRIVER,key-secret=keysec0"
|
|
|
|
fi
|
2016-05-10 18:11:27 +02: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
|
2019-12-18 11:48:55 +01:00
|
|
|
TEST_IMG="$DRIVER,file.driver=nbd,file.type=unix"
|
|
|
|
TEST_IMG="$TEST_IMG,file.path=$SOCK_DIR/nbd"
|
2016-05-10 18:11:27 +02:00
|
|
|
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 13:16:56 +02:00
|
|
|
TEST_IMG=$TEST_DIR/t.$IMGFMT
|
2016-05-10 18:11:27 +02:00
|
|
|
else
|
|
|
|
TEST_IMG="$DRIVER,file.driver=$IMGPROTO,file.filename=$TEST_DIR/t.$IMGFMT"
|
|
|
|
fi
|
2011-01-17 18:01:17 +01:00
|
|
|
else
|
2017-09-12 16:44:56 +02:00
|
|
|
QEMU_IMG_EXTRA_ARGS=
|
2016-05-10 18:11:27 +02:00
|
|
|
if [ "$IMGPROTO" = "file" ]; then
|
|
|
|
TEST_IMG=$TEST_DIR/t.$IMGFMT
|
|
|
|
elif [ "$IMGPROTO" = "nbd" ]; then
|
|
|
|
TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT
|
2019-11-14 22:34:13 +01:00
|
|
|
TEST_IMG="nbd+unix:///?socket=$SOCK_DIR/nbd"
|
2016-05-10 18:11:27 +02:00
|
|
|
elif [ "$IMGPROTO" = "ssh" ]; then
|
|
|
|
TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT
|
2019-02-25 20:08:27 +01:00
|
|
|
REMOTE_TEST_DIR="ssh://\\($USER@\\)\\?127.0.0.1\\(:[0-9]\\+\\)\\?$TEST_DIR"
|
2016-05-10 18:11:27 +02:00
|
|
|
TEST_IMG="ssh://127.0.0.1$TEST_IMG_FILE"
|
|
|
|
elif [ "$IMGPROTO" = "nfs" ]; then
|
2018-05-17 17:26:14 +02:00
|
|
|
TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT
|
2018-05-17 18:33:52 +02:00
|
|
|
REMOTE_TEST_DIR="nfs://127.0.0.1$TEST_DIR"
|
2018-05-17 17:26:14 +02:00
|
|
|
TEST_IMG="nfs://127.0.0.1$TEST_IMG_FILE"
|
2016-05-10 18:11:27 +02:00
|
|
|
else
|
|
|
|
TEST_IMG=$IMGPROTO:$TEST_DIR/t.$IMGFMT
|
|
|
|
fi
|
2011-01-17 18:01:17 +01:00
|
|
|
fi
|
2017-07-27 15:13:20 +02:00
|
|
|
ORIG_TEST_IMG="$TEST_IMG"
|
2009-06-22 18:29:05 +02:00
|
|
|
|
2017-09-12 16:44:56 +02:00
|
|
|
if [ -z "$TEST_DIR" ]; then
|
2018-11-16 21:33:03 +01:00
|
|
|
TEST_DIR=$PWD/scratch
|
2017-09-12 16:44:56 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
QEMU_TEST_DIR="${TEST_DIR}"
|
|
|
|
|
|
|
|
if [ ! -e "$TEST_DIR" ]; then
|
|
|
|
mkdir "$TEST_DIR"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d "$TEST_DIR" ]; then
|
2018-10-04 18:18:46 +02:00
|
|
|
echo "common.rc: Error: \$TEST_DIR ($TEST_DIR) is not a directory"
|
2017-09-12 16:44:56 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-05-17 18:33:52 +02:00
|
|
|
if [ -z "$REMOTE_TEST_DIR" ]; then
|
|
|
|
REMOTE_TEST_DIR="$TEST_DIR"
|
|
|
|
fi
|
|
|
|
|
2017-09-12 16:44:56 +02:00
|
|
|
if [ ! -d "$SAMPLE_IMG_DIR" ]; then
|
2018-10-04 18:18:46 +02:00
|
|
|
echo "common.rc: Error: \$SAMPLE_IMG_DIR ($SAMPLE_IMG_DIR) is not a directory"
|
2017-09-12 16:44:56 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2013-09-25 14:12:20 +02: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 08:40:46 +02: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}
|
2019-11-14 22:34:13 +01:00
|
|
|
rm -f "${QEMU_TEST_DIR}/qemu-nbd.pid" "$SOCK_DIR/nbd"
|
2018-07-11 08:40:46 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-11-07 17:37:08 +01:00
|
|
|
# Gets the data_file value from IMGOPTS and replaces the '$TEST_IMG'
|
|
|
|
# pattern by '$1'
|
|
|
|
# Caution: The replacement is done with sed, so $1 must be escaped
|
|
|
|
# properly. (The delimiter is '#'.)
|
|
|
|
_get_data_file()
|
|
|
|
{
|
|
|
|
if ! echo "$IMGOPTS" | grep -q 'data_file='; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "$IMGOPTS" | sed -e 's/.*data_file=\([^,]*\).*/\1/' \
|
|
|
|
| sed -e "s#\\\$TEST_IMG#$1#"
|
|
|
|
}
|
|
|
|
|
2009-06-22 18:29:05 +02: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 19:57:23 +01:00
|
|
|
local extra_img_options=""
|
2012-03-27 13:45:14 +02:00
|
|
|
local optstr=""
|
2012-11-02 14:01:23 +01:00
|
|
|
local img_name=""
|
2013-10-31 16:57:37 +01:00
|
|
|
local use_backing=0
|
|
|
|
local backing_file=""
|
2016-05-10 18:11:28 +02:00
|
|
|
local object_options=""
|
2019-11-07 17:36:55 +01:00
|
|
|
local opts_param=false
|
2019-11-07 17:36:54 +01:00
|
|
|
local misc_params=()
|
2012-11-02 14:01:23 +01:00
|
|
|
|
|
|
|
if [ -n "$TEST_IMG_FILE" ]; then
|
|
|
|
img_name=$TEST_IMG_FILE
|
|
|
|
else
|
|
|
|
img_name=$TEST_IMG
|
|
|
|
fi
|
2012-03-27 13:45:14 +02:00
|
|
|
|
|
|
|
if [ -n "$IMGOPTS" ]; then
|
2019-11-07 17:37:08 +01:00
|
|
|
imgopts_expanded=$(echo "$IMGOPTS" | sed -e "s#\\\$TEST_IMG#$img_name#")
|
|
|
|
optstr=$(_optstr_add "$optstr" "$imgopts_expanded")
|
2012-03-27 13:45:14 +02:00
|
|
|
fi
|
2016-05-10 18:11:28 +02:00
|
|
|
if [ -n "$IMGKEYSECRET" ]; then
|
|
|
|
object_options="--object secret,id=keysec0,data=$IMGKEYSECRET"
|
|
|
|
optstr=$(_optstr_add "$optstr" "key-secret=keysec0")
|
|
|
|
fi
|
2009-06-22 18:29:05 +02:00
|
|
|
|
2019-11-07 17:36:54 +01:00
|
|
|
for param; do
|
|
|
|
if [ "$use_backing" = "1" -a -z "$backing_file" ]; then
|
|
|
|
backing_file=$param
|
|
|
|
continue
|
2019-11-07 17:36:55 +01:00
|
|
|
elif $opts_param; then
|
|
|
|
optstr=$(_optstr_add "$optstr" "$param")
|
|
|
|
opts_param=false
|
|
|
|
continue
|
2019-11-07 17:36:54 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
case "$param" in
|
|
|
|
-b)
|
|
|
|
use_backing=1
|
|
|
|
;;
|
|
|
|
|
2019-11-07 17:36:55 +01:00
|
|
|
-o)
|
|
|
|
opts_param=true
|
|
|
|
;;
|
|
|
|
|
|
|
|
--no-opts)
|
|
|
|
optstr=""
|
|
|
|
;;
|
|
|
|
|
2019-11-07 17:36:54 +01:00
|
|
|
*)
|
|
|
|
misc_params=("${misc_params[@]}" "$param")
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2010-10-31 21:10:20 +01:00
|
|
|
if [ \( "$IMGFMT" = "qcow2" -o "$IMGFMT" = "qed" \) -a -n "$CLUSTER_SIZE" ]; then
|
2012-03-27 13:45:14 +02: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 19:29:59 +02:00
|
|
|
fi
|
|
|
|
|
2018-07-11 08:40:46 +02:00
|
|
|
if [ $IMGPROTO = "nbd" ]; then
|
|
|
|
_stop_nbd_server
|
|
|
|
fi
|
|
|
|
|
2009-06-22 18:29:05 +02:00
|
|
|
# XXX(hch): have global image options?
|
2013-10-31 16:57:37 +01:00
|
|
|
(
|
|
|
|
if [ $use_backing = 1 ]; then
|
2019-11-07 17:36:54 +01:00
|
|
|
$QEMU_IMG create $object_options -f $IMGFMT $extra_img_options -b "$backing_file" "$img_name" "${misc_params[@]}" 2>&1
|
2013-10-31 16:57:37 +01:00
|
|
|
else
|
2019-11-07 17:36:54 +01:00
|
|
|
$QEMU_IMG create $object_options -f $IMGFMT $extra_img_options "$img_name" "${misc_params[@]}" 2>&1
|
2013-10-31 16:57:37 +01:00
|
|
|
fi
|
2014-08-19 19:28:58 +02:00
|
|
|
) | _filter_img_create
|
2012-11-02 14:01:23 +01:00
|
|
|
|
2019-11-14 22:34:13 +01:00
|
|
|
# Start an NBD server on the image file, which is what we'll be talking to.
|
|
|
|
# Once NBD gains resize support, we may also want to use -f raw at the
|
|
|
|
# server and interpret format over NBD, but for now, the format is
|
|
|
|
# interpreted at the server and raw data sent over NBD.
|
2012-11-02 14:01:23 +01:00
|
|
|
if [ $IMGPROTO = "nbd" ]; then
|
2017-04-26 16:14:07 +02:00
|
|
|
# Pass a sufficiently high number to -e that should be enough for all
|
|
|
|
# tests
|
2019-11-14 22:34:13 +01:00
|
|
|
eval "$QEMU_NBD -v -t -k '$SOCK_DIR/nbd' -f $IMGFMT -e 42 -x '' $TEST_IMG_FILE >/dev/null &"
|
2012-11-02 14:01:23 +01:00
|
|
|
sleep 1 # FIXME: qemu-nbd needs to be listening before we continue
|
|
|
|
fi
|
2009-06-22 18:29:05 +02:00
|
|
|
}
|
|
|
|
|
2013-11-26 07:40:34 +01:00
|
|
|
_rm_test_img()
|
|
|
|
{
|
|
|
|
local img=$1
|
|
|
|
if [ "$IMGFMT" = "vmdk" ]; then
|
|
|
|
# Remove all the extents for vmdk
|
2014-04-10 22:47:39 +02:00
|
|
|
"$QEMU_IMG" info "$img" 2>/dev/null | grep 'filename:' | cut -f 2 -d: \
|
2013-11-26 07:40:34 +01:00
|
|
|
| xargs -I {} rm -f "{}"
|
2019-11-07 17:37:08 +01:00
|
|
|
elif [ "$IMGFMT" = "qcow2" ]; then
|
|
|
|
# Remove external data file
|
|
|
|
if data_file=$(_get_data_file "$img"); then
|
|
|
|
rm -f "$data_file"
|
|
|
|
fi
|
2013-11-26 07:40:34 +01:00
|
|
|
fi
|
2014-04-10 22:47:39 +02:00
|
|
|
rm -f "$img"
|
2013-11-26 07:40:34 +01:00
|
|
|
}
|
|
|
|
|
2009-06-22 18:29:05 +02:00
|
|
|
_cleanup_test_img()
|
|
|
|
{
|
2011-01-17 18:01:17 +01:00
|
|
|
case "$IMGPROTO" in
|
|
|
|
|
2012-11-02 14:01:23 +01:00
|
|
|
nbd)
|
2018-07-11 08:40:46 +02:00
|
|
|
_stop_nbd_server
|
2013-09-25 14:12:22 +02:00
|
|
|
rm -f "$TEST_IMG_FILE"
|
2012-11-02 14:01:23 +01:00
|
|
|
;;
|
2017-04-04 05:48:09 +02:00
|
|
|
|
2011-01-17 18:01:17 +01:00
|
|
|
file)
|
2013-11-26 07:40:34 +01: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 14:12:20 +02:00
|
|
|
if [ -n "$SAMPLE_IMG_FILE" ]
|
|
|
|
then
|
|
|
|
rm -f "$TEST_DIR/$SAMPLE_IMG_FILE"
|
2017-07-27 15:13:20 +02:00
|
|
|
SAMPLE_IMG_FILE=
|
|
|
|
TEST_IMG="$ORIG_TEST_IMG"
|
2013-09-25 14:12:20 +02:00
|
|
|
fi
|
2011-01-17 18:01:17 +01:00
|
|
|
;;
|
|
|
|
|
|
|
|
rbd)
|
2014-01-08 21:05:38 +01:00
|
|
|
rbd --no-progress rm "$TEST_DIR/t.$IMGFMT" > /dev/null
|
2011-01-17 18:01:17 +01:00
|
|
|
;;
|
|
|
|
|
|
|
|
sheepdog)
|
2013-09-25 14:12:22 +02:00
|
|
|
collie vdi delete "$TEST_DIR/t.$IMGFMT"
|
2011-01-17 18:01:17 +01:00
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|
2009-06-22 18:29:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_check_test_img()
|
|
|
|
{
|
2016-05-10 18:11:27 +02: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 04:43:12 +02:00
|
|
|
) | _filter_testdir | _filter_qemu_img_check
|
2019-09-16 19:53:20 +02:00
|
|
|
|
|
|
|
# return real qemu_img check status, to analyze in
|
|
|
|
# _check_test_img_ignore_leaks
|
|
|
|
return ${PIPESTATUS[0]}
|
|
|
|
}
|
|
|
|
|
|
|
|
_check_test_img_ignore_leaks()
|
|
|
|
{
|
|
|
|
out=$(_check_test_img "$@")
|
|
|
|
status=$?
|
|
|
|
if [ $status = 3 ]; then
|
|
|
|
# This must correspond to success output in dump_human_image_check()
|
|
|
|
echo "No errors were found on the image."
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
echo "$out"
|
|
|
|
return $status
|
2009-06-22 18:29:05 +02:00
|
|
|
}
|
|
|
|
|
2012-10-17 14:02:32 +02:00
|
|
|
_img_info()
|
|
|
|
{
|
2014-11-27 15:03:53 +01: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 10:46:19 +02:00
|
|
|
discard=0
|
|
|
|
regex_json_spec_start='^ *"format-specific": \{'
|
2018-03-02 18:38:14 +01:00
|
|
|
$QEMU_IMG info $QEMU_IMG_EXTRA_ARGS "$@" "$TEST_IMG" 2>&1 | \
|
2018-05-17 18:33:52 +02:00
|
|
|
sed -e "s#$REMOTE_TEST_DIR#TEST_DIR#g" \
|
|
|
|
-e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
|
2012-10-17 14:02:32 +02: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 10:46:19 +02:00
|
|
|
-e "/actual-size/ D" | \
|
2017-11-23 03:08:20 +01:00
|
|
|
while IFS='' read -r line; do
|
2014-11-27 15:03:53 +01: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 10:46:19 +02: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 14:02:32 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 18:29:05 +02:00
|
|
|
# bail out, setting up .notrun file
|
|
|
|
#
|
|
|
|
_notrun()
|
|
|
|
{
|
2014-05-24 23:24:55 +02:00
|
|
|
echo "$*" >"$OUTPUT_DIR/$seq.notrun"
|
2009-06-22 18:29:05 +02:00
|
|
|
echo "$seq not run: $*"
|
|
|
|
status=0
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
2019-09-04 11:11:21 +02:00
|
|
|
# bail out, setting up .casenotrun file
|
|
|
|
# The function _casenotrun() is used as a notifier. It is the
|
|
|
|
# caller's responsibility to make skipped a particular test.
|
|
|
|
#
|
|
|
|
_casenotrun()
|
|
|
|
{
|
|
|
|
echo " [case not run] $*" >>"$OUTPUT_DIR/$seq.casenotrun"
|
|
|
|
}
|
|
|
|
|
2009-06-22 18:29:05 +02:00
|
|
|
# just plain bail out
|
|
|
|
#
|
|
|
|
_fail()
|
|
|
|
{
|
2014-05-24 23:24:55 +02:00
|
|
|
echo "$*" | tee -a "$OUTPUT_DIR/$seq.full"
|
2009-06-22 18:29:05 +02: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 13:05:23 +01: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 18:29:05 +02:00
|
|
|
for f; do
|
2013-09-27 14:48:15 +02:00
|
|
|
if [ "$f" = "$IMGFMT" -o "$f" = "generic" -a "$IMGFMT_GENERIC" = "true" ]; then
|
2020-06-25 14:55:35 +02:00
|
|
|
if [ "$IMGFMT" = "luks" ]; then
|
|
|
|
_require_working_luks
|
|
|
|
fi
|
2013-09-04 13:16:04 +02:00
|
|
|
return
|
|
|
|
fi
|
2009-06-22 18:29:05 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
_notrun "not suitable for this image format: $IMGFMT"
|
|
|
|
}
|
|
|
|
|
2017-02-01 01:31:19 +01: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 18:01:17 +01:00
|
|
|
# tests whether $IMGPROTO is one of the supported image protocols for a test
|
|
|
|
#
|
|
|
|
_supported_proto()
|
|
|
|
{
|
|
|
|
for f; do
|
2013-09-04 13:16:04 +02:00
|
|
|
if [ "$f" = "$IMGPROTO" -o "$f" = "generic" ]; then
|
|
|
|
return
|
|
|
|
fi
|
2011-01-17 18:01:17 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
_notrun "not suitable for this image protocol: $IMGPROTO"
|
|
|
|
}
|
|
|
|
|
2017-02-14 17:21:17 +01: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 18:29:05 +02:00
|
|
|
# tests whether the host OS is one of the supported OSes for a test
|
|
|
|
#
|
|
|
|
_supported_os()
|
|
|
|
{
|
|
|
|
for h
|
|
|
|
do
|
2013-09-04 13:16:04 +02:00
|
|
|
if [ "$h" = "$HOSTOS" ]
|
|
|
|
then
|
|
|
|
return
|
|
|
|
fi
|
2009-06-22 18:29:05 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
_notrun "not suitable for this OS: $HOSTOS"
|
|
|
|
}
|
|
|
|
|
2013-12-04 02:07:00 +01:00
|
|
|
_supported_cache_modes()
|
2012-08-09 14:05:57 +02:00
|
|
|
{
|
2013-12-04 02:07:00 +01:00
|
|
|
for mode; do
|
|
|
|
if [ "$mode" = "$CACHEMODE" ]; then
|
|
|
|
return
|
|
|
|
fi
|
2012-08-09 14:05:57 +02:00
|
|
|
done
|
2013-12-04 02:07:00 +01:00
|
|
|
_notrun "not suitable for cache mode: $CACHEMODE"
|
|
|
|
}
|
|
|
|
|
2020-04-30 14:47:06 +02:00
|
|
|
# Check whether the filesystem supports O_DIRECT
|
|
|
|
_check_o_direct()
|
|
|
|
{
|
|
|
|
$QEMU_IMG create -f raw "$TEST_IMG".test_o_direct 1M > /dev/null
|
|
|
|
out=$($QEMU_IO -f raw -t none -c quit "$TEST_IMG".test_o_direct 2>&1)
|
|
|
|
rm -f "$TEST_IMG".test_o_direct
|
|
|
|
|
|
|
|
[[ "$out" != *"O_DIRECT"* ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
_require_o_direct()
|
|
|
|
{
|
|
|
|
if ! _check_o_direct; then
|
|
|
|
_notrun "file system on $TEST_DIR does not support O_DIRECT"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
_check_cache_mode()
|
|
|
|
{
|
|
|
|
if [ $CACHEMODE == "none" ] || [ $CACHEMODE == "directsync" ]; then
|
|
|
|
_require_o_direct
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
_check_cache_mode
|
|
|
|
|
|
|
|
# $1 - cache mode to use by default
|
|
|
|
# $2 - (optional) cache mode to use by default if O_DIRECT is not supported
|
2013-12-04 02:07:00 +01:00
|
|
|
_default_cache_mode()
|
|
|
|
{
|
|
|
|
if $CACHEMODE_IS_DEFAULT; then
|
2020-04-30 14:47:06 +02:00
|
|
|
if [ -z "$2" ] || _check_o_direct; then
|
|
|
|
CACHEMODE="$1"
|
|
|
|
else
|
|
|
|
CACHEMODE="$2"
|
|
|
|
fi
|
|
|
|
QEMU_IO="$QEMU_IO --cache $CACHEMODE"
|
|
|
|
_check_cache_mode
|
2013-12-04 02:07:00 +01:00
|
|
|
return
|
|
|
|
fi
|
2012-08-09 14:05:57 +02:00
|
|
|
}
|
2020-01-20 15:18:57 +01:00
|
|
|
_supported_aio_modes()
|
|
|
|
{
|
|
|
|
for mode; do
|
|
|
|
if [ "$mode" = "$AIOMODE" ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
_notrun "not suitable for aio mode: $AIOMODE"
|
|
|
|
}
|
|
|
|
_default_aio_mode()
|
|
|
|
{
|
|
|
|
AIOMODE="$1"
|
|
|
|
QEMU_IO="$QEMU_IO --aio $1"
|
|
|
|
}
|
2012-08-09 14:05:57 +02:00
|
|
|
|
2013-11-26 07:40:32 +01: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
|
|
|
|
}
|
|
|
|
|
2020-06-25 14:55:32 +02:00
|
|
|
# Caution: Overwrites $TEST_DIR/t.luks
|
|
|
|
_require_working_luks()
|
|
|
|
{
|
|
|
|
file="$TEST_DIR/t.luks"
|
|
|
|
|
|
|
|
output=$(
|
|
|
|
$QEMU_IMG create -f luks \
|
|
|
|
--object secret,id=sec0,data=hunter0 \
|
|
|
|
-o key-secret=sec0 \
|
|
|
|
-o iter-time=10 \
|
|
|
|
"$file" \
|
|
|
|
1M \
|
|
|
|
2>&1
|
|
|
|
)
|
|
|
|
status=$?
|
|
|
|
|
|
|
|
IMGFMT='luks' _rm_test_img "$file"
|
|
|
|
|
|
|
|
if [ $status != 0 ]; then
|
|
|
|
reason=$(echo "$output" | grep "$file:" | $SED -e "s#.*$file: *##")
|
|
|
|
if [ -z "$reason" ]; then
|
|
|
|
reason="Failed to create a LUKS image"
|
|
|
|
fi
|
|
|
|
_notrun "$reason"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2009-06-22 18:29:05 +02:00
|
|
|
# this test requires that a specified command (executable) exists
|
|
|
|
#
|
|
|
|
_require_command()
|
|
|
|
{
|
2015-09-02 20:52:27 +02: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 10:10:56 +01:00
|
|
|
[ -x "$c" ] || _notrun "$1 utility required, skipped this test"
|
2009-06-22 18:29:05 +02:00
|
|
|
}
|
|
|
|
|
2019-08-23 15:35:52 +02:00
|
|
|
# Check that a set of drivers has been whitelisted in the QEMU binary
|
|
|
|
#
|
|
|
|
_require_drivers()
|
|
|
|
{
|
|
|
|
available=$($QEMU -drive format=help | \
|
|
|
|
sed -e '/Supported formats:/!d' -e 's/Supported formats://')
|
|
|
|
for driver
|
|
|
|
do
|
|
|
|
if ! echo "$available" | grep -q " $driver\( \|$\)"; then
|
|
|
|
_notrun "$driver not available"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2019-12-02 11:16:29 +01:00
|
|
|
# Check that we have a file system that allows huge (but very sparse) files
|
|
|
|
#
|
|
|
|
_require_large_file()
|
|
|
|
{
|
|
|
|
if ! truncate --size="$1" "$TEST_IMG"; then
|
|
|
|
_notrun "file system on $TEST_DIR does not support large enough files"
|
|
|
|
fi
|
|
|
|
rm "$TEST_IMG"
|
|
|
|
}
|
|
|
|
|
2020-01-21 10:52:03 +01:00
|
|
|
# Check that a set of devices is available in the QEMU binary
|
|
|
|
#
|
|
|
|
_require_devices()
|
|
|
|
{
|
|
|
|
available=$($QEMU -M none -device help | \
|
|
|
|
grep ^name | sed -e 's/^name "//' -e 's/".*$//')
|
|
|
|
for device
|
|
|
|
do
|
|
|
|
if ! echo "$available" | grep -q "$device" ; then
|
|
|
|
_notrun "$device not available"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2009-06-22 18:29:05 +02:00
|
|
|
# make sure this script returns success
|
2015-01-04 02:53:48 +01:00
|
|
|
true
|