xref: /openbmc/qemu/tests/qemu-iotests/200 (revision 52a97b5a42d485e89ce61c0310c3cd78fb998938)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
2d975301dSJeff Cody#
3d975301dSJeff Cody# Block job co-routine race condition test.
4d975301dSJeff Cody#
5d975301dSJeff Cody# See: https://bugzilla.redhat.com/show_bug.cgi?id=1508708
6d975301dSJeff Cody#
7d975301dSJeff Cody# Copyright (C) 2017 Red Hat, Inc.
8d975301dSJeff Cody#
9d975301dSJeff Cody# This program is free software; you can redistribute it and/or modify
10d975301dSJeff Cody# it under the terms of the GNU General Public License as published by
11d975301dSJeff Cody# the Free Software Foundation; either version 2 of the License, or
12d975301dSJeff Cody# (at your option) any later version.
13d975301dSJeff Cody#
14d975301dSJeff Cody# This program is distributed in the hope that it will be useful,
15d975301dSJeff Cody# but WITHOUT ANY WARRANTY; without even the implied warranty of
16d975301dSJeff Cody# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17d975301dSJeff Cody# GNU General Public License for more details.
18d975301dSJeff Cody#
19d975301dSJeff Cody# You should have received a copy of the GNU General Public License
20d975301dSJeff Cody# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21d975301dSJeff Cody#
22d975301dSJeff Cody
23d975301dSJeff Cody# creator
24d975301dSJeff Codyowner=jcody@redhat.com
25d975301dSJeff Cody
26d975301dSJeff Codyseq=`basename $0`
27d975301dSJeff Codyecho "QA output created by $seq"
28d975301dSJeff Cody
29d975301dSJeff Codystatus=1    # failure is the default!
30d975301dSJeff Cody
31d975301dSJeff Cody_cleanup()
32d975301dSJeff Cody{
33d975301dSJeff Cody    _cleanup_qemu
34d975301dSJeff Cody    rm -f "${TEST_IMG}" "${BACKING_IMG}"
35d975301dSJeff Cody}
36d975301dSJeff Codytrap "_cleanup; exit \$status" 0 1 2 3 15
37d975301dSJeff Cody
38d975301dSJeff Cody# get standard environment, filters and checks
39d975301dSJeff Cody. ./common.rc
40d975301dSJeff Cody. ./common.filter
41d975301dSJeff Cody. ./common.qemu
42d975301dSJeff Cody
43d975301dSJeff Cody_supported_fmt qcow2 qed
44d975301dSJeff Cody_supported_proto file
45d975301dSJeff Cody
46d975301dSJeff CodyBACKING_IMG="${TEST_DIR}/backing.img"
47d975301dSJeff CodyTEST_IMG="${TEST_DIR}/test.img"
48d975301dSJeff Cody
49*52a97b5aSMax ReitzTEST_IMG="$BACKING_IMG" _make_test_img 512M
50*52a97b5aSMax Reitz_make_test_img -F $IMGFMT -b "$BACKING_IMG" 512M
51d975301dSJeff Cody
52d975301dSJeff Cody${QEMU_IO} -c "write -P 0xa5 512 300M" "${BACKING_IMG}" | _filter_qemu_io
53d975301dSJeff Cody
54e0a59749SThomas Huthcase "$QEMU_DEFAULT_MACHINE" in
55e0a59749SThomas Huth  s390-ccw-virtio)
56e0a59749SThomas Huth      virtio_scsi="-device virtio-scsi-ccw,id=scsi0,iothread=iothread0"
57e0a59749SThomas Huth      ;;
58e0a59749SThomas Huth  *)
59e0a59749SThomas Huth      virtio_scsi="-device pci-bridge,id=bridge1,chassis_nr=1,bus=pci.0
60e0a59749SThomas Huth          -device virtio-scsi-pci,bus=bridge1,addr=0x1f,id=scsi0,iothread=iothread0"
61e0a59749SThomas Huth      ;;
62e0a59749SThomas Huthesac
63e0a59749SThomas Huth
64d975301dSJeff Codyecho
65d975301dSJeff Codyecho === Starting QEMU VM ===
66d975301dSJeff Codyecho
67d975301dSJeff Codyqemu_comm_method="qmp"
68e0a59749SThomas Huth_launch_qemu -object iothread,id=iothread0 $virtio_scsi \
6945a79646SMax Reitz             -drive file="${TEST_IMG}",media=disk,if=none,cache=$CACHEMODE,id=drive_sysdisk,format=$IMGFMT \
70d975301dSJeff Cody             -device scsi-hd,drive=drive_sysdisk,bus=scsi0.0,id=sysdisk,bootindex=0
71d975301dSJeff Codyh1=$QEMU_HANDLE
72d975301dSJeff Cody
73d975301dSJeff Cody_send_qemu_cmd $h1 "{ 'execute': 'qmp_capabilities' }" 'return'
74d975301dSJeff Cody
75d975301dSJeff Codyecho
76d975301dSJeff Codyecho === Sending stream/cancel, checking for SIGSEGV only  ===
77d975301dSJeff Codyecho
78d975301dSJeff Codyfor (( i=1;i<500;i++ ))
79d975301dSJeff Codydo
80d975301dSJeff Cody    mismatch_only='y' qemu_error_no_exit='n' _send_qemu_cmd $h1 \
81d975301dSJeff Cody                       "{
82d975301dSJeff Cody                            'execute': 'block-stream',
83d975301dSJeff Cody                            'arguments': {
84d975301dSJeff Cody                                'device': 'drive_sysdisk',
85d975301dSJeff Cody                                'speed': 10000000,
86d975301dSJeff Cody                                'on-error': 'report',
87d975301dSJeff Cody                                'job-id': 'job-$i'
88d975301dSJeff Cody                             }
89d975301dSJeff Cody                        }
90d975301dSJeff Cody                        {
91d975301dSJeff Cody                            'execute': 'block-job-cancel',
92d975301dSJeff Cody                            'arguments': {
93d975301dSJeff Cody                                'device': 'job-$i'
94d975301dSJeff Cody                             }
95d975301dSJeff Cody                        }" \
96d975301dSJeff Cody                       "{.*{.*}.*}"  # should match all well-formed QMP responses
97d975301dSJeff Codydone
98d975301dSJeff Cody
99d975301dSJeff Codysilent='y' _send_qemu_cmd $h1  "{ 'execute': 'quit' }" 'return'
100d975301dSJeff Cody
101d975301dSJeff Codyecho "$i iterations performed"
102d975301dSJeff Cody
103d975301dSJeff Codyecho "*** done"
104d975301dSJeff Codyrm -f $seq.full
105d975301dSJeff Codystatus=0
106