2019-03-07 17:58:38 +03:00
|
|
|
#!/usr/bin/env bash
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
#
|
|
|
|
# This allows for launching of multiple QEMU instances, with independent
|
|
|
|
# communication possible to each instance.
|
|
|
|
#
|
|
|
|
# Each instance can choose, at launch, to use either the QMP or the
|
|
|
|
# HMP (monitor) interface.
|
|
|
|
#
|
|
|
|
# All instances are cleaned up via _cleanup_qemu, including killing the
|
|
|
|
# running qemu instance.
|
|
|
|
#
|
|
|
|
# Copyright (C) 2014 Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# 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; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will 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
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
QEMU_COMM_TIMEOUT=10
|
|
|
|
|
2017-01-26 04:08:21 +03:00
|
|
|
QEMU_FIFO_IN="${QEMU_TEST_DIR}/qmp-in-$$"
|
|
|
|
QEMU_FIFO_OUT="${QEMU_TEST_DIR}/qmp-out-$$"
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
|
|
|
|
QEMU_HANDLE=0
|
2017-09-12 17:44:56 +03:00
|
|
|
export _QEMU_HANDLE=0
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
|
|
|
|
# If bash version is >= 4.1, these will be overwritten and dynamic
|
|
|
|
# file descriptor values assigned.
|
|
|
|
_out_fd=3
|
|
|
|
_in_fd=4
|
|
|
|
|
|
|
|
# Wait for expected QMP response from QEMU. Will time out
|
|
|
|
# after 10 seconds, which counts as failure.
|
|
|
|
#
|
|
|
|
# Override QEMU_COMM_TIMEOUT for a timeout different than the
|
|
|
|
# default 10 seconds
|
|
|
|
#
|
|
|
|
# $1: The handle to use
|
|
|
|
# $2+ All remaining arguments comprise the string to search for
|
|
|
|
# in the response.
|
|
|
|
#
|
|
|
|
# If $silent is set to anything but an empty string, then
|
|
|
|
# response is not echoed out.
|
2017-11-20 02:25:50 +03:00
|
|
|
# If $mismatch_only is set, only non-matching responses will
|
|
|
|
# be echoed.
|
2018-04-06 18:17:30 +03:00
|
|
|
#
|
2021-02-04 15:48:32 +03:00
|
|
|
# If $capture_events is non-empty, then any QMP event names it lists
|
|
|
|
# will not be echoed out, but instead collected in the $QEMU_EVENTS
|
|
|
|
# variable. The _wait_event function can later be used to receive
|
|
|
|
# the cached events.
|
|
|
|
#
|
|
|
|
# If $only_capture_events is set to anything but an empty string,
|
|
|
|
# then an error will be raised if a QMP message is seen which is
|
|
|
|
# not an event listed in $capture_events.
|
|
|
|
#
|
2018-04-06 18:17:30 +03:00
|
|
|
# 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).
|
2018-11-17 00:50:02 +03:00
|
|
|
_timed_wait_for()
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
{
|
|
|
|
local h=${1}
|
|
|
|
shift
|
|
|
|
|
2018-04-06 18:17:30 +03:00
|
|
|
if [ -z "${success_or_failure}" ]; then
|
|
|
|
success_match=${*}
|
|
|
|
failure_match=
|
|
|
|
else
|
|
|
|
success_match=${1}
|
|
|
|
failure_match=${2}
|
|
|
|
fi
|
|
|
|
|
|
|
|
timeout=yes
|
|
|
|
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
QEMU_STATUS[$h]=0
|
2017-06-29 19:54:24 +03:00
|
|
|
while IFS= read -t ${QEMU_COMM_TIMEOUT} resp <&${QEMU_OUT[$h]}
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
do
|
2021-02-04 15:48:32 +03:00
|
|
|
if [ -n "$capture_events" ]; then
|
|
|
|
capture=0
|
|
|
|
local evname
|
|
|
|
for evname in $capture_events
|
|
|
|
do
|
|
|
|
case ${resp} in
|
|
|
|
*\"event\":\ \"${evname}\"* ) capture=1 ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
if [ $capture = 1 ];
|
|
|
|
then
|
|
|
|
ev=$(echo "${resp}" | tr -d '\r' | tr % .)
|
|
|
|
QEMU_EVENTS="${QEMU_EVENTS:+${QEMU_EVENTS}%}${ev}"
|
|
|
|
if [ -n "$only_capture_events" ]; then
|
|
|
|
return
|
|
|
|
else
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ -n "$only_capture_events" ]; then
|
|
|
|
echo "Only expected $capture_events but got ${resp}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-11-20 02:25:50 +03:00
|
|
|
if [ -z "${silent}" ] && [ -z "${mismatch_only}" ]; then
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
echo "${resp}" | _filter_testdir | _filter_qemu \
|
2017-04-13 20:19:51 +03:00
|
|
|
| _filter_qemu_io | _filter_qmp | _filter_hmp
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
fi
|
2018-04-06 18:17:30 +03:00
|
|
|
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}")
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
return
|
2018-04-06 18:17:30 +03:00
|
|
|
fi
|
|
|
|
if [ -z "${silent}" ] && [ -n "${mismatch_only}" ]; then
|
2017-11-20 02:25:50 +03:00
|
|
|
echo "${resp}" | _filter_testdir | _filter_qemu \
|
|
|
|
| _filter_qemu_io | _filter_qmp | _filter_hmp
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
fi
|
2017-11-20 02:25:50 +03:00
|
|
|
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
done
|
|
|
|
QEMU_STATUS[$h]=-1
|
|
|
|
if [ -z "${qemu_error_no_exit}" ]; then
|
2018-04-06 18:17:30 +03:00
|
|
|
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
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Sends QMP or HMP command to QEMU, and waits for the expected response
|
|
|
|
#
|
|
|
|
# $1: QEMU handle to use
|
|
|
|
# $2: String of the QMP command to send
|
|
|
|
# ${@: -1} (Last string passed)
|
|
|
|
# String that the QEMU response should contain. If it is a null
|
|
|
|
# string, do not wait for a response
|
|
|
|
#
|
|
|
|
# Set qemu_cmd_repeat to the number of times to repeat the cmd
|
|
|
|
# until either timeout, or a response. If it is not set, or <=0,
|
|
|
|
# then the command is only sent once.
|
|
|
|
#
|
2019-11-15 00:34:14 +03:00
|
|
|
# If neither $silent nor $mismatch_only is set, and $cmd begins with '{',
|
|
|
|
# echo the command before sending it the first time.
|
|
|
|
#
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
# 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.
|
2018-04-06 18:17:30 +03:00
|
|
|
#
|
|
|
|
# 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.
|
2018-11-17 00:50:02 +03:00
|
|
|
_send_qemu_cmd()
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
{
|
|
|
|
local h=${1}
|
|
|
|
local count=1
|
|
|
|
local cmd=
|
|
|
|
local use_error=${qemu_error_no_exit}
|
|
|
|
shift
|
|
|
|
|
|
|
|
if [ ${qemu_cmd_repeat} -gt 0 ] 2>/dev/null; then
|
|
|
|
count=${qemu_cmd_repeat}
|
|
|
|
use_error="no"
|
|
|
|
fi
|
iotests: Fix _send_qemu_cmd with bash 5.1
With bash 5.1, the output of the following script changes:
a=("double space")
a=${a[@]:0:1}
echo "$a"
from "double space" to "double space", i.e. all white space is
preserved as-is. This is probably what we actually want here (judging
from the "...to accommodate pathnames with spaces" comment), but before
5.1, we would have to quote the ${} slice to get the same behavior.
In any case, without quoting, the reference output of many iotests is
different between bash 5.1 and pre-5.1, which is not very good. The
output of 5.1 is what we want, so whatever we do to get pre-5.1 to the
same result, it means we have to fix the reference output of basically
all tests that invoke _send_qemu_cmd (except the ones that only use
single spaces in the commands they invoke).
Instead of quoting the ${} slice (cmd="${$@: 1:...}"), we can also just
not use array slicing and replace the whole thing with a simple "cmd=$1;
shift", which works because all callers quote the whole $cmd argument
anyway.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20201217153803.101231-3-mreitz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
2020-12-17 18:38:03 +03:00
|
|
|
|
|
|
|
cmd=$1
|
|
|
|
shift
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
|
2019-11-15 00:34:14 +03:00
|
|
|
# Display QMP being sent, but not HMP (since HMP already echoes its
|
|
|
|
# input back to output); decide based on leading '{'
|
|
|
|
if [ -z "$silent" ] && [ -z "$mismatch_only" ] &&
|
|
|
|
[ "$cmd" != "${cmd#\{}" ]; then
|
|
|
|
echo "${cmd}" | _filter_testdir | _filter_imgfmt
|
|
|
|
fi
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
while [ ${count} -gt 0 ]
|
|
|
|
do
|
|
|
|
echo "${cmd}" >&${QEMU_IN[${h}]}
|
|
|
|
if [ -n "${1}" ]; then
|
2018-04-06 18:17:30 +03:00
|
|
|
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
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
if [ ${QEMU_STATUS[$h]} -eq 0 ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
let count--;
|
|
|
|
done
|
|
|
|
if [ ${QEMU_STATUS[$h]} -ne 0 ] && [ -z "${qemu_error_no_exit}" ]; then
|
2021-02-04 15:48:32 +03:00
|
|
|
echo "Timeout waiting for command ${1} response on handle ${h}"
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
exit 1 #Timeout means the test failed
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-04 15:48:32 +03:00
|
|
|
# Check event cache for a named QMP event
|
|
|
|
#
|
|
|
|
# Input parameters:
|
|
|
|
# $1: Name of the QMP event to check for
|
|
|
|
#
|
|
|
|
# Checks if the named QMP event that was previously captured
|
|
|
|
# into $QEMU_EVENTS. When matched, the QMP event will be echoed
|
|
|
|
# and the $matched variable set to 1.
|
|
|
|
#
|
|
|
|
# _wait_event is more suitable for test usage in most cases
|
|
|
|
_check_cached_events()
|
|
|
|
{
|
|
|
|
local evname=${1}
|
|
|
|
|
|
|
|
local match="\"event\": \"$evname\""
|
|
|
|
|
|
|
|
matched=0
|
|
|
|
if [ -n "$QEMU_EVENTS" ]; then
|
|
|
|
CURRENT_QEMU_EVENTS=$QEMU_EVENTS
|
|
|
|
QEMU_EVENTS=
|
|
|
|
old_IFS=$IFS
|
|
|
|
IFS="%"
|
|
|
|
for ev in $CURRENT_QEMU_EVENTS
|
|
|
|
do
|
|
|
|
grep -q "$match" < <(echo "${ev}")
|
|
|
|
if [ $? -eq 0 ] && [ $matched = 0 ]; then
|
|
|
|
echo "${ev}" | _filter_testdir | _filter_qemu \
|
|
|
|
| _filter_qemu_io | _filter_qmp | _filter_hmp
|
|
|
|
matched=1
|
|
|
|
else
|
|
|
|
QEMU_EVENTS="${QEMU_EVENTS:+${QEMU_EVENTS}%}${ev}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
IFS=$old_IFS
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Wait for a named QMP event
|
|
|
|
#
|
|
|
|
# Input parameters:
|
|
|
|
# $1: QEMU handle to use
|
|
|
|
# $2: Name of the QMP event to wait for
|
|
|
|
#
|
|
|
|
# Checks if the named QMP even was previously captured
|
|
|
|
# into $QEMU_EVENTS. If none are present, then waits for the
|
|
|
|
# event to arrive on the QMP channel. When matched, the QMP
|
|
|
|
# event will be echoed
|
|
|
|
_wait_event()
|
|
|
|
{
|
|
|
|
local h=${1}
|
|
|
|
local evname=${2}
|
|
|
|
|
|
|
|
while true
|
|
|
|
do
|
|
|
|
_check_cached_events $evname
|
|
|
|
|
|
|
|
if [ $matched = 1 ];
|
|
|
|
then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
only_capture_events=1 qemu_error_no_exit=1 _timed_wait_for ${h}
|
|
|
|
|
|
|
|
if [ ${QEMU_STATUS[$h]} -ne 0 ] ; then
|
|
|
|
echo "Timeout waiting for event ${evname} on handle ${h}"
|
|
|
|
exit 1 #Timeout means the test failed
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
# Launch a QEMU process.
|
|
|
|
#
|
|
|
|
# Input parameters:
|
|
|
|
# $qemu_comm_method: set this variable to 'monitor' (case insensitive)
|
|
|
|
# to use the QEMU HMP monitor for communication.
|
|
|
|
# Otherwise, the default of QMP is used.
|
2017-06-29 19:54:24 +03:00
|
|
|
# $qmp_pretty: Set this variable to 'y' to enable QMP pretty printing.
|
2016-01-25 21:41:14 +03:00
|
|
|
# $keep_stderr: Set this variable to 'y' to keep QEMU's stderr output on stderr.
|
|
|
|
# If this variable is empty, stderr will be redirected to stdout.
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
# Returns:
|
|
|
|
# $QEMU_HANDLE: set to a handle value to communicate with this QEMU instance.
|
|
|
|
#
|
2018-11-17 00:50:02 +03:00
|
|
|
_launch_qemu()
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
{
|
|
|
|
local comm=
|
|
|
|
local fifo_out=
|
|
|
|
local fifo_in=
|
|
|
|
|
|
|
|
if (shopt -s nocasematch; [[ "${qemu_comm_method}" == "monitor" ]])
|
|
|
|
then
|
|
|
|
comm="-monitor stdio"
|
|
|
|
else
|
|
|
|
local qemu_comm_method="qmp"
|
2017-06-29 19:54:24 +03:00
|
|
|
if [ "$qmp_pretty" = "y" ]; then
|
|
|
|
comm="-monitor none -qmp-pretty stdio"
|
|
|
|
else
|
|
|
|
comm="-monitor none -qmp stdio"
|
|
|
|
fi
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
fi
|
|
|
|
|
|
|
|
fifo_out=${QEMU_FIFO_OUT}_${_QEMU_HANDLE}
|
|
|
|
fifo_in=${QEMU_FIFO_IN}_${_QEMU_HANDLE}
|
|
|
|
mkfifo "${fifo_out}"
|
|
|
|
mkfifo "${fifo_in}"
|
|
|
|
|
2017-06-26 15:35:07 +03:00
|
|
|
object_options=
|
|
|
|
if [ -n "$IMGKEYSECRET" ]; then
|
|
|
|
object_options="--object secret,id=keysec0,data=$IMGKEYSECRET"
|
|
|
|
fi
|
|
|
|
|
2016-01-25 21:41:14 +03:00
|
|
|
if [ -z "$keep_stderr" ]; then
|
|
|
|
QEMU_NEED_PID='y'\
|
2017-06-26 15:35:07 +03:00
|
|
|
${QEMU} ${object_options} -nographic -serial none ${comm} "${@}" >"${fifo_out}" \
|
2016-10-17 21:39:17 +03:00
|
|
|
2>&1 \
|
|
|
|
<"${fifo_in}" &
|
2016-01-25 21:41:14 +03:00
|
|
|
elif [ "$keep_stderr" = "y" ]; then
|
|
|
|
QEMU_NEED_PID='y'\
|
2017-06-26 15:35:07 +03:00
|
|
|
${QEMU} ${object_options} -nographic -serial none ${comm} "${@}" >"${fifo_out}" \
|
2016-10-17 21:39:17 +03:00
|
|
|
<"${fifo_in}" &
|
2016-01-25 21:41:14 +03:00
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
|
|
|
|
if [[ "${BASH_VERSINFO[0]}" -ge "5" ||
|
|
|
|
("${BASH_VERSINFO[0]}" -ge "4" && "${BASH_VERSINFO[1]}" -ge "1") ]]
|
|
|
|
then
|
|
|
|
# bash >= 4.1 required for automatic fd
|
|
|
|
exec {_out_fd}<"${fifo_out}"
|
|
|
|
exec {_in_fd}>"${fifo_in}"
|
|
|
|
else
|
|
|
|
let _out_fd++
|
|
|
|
let _in_fd++
|
|
|
|
eval "exec ${_out_fd}<'${fifo_out}'"
|
|
|
|
eval "exec ${_in_fd}>'${fifo_in}'"
|
|
|
|
fi
|
|
|
|
|
|
|
|
QEMU_OUT[${_QEMU_HANDLE}]=${_out_fd}
|
|
|
|
QEMU_IN[${_QEMU_HANDLE}]=${_in_fd}
|
|
|
|
QEMU_STATUS[${_QEMU_HANDLE}]=0
|
|
|
|
|
|
|
|
if [ "${qemu_comm_method}" == "qmp" ]
|
|
|
|
then
|
|
|
|
# Don't print response, since it has version information in it
|
|
|
|
silent=yes _timed_wait_for ${_QEMU_HANDLE} "capabilities"
|
2017-06-29 19:54:24 +03:00
|
|
|
if [ "$qmp_pretty" = "y" ]; then
|
|
|
|
silent=yes _timed_wait_for ${_QEMU_HANDLE} "^}"
|
|
|
|
fi
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
fi
|
|
|
|
QEMU_HANDLE=${_QEMU_HANDLE}
|
|
|
|
let _QEMU_HANDLE++
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-13 08:47:55 +03:00
|
|
|
# Silently kills the QEMU process
|
2015-02-07 00:06:17 +03:00
|
|
|
#
|
|
|
|
# If $wait is set to anything other than the empty string, the process will not
|
|
|
|
# be killed but only waited for, and any output will be forwarded to stdout. If
|
|
|
|
# $wait is empty, the process will be killed and all output will be suppressed.
|
2018-11-17 00:50:02 +03:00
|
|
|
_cleanup_qemu()
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
{
|
|
|
|
# QEMU_PID[], QEMU_IN[], QEMU_OUT[] all use same indices
|
|
|
|
for i in "${!QEMU_OUT[@]}"
|
|
|
|
do
|
2015-10-30 22:25:17 +03:00
|
|
|
local QEMU_PID
|
2017-01-26 04:08:21 +03:00
|
|
|
if [ -f "${QEMU_TEST_DIR}/qemu-${i}.pid" ]; then
|
|
|
|
read QEMU_PID < "${QEMU_TEST_DIR}/qemu-${i}.pid"
|
|
|
|
rm -f "${QEMU_TEST_DIR}/qemu-${i}.pid"
|
2015-10-30 22:25:17 +03:00
|
|
|
if [ -z "${wait}" ] && [ -n "${QEMU_PID}" ]; then
|
|
|
|
kill -KILL ${QEMU_PID} 2>/dev/null
|
|
|
|
fi
|
|
|
|
if [ -n "${QEMU_PID}" ]; then
|
|
|
|
wait ${QEMU_PID} 2>/dev/null # silent kill
|
|
|
|
fi
|
2015-02-07 00:06:17 +03:00
|
|
|
fi
|
2015-10-30 22:25:17 +03:00
|
|
|
|
2015-02-07 00:06:17 +03:00
|
|
|
if [ -n "${wait}" ]; then
|
|
|
|
cat <&${QEMU_OUT[$i]} | _filter_testdir | _filter_qemu \
|
2017-04-13 20:19:51 +03:00
|
|
|
| _filter_qemu_io | _filter_qmp | _filter_hmp
|
2015-02-07 00:06:17 +03:00
|
|
|
fi
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
rm -f "${QEMU_FIFO_IN}_${i}" "${QEMU_FIFO_OUT}_${i}"
|
|
|
|
eval "exec ${QEMU_IN[$i]}<&-" # close file descriptors
|
|
|
|
eval "exec ${QEMU_OUT[$i]}<&-"
|
2017-06-09 14:32:48 +03:00
|
|
|
|
|
|
|
unset QEMU_IN[$i]
|
|
|
|
unset QEMU_OUT[$i]
|
block: qemu-iotests - add common.qemu, for bash-controlled qemu tests
This creates some common functions for bash language qemu-iotests
to control, and communicate with, a running QEMU process.
4 functions are introduced:
1. _launch_qemu()
This launches the QEMU process(es), and sets up the file
descriptors and fifos for communication. You can choose to
launch each QEMU process listening for either QMP or HMP
monitor. You can call this function multiple times, and
save the handle returned from each. The returned handle is
in $QEMU_HANDLE. You must copy this value.
Commands 2 and 3 use the handle received from _launch_qemu(), to talk
to the appropriate process.
2. _send_qemu_cmd()
Sends a command string, specified by $2, to QEMU. If $3 is
non-NULL, _send_qemu_cmd() will wait to receive $3 as a
required result string from QEMU. Failure to receive $3 will
cause the test to fail. The command can optionally be retried
$qemu_cmd_repeat number of times. Set $qemu_error_no_exit
to not force the test the fail on exit; in this case,
$QEMU_STATUS[$1] will be set to -1 on failure.
3. _timed_wait_for()
Waits for a response, for up to a default of 10 seconds. If
$2 is not seen in that time (anywhere in the response), then
the test fails. Primarily used by _send_qemu_cmd, but could
be useful standalone, as well. To prevent automatic exit
(and therefore test failure), set $qemu_error_no_exit to a
non-NULL value. If $silent is a non-NULL value, then output
to stdout will be suppressed.
4. _cleanup_qemu()
Kills the running QEMU processes, and removes the fifos.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-04-30 18:55:08 +04:00
|
|
|
done
|
|
|
|
}
|