echo "creating image"
_make_test_img $size
-function generate_requests() {
+generate_requests() {
for i in $(seq 0 63); do
echo "aio_write ${i}M 512"
echo "aio_write ${i}M 512"
_make_test_img $size
-function backing_io()
+backing_io()
{
local offset=$1
local sectors=$2
_make_test_img $size
-function backing_io()
+backing_io()
{
local offset=$1
local sectors=$2
echo
echo "== Some concurrent requests touching the same cluster =="
-function overlay_io()
+overlay_io()
{
# Start with a request touching two clusters
echo aio_write -P 0x80 2020k 80k
echo
echo "== Verify image content =="
-function verify_io()
+verify_io()
{
echo read -P 31 2016k 4k
echo read -P 0x80 2020k 80k
_make_test_img $size
-function backing_io()
+backing_io()
{
local offset=$1
local sectors=$2
echo
echo "== Some concurrent requests touching the same cluster =="
-function overlay_io()
+overlay_io()
{
# Allocate middle of cluster 1, then write to somewhere before and after it
cat <<EOF
echo
echo "== Verify image content =="
-function verify_io()
+verify_io()
{
if ($QEMU_IMG info -U -f "$IMGFMT" "$TEST_IMG" | grep "compat: 0.10" > /dev/null); then
# For v2 images, discarded clusters are read from the backing file
_make_test_img $size
-function qemu_io_cmds()
+qemu_io_cmds()
{
cat <<EOF
write -P 0x66 0 320k
_supported_proto file
_supported_os Linux
-function filter_test_dir()
+filter_test_dir()
{
sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
-e "s#$TEST_DIR#TEST_DIR#g"
}
-function test_qemu_img()
+test_qemu_img()
{
echo qemu-img "$@" | filter_test_dir
$QEMU_IMG "$@" 2>&1 | filter_test_dir
# other than refcount_bits=16
_unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)'
-function do_run_qemu()
+do_run_qemu()
{
echo Testing: "$@"
(
echo
}
-function run_qemu()
+run_qemu()
{
do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu |
_filter_generated_node_ids | _filter_hmp
# Because anything other than 16 would change the output of query-block
_unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)'
-function do_run_qemu()
+do_run_qemu()
{
echo Testing: "$@"
$QEMU -nographic -qmp-pretty stdio -serial none "$@"
| tr '\t' '\n'
}
-function run_qemu()
+run_qemu()
{
do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp | _filter_qemu \
| _filter_actual_image_size \
_supported_proto file
_supported_os Linux
-function do_run_qemu()
+do_run_qemu()
{
echo Testing: "$@" | _filter_imgfmt
$QEMU -nographic -qmp stdio -serial none "$@"
echo
}
-function run_qemu()
+run_qemu()
{
do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp | _filter_qemu_io
}
echo
echo "== Some concurrent requests involving RMW =="
-function test_io()
+test_io()
{
echo "open -o driver=$IMGFMT,file.align=4k blkdebug::$TEST_IMG"
# A simple RMW request
echo
echo "== Verify image content =="
-function verify_io()
+verify_io()
{
# A simple RMW request
echo read -P 0 0 0x200
_supported_proto file
_supported_os Linux
-function do_run_qemu()
+do_run_qemu()
{
echo Testing: "$@" | _filter_imgfmt
$QEMU -nographic -qmp stdio -serial none "$@"
echo
}
-function run_qemu()
+run_qemu()
{
do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp\
| _filter_qemu_io | _filter_generated_node_ids
_supported_proto file nfs
_supported_os Linux
-function run_qemu_img()
+run_qemu_img()
{
echo
echo Testing: "$@" | _filter_testdir
# ${1}: unique identifier for the snapshot filename
-function create_single_snapshot()
+create_single_snapshot()
{
cmd="{ 'execute': 'blockdev-snapshot-sync',
'arguments': { 'device': 'virtio0',
}
# ${1}: unique identifier for the snapshot filename
-function create_group_snapshot()
+create_group_snapshot()
{
cmd="{ 'execute': 'transaction', 'arguments':
{'actions': [
# ${1}: unique identifier for the snapshot filename
# ${2}: extra_params to the blockdev-add command
# ${3}: filename
-function do_blockdev_add()
+do_blockdev_add()
{
cmd="{ 'execute': 'blockdev-add', 'arguments':
{ 'driver': 'qcow2', 'node-name': 'snap_${1}', ${2}
}
# ${1}: unique identifier for the snapshot filename
-function add_snapshot_image()
+add_snapshot_image()
{
base_image="${TEST_DIR}/$((${1}-1))-${snapshot_virt0}"
snapshot_file="${TEST_DIR}/${1}-${snapshot_virt0}"
# ${1}: unique identifier for the snapshot filename
# ${2}: expected response, defaults to 'return'
-function blockdev_snapshot()
+blockdev_snapshot()
{
cmd="{ 'execute': 'blockdev-snapshot',
'arguments': { 'node': 'virtio0',
_supported_proto file
_supported_os Linux
-function run_qemu_img()
+run_qemu_img()
{
echo
echo Testing: "$@" | _filter_testdir
_supported_proto file
_supported_os Linux
-function do_run_qemu()
+do_run_qemu()
{
echo Testing: "$@"
$QEMU -nographic -qmp stdio -serial none "$@"
echo
}
-function run_qemu()
+run_qemu()
{
do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \
| _filter_qemu | _filter_imgfmt \
echo
# Skip this test if AIO is not enabled in this build
-function run_qemu_filter_aio()
+run_qemu_filter_aio()
{
run_qemu "$@" | \
sed -e 's/is not supported in this build/it requires cache.direct=on, which was not specified/'
_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \
"subformat=twoGbMaxExtentSparse"
-function do_run_qemu()
+do_run_qemu()
{
$QEMU -nographic -qmp stdio -serial none "$@"
}
-function run_qemu()
+run_qemu()
{
# Get the "file": "foo" entry ($foo may only contain escaped double quotes,
# which is how we can extract it)
| sed -e 's/^.*"file": "\(\(\\"\|[^"]\)*\)".*$/\1/' -e 's/\\"/"/g'
}
-function test_qemu()
+test_qemu()
{
run_qemu -drive "if=none,id=drv0,$1" <<EOF
{ 'execute': 'qmp_capabilities' }
qemu_comm_method=qmp
-function run_qemu()
+run_qemu()
{
local raw_img="$1"
local source_img="$2"
# manual setting; compat will be overridden as well
_unsupported_imgopts refcount_bits 'compat=0.10'
-function print_refcount_bits()
+print_refcount_bits()
{
$QEMU_IMG info "$TEST_IMG" | sed -n '/refcount bits:/ s/^ *//p'
}
_default_cache_mode none
_supported_cache_modes none directsync
-function do_run_qemu()
+do_run_qemu()
{
echo Testing: "$@"
(
echo
}
-function run_qemu()
+run_qemu()
{
do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_hmp
}
files="if=none,file=$TEST_IMG,backing.file.filename=$TEST_IMG.base"
ids="node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file"
-function check_cache_all()
+check_cache_all()
{
# cache.direct is supposed to be inherited by both bs->file and
# bs->backing
drv_file="if=none,driver=file,filename=$TEST_IMG,node-name=file"
drv_img="if=none,id=blk,file=json:{'driver':'$IMGFMT',,'file':'file',,'backing':'backing',,'node-name':'image'}"
-function check_cache_all_separate()
+check_cache_all_separate()
{
# Check cache.direct
(echo "$@"; "$@" 2>&1 1>/dev/null) | _filter_testdir
}
-function _do_run_qemu()
+_do_run_qemu()
{
(
if ! test -t 0; then
) | $QEMU -nographic -monitor stdio -serial none "$@" 1>/dev/null
}
-function _run_qemu_with_images()
+_run_qemu_with_images()
{
_do_run_qemu \
$(for i in $@; do echo "-drive if=none,file=$i"; done) 2>&1 \
_supported_proto file
_supported_os Linux
-function do_run_qemu()
+do_run_qemu()
{
(
if ! test -t 0; then
echo
}
-function run_qemu()
+run_qemu()
{
do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_imgfmt \
| _filter_qemu | _filter_generated_node_ids
_notrun "Requires a PC machine"
fi
-function do_run_qemu()
+do_run_qemu()
{
(
if ! test -t 0; then
echo
}
-function check_floppy_qtree()
+check_floppy_qtree()
{
echo
echo Testing: "$@" | _filter_testdir
_filter_win32 | _filter_qemu
}
-function check_cache_mode()
+check_cache_mode()
{
echo "info block none0" |
QEMU_OPTIONS="" do_run_qemu -drive if=none,file="$TEST_IMG" "$@" |
# Persistent dirty bitmaps require compat=1.1
_unsupported_imgopts 'compat=0.10'
-function run_qemu()
+run_qemu()
{
$QEMU -nographic -qmp stdio -serial none "$@" 2>&1 \
| _filter_testdir | _filter_qmp | _filter_qemu \
echo
echo "== verify image content =="
-function verify_io()
+verify_io()
{
if ($QEMU_IMG info -f "$IMGFMT" "$TEST_IMG" |
grep "compat: 0.10" > /dev/null); then
_supported_os Linux
-function do_run_qemu()
+do_run_qemu()
{
echo Testing: "$@" | _filter_imgfmt
$QEMU -nographic -qmp-pretty stdio -serial none "$@"
echo
}
-function run_qemu()
+run_qemu()
{
do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp\
| _filter_qemu_io | _filter_generated_node_ids \
_notrun "Requires a PC machine"
fi
-function do_run_qemu()
+do_run_qemu()
{
echo Testing: "$@"
echo
}
-function check_info_block()
+check_info_block()
{
echo "info block" |
do_run_qemu "$@" | _filter_win32 | _filter_hmp | _filter_qemu |
_supported_proto file
_supported_os Linux
-function do_run_qemu()
+do_run_qemu()
{
echo Testing: "$@"
$QEMU -nographic -qmp-pretty stdio -serial none "$@"
echo
}
-function run_qemu()
+run_qemu()
{
do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_imgfmt | _filter_qemu \
| _filter_qmp | _filter_qemu_io \
echo
echo "== verify image content =="
-function verify_io()
+verify_io()
{
echo read -P 22 0 1000
echo read -P 33 1000 128k
# Persistent dirty bitmaps require compat=1.1
_unsupported_imgopts 'compat=0.10'
-function do_run_qemu()
+do_run_qemu()
{
echo Testing: "$@"
$QEMU -nographic -qmp stdio -serial none "$@"
echo
}
-function run_qemu()
+run_qemu()
{
do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \
| _filter_qemu | _filter_imgfmt \
_supported_proto file
_supported_os Linux
-function do_run_qemu()
+do_run_qemu()
{
echo Testing: "$@"
$QEMU -nographic -qmp-pretty stdio -serial none "$@"
echo
}
-function run_qemu()
+run_qemu()
{
do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \
| _filter_qemu | _filter_imgfmt \
_supported_proto file
_supported_os Linux
-function do_run_qemu()
+do_run_qemu()
{
echo Testing: "$@"
(
echo
}
-function run_qemu()
+run_qemu()
{
do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_hmp |
_filter_generated_node_ids | _filter_imgfmt
}
-function run_qemu_info_block()
+run_qemu_info_block()
{
echo "info block -n" | run_qemu "$@" | grep -e "(file" -e "QEMU_PROG"
}
nbd_tcp_addr="127.0.0.1"
nbd_pid_file="${TEST_DIR}/qemu-nbd.pid"
-function nbd_server_stop()
+nbd_server_stop()
{
local NBD_PID
if [ -f "$nbd_pid_file" ]; then
rm -f "$nbd_unix_socket"
}
-function nbd_server_wait_for_unix_socket()
+nbd_server_wait_for_unix_socket()
{
pid=$1
exit 1
}
-function nbd_server_start_unix_socket()
+nbd_server_start_unix_socket()
{
nbd_server_stop
$QEMU_NBD -v -t -k "$nbd_unix_socket" "$@" &
nbd_server_wait_for_unix_socket $!
}
-function nbd_server_set_tcp_port()
+nbd_server_set_tcp_port()
{
(ss --help) >/dev/null 2>&1 || _notrun "ss utility not found, skipping test"
exit 1
}
-function nbd_server_wait_for_tcp_socket()
+nbd_server_wait_for_tcp_socket()
{
pid=$1
exit 1
}
-function nbd_server_start_tcp_socket()
+nbd_server_start_tcp_socket()
{
nbd_server_stop
$QEMU_NBD -v -t -b $nbd_tcp_addr -p $nbd_tcp_port "$@" &
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-function do_is_allocated() {
+do_is_allocated() {
local start=$1
local size=$2
local step=$3
done
}
-function is_allocated() {
+is_allocated() {
do_is_allocated "$@" | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
}
-function do_io() {
+do_io() {
local op=$1
local start=$2
local size=$3
done
}
-function io_pattern() {
+io_pattern() {
do_io "$@" | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
}
-function io() {
+io() {
local start=$2
local pattern=$(( (start >> 9) % 256 ))
do_io "$@" $pattern | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
}
-function io_zero() {
+io_zero() {
do_io "$@" 0 | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
}
-function io_test() {
+io_test() {
local op=$1
local offset=$2
local cluster_size=$3
offset=$((offset + num_large * ( l2_size + half_cluster )))
}
-function io_test2() {
+io_test2() {
local orig_offset=$1
local cluster_size=$2
local num=$3
# $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()
+_timed_wait_for()
{
local h=${1}
shift
# 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()
+_send_qemu_cmd()
{
local h=${1}
local count=1
# Returns:
# $QEMU_HANDLE: set to a handle value to communicate with this QEMU instance.
#
-function _launch_qemu()
+_launch_qemu()
{
local comm=
local fifo_out=
# 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.
-function _cleanup_qemu()
+_cleanup_qemu()
{
# QEMU_PID[], QEMU_IN[], QEMU_OUT[] all use same indices
for i in "${!QEMU_OUT[@]}"
tls_dir="${TEST_DIR}/tls"
-function tls_x509_cleanup()
+tls_x509_cleanup()
{
rm -f "${tls_dir}"/*.pem
rm -f "${tls_dir}"/*/*.pem
}
-function tls_x509_init()
+tls_x509_init()
{
mkdir -p "${tls_dir}"
}
-function tls_x509_create_root_ca()
+tls_x509_create_root_ca()
{
name=${1:-ca-cert}
}
-function tls_x509_create_server()
+tls_x509_create_server()
{
caname=$1
name=$2
}
-function tls_x509_create_client()
+tls_x509_create_client()
{
caname=$1
name=$2