thebeanogamer / rpms / qemu-kvm

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