xref: /openbmc/qemu/tests/qemu-iotests/240 (revision 45e92a9011bff4f6660dae1e011083c5790d121b)
1f3d07ce8SThomas Huth#!/usr/bin/env 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
30*45e92a90SKevin Wolf_cleanup()
31*45e92a90SKevin Wolf{
32*45e92a90SKevin Wolf    rm -f "$TEST_DIR/nbd"
33*45e92a90SKevin Wolf}
34*45e92a90SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
35*45e92a90SKevin Wolf
36a6f230c8SAlberto Garcia# get standard environment, filters and checks
37a6f230c8SAlberto Garcia. ./common.rc
38a6f230c8SAlberto Garcia. ./common.filter
39a6f230c8SAlberto Garcia
40a6f230c8SAlberto Garcia_supported_fmt generic
41a6f230c8SAlberto Garcia_supported_proto generic
42a6f230c8SAlberto Garcia
43a6f230c8SAlberto Garciado_run_qemu()
44a6f230c8SAlberto Garcia{
45a6f230c8SAlberto Garcia    echo Testing: "$@"
46a6f230c8SAlberto Garcia    $QEMU -nographic -qmp stdio -serial none "$@"
47a6f230c8SAlberto Garcia    echo
48a6f230c8SAlberto Garcia}
49a6f230c8SAlberto Garcia
50a6f230c8SAlberto Garcia# Remove QMP events from (pretty-printed) output. Doesn't handle
51a6f230c8SAlberto Garcia# nested dicts correctly, but we don't get any of those in this test.
52a6f230c8SAlberto Garcia_filter_qmp_events()
53a6f230c8SAlberto Garcia{
54a6f230c8SAlberto Garcia    tr '\n' '\t' | sed -e \
55a6f230c8SAlberto Garcia	's/{\s*"timestamp":\s*{[^}]*},\s*"event":[^,}]*\(,\s*"data":\s*{[^}]*}\)\?\s*}\s*//g' \
56a6f230c8SAlberto Garcia	| tr '\t' '\n'
57a6f230c8SAlberto Garcia}
58a6f230c8SAlberto Garcia
59a6f230c8SAlberto Garciarun_qemu()
60a6f230c8SAlberto Garcia{
61a6f230c8SAlberto Garcia    do_run_qemu "$@" 2>&1 | _filter_qmp | _filter_qmp_events
62a6f230c8SAlberto Garcia}
63a6f230c8SAlberto Garcia
64a6f230c8SAlberto Garciacase "$QEMU_DEFAULT_MACHINE" in
65a6f230c8SAlberto Garcia  s390-ccw-virtio)
66a6f230c8SAlberto Garcia      virtio_scsi=virtio-scsi-ccw
67a6f230c8SAlberto Garcia      ;;
68a6f230c8SAlberto Garcia  *)
69a6f230c8SAlberto Garcia      virtio_scsi=virtio-scsi-pci
70a6f230c8SAlberto Garcia      ;;
71a6f230c8SAlberto Garciaesac
72a6f230c8SAlberto Garcia
73a6f230c8SAlberto Garciaecho
74a6f230c8SAlberto Garciaecho === Unplug a SCSI disk and then plug it again ===
75a6f230c8SAlberto Garciaecho
76a6f230c8SAlberto Garcia
77a6f230c8SAlberto Garciarun_qemu <<EOF
78a6f230c8SAlberto Garcia{ "execute": "qmp_capabilities" }
79a6f230c8SAlberto Garcia{ "execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "hd0"}}
80a6f230c8SAlberto Garcia{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread0"}}
81a6f230c8SAlberto Garcia{ "execute": "device_add", "arguments": {"id": "scsi0", "driver": "${virtio_scsi}", "iothread": "iothread0"}}
82a6f230c8SAlberto Garcia{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0"}}
83a6f230c8SAlberto Garcia{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}}
84a6f230c8SAlberto Garcia{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0"}}
85a6f230c8SAlberto Garcia{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}}
86a6f230c8SAlberto Garcia{ "execute": "device_del", "arguments": {"id": "scsi0"}}
87a6f230c8SAlberto Garcia{ "execute": "blockdev-del", "arguments": {"node-name": "hd0"}}
88a6f230c8SAlberto Garcia{ "execute": "quit"}
89a6f230c8SAlberto GarciaEOF
90a6f230c8SAlberto Garcia
913ff35ba3SAlberto Garciaecho
923ff35ba3SAlberto Garciaecho === Attach two SCSI disks using the same block device and the same iothread ===
933ff35ba3SAlberto Garciaecho
943ff35ba3SAlberto Garcia
953ff35ba3SAlberto Garciarun_qemu <<EOF
963ff35ba3SAlberto Garcia{ "execute": "qmp_capabilities" }
973ff35ba3SAlberto Garcia{ "execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "hd0", "read-only": true}}
983ff35ba3SAlberto Garcia{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread0"}}
993ff35ba3SAlberto Garcia{ "execute": "device_add", "arguments": {"id": "scsi0", "driver": "${virtio_scsi}", "iothread": "iothread0"}}
1003ff35ba3SAlberto Garcia{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0"}}
1013ff35ba3SAlberto Garcia{ "execute": "device_add", "arguments": {"id": "scsi-hd1", "driver": "scsi-hd", "drive": "hd0"}}
1023ff35ba3SAlberto Garcia{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}}
1033ff35ba3SAlberto Garcia{ "execute": "device_del", "arguments": {"id": "scsi-hd1"}}
1043ff35ba3SAlberto Garcia{ "execute": "device_del", "arguments": {"id": "scsi0"}}
1053ff35ba3SAlberto Garcia{ "execute": "blockdev-del", "arguments": {"node-name": "hd0"}}
1063ff35ba3SAlberto Garcia{ "execute": "quit"}
1073ff35ba3SAlberto GarciaEOF
1083ff35ba3SAlberto Garcia
109eb97813fSAlberto Garciaecho
110eb97813fSAlberto Garciaecho === Attach two SCSI disks using the same block device but different iothreads ===
111eb97813fSAlberto Garciaecho
112eb97813fSAlberto Garcia
113eb97813fSAlberto Garciarun_qemu <<EOF
114eb97813fSAlberto Garcia{ "execute": "qmp_capabilities" }
115eb97813fSAlberto Garcia{ "execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "hd0", "read-only": true}}
116eb97813fSAlberto Garcia{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread0"}}
117eb97813fSAlberto Garcia{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread1"}}
118eb97813fSAlberto Garcia{ "execute": "device_add", "arguments": {"id": "scsi0", "driver": "${virtio_scsi}", "iothread": "iothread0"}}
119eb97813fSAlberto Garcia{ "execute": "device_add", "arguments": {"id": "scsi1", "driver": "${virtio_scsi}", "iothread": "iothread1"}}
120eb97813fSAlberto Garcia{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0", "bus": "scsi0.0"}}
121eb97813fSAlberto Garcia{ "execute": "device_add", "arguments": {"id": "scsi-hd1", "driver": "scsi-hd", "drive": "hd0", "bus": "scsi1.0"}}
122eb97813fSAlberto Garcia{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}}
123eb97813fSAlberto Garcia{ "execute": "device_add", "arguments": {"id": "scsi-hd1", "driver": "scsi-hd", "drive": "hd0", "bus": "scsi1.0"}}
124eb97813fSAlberto Garcia{ "execute": "device_del", "arguments": {"id": "scsi-hd1"}}
125eb97813fSAlberto Garcia{ "execute": "device_del", "arguments": {"id": "scsi0"}}
126eb97813fSAlberto Garcia{ "execute": "device_del", "arguments": {"id": "scsi1"}}
127eb97813fSAlberto Garcia{ "execute": "blockdev-del", "arguments": {"node-name": "hd0"}}
128eb97813fSAlberto Garcia{ "execute": "quit"}
129eb97813fSAlberto GarciaEOF
130eb97813fSAlberto Garcia
131*45e92a90SKevin Wolfecho
132*45e92a90SKevin Wolfecho === Attach a SCSI disks using the same block device as a NBD server ===
133*45e92a90SKevin Wolfecho
134*45e92a90SKevin Wolf
135*45e92a90SKevin Wolfrun_qemu <<EOF
136*45e92a90SKevin Wolf{ "execute": "qmp_capabilities" }
137*45e92a90SKevin Wolf{ "execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "hd0", "read-only": true}}
138*45e92a90SKevin Wolf{ "execute": "nbd-server-start", "arguments": {"addr":{"type":"unix","data":{"path":"$TEST_DIR/nbd"}}}}
139*45e92a90SKevin Wolf{ "execute": "nbd-server-add", "arguments": {"device":"hd0"}}
140*45e92a90SKevin Wolf{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread0"}}
141*45e92a90SKevin Wolf{ "execute": "device_add", "arguments": {"id": "scsi0", "driver": "${virtio_scsi}", "iothread": "iothread0"}}
142*45e92a90SKevin Wolf{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0", "bus": "scsi0.0"}}
143*45e92a90SKevin Wolf{ "execute": "quit"}
144*45e92a90SKevin WolfEOF
145*45e92a90SKevin Wolf
146a6f230c8SAlberto Garcia# success, all done
147a6f230c8SAlberto Garciaecho "*** done"
148a6f230c8SAlberto Garciarm -f $seq.full
149a6f230c8SAlberto Garciastatus=0
150