|
|
1bdc94 |
From 2ffef795b5aed20b6fc2fba3951ff8f5c97cef5a Mon Sep 17 00:00:00 2001
|
|
|
1bdc94 |
From: Jeffrey Cody <jcody@redhat.com>
|
|
|
1bdc94 |
Date: Tue, 28 Aug 2018 21:08:17 +0200
|
|
|
1bdc94 |
Subject: [PATCH 04/29] iotests: Add failure matching to common.qemu
|
|
|
1bdc94 |
|
|
|
1bdc94 |
RH-Author: Jeffrey Cody <jcody@redhat.com>
|
|
|
1bdc94 |
Message-id: <7850ea2daac60087a2cd5e300f8b7042b167ef24.1535490170.git.jcody@redhat.com>
|
|
|
1bdc94 |
Patchwork-id: 81955
|
|
|
1bdc94 |
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 2/3] iotests: Add failure matching to common.qemu
|
|
|
1bdc94 |
Bugzilla: 1605026
|
|
|
1bdc94 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
1bdc94 |
RH-Acked-by: John Snow <jsnow@redhat.com>
|
|
|
1bdc94 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
1bdc94 |
|
|
|
1bdc94 |
From: Max Reitz <mreitz@redhat.com>
|
|
|
1bdc94 |
|
|
|
1bdc94 |
Currently, common.qemu only allows to match for results indicating
|
|
|
1bdc94 |
success. The only way to fail is by provoking a timeout. However,
|
|
|
1bdc94 |
sometimes we do have a defined failure output and can match for that,
|
|
|
1bdc94 |
which saves us from having to wait for the timeout in case of failure.
|
|
|
1bdc94 |
Because failure can sometimes just result in a _notrun in the test, it
|
|
|
1bdc94 |
is actually important to care about being able to fail quickly.
|
|
|
1bdc94 |
|
|
|
1bdc94 |
Also, sometimes we simply do not get any specific output in case of
|
|
|
1bdc94 |
success. The only way to handle this currently would be to define an
|
|
|
1bdc94 |
error message as the string to look for, which means that actual success
|
|
|
1bdc94 |
results in a timeout. This is really bad because it unnecessarily slows
|
|
|
1bdc94 |
down a succeeding test.
|
|
|
1bdc94 |
|
|
|
1bdc94 |
Therefore, this patch adds a new parameter $success_or_failure to
|
|
|
1bdc94 |
_timed_wait_for and _send_qemu_cmd. Setting this to a non-empty string
|
|
|
1bdc94 |
makes both commands expect two match parameters: If the first matches,
|
|
|
1bdc94 |
the function succeeds. If the second matches, the function fails.
|
|
|
1bdc94 |
|
|
|
1bdc94 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
1bdc94 |
Message-id: 20180406151731.4285-2-mreitz@redhat.com
|
|
|
1bdc94 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
1bdc94 |
(cherry picked from commit 81c6ddf49a76a663cea16c07a07d51b67c853209)
|
|
|
1bdc94 |
Signed-off-by: Jeff Cody <jcody@redhat.com>
|
|
|
1bdc94 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
1bdc94 |
---
|
|
|
1bdc94 |
tests/qemu-iotests/common.qemu | 58 +++++++++++++++++++++++++++++++++++++-----
|
|
|
1bdc94 |
1 file changed, 51 insertions(+), 7 deletions(-)
|
|
|
1bdc94 |
|
|
|
1bdc94 |
diff --git a/tests/qemu-iotests/common.qemu b/tests/qemu-iotests/common.qemu
|
|
|
1bdc94 |
index 85f66b8..f285484 100644
|
|
|
1bdc94 |
--- a/tests/qemu-iotests/common.qemu
|
|
|
1bdc94 |
+++ b/tests/qemu-iotests/common.qemu
|
|
|
1bdc94 |
@@ -52,11 +52,29 @@ _in_fd=4
|
|
|
1bdc94 |
# response is not echoed out.
|
|
|
1bdc94 |
# If $mismatch_only is set, only non-matching responses will
|
|
|
1bdc94 |
# be echoed.
|
|
|
1bdc94 |
+#
|
|
|
1bdc94 |
+# If $success_or_failure is set, the meaning of the arguments is
|
|
|
1bdc94 |
+# changed as follows:
|
|
|
1bdc94 |
+# $2: A string to search for in the response; if found, this indicates
|
|
|
1bdc94 |
+# success and ${QEMU_STATUS[$1]} is set to 0.
|
|
|
1bdc94 |
+# $3: A string to search for in the response; if found, this indicates
|
|
|
1bdc94 |
+# failure and the test is either aborted (if $qemu_error_no_exit
|
|
|
1bdc94 |
+# is not set) or ${QEMU_STATUS[$1]} is set to -1 (otherwise).
|
|
|
1bdc94 |
function _timed_wait_for()
|
|
|
1bdc94 |
{
|
|
|
1bdc94 |
local h=${1}
|
|
|
1bdc94 |
shift
|
|
|
1bdc94 |
|
|
|
1bdc94 |
+ if [ -z "${success_or_failure}" ]; then
|
|
|
1bdc94 |
+ success_match=${*}
|
|
|
1bdc94 |
+ failure_match=
|
|
|
1bdc94 |
+ else
|
|
|
1bdc94 |
+ success_match=${1}
|
|
|
1bdc94 |
+ failure_match=${2}
|
|
|
1bdc94 |
+ fi
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+ timeout=yes
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
QEMU_STATUS[$h]=0
|
|
|
1bdc94 |
while IFS= read -t ${QEMU_COMM_TIMEOUT} resp <&${QEMU_OUT[$h]}
|
|
|
1bdc94 |
do
|
|
|
1bdc94 |
@@ -64,10 +82,18 @@ function _timed_wait_for()
|
|
|
1bdc94 |
echo "${resp}" | _filter_testdir | _filter_qemu \
|
|
|
1bdc94 |
| _filter_qemu_io | _filter_qmp | _filter_hmp
|
|
|
1bdc94 |
fi
|
|
|
1bdc94 |
- grep -q "${*}" < <(echo "${resp}")
|
|
|
1bdc94 |
+ if [ -n "${failure_match}" ]; then
|
|
|
1bdc94 |
+ grep -q "${failure_match}" < <(echo "${resp}")
|
|
|
1bdc94 |
+ if [ $? -eq 0 ]; then
|
|
|
1bdc94 |
+ timeout=
|
|
|
1bdc94 |
+ break
|
|
|
1bdc94 |
+ fi
|
|
|
1bdc94 |
+ fi
|
|
|
1bdc94 |
+ grep -q "${success_match}" < <(echo "${resp}")
|
|
|
1bdc94 |
if [ $? -eq 0 ]; then
|
|
|
1bdc94 |
return
|
|
|
1bdc94 |
- elif [ -z "${silent}" ] && [ -n "${mismatch_only}" ]; then
|
|
|
1bdc94 |
+ fi
|
|
|
1bdc94 |
+ if [ -z "${silent}" ] && [ -n "${mismatch_only}" ]; then
|
|
|
1bdc94 |
echo "${resp}" | _filter_testdir | _filter_qemu \
|
|
|
1bdc94 |
| _filter_qemu_io | _filter_qmp | _filter_hmp
|
|
|
1bdc94 |
fi
|
|
|
1bdc94 |
@@ -75,8 +101,12 @@ function _timed_wait_for()
|
|
|
1bdc94 |
done
|
|
|
1bdc94 |
QEMU_STATUS[$h]=-1
|
|
|
1bdc94 |
if [ -z "${qemu_error_no_exit}" ]; then
|
|
|
1bdc94 |
- echo "Timeout waiting for ${*} on handle ${h}"
|
|
|
1bdc94 |
- exit 1 # Timeout means the test failed
|
|
|
1bdc94 |
+ if [ -n "${timeout}" ]; then
|
|
|
1bdc94 |
+ echo "Timeout waiting for ${success_match} on handle ${h}"
|
|
|
1bdc94 |
+ else
|
|
|
1bdc94 |
+ echo "Wrong response matching ${failure_match} on handle ${h}"
|
|
|
1bdc94 |
+ fi
|
|
|
1bdc94 |
+ exit 1 # Timeout or wrong match mean the test failed
|
|
|
1bdc94 |
fi
|
|
|
1bdc94 |
}
|
|
|
1bdc94 |
|
|
|
1bdc94 |
@@ -96,6 +126,11 @@ function _timed_wait_for()
|
|
|
1bdc94 |
# If $qemu_error_no_exit is set, then even if the expected response
|
|
|
1bdc94 |
# is not seen, we will not exit. $QEMU_STATUS[$1] will be set it -1 in
|
|
|
1bdc94 |
# that case.
|
|
|
1bdc94 |
+#
|
|
|
1bdc94 |
+# If $success_or_failure is set, then the last two strings are the
|
|
|
1bdc94 |
+# strings the response will be scanned for. The first of the two
|
|
|
1bdc94 |
+# indicates success, the latter indicates failure. Failure is handled
|
|
|
1bdc94 |
+# like a timeout.
|
|
|
1bdc94 |
function _send_qemu_cmd()
|
|
|
1bdc94 |
{
|
|
|
1bdc94 |
local h=${1}
|
|
|
1bdc94 |
@@ -109,14 +144,23 @@ function _send_qemu_cmd()
|
|
|
1bdc94 |
use_error="no"
|
|
|
1bdc94 |
fi
|
|
|
1bdc94 |
# This array element extraction is done to accommodate pathnames with spaces
|
|
|
1bdc94 |
- cmd=${@: 1:${#@}-1}
|
|
|
1bdc94 |
- shift $(($# - 1))
|
|
|
1bdc94 |
+ if [ -z "${success_or_failure}" ]; then
|
|
|
1bdc94 |
+ cmd=${@: 1:${#@}-1}
|
|
|
1bdc94 |
+ shift $(($# - 1))
|
|
|
1bdc94 |
+ else
|
|
|
1bdc94 |
+ cmd=${@: 1:${#@}-2}
|
|
|
1bdc94 |
+ shift $(($# - 2))
|
|
|
1bdc94 |
+ fi
|
|
|
1bdc94 |
|
|
|
1bdc94 |
while [ ${count} -gt 0 ]
|
|
|
1bdc94 |
do
|
|
|
1bdc94 |
echo "${cmd}" >&${QEMU_IN[${h}]}
|
|
|
1bdc94 |
if [ -n "${1}" ]; then
|
|
|
1bdc94 |
- qemu_error_no_exit=${use_error} _timed_wait_for ${h} "${1}"
|
|
|
1bdc94 |
+ if [ -z "${success_or_failure}" ]; then
|
|
|
1bdc94 |
+ qemu_error_no_exit=${use_error} _timed_wait_for ${h} "${1}"
|
|
|
1bdc94 |
+ else
|
|
|
1bdc94 |
+ qemu_error_no_exit=${use_error} _timed_wait_for ${h} "${1}" "${2}"
|
|
|
1bdc94 |
+ fi
|
|
|
1bdc94 |
if [ ${QEMU_STATUS[$h]} -eq 0 ]; then
|
|
|
1bdc94 |
return
|
|
|
1bdc94 |
fi
|
|
|
1bdc94 |
--
|
|
|
1bdc94 |
1.8.3.1
|
|
|
1bdc94 |
|