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