aboutsummaryrefslogtreecommitdiff
path: root/tests/qemu-iotests/common.rc
diff options
context:
space:
mode:
Diffstat (limited to 'tests/qemu-iotests/common.rc')
-rw-r--r--tests/qemu-iotests/common.rc205
1 files changed, 92 insertions, 113 deletions
diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
index 8d486dbeb4..0e8a33c696 100644
--- a/tests/qemu-iotests/common.rc
+++ b/tests/qemu-iotests/common.rc
@@ -40,21 +40,84 @@ poke_file()
printf "$3" | dd "of=$1" bs=1 "seek=$2" conv=notrunc &>/dev/null
}
-# we need common.config
-if [ "$iam" != "check" ]
-then
- if ! . ./common.config
- then
- echo "$iam: failed to source common.config"
- exit 1
- fi
+
+if ! . ./common.config
+ then
+ echo "$0: failed to source common.config"
+ exit 1
fi
-# make sure we have a standard umask
-umask 022
+_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
if [ "$IMGOPTSSYNTAX" = "true" ]; then
DRIVER="driver=$IMGFMT"
+ 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
if [ "$IMGFMT" = "luks" ]; then
DRIVER="$DRIVER,key-secret=keysec0"
fi
@@ -74,6 +137,7 @@ if [ "$IMGOPTSSYNTAX" = "true" ]; then
TEST_IMG="$DRIVER,file.driver=$IMGPROTO,file.filename=$TEST_DIR/t.$IMGFMT"
fi
else
+ QEMU_IMG_EXTRA_ARGS=
if [ "$IMGPROTO" = "file" ]; then
TEST_IMG=$TEST_DIR/t.$IMGFMT
elif [ "$IMGPROTO" = "nbd" ]; then
@@ -94,24 +158,25 @@ else
fi
ORIG_TEST_IMG="$TEST_IMG"
-_optstr_add()
-{
- if [ -n "$1" ]; then
- echo "$1,$2"
- else
- echo "$2"
- fi
-}
+if [ -z "$TEST_DIR" ]; then
+ TEST_DIR=`pwd`/scratch
+fi
-_set_default_imgopts()
-{
- if [ "$IMGFMT" == "qcow2" ] && ! (echo "$IMGOPTS" | grep "compat=" > /dev/null); then
- IMGOPTS=$(_optstr_add "$IMGOPTS" "compat=1.1")
- fi
- if [ "$IMGFMT" == "luks" ] && ! (echo "$IMGOPTS" | grep "iter-time=" > /dev/null); then
- IMGOPTS=$(_optstr_add "$IMGOPTS" "iter-time=10")
- 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
+
+if [ ! -d "$SAMPLE_IMG_DIR" ]; then
+ echo "common.config: Error: \$SAMPLE_IMG_DIR ($SAMPLE_IMG_DIR) is not a directory"
+ exit 1
+fi
_use_sample_img()
{
@@ -293,51 +358,6 @@ _img_info()
done
}
-_get_pids_by_name()
-{
- if [ $# -ne 1 ]
- then
- echo "Usage: _get_pids_by_name process-name" 1>&2
- exit 1
- fi
-
- # Algorithm ... all ps(1) variants have a time of the form MM:SS or
- # HH:MM:SS before the psargs field, use this as the search anchor.
- #
- # Matches with $1 (process-name) occur if the first psarg is $1
- # or ends in /$1 ... the matching uses sed's regular expressions,
- # so passing a regex into $1 will work.
-
- ps $PS_ALL_FLAGS \
- | sed -n \
- -e 's/$/ /' \
- -e 's/[ ][ ]*/ /g' \
- -e 's/^ //' \
- -e 's/^[^ ]* //' \
- -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \
- -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p"
-}
-
-# fqdn for localhost
-#
-_get_fqdn()
-{
- host=`hostname`
- $NSLOOKUP_PROG $host | $AWK_PROG '{ if ($1 == "Name:") print $2 }'
-}
-
-# check if run as root
-#
-_need_to_be_root()
-{
- id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
- if [ "$id" -ne 0 ]
- then
- echo "Arrgh ... you need to be root (not uid=$id) to run this test"
- exit 1
- fi
-}
-
# bail out, setting up .notrun file
#
_notrun()
@@ -473,46 +493,5 @@ _require_command()
[ -x "$c" ] || _notrun "$1 utility required, skipped this test"
}
-_full_imgfmt_details()
-{
- if [ -n "$IMGOPTS" ]; then
- echo "$IMGFMT ($IMGOPTS)"
- else
- echo "$IMGFMT"
- fi
-}
-
-_full_platform_details()
-{
- os=`uname -s`
- host=`hostname -s`
- kernel=`uname -r`
- platform=`uname -m`
- echo "$os/$platform $host $kernel"
-}
-
-_link_out_file()
-{
- if [ -z "$1" ]; then
- echo Error must pass \$seq.
- exit
- fi
- rm -f $1
- if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then
- ln -s $1.irix $1
- elif [ "`uname`" == "Linux" ]; then
- ln -s $1.linux $1
- else
- echo Error test $seq does not run on the operating system: `uname`
- exit
- fi
-}
-
-_die()
-{
- echo $@
- exit 1
-}
-
# make sure this script returns success
true