[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 22/37] iotests: Add failure matching to common.qemu
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 22/37] iotests: Add failure matching to common.qemu |
Date: |
Tue, 15 May 2018 17:40:18 +0200 |
From: Max Reitz <address@hidden>
Currently, common.qemu only allows to match for results indicating
success. The only way to fail is by provoking a timeout. However,
sometimes we do have a defined failure output and can match for that,
which saves us from having to wait for the timeout in case of failure.
Because failure can sometimes just result in a _notrun in the test, it
is actually important to care about being able to fail quickly.
Also, sometimes we simply do not get any specific output in case of
success. The only way to handle this currently would be to define an
error message as the string to look for, which means that actual success
results in a timeout. This is really bad because it unnecessarily slows
down a succeeding test.
Therefore, this patch adds a new parameter $success_or_failure to
_timed_wait_for and _send_qemu_cmd. Setting this to a non-empty string
makes both commands expect two match parameters: If the first matches,
the function succeeds. If the second matches, the function fails.
Signed-off-by: Max Reitz <address@hidden>
Message-id: address@hidden
Signed-off-by: Max Reitz <address@hidden>
---
tests/qemu-iotests/common.qemu | 58 +++++++++++++++++++++++++++++++++++++-----
1 file changed, 51 insertions(+), 7 deletions(-)
diff --git a/tests/qemu-iotests/common.qemu b/tests/qemu-iotests/common.qemu
index 85f66b852c..f285484951 100644
--- a/tests/qemu-iotests/common.qemu
+++ b/tests/qemu-iotests/common.qemu
@@ -52,11 +52,29 @@ _in_fd=4
# response is not echoed out.
# If $mismatch_only is set, only non-matching responses will
# be echoed.
+#
+# If $success_or_failure is set, the meaning of the arguments is
+# changed as follows:
+# $2: A string to search for in the response; if found, this indicates
+# success and ${QEMU_STATUS[$1]} is set to 0.
+# $3: A string to search for in the response; if found, this indicates
+# failure and the test is either aborted (if $qemu_error_no_exit
+# is not set) or ${QEMU_STATUS[$1]} is set to -1 (otherwise).
function _timed_wait_for()
{
local h=${1}
shift
+ if [ -z "${success_or_failure}" ]; then
+ success_match=${*}
+ failure_match=
+ else
+ success_match=${1}
+ failure_match=${2}
+ fi
+
+ timeout=yes
+
QEMU_STATUS[$h]=0
while IFS= read -t ${QEMU_COMM_TIMEOUT} resp <&${QEMU_OUT[$h]}
do
@@ -64,10 +82,18 @@ function _timed_wait_for()
echo "${resp}" | _filter_testdir | _filter_qemu \
| _filter_qemu_io | _filter_qmp | _filter_hmp
fi
- grep -q "${*}" < <(echo "${resp}")
+ if [ -n "${failure_match}" ]; then
+ grep -q "${failure_match}" < <(echo "${resp}")
+ if [ $? -eq 0 ]; then
+ timeout=
+ break
+ fi
+ fi
+ grep -q "${success_match}" < <(echo "${resp}")
if [ $? -eq 0 ]; then
return
- elif [ -z "${silent}" ] && [ -n "${mismatch_only}" ]; then
+ fi
+ if [ -z "${silent}" ] && [ -n "${mismatch_only}" ]; then
echo "${resp}" | _filter_testdir | _filter_qemu \
| _filter_qemu_io | _filter_qmp | _filter_hmp
fi
@@ -75,8 +101,12 @@ function _timed_wait_for()
done
QEMU_STATUS[$h]=-1
if [ -z "${qemu_error_no_exit}" ]; then
- echo "Timeout waiting for ${*} on handle ${h}"
- exit 1 # Timeout means the test failed
+ if [ -n "${timeout}" ]; then
+ echo "Timeout waiting for ${success_match} on handle ${h}"
+ else
+ echo "Wrong response matching ${failure_match} on handle ${h}"
+ fi
+ exit 1 # Timeout or wrong match mean the test failed
fi
}
@@ -96,6 +126,11 @@ function _timed_wait_for()
# If $qemu_error_no_exit is set, then even if the expected response
# is not seen, we will not exit. $QEMU_STATUS[$1] will be set it -1 in
# that case.
+#
+# If $success_or_failure is set, then the last two strings are the
+# strings the response will be scanned for. The first of the two
+# indicates success, the latter indicates failure. Failure is handled
+# like a timeout.
function _send_qemu_cmd()
{
local h=${1}
@@ -109,14 +144,23 @@ function _send_qemu_cmd()
use_error="no"
fi
# This array element extraction is done to accommodate pathnames with
spaces
- cmd=${@: 1:address@hidden
- shift $(($# - 1))
+ if [ -z "${success_or_failure}" ]; then
+ cmd=${@: 1:address@hidden
+ shift $(($# - 1))
+ else
+ cmd=${@: 1:address@hidden
+ shift $(($# - 2))
+ fi
while [ ${count} -gt 0 ]
do
echo "${cmd}" >&${QEMU_IN[${h}]}
if [ -n "${1}" ]; then
- qemu_error_no_exit=${use_error} _timed_wait_for ${h} "${1}"
+ if [ -z "${success_or_failure}" ]; then
+ qemu_error_no_exit=${use_error} _timed_wait_for ${h} "${1}"
+ else
+ qemu_error_no_exit=${use_error} _timed_wait_for ${h} "${1}"
"${2}"
+ fi
if [ ${QEMU_STATUS[$h]} -eq 0 ]; then
return
fi
--
2.13.6
- [Qemu-block] [PULL 01/37] block-backend: simplify blk_get_aio_context, (continued)
- [Qemu-block] [PULL 01/37] block-backend: simplify blk_get_aio_context, Kevin Wolf, 2018/05/15
- [Qemu-block] [PULL 10/37] blockjob: expose error string via query, Kevin Wolf, 2018/05/15
- [Qemu-block] [PULL 15/37] blockjob: Introduce block_job_ratelimit_get_delay(), Kevin Wolf, 2018/05/15
- [Qemu-block] [PULL 11/37] blockjob: Fix assertion in block_job_finalize(), Kevin Wolf, 2018/05/15
- [Qemu-block] [PULL 16/37] blockjob: Add block_job_driver(), Kevin Wolf, 2018/05/15
- [Qemu-block] [PULL 14/37] blockjob: Implement block_job_set_speed() centrally, Kevin Wolf, 2018/05/15
- [Qemu-block] [PULL 19/37] specs/qcow2: Clarify that compressed clusters have the COPIED bit reset, Kevin Wolf, 2018/05/15
- [Qemu-block] [PULL 13/37] blockjob: Move RateLimit to BlockJob, Kevin Wolf, 2018/05/15
- [Qemu-block] [PULL 12/37] blockjob: Wrappers for progress counter access, Kevin Wolf, 2018/05/15
- [Qemu-block] [PULL 17/37] iotests: Split 214 off of 122, Kevin Wolf, 2018/05/15
- [Qemu-block] [PULL 22/37] iotests: Add failure matching to common.qemu,
Kevin Wolf <=
- [Qemu-block] [PULL 20/37] qcow2: Give the refcount cache the minimum possible size by default, Kevin Wolf, 2018/05/15
[Qemu-block] [PULL 21/37] docs: Document the new default sizes of the qcow2 caches, Kevin Wolf, 2018/05/15
[Qemu-block] [PULL 26/37] block: Add BDRV_REQ_WRITE_UNCHANGED flag, Kevin Wolf, 2018/05/15
[Qemu-block] [PULL 28/37] block/quorum: Support BDRV_REQ_WRITE_UNCHANGED, Kevin Wolf, 2018/05/15
[Qemu-block] [PULL 18/37] Fix error message about compressed clusters with OFLAG_COPIED, Kevin Wolf, 2018/05/15