xref: /openbmc/qemu/tests/qemu-iotests/240 (revision b15c0f7d)
1#!/usr/bin/env 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
37do_run_qemu()
38{
39    echo Testing: "$@"
40    $QEMU -nographic -qmp stdio -serial none "$@"
41    echo
42}
43
44# Remove QMP events from (pretty-printed) output. Doesn't handle
45# nested dicts correctly, but we don't get any of those in this test.
46_filter_qmp_events()
47{
48    tr '\n' '\t' | sed -e \
49	's/{\s*"timestamp":\s*{[^}]*},\s*"event":[^,}]*\(,\s*"data":\s*{[^}]*}\)\?\s*}\s*//g' \
50	| tr '\t' '\n'
51}
52
53run_qemu()
54{
55    do_run_qemu "$@" 2>&1 | _filter_qmp | _filter_qmp_events
56}
57
58case "$QEMU_DEFAULT_MACHINE" in
59  s390-ccw-virtio)
60      virtio_scsi=virtio-scsi-ccw
61      ;;
62  *)
63      virtio_scsi=virtio-scsi-pci
64      ;;
65esac
66
67echo
68echo === Unplug a SCSI disk and then plug it again ===
69echo
70
71run_qemu <<EOF
72{ "execute": "qmp_capabilities" }
73{ "execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "hd0"}}
74{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread0"}}
75{ "execute": "device_add", "arguments": {"id": "scsi0", "driver": "${virtio_scsi}", "iothread": "iothread0"}}
76{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0"}}
77{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}}
78{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0"}}
79{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}}
80{ "execute": "device_del", "arguments": {"id": "scsi0"}}
81{ "execute": "blockdev-del", "arguments": {"node-name": "hd0"}}
82{ "execute": "quit"}
83EOF
84
85echo
86echo === Attach two SCSI disks using the same block device and the same iothread ===
87echo
88
89run_qemu <<EOF
90{ "execute": "qmp_capabilities" }
91{ "execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "hd0", "read-only": true}}
92{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread0"}}
93{ "execute": "device_add", "arguments": {"id": "scsi0", "driver": "${virtio_scsi}", "iothread": "iothread0"}}
94{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0"}}
95{ "execute": "device_add", "arguments": {"id": "scsi-hd1", "driver": "scsi-hd", "drive": "hd0"}}
96{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}}
97{ "execute": "device_del", "arguments": {"id": "scsi-hd1"}}
98{ "execute": "device_del", "arguments": {"id": "scsi0"}}
99{ "execute": "blockdev-del", "arguments": {"node-name": "hd0"}}
100{ "execute": "quit"}
101EOF
102
103echo
104echo === Attach two SCSI disks using the same block device but different iothreads ===
105echo
106
107run_qemu <<EOF
108{ "execute": "qmp_capabilities" }
109{ "execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "hd0", "read-only": true}}
110{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread0"}}
111{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread1"}}
112{ "execute": "device_add", "arguments": {"id": "scsi0", "driver": "${virtio_scsi}", "iothread": "iothread0"}}
113{ "execute": "device_add", "arguments": {"id": "scsi1", "driver": "${virtio_scsi}", "iothread": "iothread1"}}
114{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0", "bus": "scsi0.0"}}
115{ "execute": "device_add", "arguments": {"id": "scsi-hd1", "driver": "scsi-hd", "drive": "hd0", "bus": "scsi1.0"}}
116{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}}
117{ "execute": "device_add", "arguments": {"id": "scsi-hd1", "driver": "scsi-hd", "drive": "hd0", "bus": "scsi1.0"}}
118{ "execute": "device_del", "arguments": {"id": "scsi-hd1"}}
119{ "execute": "device_del", "arguments": {"id": "scsi0"}}
120{ "execute": "device_del", "arguments": {"id": "scsi1"}}
121{ "execute": "blockdev-del", "arguments": {"node-name": "hd0"}}
122{ "execute": "quit"}
123EOF
124
125# success, all done
126echo "*** done"
127rm -f $seq.full
128status=0
129