xref: /openbmc/qemu/tests/qemu-iotests/071 (revision 8e9e653038db97bfd343c3fb217b7bf4da765a89)
130bd6a4dSMax Reitz#!/bin/bash
230bd6a4dSMax Reitz#
330bd6a4dSMax Reitz# Test case for the QMP blkdebug and blkverify interfaces
430bd6a4dSMax Reitz#
530bd6a4dSMax Reitz# Copyright (C) 2013 Red Hat, Inc.
630bd6a4dSMax Reitz#
730bd6a4dSMax Reitz# This program is free software; you can redistribute it and/or modify
830bd6a4dSMax Reitz# it under the terms of the GNU General Public License as published by
930bd6a4dSMax Reitz# the Free Software Foundation; either version 2 of the License, or
1030bd6a4dSMax Reitz# (at your option) any later version.
1130bd6a4dSMax Reitz#
1230bd6a4dSMax Reitz# This program is distributed in the hope that it will be useful,
1330bd6a4dSMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
1430bd6a4dSMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1530bd6a4dSMax Reitz# GNU General Public License for more details.
1630bd6a4dSMax Reitz#
1730bd6a4dSMax Reitz# You should have received a copy of the GNU General Public License
1830bd6a4dSMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
1930bd6a4dSMax Reitz#
2030bd6a4dSMax Reitz
2130bd6a4dSMax Reitz# creator
2230bd6a4dSMax Reitzowner=mreitz@redhat.com
2330bd6a4dSMax Reitz
2430bd6a4dSMax Reitzseq="$(basename $0)"
2530bd6a4dSMax Reitzecho "QA output created by $seq"
2630bd6a4dSMax Reitz
2730bd6a4dSMax Reitzhere="$PWD"
2830bd6a4dSMax Reitztmp=/tmp/$$
2930bd6a4dSMax Reitzstatus=1	# failure is the default!
3030bd6a4dSMax Reitz
3130bd6a4dSMax Reitz_cleanup()
3230bd6a4dSMax Reitz{
3330bd6a4dSMax Reitz	_cleanup_test_img
3430bd6a4dSMax Reitz}
3530bd6a4dSMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
3630bd6a4dSMax Reitz
3730bd6a4dSMax Reitz# get standard environment, filters and checks
3830bd6a4dSMax Reitz. ./common.rc
3930bd6a4dSMax Reitz. ./common.filter
4030bd6a4dSMax Reitz
411b7650efSStefan Hajnoczi_supported_fmt qcow2
421f7bf7d0SPeter Lieven_supported_proto file
4330bd6a4dSMax Reitz_supported_os Linux
4430bd6a4dSMax Reitz
4530bd6a4dSMax Reitzfunction do_run_qemu()
4630bd6a4dSMax Reitz{
4730bd6a4dSMax Reitz    echo Testing: "$@" | _filter_imgfmt
4830bd6a4dSMax Reitz    $QEMU -nographic -qmp stdio -serial none "$@"
4930bd6a4dSMax Reitz    echo
5030bd6a4dSMax Reitz}
5130bd6a4dSMax Reitz
5230bd6a4dSMax Reitzfunction run_qemu()
5330bd6a4dSMax Reitz{
544dd7b8d3SMax Reitz    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp | _filter_qemu_io
5530bd6a4dSMax Reitz}
5630bd6a4dSMax Reitz
5730bd6a4dSMax ReitzIMG_SIZE=64M
5830bd6a4dSMax Reitz
5930bd6a4dSMax Reitzecho
6030bd6a4dSMax Reitzecho "=== Testing blkverify through filename ==="
6130bd6a4dSMax Reitzecho
6230bd6a4dSMax Reitz
6330bd6a4dSMax ReitzTEST_IMG="$TEST_IMG.base" IMGOPTS="" IMGFMT="raw" _make_test_img $IMG_SIZE |\
6430bd6a4dSMax Reitz    _filter_imgfmt
6530bd6a4dSMax Reitz_make_test_img $IMG_SIZE
668f9e835fSKevin Wolf$QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
6730bd6a4dSMax Reitz         -c 'read 0 512' -c 'write -P 42 0x38000 512' -c 'read -P 42 0x38000 512' | _filter_qemu_io
6830bd6a4dSMax Reitz
6930bd6a4dSMax Reitz$QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io
7030bd6a4dSMax Reitz
718f9e835fSKevin Wolf$QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
7230bd6a4dSMax Reitz         -c 'read -P 42 0 512' | _filter_qemu_io
7330bd6a4dSMax Reitz
7430bd6a4dSMax Reitzecho
7530bd6a4dSMax Reitzecho "=== Testing blkverify through file blockref ==="
7630bd6a4dSMax Reitzecho
7730bd6a4dSMax Reitz
7830bd6a4dSMax ReitzTEST_IMG="$TEST_IMG.base" IMGOPTS="" IMGFMT="raw" _make_test_img $IMG_SIZE |\
7930bd6a4dSMax Reitz    _filter_imgfmt
8030bd6a4dSMax Reitz_make_test_img $IMG_SIZE
818f9e835fSKevin Wolf$QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base,file.test.driver=$IMGFMT,file.test.file.filename=$TEST_IMG" \
8230bd6a4dSMax Reitz         -c 'read 0 512' -c 'write -P 42 0x38000 512' -c 'read -P 42 0x38000 512' | _filter_qemu_io
8330bd6a4dSMax Reitz
8430bd6a4dSMax Reitz$QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io
8530bd6a4dSMax Reitz
868f9e835fSKevin Wolf$QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
8730bd6a4dSMax Reitz         -c 'read -P 42 0 512' | _filter_qemu_io
8830bd6a4dSMax Reitz
8930bd6a4dSMax Reitzecho
9030bd6a4dSMax Reitzecho "=== Testing blkdebug through filename ==="
9130bd6a4dSMax Reitzecho
9230bd6a4dSMax Reitz
9330bd6a4dSMax Reitz$QEMU_IO -c "open -o file.driver=blkdebug,file.inject-error.event=l2_load $TEST_IMG" \
9430bd6a4dSMax Reitz         -c 'read -P 42 0x38000 512'
9530bd6a4dSMax Reitz
9630bd6a4dSMax Reitzecho
9730bd6a4dSMax Reitzecho "=== Testing blkdebug through file blockref ==="
9830bd6a4dSMax Reitzecho
9930bd6a4dSMax Reitz
10030bd6a4dSMax Reitz$QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.inject-error.event=l2_load,file.image.filename=$TEST_IMG" \
10130bd6a4dSMax Reitz         -c 'read -P 42 0x38000 512'
10230bd6a4dSMax Reitz
10330bd6a4dSMax Reitzecho
10430bd6a4dSMax Reitzecho "=== Testing blkdebug on existing block device ==="
10530bd6a4dSMax Reitzecho
10630bd6a4dSMax Reitz
107*8e9e6530SMax Reitzrun_qemu <<EOF
10830bd6a4dSMax Reitz{ "execute": "qmp_capabilities" }
10930bd6a4dSMax Reitz{ "execute": "blockdev-add",
11030bd6a4dSMax Reitz    "arguments": {
11130bd6a4dSMax Reitz        "options": {
112*8e9e6530SMax Reitz            "node-name": "drive0",
113*8e9e6530SMax Reitz            "driver": "file",
114*8e9e6530SMax Reitz            "filename": "$TEST_IMG"
115*8e9e6530SMax Reitz        }
116*8e9e6530SMax Reitz    }
117*8e9e6530SMax Reitz}
118*8e9e6530SMax Reitz{ "execute": "blockdev-add",
119*8e9e6530SMax Reitz    "arguments": {
120*8e9e6530SMax Reitz        "options": {
12130bd6a4dSMax Reitz            "driver": "$IMGFMT",
12230bd6a4dSMax Reitz            "id": "drive0-debug",
12330bd6a4dSMax Reitz            "file": {
12430bd6a4dSMax Reitz                "driver": "blkdebug",
12530bd6a4dSMax Reitz                "image": "drive0",
12630bd6a4dSMax Reitz                "inject-error": [{
12730bd6a4dSMax Reitz                    "event": "l2_load"
12830bd6a4dSMax Reitz                }]
12930bd6a4dSMax Reitz            }
13030bd6a4dSMax Reitz        }
13130bd6a4dSMax Reitz    }
13230bd6a4dSMax Reitz}
13330bd6a4dSMax Reitz{ "execute": "human-monitor-command",
13430bd6a4dSMax Reitz    "arguments": {
13530bd6a4dSMax Reitz        "command-line": 'qemu-io drive0-debug "read 0 512"'
13630bd6a4dSMax Reitz    }
13730bd6a4dSMax Reitz}
13830bd6a4dSMax Reitz{ "execute": "quit" }
13930bd6a4dSMax ReitzEOF
14030bd6a4dSMax Reitz
14130bd6a4dSMax Reitzecho
14230bd6a4dSMax Reitzecho "=== Testing blkverify on existing block device ==="
14330bd6a4dSMax Reitzecho
14430bd6a4dSMax Reitz
145*8e9e6530SMax Reitzrun_qemu <<EOF
14630bd6a4dSMax Reitz{ "execute": "qmp_capabilities" }
14730bd6a4dSMax Reitz{ "execute": "blockdev-add",
14830bd6a4dSMax Reitz    "arguments": {
14930bd6a4dSMax Reitz        "options": {
150*8e9e6530SMax Reitz            "node-name": "drive0",
151*8e9e6530SMax Reitz            "driver": "$IMGFMT",
152*8e9e6530SMax Reitz            "file": {
153*8e9e6530SMax Reitz                "driver": "file",
154*8e9e6530SMax Reitz                "filename": "$TEST_IMG"
155*8e9e6530SMax Reitz            }
156*8e9e6530SMax Reitz        }
157*8e9e6530SMax Reitz    }
158*8e9e6530SMax Reitz}
159*8e9e6530SMax Reitz{ "execute": "blockdev-add",
160*8e9e6530SMax Reitz    "arguments": {
161*8e9e6530SMax Reitz        "options": {
16230bd6a4dSMax Reitz            "driver": "blkverify",
16330bd6a4dSMax Reitz            "id": "drive0-verify",
16430bd6a4dSMax Reitz            "test": "drive0",
16530bd6a4dSMax Reitz            "raw": {
16630bd6a4dSMax Reitz                "driver": "file",
16730bd6a4dSMax Reitz                "filename": "$TEST_IMG.base"
16830bd6a4dSMax Reitz            }
16930bd6a4dSMax Reitz        }
17030bd6a4dSMax Reitz    }
17130bd6a4dSMax Reitz}
17230bd6a4dSMax Reitz{ "execute": "human-monitor-command",
17330bd6a4dSMax Reitz    "arguments": {
17430bd6a4dSMax Reitz        "command-line": 'qemu-io drive0-verify "read 0 512"'
17530bd6a4dSMax Reitz    }
17630bd6a4dSMax Reitz}
17730bd6a4dSMax Reitz{ "execute": "quit" }
17830bd6a4dSMax ReitzEOF
17930bd6a4dSMax Reitz
18030bd6a4dSMax Reitzecho
18130bd6a4dSMax Reitzecho "=== Testing blkverify on existing raw block device ==="
18230bd6a4dSMax Reitzecho
18330bd6a4dSMax Reitz
184*8e9e6530SMax Reitzrun_qemu <<EOF
18530bd6a4dSMax Reitz{ "execute": "qmp_capabilities" }
18630bd6a4dSMax Reitz{ "execute": "blockdev-add",
18730bd6a4dSMax Reitz    "arguments": {
18830bd6a4dSMax Reitz        "options": {
189*8e9e6530SMax Reitz            "node-name": "drive0",
190*8e9e6530SMax Reitz            "driver": "file",
191*8e9e6530SMax Reitz            "filename": "$TEST_IMG.base"
192*8e9e6530SMax Reitz        }
193*8e9e6530SMax Reitz    }
194*8e9e6530SMax Reitz}
195*8e9e6530SMax Reitz{ "execute": "blockdev-add",
196*8e9e6530SMax Reitz    "arguments": {
197*8e9e6530SMax Reitz        "options": {
19830bd6a4dSMax Reitz            "driver": "blkverify",
19930bd6a4dSMax Reitz            "id": "drive0-verify",
20030bd6a4dSMax Reitz            "test": {
20130bd6a4dSMax Reitz                "driver": "$IMGFMT",
20230bd6a4dSMax Reitz                "file": {
20330bd6a4dSMax Reitz                    "driver": "file",
20430bd6a4dSMax Reitz                    "filename": "$TEST_IMG"
20530bd6a4dSMax Reitz                }
20630bd6a4dSMax Reitz            },
20730bd6a4dSMax Reitz            "raw": "drive0"
20830bd6a4dSMax Reitz        }
20930bd6a4dSMax Reitz    }
21030bd6a4dSMax Reitz}
21130bd6a4dSMax Reitz{ "execute": "human-monitor-command",
21230bd6a4dSMax Reitz    "arguments": {
21330bd6a4dSMax Reitz        "command-line": 'qemu-io drive0-verify "read 0 512"'
21430bd6a4dSMax Reitz    }
21530bd6a4dSMax Reitz}
21630bd6a4dSMax Reitz{ "execute": "quit" }
21730bd6a4dSMax ReitzEOF
21830bd6a4dSMax Reitz
21930bd6a4dSMax Reitzecho
22030bd6a4dSMax Reitzecho "=== Testing blkdebug's set-state through QMP ==="
22130bd6a4dSMax Reitzecho
22230bd6a4dSMax Reitz
223*8e9e6530SMax Reitzrun_qemu <<EOF
22430bd6a4dSMax Reitz{ "execute": "qmp_capabilities" }
22530bd6a4dSMax Reitz{ "execute": "blockdev-add",
22630bd6a4dSMax Reitz    "arguments": {
22730bd6a4dSMax Reitz        "options": {
228*8e9e6530SMax Reitz            "node-name": "drive0",
229*8e9e6530SMax Reitz            "driver": "file",
230*8e9e6530SMax Reitz            "filename": "$TEST_IMG"
231*8e9e6530SMax Reitz        }
232*8e9e6530SMax Reitz    }
233*8e9e6530SMax Reitz}
234*8e9e6530SMax Reitz{ "execute": "blockdev-add",
235*8e9e6530SMax Reitz    "arguments": {
236*8e9e6530SMax Reitz        "options": {
23730bd6a4dSMax Reitz            "driver": "$IMGFMT",
23830bd6a4dSMax Reitz            "id": "drive0-debug",
23930bd6a4dSMax Reitz            "file": {
24030bd6a4dSMax Reitz                "driver": "blkdebug",
24130bd6a4dSMax Reitz                "image": "drive0",
24230bd6a4dSMax Reitz                "inject-error": [{
24330bd6a4dSMax Reitz                    "event": "read_aio",
24430bd6a4dSMax Reitz                    "state": 42
24530bd6a4dSMax Reitz                }],
24630bd6a4dSMax Reitz                "set-state": [{
24730bd6a4dSMax Reitz                    "event": "write_aio",
24830bd6a4dSMax Reitz                    "new_state": 42
24930bd6a4dSMax Reitz                }]
25030bd6a4dSMax Reitz            }
25130bd6a4dSMax Reitz        }
25230bd6a4dSMax Reitz    }
25330bd6a4dSMax Reitz}
25430bd6a4dSMax Reitz{ "execute": "human-monitor-command",
25530bd6a4dSMax Reitz    "arguments": {
25630bd6a4dSMax Reitz        "command-line": 'qemu-io drive0-debug "read 0 512"'
25730bd6a4dSMax Reitz    }
25830bd6a4dSMax Reitz}
25930bd6a4dSMax Reitz{ "execute": "human-monitor-command",
26030bd6a4dSMax Reitz    "arguments": {
26130bd6a4dSMax Reitz        "command-line": 'qemu-io drive0-debug "write 0 512"'
26230bd6a4dSMax Reitz    }
26330bd6a4dSMax Reitz}
26430bd6a4dSMax Reitz{ "execute": "human-monitor-command",
26530bd6a4dSMax Reitz    "arguments": {
26630bd6a4dSMax Reitz        "command-line": 'qemu-io drive0-debug "read 0 512"'
26730bd6a4dSMax Reitz    }
26830bd6a4dSMax Reitz}
26930bd6a4dSMax Reitz{ "execute": "quit" }
27030bd6a4dSMax ReitzEOF
27130bd6a4dSMax Reitz
27230bd6a4dSMax Reitz# success, all done
27330bd6a4dSMax Reitzecho "*** done"
27430bd6a4dSMax Reitzrm -f $seq.full
27530bd6a4dSMax Reitzstatus=0
276