xref: /openbmc/qemu/tests/qemu-iotests/071 (revision 96420a30)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
29dd003a9SVladimir Sementsov-Ogievskiy# group: rw auto quick
330bd6a4dSMax Reitz#
430bd6a4dSMax Reitz# Test case for the QMP blkdebug and blkverify interfaces
530bd6a4dSMax Reitz#
630bd6a4dSMax Reitz# Copyright (C) 2013 Red Hat, Inc.
730bd6a4dSMax Reitz#
830bd6a4dSMax Reitz# This program is free software; you can redistribute it and/or modify
930bd6a4dSMax Reitz# it under the terms of the GNU General Public License as published by
1030bd6a4dSMax Reitz# the Free Software Foundation; either version 2 of the License, or
1130bd6a4dSMax Reitz# (at your option) any later version.
1230bd6a4dSMax Reitz#
1330bd6a4dSMax Reitz# This program is distributed in the hope that it will be useful,
1430bd6a4dSMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
1530bd6a4dSMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1630bd6a4dSMax Reitz# GNU General Public License for more details.
1730bd6a4dSMax Reitz#
1830bd6a4dSMax Reitz# You should have received a copy of the GNU General Public License
1930bd6a4dSMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
2030bd6a4dSMax Reitz#
2130bd6a4dSMax Reitz
2230bd6a4dSMax Reitz# creator
2342a5009dSJohn Snowowner=hreitz@redhat.com
2430bd6a4dSMax Reitz
2530bd6a4dSMax Reitzseq="$(basename $0)"
2630bd6a4dSMax Reitzecho "QA output created by $seq"
2730bd6a4dSMax Reitz
2830bd6a4dSMax Reitzstatus=1	# failure is the default!
2930bd6a4dSMax Reitz
3030bd6a4dSMax Reitz_cleanup()
3130bd6a4dSMax Reitz{
3230bd6a4dSMax Reitz	_cleanup_test_img
3330bd6a4dSMax Reitz}
3430bd6a4dSMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
3530bd6a4dSMax Reitz
3630bd6a4dSMax Reitz# get standard environment, filters and checks
3730bd6a4dSMax Reitz. ./common.rc
3830bd6a4dSMax Reitz. ./common.filter
3930bd6a4dSMax Reitz
401b7650efSStefan Hajnoczi_supported_fmt qcow2
4157284d2aSMax Reitz_supported_proto file fuse
4221b43d00SThomas Huth_require_drivers blkdebug blkverify
433be2024aSMax Reitz# blkdebug can only inject errors on bs->file, not on the data_file,
44*96420a30SMichael Tokarev# so this test does not work with external data files
453be2024aSMax Reitz_unsupported_imgopts data_file
4630bd6a4dSMax Reitz
478cedcffdSEric Blakedo_run_qemu()
4830bd6a4dSMax Reitz{
4930bd6a4dSMax Reitz    echo Testing: "$@" | _filter_imgfmt
5030bd6a4dSMax Reitz    $QEMU -nographic -qmp stdio -serial none "$@"
5130bd6a4dSMax Reitz    echo
5230bd6a4dSMax Reitz}
5330bd6a4dSMax Reitz
548cedcffdSEric Blakerun_qemu()
5530bd6a4dSMax Reitz{
564dd7b8d3SMax Reitz    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp | _filter_qemu_io
5730bd6a4dSMax Reitz}
5830bd6a4dSMax Reitz
5930bd6a4dSMax ReitzIMG_SIZE=64M
6030bd6a4dSMax Reitz
6130bd6a4dSMax Reitzecho
6230bd6a4dSMax Reitzecho "=== Testing blkverify through filename ==="
6330bd6a4dSMax Reitzecho
6430bd6a4dSMax Reitz
65d81fe252SMax Reitz# _make_test_img may set variables that we need to retain.  Everything
66d81fe252SMax Reitz# in a pipe is executed in a subshell, so doing so would throw away
67d81fe252SMax Reitz# all changes.  Therefore, we have to store the output in some temp
68d81fe252SMax Reitz# file and filter that.
69d81fe252SMax Reitzscratch_out="$TEST_DIR/img-create.out"
70d81fe252SMax Reitz
71d81fe252SMax ReitzTEST_IMG="$TEST_IMG.base" IMGFMT="raw" _make_test_img --no-opts $IMG_SIZE \
72d81fe252SMax Reitz    >"$scratch_out"
73d81fe252SMax Reitz_filter_imgfmt <"$scratch_out"
74d81fe252SMax Reitzrm -f "$scratch_out"
75d81fe252SMax Reitz
7630bd6a4dSMax Reitz_make_test_img $IMG_SIZE
778f9e835fSKevin Wolf$QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
7830bd6a4dSMax Reitz         -c 'read 0 512' -c 'write -P 42 0x38000 512' -c 'read -P 42 0x38000 512' | _filter_qemu_io
7930bd6a4dSMax Reitz
8030bd6a4dSMax Reitz$QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io
8130bd6a4dSMax Reitz
828f9e835fSKevin Wolf$QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
8330bd6a4dSMax Reitz         -c 'read -P 42 0 512' | _filter_qemu_io
8430bd6a4dSMax Reitz
8530bd6a4dSMax Reitzecho
8630bd6a4dSMax Reitzecho "=== Testing blkverify through file blockref ==="
8730bd6a4dSMax Reitzecho
8830bd6a4dSMax Reitz
89d81fe252SMax ReitzTEST_IMG="$TEST_IMG.base" IMGFMT="raw" _make_test_img --no-opts $IMG_SIZE \
90d81fe252SMax Reitz    >"$scratch_out"
91d81fe252SMax Reitz_filter_imgfmt <"$scratch_out"
92d81fe252SMax Reitz
9330bd6a4dSMax Reitz_make_test_img $IMG_SIZE
948f9e835fSKevin 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" \
9530bd6a4dSMax Reitz         -c 'read 0 512' -c 'write -P 42 0x38000 512' -c 'read -P 42 0x38000 512' | _filter_qemu_io
9630bd6a4dSMax Reitz
9730bd6a4dSMax Reitz$QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io
9830bd6a4dSMax Reitz
998f9e835fSKevin Wolf$QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
10030bd6a4dSMax Reitz         -c 'read -P 42 0 512' | _filter_qemu_io
10130bd6a4dSMax Reitz
10230bd6a4dSMax Reitzecho
10330bd6a4dSMax Reitzecho "=== Testing blkdebug through filename ==="
10430bd6a4dSMax Reitzecho
10530bd6a4dSMax Reitz
10630bd6a4dSMax Reitz$QEMU_IO -c "open -o file.driver=blkdebug,file.inject-error.event=l2_load $TEST_IMG" \
10730bd6a4dSMax Reitz         -c 'read -P 42 0x38000 512'
10830bd6a4dSMax Reitz
10930bd6a4dSMax Reitzecho
11030bd6a4dSMax Reitzecho "=== Testing blkdebug through file blockref ==="
11130bd6a4dSMax Reitzecho
11230bd6a4dSMax Reitz
11330bd6a4dSMax Reitz$QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.inject-error.event=l2_load,file.image.filename=$TEST_IMG" \
11430bd6a4dSMax Reitz         -c 'read -P 42 0x38000 512'
11530bd6a4dSMax Reitz
11630bd6a4dSMax Reitzecho
11730bd6a4dSMax Reitzecho "=== Testing blkdebug on existing block device ==="
11830bd6a4dSMax Reitzecho
11930bd6a4dSMax Reitz
1208e9e6530SMax Reitzrun_qemu <<EOF
12130bd6a4dSMax Reitz{ "execute": "qmp_capabilities" }
12230bd6a4dSMax Reitz{ "execute": "blockdev-add",
12330bd6a4dSMax Reitz    "arguments": {
1248e9e6530SMax Reitz        "node-name": "drive0",
1258e9e6530SMax Reitz        "driver": "file",
1268e9e6530SMax Reitz        "filename": "$TEST_IMG"
1278e9e6530SMax Reitz    }
1288e9e6530SMax Reitz}
1298e9e6530SMax Reitz{ "execute": "blockdev-add",
1308e9e6530SMax Reitz    "arguments": {
13130bd6a4dSMax Reitz        "driver": "$IMGFMT",
132ffec99f7SKevin Wolf        "node-name": "drive0-debug",
13330bd6a4dSMax Reitz        "file": {
13430bd6a4dSMax Reitz            "driver": "blkdebug",
13530bd6a4dSMax Reitz            "image": "drive0",
13630bd6a4dSMax Reitz            "inject-error": [{
13730bd6a4dSMax Reitz                "event": "l2_load"
13830bd6a4dSMax Reitz            }]
13930bd6a4dSMax Reitz        }
14030bd6a4dSMax Reitz    }
14130bd6a4dSMax Reitz}
14230bd6a4dSMax Reitz{ "execute": "human-monitor-command",
14330bd6a4dSMax Reitz    "arguments": {
14430bd6a4dSMax Reitz        "command-line": 'qemu-io drive0-debug "read 0 512"'
14530bd6a4dSMax Reitz    }
14630bd6a4dSMax Reitz}
14730bd6a4dSMax Reitz{ "execute": "quit" }
14830bd6a4dSMax ReitzEOF
14930bd6a4dSMax Reitz
15030bd6a4dSMax Reitzecho
15130bd6a4dSMax Reitzecho "=== Testing blkverify on existing block device ==="
15230bd6a4dSMax Reitzecho
15330bd6a4dSMax Reitz
1548e9e6530SMax Reitzrun_qemu <<EOF
15530bd6a4dSMax Reitz{ "execute": "qmp_capabilities" }
15630bd6a4dSMax Reitz{ "execute": "blockdev-add",
15730bd6a4dSMax Reitz    "arguments": {
1588e9e6530SMax Reitz        "node-name": "drive0",
1598e9e6530SMax Reitz        "driver": "$IMGFMT",
1608e9e6530SMax Reitz        "file": {
1618e9e6530SMax Reitz            "driver": "file",
1628e9e6530SMax Reitz            "filename": "$TEST_IMG"
1638e9e6530SMax Reitz        }
1648e9e6530SMax Reitz    }
1658e9e6530SMax Reitz}
1668e9e6530SMax Reitz{ "execute": "blockdev-add",
1678e9e6530SMax Reitz    "arguments": {
16830bd6a4dSMax Reitz        "driver": "blkverify",
169ffec99f7SKevin Wolf        "node-name": "drive0-verify",
17030bd6a4dSMax Reitz        "test": "drive0",
17130bd6a4dSMax Reitz        "raw": {
17230bd6a4dSMax Reitz            "driver": "file",
17330bd6a4dSMax Reitz            "filename": "$TEST_IMG.base"
17430bd6a4dSMax Reitz        }
17530bd6a4dSMax Reitz    }
17630bd6a4dSMax Reitz}
17730bd6a4dSMax Reitz{ "execute": "human-monitor-command",
17830bd6a4dSMax Reitz    "arguments": {
17930bd6a4dSMax Reitz        "command-line": 'qemu-io drive0-verify "read 0 512"'
18030bd6a4dSMax Reitz    }
18130bd6a4dSMax Reitz}
18230bd6a4dSMax Reitz{ "execute": "quit" }
18330bd6a4dSMax ReitzEOF
18430bd6a4dSMax Reitz
18530bd6a4dSMax Reitzecho
18630bd6a4dSMax Reitzecho "=== Testing blkverify on existing raw block device ==="
18730bd6a4dSMax Reitzecho
18830bd6a4dSMax Reitz
1898e9e6530SMax Reitzrun_qemu <<EOF
19030bd6a4dSMax Reitz{ "execute": "qmp_capabilities" }
19130bd6a4dSMax Reitz{ "execute": "blockdev-add",
19230bd6a4dSMax Reitz    "arguments": {
1938e9e6530SMax Reitz        "node-name": "drive0",
1948e9e6530SMax Reitz        "driver": "file",
1958e9e6530SMax Reitz        "filename": "$TEST_IMG.base"
1968e9e6530SMax Reitz    }
1978e9e6530SMax Reitz}
1988e9e6530SMax Reitz{ "execute": "blockdev-add",
1998e9e6530SMax Reitz    "arguments": {
20030bd6a4dSMax Reitz        "driver": "blkverify",
201ffec99f7SKevin Wolf        "node-name": "drive0-verify",
20230bd6a4dSMax Reitz        "test": {
20330bd6a4dSMax Reitz            "driver": "$IMGFMT",
20430bd6a4dSMax Reitz            "file": {
20530bd6a4dSMax Reitz                "driver": "file",
20630bd6a4dSMax Reitz                "filename": "$TEST_IMG"
20730bd6a4dSMax Reitz            }
20830bd6a4dSMax Reitz        },
20930bd6a4dSMax Reitz        "raw": "drive0"
21030bd6a4dSMax Reitz    }
21130bd6a4dSMax Reitz}
21230bd6a4dSMax Reitz{ "execute": "human-monitor-command",
21330bd6a4dSMax Reitz    "arguments": {
21430bd6a4dSMax Reitz        "command-line": 'qemu-io drive0-verify "read 0 512"'
21530bd6a4dSMax Reitz    }
21630bd6a4dSMax Reitz}
21730bd6a4dSMax Reitz{ "execute": "quit" }
21830bd6a4dSMax ReitzEOF
21930bd6a4dSMax Reitz
22030bd6a4dSMax Reitzecho
22130bd6a4dSMax Reitzecho "=== Testing blkdebug's set-state through QMP ==="
22230bd6a4dSMax Reitzecho
22330bd6a4dSMax Reitz
2248e9e6530SMax Reitzrun_qemu <<EOF
22530bd6a4dSMax Reitz{ "execute": "qmp_capabilities" }
22630bd6a4dSMax Reitz{ "execute": "blockdev-add",
22730bd6a4dSMax Reitz    "arguments": {
2288e9e6530SMax Reitz        "node-name": "drive0",
2298e9e6530SMax Reitz        "driver": "file",
2308e9e6530SMax Reitz        "filename": "$TEST_IMG"
2318e9e6530SMax Reitz    }
2328e9e6530SMax Reitz}
2338e9e6530SMax Reitz{ "execute": "blockdev-add",
2348e9e6530SMax Reitz    "arguments": {
23530bd6a4dSMax Reitz        "driver": "$IMGFMT",
236ffec99f7SKevin Wolf        "node-name": "drive0-debug",
23730bd6a4dSMax Reitz        "file": {
23830bd6a4dSMax Reitz            "driver": "blkdebug",
23930bd6a4dSMax Reitz            "image": "drive0",
24030bd6a4dSMax Reitz            "inject-error": [{
24130bd6a4dSMax Reitz                "event": "read_aio",
24230bd6a4dSMax Reitz                "state": 42
24330bd6a4dSMax Reitz            }],
24430bd6a4dSMax Reitz            "set-state": [{
24530bd6a4dSMax Reitz                "event": "write_aio",
24630bd6a4dSMax Reitz                "new_state": 42
24730bd6a4dSMax Reitz            }]
24830bd6a4dSMax Reitz        }
24930bd6a4dSMax Reitz    }
25030bd6a4dSMax Reitz}
25130bd6a4dSMax Reitz{ "execute": "human-monitor-command",
25230bd6a4dSMax Reitz    "arguments": {
25330bd6a4dSMax Reitz        "command-line": 'qemu-io drive0-debug "read 0 512"'
25430bd6a4dSMax Reitz    }
25530bd6a4dSMax Reitz}
25630bd6a4dSMax Reitz{ "execute": "human-monitor-command",
25730bd6a4dSMax Reitz    "arguments": {
25830bd6a4dSMax Reitz        "command-line": 'qemu-io drive0-debug "write 0 512"'
25930bd6a4dSMax Reitz    }
26030bd6a4dSMax Reitz}
26130bd6a4dSMax Reitz{ "execute": "human-monitor-command",
26230bd6a4dSMax Reitz    "arguments": {
26330bd6a4dSMax Reitz        "command-line": 'qemu-io drive0-debug "read 0 512"'
26430bd6a4dSMax Reitz    }
26530bd6a4dSMax Reitz}
26630bd6a4dSMax Reitz{ "execute": "quit" }
26730bd6a4dSMax ReitzEOF
26830bd6a4dSMax Reitz
26930bd6a4dSMax Reitz# success, all done
27030bd6a4dSMax Reitzecho "*** done"
27130bd6a4dSMax Reitzrm -f $seq.full
27230bd6a4dSMax Reitzstatus=0
273