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