block: fix NetBSD qemu-iotests failure
[qemu/ar7.git] / tests / qemu-iotests / 067
blob926c79b37c45703f7140e9d0eabe10bc87dd969f
1 #!/usr/bin/env bash
3 # Test automatic deletion of BDSes created by -drive/drive_add
5 # Copyright (C) 2013 Red Hat, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # creator
22 owner=kwolf@redhat.com
24 seq=`basename $0`
25 echo "QA output created by $seq"
27 status=1 # failure is the default!
29 # get standard environment, filters and checks
30 . ./common.rc
31 . ./common.filter
33 _supported_fmt qcow2
34 _supported_proto file
35 # Because anything other than 16 would change the output of query-block
36 _unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)'
38 do_run_qemu()
40 echo Testing: "$@"
41 $QEMU -nographic -qmp-pretty stdio -serial none "$@"
42 echo
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()
49 tr '\n' '\t' | sed -e \
50 's/{\s*"timestamp":\s*{[^}]*},\s*"event":[^,}]*\(,\s*"data":\s*{[^}]*}\)\?\s*}\s*//g' \
51 | tr '\t' '\n'
54 run_qemu()
56 do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp | _filter_qemu \
57 | _filter_actual_image_size \
58 | _filter_generated_node_ids | _filter_qmp_events \
59 | _filter_img_info
62 size=128M
64 _make_test_img $size
66 echo
67 echo === -drive/-device and device_del ===
68 echo
70 run_qemu -drive file=$TEST_IMG,format=$IMGFMT,if=none,id=disk -device virtio-blk,drive=disk,id=virtio0 <<EOF
71 { "execute": "qmp_capabilities" }
72 { "execute": "query-block" }
73 { "execute": "device_del", "arguments": { "id": "virtio0" } }
74 { "execute": "system_reset" }
75 { "execute": "query-block" }
76 { "execute": "quit" }
77 EOF
79 echo
80 echo === -drive/device_add and device_del ===
81 echo
83 run_qemu -drive file=$TEST_IMG,format=$IMGFMT,if=none,id=disk <<EOF
84 { "execute": "qmp_capabilities" }
85 { "execute": "query-block" }
86 { "execute": "device_add",
87 "arguments": { "driver": "virtio-blk", "drive": "disk",
88 "id": "virtio0" } }
89 { "execute": "device_del", "arguments": { "id": "virtio0" } }
90 { "execute": "system_reset" }
91 { "execute": "query-block" }
92 { "execute": "quit" }
93 EOF
95 echo
96 echo === drive_add/device_add and device_del ===
97 echo
99 run_qemu <<EOF
100 { "execute": "qmp_capabilities" }
101 { "execute": "human-monitor-command",
102 "arguments": { "command-line": "drive_add 0 file=$TEST_IMG,format=$IMGFMT,if=none,id=disk" } }
103 { "execute": "query-block" }
104 { "execute": "device_add",
105 "arguments": { "driver": "virtio-blk", "drive": "disk",
106 "id": "virtio0" } }
107 { "execute": "device_del", "arguments": { "id": "virtio0" } }
108 { "execute": "system_reset" }
109 { "execute": "query-block" }
110 { "execute": "quit" }
113 echo
114 echo === blockdev_add/device_add and device_del ===
115 echo
117 run_qemu <<EOF
118 { "execute": "qmp_capabilities" }
119 { "execute": "blockdev-add",
120 "arguments": {
121 "driver": "$IMGFMT",
122 "node-name": "disk",
123 "file": {
124 "driver": "file",
125 "filename": "$TEST_IMG"
129 { "execute": "query-named-block-nodes" }
130 { "execute": "device_add",
131 "arguments": { "driver": "virtio-blk", "drive": "disk",
132 "id": "virtio0" } }
133 { "execute": "device_del", "arguments": { "id": "virtio0" } }
134 { "execute": "system_reset" }
135 { "execute": "query-named-block-nodes" }
136 { "execute": "quit" }
139 echo
140 echo === Empty drive with -device and device_del ===
141 echo
143 run_qemu -device virtio-scsi -device scsi-cd,id=cd0 <<EOF
144 { "execute": "qmp_capabilities" }
145 { "execute": "query-block" }
146 { "execute": "device_del", "arguments": { "id": "cd0" } }
147 { "execute": "system_reset" }
148 { "execute": "query-block" }
149 { "execute": "quit" }
152 # success, all done
153 echo "*** done"
154 rm -f $seq.full
155 status=0