xref: /openbmc/qemu/tests/qemu-iotests/240 (revision 99d46107)
1#!/bin/bash
2#
3# Test hot plugging and unplugging with iothreads
4#
5# Copyright (C) 2019 Igalia, S.L.
6# Author: Alberto Garcia <berto@igalia.com>
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20#
21
22# creator
23owner=berto@igalia.com
24
25seq=`basename $0`
26echo "QA output created by $seq"
27
28status=1	# failure is the default!
29
30# get standard environment, filters and checks
31. ./common.rc
32. ./common.filter
33
34_supported_fmt generic
35_supported_proto generic
36_supported_os Linux
37
38do_run_qemu()
39{
40    echo Testing: "$@"
41    $QEMU -nographic -qmp stdio -serial none "$@"
42    echo
43}
44
45# Remove QMP events from (pretty-printed) output. Doesn't handle
46# nested dicts correctly, but we don't get any of those in this test.
47_filter_qmp_events()
48{
49    tr '\n' '\t' | sed -e \
50	's/{\s*"timestamp":\s*{[^}]*},\s*"event":[^,}]*\(,\s*"data":\s*{[^}]*}\)\?\s*}\s*//g' \
51	| tr '\t' '\n'
52}
53
54run_qemu()
55{
56    do_run_qemu "$@" 2>&1 | _filter_qmp | _filter_qmp_events
57}
58
59case "$QEMU_DEFAULT_MACHINE" in
60  s390-ccw-virtio)
61      virtio_scsi=virtio-scsi-ccw
62      ;;
63  *)
64      virtio_scsi=virtio-scsi-pci
65      ;;
66esac
67
68echo
69echo === Unplug a SCSI disk and then plug it again ===
70echo
71
72run_qemu <<EOF
73{ "execute": "qmp_capabilities" }
74{ "execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "hd0"}}
75{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread0"}}
76{ "execute": "device_add", "arguments": {"id": "scsi0", "driver": "${virtio_scsi}", "iothread": "iothread0"}}
77{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0"}}
78{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}}
79{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0"}}
80{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}}
81{ "execute": "device_del", "arguments": {"id": "scsi0"}}
82{ "execute": "blockdev-del", "arguments": {"node-name": "hd0"}}
83{ "execute": "quit"}
84EOF
85
86echo
87echo === Attach two SCSI disks using the same block device and the same iothread ===
88echo
89
90run_qemu <<EOF
91{ "execute": "qmp_capabilities" }
92{ "execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "hd0", "read-only": true}}
93{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread0"}}
94{ "execute": "device_add", "arguments": {"id": "scsi0", "driver": "${virtio_scsi}", "iothread": "iothread0"}}
95{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0"}}
96{ "execute": "device_add", "arguments": {"id": "scsi-hd1", "driver": "scsi-hd", "drive": "hd0"}}
97{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}}
98{ "execute": "device_del", "arguments": {"id": "scsi-hd1"}}
99{ "execute": "device_del", "arguments": {"id": "scsi0"}}
100{ "execute": "blockdev-del", "arguments": {"node-name": "hd0"}}
101{ "execute": "quit"}
102EOF
103
104echo
105echo === Attach two SCSI disks using the same block device but different iothreads ===
106echo
107
108run_qemu <<EOF
109{ "execute": "qmp_capabilities" }
110{ "execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "hd0", "read-only": true}}
111{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread0"}}
112{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread1"}}
113{ "execute": "device_add", "arguments": {"id": "scsi0", "driver": "${virtio_scsi}", "iothread": "iothread0"}}
114{ "execute": "device_add", "arguments": {"id": "scsi1", "driver": "${virtio_scsi}", "iothread": "iothread1"}}
115{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0", "bus": "scsi0.0"}}
116{ "execute": "device_add", "arguments": {"id": "scsi-hd1", "driver": "scsi-hd", "drive": "hd0", "bus": "scsi1.0"}}
117{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}}
118{ "execute": "device_add", "arguments": {"id": "scsi-hd1", "driver": "scsi-hd", "drive": "hd0", "bus": "scsi1.0"}}
119{ "execute": "device_del", "arguments": {"id": "scsi-hd1"}}
120{ "execute": "device_del", "arguments": {"id": "scsi0"}}
121{ "execute": "device_del", "arguments": {"id": "scsi1"}}
122{ "execute": "blockdev-del", "arguments": {"node-name": "hd0"}}
123{ "execute": "quit"}
124EOF
125
126# success, all done
127echo "*** done"
128rm -f $seq.full
129status=0
130