xref: /openbmc/qemu/tests/qemu-iotests/071 (revision 3be2024aefe0024ada2fb5044c230c867ef59c67)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env 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 Reitzstatus=1	# failure is the default!
2830bd6a4dSMax Reitz
2930bd6a4dSMax Reitz_cleanup()
3030bd6a4dSMax Reitz{
3130bd6a4dSMax Reitz	_cleanup_test_img
3230bd6a4dSMax Reitz}
3330bd6a4dSMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
3430bd6a4dSMax Reitz
3530bd6a4dSMax Reitz# get standard environment, filters and checks
3630bd6a4dSMax Reitz. ./common.rc
3730bd6a4dSMax Reitz. ./common.filter
3830bd6a4dSMax Reitz
391b7650efSStefan Hajnoczi_supported_fmt qcow2
401f7bf7d0SPeter Lieven_supported_proto file
4121b43d00SThomas Huth_require_drivers blkdebug blkverify
42*3be2024aSMax Reitz# blkdebug can only inject errors on bs->file, not on the data_file,
43*3be2024aSMax Reitz# so thie test does not work with external data files
44*3be2024aSMax Reitz_unsupported_imgopts data_file
4530bd6a4dSMax Reitz
468cedcffdSEric Blakedo_run_qemu()
4730bd6a4dSMax Reitz{
4830bd6a4dSMax Reitz    echo Testing: "$@" | _filter_imgfmt
4930bd6a4dSMax Reitz    $QEMU -nographic -qmp stdio -serial none "$@"
5030bd6a4dSMax Reitz    echo
5130bd6a4dSMax Reitz}
5230bd6a4dSMax Reitz
538cedcffdSEric Blakerun_qemu()
5430bd6a4dSMax Reitz{
554dd7b8d3SMax Reitz    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp | _filter_qemu_io
5630bd6a4dSMax Reitz}
5730bd6a4dSMax Reitz
5830bd6a4dSMax ReitzIMG_SIZE=64M
5930bd6a4dSMax Reitz
6030bd6a4dSMax Reitzecho
6130bd6a4dSMax Reitzecho "=== Testing blkverify through filename ==="
6230bd6a4dSMax Reitzecho
6330bd6a4dSMax Reitz
6410b61256SMax ReitzTEST_IMG="$TEST_IMG.base" IMGFMT="raw" _make_test_img --no-opts $IMG_SIZE |\
6530bd6a4dSMax Reitz    _filter_imgfmt
6630bd6a4dSMax Reitz_make_test_img $IMG_SIZE
678f9e835fSKevin Wolf$QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
6830bd6a4dSMax Reitz         -c 'read 0 512' -c 'write -P 42 0x38000 512' -c 'read -P 42 0x38000 512' | _filter_qemu_io
6930bd6a4dSMax Reitz
7030bd6a4dSMax Reitz$QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io
7130bd6a4dSMax Reitz
728f9e835fSKevin Wolf$QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
7330bd6a4dSMax Reitz         -c 'read -P 42 0 512' | _filter_qemu_io
7430bd6a4dSMax Reitz
7530bd6a4dSMax Reitzecho
7630bd6a4dSMax Reitzecho "=== Testing blkverify through file blockref ==="
7730bd6a4dSMax Reitzecho
7830bd6a4dSMax Reitz
7910b61256SMax ReitzTEST_IMG="$TEST_IMG.base" IMGFMT="raw" _make_test_img --no-opts $IMG_SIZE |\
8030bd6a4dSMax Reitz    _filter_imgfmt
8130bd6a4dSMax Reitz_make_test_img $IMG_SIZE
828f9e835fSKevin 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" \
8330bd6a4dSMax Reitz         -c 'read 0 512' -c 'write -P 42 0x38000 512' -c 'read -P 42 0x38000 512' | _filter_qemu_io
8430bd6a4dSMax Reitz
8530bd6a4dSMax Reitz$QEMU_IO -c 'write -P 42 0 512' "$TEST_IMG" | _filter_qemu_io
8630bd6a4dSMax Reitz
878f9e835fSKevin Wolf$QEMU_IO -c "open -o driver=raw,file.driver=blkverify,file.raw.filename=$TEST_IMG.base $TEST_IMG" \
8830bd6a4dSMax Reitz         -c 'read -P 42 0 512' | _filter_qemu_io
8930bd6a4dSMax Reitz
9030bd6a4dSMax Reitzecho
9130bd6a4dSMax Reitzecho "=== Testing blkdebug through filename ==="
9230bd6a4dSMax Reitzecho
9330bd6a4dSMax Reitz
9430bd6a4dSMax Reitz$QEMU_IO -c "open -o file.driver=blkdebug,file.inject-error.event=l2_load $TEST_IMG" \
9530bd6a4dSMax Reitz         -c 'read -P 42 0x38000 512'
9630bd6a4dSMax Reitz
9730bd6a4dSMax Reitzecho
9830bd6a4dSMax Reitzecho "=== Testing blkdebug through file blockref ==="
9930bd6a4dSMax Reitzecho
10030bd6a4dSMax Reitz
10130bd6a4dSMax Reitz$QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.inject-error.event=l2_load,file.image.filename=$TEST_IMG" \
10230bd6a4dSMax Reitz         -c 'read -P 42 0x38000 512'
10330bd6a4dSMax Reitz
10430bd6a4dSMax Reitzecho
10530bd6a4dSMax Reitzecho "=== Testing blkdebug on existing block device ==="
10630bd6a4dSMax Reitzecho
10730bd6a4dSMax Reitz
1088e9e6530SMax Reitzrun_qemu <<EOF
10930bd6a4dSMax Reitz{ "execute": "qmp_capabilities" }
11030bd6a4dSMax Reitz{ "execute": "blockdev-add",
11130bd6a4dSMax Reitz    "arguments": {
1128e9e6530SMax Reitz        "node-name": "drive0",
1138e9e6530SMax Reitz        "driver": "file",
1148e9e6530SMax Reitz        "filename": "$TEST_IMG"
1158e9e6530SMax Reitz    }
1168e9e6530SMax Reitz}
1178e9e6530SMax Reitz{ "execute": "blockdev-add",
1188e9e6530SMax Reitz    "arguments": {
11930bd6a4dSMax Reitz        "driver": "$IMGFMT",
120ffec99f7SKevin Wolf        "node-name": "drive0-debug",
12130bd6a4dSMax Reitz        "file": {
12230bd6a4dSMax Reitz            "driver": "blkdebug",
12330bd6a4dSMax Reitz            "image": "drive0",
12430bd6a4dSMax Reitz            "inject-error": [{
12530bd6a4dSMax Reitz                "event": "l2_load"
12630bd6a4dSMax Reitz            }]
12730bd6a4dSMax Reitz        }
12830bd6a4dSMax Reitz    }
12930bd6a4dSMax Reitz}
13030bd6a4dSMax Reitz{ "execute": "human-monitor-command",
13130bd6a4dSMax Reitz    "arguments": {
13230bd6a4dSMax Reitz        "command-line": 'qemu-io drive0-debug "read 0 512"'
13330bd6a4dSMax Reitz    }
13430bd6a4dSMax Reitz}
13530bd6a4dSMax Reitz{ "execute": "quit" }
13630bd6a4dSMax ReitzEOF
13730bd6a4dSMax Reitz
13830bd6a4dSMax Reitzecho
13930bd6a4dSMax Reitzecho "=== Testing blkverify on existing block device ==="
14030bd6a4dSMax Reitzecho
14130bd6a4dSMax Reitz
1428e9e6530SMax Reitzrun_qemu <<EOF
14330bd6a4dSMax Reitz{ "execute": "qmp_capabilities" }
14430bd6a4dSMax Reitz{ "execute": "blockdev-add",
14530bd6a4dSMax Reitz    "arguments": {
1468e9e6530SMax Reitz        "node-name": "drive0",
1478e9e6530SMax Reitz        "driver": "$IMGFMT",
1488e9e6530SMax Reitz        "file": {
1498e9e6530SMax Reitz            "driver": "file",
1508e9e6530SMax Reitz            "filename": "$TEST_IMG"
1518e9e6530SMax Reitz        }
1528e9e6530SMax Reitz    }
1538e9e6530SMax Reitz}
1548e9e6530SMax Reitz{ "execute": "blockdev-add",
1558e9e6530SMax Reitz    "arguments": {
15630bd6a4dSMax Reitz        "driver": "blkverify",
157ffec99f7SKevin Wolf        "node-name": "drive0-verify",
15830bd6a4dSMax Reitz        "test": "drive0",
15930bd6a4dSMax Reitz        "raw": {
16030bd6a4dSMax Reitz            "driver": "file",
16130bd6a4dSMax Reitz            "filename": "$TEST_IMG.base"
16230bd6a4dSMax Reitz        }
16330bd6a4dSMax Reitz    }
16430bd6a4dSMax Reitz}
16530bd6a4dSMax Reitz{ "execute": "human-monitor-command",
16630bd6a4dSMax Reitz    "arguments": {
16730bd6a4dSMax Reitz        "command-line": 'qemu-io drive0-verify "read 0 512"'
16830bd6a4dSMax Reitz    }
16930bd6a4dSMax Reitz}
17030bd6a4dSMax Reitz{ "execute": "quit" }
17130bd6a4dSMax ReitzEOF
17230bd6a4dSMax Reitz
17330bd6a4dSMax Reitzecho
17430bd6a4dSMax Reitzecho "=== Testing blkverify on existing raw block device ==="
17530bd6a4dSMax Reitzecho
17630bd6a4dSMax Reitz
1778e9e6530SMax Reitzrun_qemu <<EOF
17830bd6a4dSMax Reitz{ "execute": "qmp_capabilities" }
17930bd6a4dSMax Reitz{ "execute": "blockdev-add",
18030bd6a4dSMax Reitz    "arguments": {
1818e9e6530SMax Reitz        "node-name": "drive0",
1828e9e6530SMax Reitz        "driver": "file",
1838e9e6530SMax Reitz        "filename": "$TEST_IMG.base"
1848e9e6530SMax Reitz    }
1858e9e6530SMax Reitz}
1868e9e6530SMax Reitz{ "execute": "blockdev-add",
1878e9e6530SMax Reitz    "arguments": {
18830bd6a4dSMax Reitz        "driver": "blkverify",
189ffec99f7SKevin Wolf        "node-name": "drive0-verify",
19030bd6a4dSMax Reitz        "test": {
19130bd6a4dSMax Reitz            "driver": "$IMGFMT",
19230bd6a4dSMax Reitz            "file": {
19330bd6a4dSMax Reitz                "driver": "file",
19430bd6a4dSMax Reitz                "filename": "$TEST_IMG"
19530bd6a4dSMax Reitz            }
19630bd6a4dSMax Reitz        },
19730bd6a4dSMax Reitz        "raw": "drive0"
19830bd6a4dSMax Reitz    }
19930bd6a4dSMax Reitz}
20030bd6a4dSMax Reitz{ "execute": "human-monitor-command",
20130bd6a4dSMax Reitz    "arguments": {
20230bd6a4dSMax Reitz        "command-line": 'qemu-io drive0-verify "read 0 512"'
20330bd6a4dSMax Reitz    }
20430bd6a4dSMax Reitz}
20530bd6a4dSMax Reitz{ "execute": "quit" }
20630bd6a4dSMax ReitzEOF
20730bd6a4dSMax Reitz
20830bd6a4dSMax Reitzecho
20930bd6a4dSMax Reitzecho "=== Testing blkdebug's set-state through QMP ==="
21030bd6a4dSMax Reitzecho
21130bd6a4dSMax Reitz
2128e9e6530SMax Reitzrun_qemu <<EOF
21330bd6a4dSMax Reitz{ "execute": "qmp_capabilities" }
21430bd6a4dSMax Reitz{ "execute": "blockdev-add",
21530bd6a4dSMax Reitz    "arguments": {
2168e9e6530SMax Reitz        "node-name": "drive0",
2178e9e6530SMax Reitz        "driver": "file",
2188e9e6530SMax Reitz        "filename": "$TEST_IMG"
2198e9e6530SMax Reitz    }
2208e9e6530SMax Reitz}
2218e9e6530SMax Reitz{ "execute": "blockdev-add",
2228e9e6530SMax Reitz    "arguments": {
22330bd6a4dSMax Reitz        "driver": "$IMGFMT",
224ffec99f7SKevin Wolf        "node-name": "drive0-debug",
22530bd6a4dSMax Reitz        "file": {
22630bd6a4dSMax Reitz            "driver": "blkdebug",
22730bd6a4dSMax Reitz            "image": "drive0",
22830bd6a4dSMax Reitz            "inject-error": [{
22930bd6a4dSMax Reitz                "event": "read_aio",
23030bd6a4dSMax Reitz                "state": 42
23130bd6a4dSMax Reitz            }],
23230bd6a4dSMax Reitz            "set-state": [{
23330bd6a4dSMax Reitz                "event": "write_aio",
23430bd6a4dSMax Reitz                "new_state": 42
23530bd6a4dSMax Reitz            }]
23630bd6a4dSMax Reitz        }
23730bd6a4dSMax Reitz    }
23830bd6a4dSMax Reitz}
23930bd6a4dSMax Reitz{ "execute": "human-monitor-command",
24030bd6a4dSMax Reitz    "arguments": {
24130bd6a4dSMax Reitz        "command-line": 'qemu-io drive0-debug "read 0 512"'
24230bd6a4dSMax Reitz    }
24330bd6a4dSMax Reitz}
24430bd6a4dSMax Reitz{ "execute": "human-monitor-command",
24530bd6a4dSMax Reitz    "arguments": {
24630bd6a4dSMax Reitz        "command-line": 'qemu-io drive0-debug "write 0 512"'
24730bd6a4dSMax Reitz    }
24830bd6a4dSMax Reitz}
24930bd6a4dSMax Reitz{ "execute": "human-monitor-command",
25030bd6a4dSMax Reitz    "arguments": {
25130bd6a4dSMax Reitz        "command-line": 'qemu-io drive0-debug "read 0 512"'
25230bd6a4dSMax Reitz    }
25330bd6a4dSMax Reitz}
25430bd6a4dSMax Reitz{ "execute": "quit" }
25530bd6a4dSMax ReitzEOF
25630bd6a4dSMax Reitz
25730bd6a4dSMax Reitz# success, all done
25830bd6a4dSMax Reitzecho "*** done"
25930bd6a4dSMax Reitzrm -f $seq.full
26030bd6a4dSMax Reitzstatus=0
261