xref: /openbmc/qemu/tests/qemu-iotests/071 (revision 30bd6a4dafe2f79909451ef5769561c9a9d3eaca)
1*30bd6a4dSMax Reitz#!/bin/bash
2*30bd6a4dSMax Reitz#
3*30bd6a4dSMax Reitz# Test case for the QMP blkdebug and blkverify interfaces
4*30bd6a4dSMax Reitz#
5*30bd6a4dSMax Reitz# Copyright (C) 2013 Red Hat, Inc.
6*30bd6a4dSMax Reitz#
7*30bd6a4dSMax Reitz# This program is free software; you can redistribute it and/or modify
8*30bd6a4dSMax Reitz# it under the terms of the GNU General Public License as published by
9*30bd6a4dSMax Reitz# the Free Software Foundation; either version 2 of the License, or
10*30bd6a4dSMax Reitz# (at your option) any later version.
11*30bd6a4dSMax Reitz#
12*30bd6a4dSMax Reitz# This program is distributed in the hope that it will be useful,
13*30bd6a4dSMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*30bd6a4dSMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*30bd6a4dSMax Reitz# GNU General Public License for more details.
16*30bd6a4dSMax Reitz#
17*30bd6a4dSMax Reitz# You should have received a copy of the GNU General Public License
18*30bd6a4dSMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19*30bd6a4dSMax Reitz#
20*30bd6a4dSMax Reitz
21*30bd6a4dSMax Reitz# creator
22*30bd6a4dSMax Reitzowner=mreitz@redhat.com
23*30bd6a4dSMax Reitz
24*30bd6a4dSMax Reitzseq="$(basename $0)"
25*30bd6a4dSMax Reitzecho "QA output created by $seq"
26*30bd6a4dSMax Reitz
27*30bd6a4dSMax Reitzhere="$PWD"
28*30bd6a4dSMax Reitztmp=/tmp/$$
29*30bd6a4dSMax Reitzstatus=1	# failure is the default!
30*30bd6a4dSMax Reitz
31*30bd6a4dSMax Reitz_cleanup()
32*30bd6a4dSMax Reitz{
33*30bd6a4dSMax Reitz	_cleanup_test_img
34*30bd6a4dSMax Reitz}
35*30bd6a4dSMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
36*30bd6a4dSMax Reitz
37*30bd6a4dSMax Reitz# get standard environment, filters and checks
38*30bd6a4dSMax Reitz. ./common.rc
39*30bd6a4dSMax Reitz. ./common.filter
40*30bd6a4dSMax Reitz
41*30bd6a4dSMax Reitz_supported_fmt generic
42*30bd6a4dSMax Reitz_supported_proto generic
43*30bd6a4dSMax Reitz_supported_os Linux
44*30bd6a4dSMax Reitz
45*30bd6a4dSMax Reitzfunction do_run_qemu()
46*30bd6a4dSMax Reitz{
47*30bd6a4dSMax Reitz    echo Testing: "$@" | _filter_imgfmt
48*30bd6a4dSMax Reitz    $QEMU -nographic -qmp stdio -serial none "$@"
49*30bd6a4dSMax Reitz    echo
50*30bd6a4dSMax Reitz}
51*30bd6a4dSMax Reitz
52*30bd6a4dSMax Reitzfunction run_qemu()
53*30bd6a4dSMax Reitz{
54*30bd6a4dSMax Reitz    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp | _filter_qemu_io
55*30bd6a4dSMax Reitz}
56*30bd6a4dSMax Reitz
57*30bd6a4dSMax ReitzIMG_SIZE=64M
58*30bd6a4dSMax Reitz
59*30bd6a4dSMax Reitzecho
60*30bd6a4dSMax Reitzecho "=== Testing blkverify through filename ==="
61*30bd6a4dSMax Reitzecho
62*30bd6a4dSMax Reitz
63*30bd6a4dSMax ReitzTEST_IMG="$TEST_IMG.base" IMGOPTS="" IMGFMT="raw" _make_test_img $IMG_SIZE |\
64*30bd6a4dSMax Reitz    _filter_imgfmt
65*30bd6a4dSMax Reitz_make_test_img $IMG_SIZE
66*30bd6a4dSMax Reitz$QEMU_IO -c "open -o file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
67*30bd6a4dSMax Reitz         -c 'read 0 512' -c 'write -P 42 0x38000 512' -c 'read -P 42 0x38000 512' | _filter_qemu_io
68*30bd6a4dSMax Reitz
69*30bd6a4dSMax Reitz$QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io
70*30bd6a4dSMax Reitz
71*30bd6a4dSMax Reitz$QEMU_IO -c "open -o file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
72*30bd6a4dSMax Reitz         -c 'read -P 42 0 512' | _filter_qemu_io
73*30bd6a4dSMax Reitz
74*30bd6a4dSMax Reitzecho
75*30bd6a4dSMax Reitzecho "=== Testing blkverify through file blockref ==="
76*30bd6a4dSMax Reitzecho
77*30bd6a4dSMax Reitz
78*30bd6a4dSMax ReitzTEST_IMG="$TEST_IMG.base" IMGOPTS="" IMGFMT="raw" _make_test_img $IMG_SIZE |\
79*30bd6a4dSMax Reitz    _filter_imgfmt
80*30bd6a4dSMax Reitz_make_test_img $IMG_SIZE
81*30bd6a4dSMax Reitz$QEMU_IO -c "open -o file.driver=blkverify,file.raw.filename=$TEST_IMG.base,file.test.driver=$IMGFMT,file.test.file.filename=$TEST_IMG" \
82*30bd6a4dSMax Reitz         -c 'read 0 512' -c 'write -P 42 0x38000 512' -c 'read -P 42 0x38000 512' | _filter_qemu_io
83*30bd6a4dSMax Reitz
84*30bd6a4dSMax Reitz$QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io
85*30bd6a4dSMax Reitz
86*30bd6a4dSMax Reitz$QEMU_IO -c "open -o file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
87*30bd6a4dSMax Reitz         -c 'read -P 42 0 512' | _filter_qemu_io
88*30bd6a4dSMax Reitz
89*30bd6a4dSMax Reitzecho
90*30bd6a4dSMax Reitzecho "=== Testing blkdebug through filename ==="
91*30bd6a4dSMax Reitzecho
92*30bd6a4dSMax Reitz
93*30bd6a4dSMax Reitz$QEMU_IO -c "open -o file.driver=blkdebug,file.inject-error.event=l2_load $TEST_IMG" \
94*30bd6a4dSMax Reitz         -c 'read -P 42 0x38000 512'
95*30bd6a4dSMax Reitz
96*30bd6a4dSMax Reitzecho
97*30bd6a4dSMax Reitzecho "=== Testing blkdebug through file blockref ==="
98*30bd6a4dSMax Reitzecho
99*30bd6a4dSMax Reitz
100*30bd6a4dSMax Reitz$QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.inject-error.event=l2_load,file.image.filename=$TEST_IMG" \
101*30bd6a4dSMax Reitz         -c 'read -P 42 0x38000 512'
102*30bd6a4dSMax Reitz
103*30bd6a4dSMax Reitzecho
104*30bd6a4dSMax Reitzecho "=== Testing blkdebug on existing block device ==="
105*30bd6a4dSMax Reitzecho
106*30bd6a4dSMax Reitz
107*30bd6a4dSMax Reitzrun_qemu -drive "file=$TEST_IMG,format=raw,if=none,id=drive0" <<EOF
108*30bd6a4dSMax Reitz{ "execute": "qmp_capabilities" }
109*30bd6a4dSMax Reitz{ "execute": "blockdev-add",
110*30bd6a4dSMax Reitz    "arguments": {
111*30bd6a4dSMax Reitz        "options": {
112*30bd6a4dSMax Reitz            "driver": "$IMGFMT",
113*30bd6a4dSMax Reitz            "id": "drive0-debug",
114*30bd6a4dSMax Reitz            "file": {
115*30bd6a4dSMax Reitz                "driver": "blkdebug",
116*30bd6a4dSMax Reitz                "image": "drive0",
117*30bd6a4dSMax Reitz                "inject-error": [{
118*30bd6a4dSMax Reitz                    "event": "l2_load"
119*30bd6a4dSMax Reitz                }]
120*30bd6a4dSMax Reitz            }
121*30bd6a4dSMax Reitz        }
122*30bd6a4dSMax Reitz    }
123*30bd6a4dSMax Reitz}
124*30bd6a4dSMax Reitz{ "execute": "human-monitor-command",
125*30bd6a4dSMax Reitz    "arguments": {
126*30bd6a4dSMax Reitz        "command-line": 'qemu-io drive0-debug "read 0 512"'
127*30bd6a4dSMax Reitz    }
128*30bd6a4dSMax Reitz}
129*30bd6a4dSMax Reitz{ "execute": "quit" }
130*30bd6a4dSMax ReitzEOF
131*30bd6a4dSMax Reitz
132*30bd6a4dSMax Reitzecho
133*30bd6a4dSMax Reitzecho "=== Testing blkverify on existing block device ==="
134*30bd6a4dSMax Reitzecho
135*30bd6a4dSMax Reitz
136*30bd6a4dSMax Reitzrun_qemu -drive "file=$TEST_IMG,format=$IMGFMT,if=none,id=drive0" <<EOF
137*30bd6a4dSMax Reitz{ "execute": "qmp_capabilities" }
138*30bd6a4dSMax Reitz{ "execute": "blockdev-add",
139*30bd6a4dSMax Reitz    "arguments": {
140*30bd6a4dSMax Reitz        "options": {
141*30bd6a4dSMax Reitz            "driver": "blkverify",
142*30bd6a4dSMax Reitz            "id": "drive0-verify",
143*30bd6a4dSMax Reitz            "test": "drive0",
144*30bd6a4dSMax Reitz            "raw": {
145*30bd6a4dSMax Reitz                "driver": "raw",
146*30bd6a4dSMax Reitz                "file": {
147*30bd6a4dSMax Reitz                    "driver": "file",
148*30bd6a4dSMax Reitz                    "filename": "$TEST_IMG.base"
149*30bd6a4dSMax Reitz                }
150*30bd6a4dSMax Reitz            }
151*30bd6a4dSMax Reitz        }
152*30bd6a4dSMax Reitz    }
153*30bd6a4dSMax Reitz}
154*30bd6a4dSMax Reitz{ "execute": "human-monitor-command",
155*30bd6a4dSMax Reitz    "arguments": {
156*30bd6a4dSMax Reitz        "command-line": 'qemu-io drive0-verify "read 0 512"'
157*30bd6a4dSMax Reitz    }
158*30bd6a4dSMax Reitz}
159*30bd6a4dSMax Reitz{ "execute": "quit" }
160*30bd6a4dSMax ReitzEOF
161*30bd6a4dSMax Reitz
162*30bd6a4dSMax Reitzecho
163*30bd6a4dSMax Reitzecho "=== Testing blkverify on existing raw block device ==="
164*30bd6a4dSMax Reitzecho
165*30bd6a4dSMax Reitz
166*30bd6a4dSMax Reitzrun_qemu -drive "file=$TEST_IMG.base,if=none,id=drive0" <<EOF
167*30bd6a4dSMax Reitz{ "execute": "qmp_capabilities" }
168*30bd6a4dSMax Reitz{ "execute": "blockdev-add",
169*30bd6a4dSMax Reitz    "arguments": {
170*30bd6a4dSMax Reitz        "options": {
171*30bd6a4dSMax Reitz            "driver": "blkverify",
172*30bd6a4dSMax Reitz            "id": "drive0-verify",
173*30bd6a4dSMax Reitz            "test": {
174*30bd6a4dSMax Reitz                "driver": "$IMGFMT",
175*30bd6a4dSMax Reitz                "file": {
176*30bd6a4dSMax Reitz                    "driver": "file",
177*30bd6a4dSMax Reitz                    "filename": "$TEST_IMG"
178*30bd6a4dSMax Reitz                }
179*30bd6a4dSMax Reitz            },
180*30bd6a4dSMax Reitz            "raw": "drive0"
181*30bd6a4dSMax Reitz        }
182*30bd6a4dSMax Reitz    }
183*30bd6a4dSMax Reitz}
184*30bd6a4dSMax Reitz{ "execute": "human-monitor-command",
185*30bd6a4dSMax Reitz    "arguments": {
186*30bd6a4dSMax Reitz        "command-line": 'qemu-io drive0-verify "read 0 512"'
187*30bd6a4dSMax Reitz    }
188*30bd6a4dSMax Reitz}
189*30bd6a4dSMax Reitz{ "execute": "quit" }
190*30bd6a4dSMax ReitzEOF
191*30bd6a4dSMax Reitz
192*30bd6a4dSMax Reitzecho
193*30bd6a4dSMax Reitzecho "=== Testing blkdebug's set-state through QMP ==="
194*30bd6a4dSMax Reitzecho
195*30bd6a4dSMax Reitz
196*30bd6a4dSMax Reitzrun_qemu -drive "file=$TEST_IMG,format=raw,if=none,id=drive0" <<EOF
197*30bd6a4dSMax Reitz{ "execute": "qmp_capabilities" }
198*30bd6a4dSMax Reitz{ "execute": "blockdev-add",
199*30bd6a4dSMax Reitz    "arguments": {
200*30bd6a4dSMax Reitz        "options": {
201*30bd6a4dSMax Reitz            "driver": "$IMGFMT",
202*30bd6a4dSMax Reitz            "id": "drive0-debug",
203*30bd6a4dSMax Reitz            "file": {
204*30bd6a4dSMax Reitz                "driver": "blkdebug",
205*30bd6a4dSMax Reitz                "image": "drive0",
206*30bd6a4dSMax Reitz                "inject-error": [{
207*30bd6a4dSMax Reitz                    "event": "read_aio",
208*30bd6a4dSMax Reitz                    "state": 42
209*30bd6a4dSMax Reitz                }],
210*30bd6a4dSMax Reitz                "set-state": [{
211*30bd6a4dSMax Reitz                    "event": "write_aio",
212*30bd6a4dSMax Reitz                    "new_state": 42
213*30bd6a4dSMax Reitz                }]
214*30bd6a4dSMax Reitz            }
215*30bd6a4dSMax Reitz        }
216*30bd6a4dSMax Reitz    }
217*30bd6a4dSMax Reitz}
218*30bd6a4dSMax Reitz{ "execute": "human-monitor-command",
219*30bd6a4dSMax Reitz    "arguments": {
220*30bd6a4dSMax Reitz        "command-line": 'qemu-io drive0-debug "read 0 512"'
221*30bd6a4dSMax Reitz    }
222*30bd6a4dSMax Reitz}
223*30bd6a4dSMax Reitz{ "execute": "human-monitor-command",
224*30bd6a4dSMax Reitz    "arguments": {
225*30bd6a4dSMax Reitz        "command-line": 'qemu-io drive0-debug "write 0 512"'
226*30bd6a4dSMax Reitz    }
227*30bd6a4dSMax Reitz}
228*30bd6a4dSMax Reitz{ "execute": "human-monitor-command",
229*30bd6a4dSMax Reitz    "arguments": {
230*30bd6a4dSMax Reitz        "command-line": 'qemu-io drive0-debug "read 0 512"'
231*30bd6a4dSMax Reitz    }
232*30bd6a4dSMax Reitz}
233*30bd6a4dSMax Reitz{ "execute": "quit" }
234*30bd6a4dSMax ReitzEOF
235*30bd6a4dSMax Reitz
236*30bd6a4dSMax Reitz# success, all done
237*30bd6a4dSMax Reitzecho "*** done"
238*30bd6a4dSMax Reitzrm -f $seq.full
239*30bd6a4dSMax Reitzstatus=0
240