2010-04-26 17:44:05 +08:00
|
|
|
#!/bin/bash
|
2009-06-23 00:29:05 +08:00
|
|
|
#
|
|
|
|
# Copyright (C) 2009 Red Hat, Inc.
|
|
|
|
# Copyright (c) 2000-2003,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.
|
|
|
|
#
|
|
|
|
# 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-17 01:26:54 +08:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-06-23 00:29:05 +08:00
|
|
|
#
|
|
|
|
# all tests should use a common language setting to prevent golden
|
|
|
|
# output mismatches.
|
|
|
|
export LANG=C
|
|
|
|
|
|
|
|
PATH=".:$PATH"
|
|
|
|
|
|
|
|
HOSTOS=`uname -s`
|
|
|
|
|
|
|
|
export PWD=`pwd`
|
|
|
|
|
2015-10-31 03:25:17 +08:00
|
|
|
export _QEMU_HANDLE=0
|
|
|
|
|
2009-06-23 00:29:05 +08:00
|
|
|
# $1 = prog to look for, $2* = default pathnames if not found in $PATH
|
|
|
|
set_prog_path()
|
|
|
|
{
|
2014-11-19 15:07:12 +08:00
|
|
|
p=`command -v $1 2> /dev/null`
|
2009-06-23 00:29:05 +08:00
|
|
|
if [ -n "$p" -a -x "$p" ]; then
|
|
|
|
echo $p
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
p=$1
|
|
|
|
|
|
|
|
shift
|
|
|
|
for f; do
|
|
|
|
if [ -x $f ]; then
|
|
|
|
echo $f
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
_fatal()
|
|
|
|
{
|
|
|
|
echo "$*"
|
|
|
|
status=1
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2011-12-01 21:41:24 +08:00
|
|
|
if [ -z "$QEMU_PROG" ]; then
|
|
|
|
export QEMU_PROG="`set_prog_path qemu`"
|
|
|
|
fi
|
2009-06-23 00:29:05 +08:00
|
|
|
|
2011-12-01 21:41:24 +08:00
|
|
|
if [ -z "$QEMU_IMG_PROG" ]; then
|
|
|
|
export QEMU_IMG_PROG="`set_prog_path qemu-img`"
|
|
|
|
fi
|
2009-06-23 00:29:05 +08:00
|
|
|
|
2011-12-01 21:41:24 +08:00
|
|
|
if [ -z "$QEMU_IO_PROG" ]; then
|
|
|
|
export QEMU_IO_PROG="`set_prog_path qemu-io`"
|
|
|
|
fi
|
2012-11-02 21:01:23 +08:00
|
|
|
|
|
|
|
if [ -z "$QEMU_NBD_PROG" ]; then
|
|
|
|
export QEMU_NBD_PROG="`set_prog_path qemu-nbd`"
|
|
|
|
fi
|
2009-06-23 00:29:05 +08:00
|
|
|
|
2017-04-04 11:48:09 +08:00
|
|
|
if [ -z "$QEMU_VXHS_PROG" ]; then
|
|
|
|
export QEMU_VXHS_PROG="`set_prog_path qnio_server`"
|
|
|
|
fi
|
|
|
|
|
2017-07-02 23:05:09 +08:00
|
|
|
export QEMU_PROG=$(realpath -- "$(type -p "$QEMU_PROG")")
|
|
|
|
export QEMU_IMG_PROG=$(realpath -- "$(type -p "$QEMU_IMG_PROG")")
|
|
|
|
export QEMU_IO_PROG=$(realpath -- "$(type -p "$QEMU_IO_PROG")")
|
|
|
|
export QEMU_NBD_PROG=$(realpath -- "$(type -p "$QEMU_NBD_PROG")")
|
|
|
|
|
|
|
|
# This program is not built as part of qemu but (possibly) provided by the
|
|
|
|
# system, so it may not be present at all
|
|
|
|
if [ -n "$QEMU_VXHS_PROG" ]; then
|
|
|
|
export QEMU_VXHS_PROG=$(realpath -- "$(type -p "$QEMU_VXHS_PROG")")
|
|
|
|
fi
|
|
|
|
|
2015-09-03 02:52:27 +08:00
|
|
|
_qemu_wrapper()
|
|
|
|
{
|
2015-10-31 03:25:17 +08:00
|
|
|
(
|
|
|
|
if [ -n "${QEMU_NEED_PID}" ]; then
|
2017-01-26 09:08:21 +08:00
|
|
|
echo $BASHPID > "${QEMU_TEST_DIR}/qemu-${_QEMU_HANDLE}.pid"
|
2015-10-31 03:25:17 +08:00
|
|
|
fi
|
|
|
|
exec "$QEMU_PROG" $QEMU_OPTIONS "$@"
|
|
|
|
)
|
2015-09-03 02:52:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_qemu_img_wrapper()
|
|
|
|
{
|
|
|
|
(exec "$QEMU_IMG_PROG" $QEMU_IMG_OPTIONS "$@")
|
|
|
|
}
|
|
|
|
|
|
|
|
_qemu_io_wrapper()
|
|
|
|
{
|
2016-04-12 22:56:20 +08:00
|
|
|
local VALGRIND_LOGFILE="${TEST_DIR}"/$$.valgrind
|
2016-05-11 00:11:27 +08:00
|
|
|
local QEMU_IO_ARGS="$QEMU_IO_OPTIONS"
|
|
|
|
if [ "$IMGOPTSSYNTAX" = "true" ]; then
|
|
|
|
QEMU_IO_ARGS="--image-opts $QEMU_IO_ARGS"
|
2016-05-11 00:11:28 +08:00
|
|
|
if [ -n "$IMGKEYSECRET" ]; then
|
|
|
|
QEMU_IO_ARGS="--object secret,id=keysec0,data=$IMGKEYSECRET $QEMU_IO_ARGS"
|
|
|
|
fi
|
2016-05-11 00:11:27 +08:00
|
|
|
fi
|
2015-10-31 03:25:18 +08:00
|
|
|
local RETVAL
|
|
|
|
(
|
|
|
|
if [ "${VALGRIND_QEMU}" == "y" ]; then
|
2016-05-11 00:11:27 +08:00
|
|
|
exec valgrind --log-file="${VALGRIND_LOGFILE}" --error-exitcode=99 "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@"
|
2015-10-31 03:25:18 +08:00
|
|
|
else
|
2016-05-11 00:11:27 +08:00
|
|
|
exec "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@"
|
2015-10-31 03:25:18 +08:00
|
|
|
fi
|
|
|
|
)
|
|
|
|
RETVAL=$?
|
|
|
|
if [ "${VALGRIND_QEMU}" == "y" ]; then
|
|
|
|
if [ $RETVAL == 99 ]; then
|
|
|
|
cat "${VALGRIND_LOGFILE}"
|
|
|
|
fi
|
|
|
|
rm -f "${VALGRIND_LOGFILE}"
|
|
|
|
fi
|
|
|
|
(exit $RETVAL)
|
2015-09-03 02:52:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_qemu_nbd_wrapper()
|
|
|
|
{
|
2015-10-31 03:25:17 +08:00
|
|
|
(
|
2017-01-26 09:08:21 +08:00
|
|
|
echo $BASHPID > "${QEMU_TEST_DIR}/qemu-nbd.pid"
|
2015-10-31 03:25:17 +08:00
|
|
|
exec "$QEMU_NBD_PROG" $QEMU_NBD_OPTIONS "$@"
|
|
|
|
)
|
2015-09-03 02:52:27 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 11:48:09 +08:00
|
|
|
_qemu_vxhs_wrapper()
|
|
|
|
{
|
|
|
|
(
|
|
|
|
echo $BASHPID > "${TEST_DIR}/qemu-vxhs.pid"
|
|
|
|
exec "$QEMU_VXHS_PROG" $QEMU_VXHS_OPTIONS "$@"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2015-09-03 02:52:27 +08:00
|
|
|
export QEMU=_qemu_wrapper
|
|
|
|
export QEMU_IMG=_qemu_img_wrapper
|
|
|
|
export QEMU_IO=_qemu_io_wrapper
|
|
|
|
export QEMU_NBD=_qemu_nbd_wrapper
|
2017-04-04 11:48:09 +08:00
|
|
|
export QEMU_VXHS=_qemu_vxhs_wrapper
|
2015-09-03 02:52:27 +08:00
|
|
|
|
2016-05-11 00:11:27 +08:00
|
|
|
QEMU_IMG_EXTRA_ARGS=
|
|
|
|
if [ "$IMGOPTSSYNTAX" = "true" ]; then
|
|
|
|
QEMU_IMG_EXTRA_ARGS="--image-opts $QEMU_IMG_EXTRA_ARGS"
|
2016-05-11 00:11:28 +08:00
|
|
|
if [ -n "$IMGKEYSECRET" ]; then
|
|
|
|
QEMU_IMG_EXTRA_ARGS="--object secret,id=keysec0,data=$IMGKEYSECRET $QEMU_IMG_EXTRA_ARGS"
|
|
|
|
fi
|
2016-05-11 00:11:27 +08:00
|
|
|
fi
|
|
|
|
export QEMU_IMG_EXTRA_ARGS
|
|
|
|
|
|
|
|
|
2015-12-03 18:01:29 +08:00
|
|
|
default_machine=$($QEMU -machine help | sed -n '/(default)/ s/ .*//p')
|
|
|
|
default_alias_machine=$($QEMU -machine help | \
|
|
|
|
sed -n "/(alias of $default_machine)/ { s/ .*//p; q; }")
|
|
|
|
if [[ "$default_alias_machine" ]]; then
|
2015-07-03 15:28:46 +08:00
|
|
|
default_machine="$default_alias_machine"
|
|
|
|
fi
|
|
|
|
|
|
|
|
export QEMU_DEFAULT_MACHINE="$default_machine"
|
2009-06-23 00:29:05 +08:00
|
|
|
|
2011-04-12 04:05:44 +08:00
|
|
|
if [ -z "$TEST_DIR" ]; then
|
2013-09-04 19:16:04 +08:00
|
|
|
TEST_DIR=`pwd`/scratch
|
2011-04-12 04:05:44 +08:00
|
|
|
fi
|
|
|
|
|
2017-01-26 09:08:21 +08:00
|
|
|
QEMU_TEST_DIR="${TEST_DIR}"
|
|
|
|
|
2009-06-23 00:29:05 +08:00
|
|
|
if [ ! -e "$TEST_DIR" ]; then
|
2013-09-04 19:16:04 +08:00
|
|
|
mkdir "$TEST_DIR"
|
2009-06-23 00:29:05 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d "$TEST_DIR" ]; then
|
|
|
|
echo "common.config: Error: \$TEST_DIR ($TEST_DIR) is not a directory"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2012-02-29 21:25:20 +08:00
|
|
|
export TEST_DIR
|
|
|
|
|
2013-09-25 20:12:20 +08:00
|
|
|
if [ -z "$SAMPLE_IMG_DIR" ]; then
|
2014-05-25 05:24:55 +08:00
|
|
|
SAMPLE_IMG_DIR="$source_iotests/sample_images"
|
2013-09-25 20:12:20 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d "$SAMPLE_IMG_DIR" ]; then
|
|
|
|
echo "common.config: Error: \$SAMPLE_IMG_DIR ($SAMPLE_IMG_DIR) is not a directory"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
export SAMPLE_IMG_DIR
|
|
|
|
|
2009-06-23 00:29:05 +08:00
|
|
|
# make sure this script returns success
|
2015-01-04 09:53:48 +08:00
|
|
|
true
|