xref: /qemu/tests/qemu-iotests/081 (revision 6141f3bd6904df7cf9519c6444a14a608b9874c4)
1c7fc5bc2SBenoît Canet#!/bin/bash
2c7fc5bc2SBenoît Canet#
3c7fc5bc2SBenoît Canet# Test Quorum block driver
4c7fc5bc2SBenoît Canet#
5c7fc5bc2SBenoît Canet# Copyright (C) 2013 Nodalink, SARL.
6c7fc5bc2SBenoît Canet#
7c7fc5bc2SBenoît Canet# This program is free software; you can redistribute it and/or modify
8c7fc5bc2SBenoît Canet# it under the terms of the GNU General Public License as published by
9c7fc5bc2SBenoît Canet# the Free Software Foundation; either version 2 of the License, or
10c7fc5bc2SBenoît Canet# (at your option) any later version.
11c7fc5bc2SBenoît Canet#
12c7fc5bc2SBenoît Canet# This program is distributed in the hope that it will be useful,
13c7fc5bc2SBenoît Canet# but WITHOUT ANY WARRANTY; without even the implied warranty of
14c7fc5bc2SBenoît Canet# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15c7fc5bc2SBenoît Canet# GNU General Public License for more details.
16c7fc5bc2SBenoît Canet#
17c7fc5bc2SBenoît Canet# You should have received a copy of the GNU General Public License
18c7fc5bc2SBenoît Canet# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19c7fc5bc2SBenoît Canet#
20c7fc5bc2SBenoît Canet
21c7fc5bc2SBenoît Canet# creator
22c7fc5bc2SBenoît Canetowner=benoit@irqsave.net
23c7fc5bc2SBenoît Canet
24c7fc5bc2SBenoît Canetseq=`basename $0`
25c7fc5bc2SBenoît Canetecho "QA output created by $seq"
26c7fc5bc2SBenoît Canet
27c7fc5bc2SBenoît Canethere=`pwd`
28c7fc5bc2SBenoît Canettmp=/tmp/$$
29c7fc5bc2SBenoît Canetstatus=1	# failure is the default!
30c7fc5bc2SBenoît Canet
31c7fc5bc2SBenoît Canet_cleanup()
32c7fc5bc2SBenoît Canet{
33c7fc5bc2SBenoît Canet    rm -rf $TEST_DIR/1.raw
34c7fc5bc2SBenoît Canet    rm -rf $TEST_DIR/2.raw
35c7fc5bc2SBenoît Canet    rm -rf $TEST_DIR/3.raw
36c7fc5bc2SBenoît Canet}
37c7fc5bc2SBenoît Canettrap "_cleanup; exit \$status" 0 1 2 3 15
38c7fc5bc2SBenoît Canet
39c7fc5bc2SBenoît Canet# get standard environment, filters and checks
40c7fc5bc2SBenoît Canet. ./common.rc
41c7fc5bc2SBenoît Canet. ./common.filter
42c7fc5bc2SBenoît Canet
43c7fc5bc2SBenoît Canet_supported_fmt raw
44c7fc5bc2SBenoît Canet_supported_proto generic
45c7fc5bc2SBenoît Canet_supported_os Linux
46c7fc5bc2SBenoît Canet
47*6141f3bdSMax Reitzfunction do_run_qemu()
48*6141f3bdSMax Reitz{
49*6141f3bdSMax Reitz    echo Testing: "$@" | _filter_imgfmt
50*6141f3bdSMax Reitz    $QEMU -nographic -qmp stdio -serial none "$@"
51*6141f3bdSMax Reitz    echo
52*6141f3bdSMax Reitz}
53*6141f3bdSMax Reitz
54*6141f3bdSMax Reitzfunction run_qemu()
55*6141f3bdSMax Reitz{
56*6141f3bdSMax Reitz    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp | _filter_qemu_io
57*6141f3bdSMax Reitz}
58*6141f3bdSMax Reitz
59c7fc5bc2SBenoît Canetquorum="file.driver=quorum,file.children.0.file.filename=$TEST_DIR/1.raw"
60c7fc5bc2SBenoît Canetquorum="$quorum,file.children.1.file.filename=$TEST_DIR/2.raw"
61c7fc5bc2SBenoît Canetquorum="$quorum,file.children.2.file.filename=$TEST_DIR/3.raw,file.vote-threshold=2"
62c7fc5bc2SBenoît Canet
63c7fc5bc2SBenoît Canetecho
64c7fc5bc2SBenoît Canetecho "== creating quorum files =="
65c7fc5bc2SBenoît Canet
66c7fc5bc2SBenoît Canetsize=10M
67c7fc5bc2SBenoît Canet
68c7fc5bc2SBenoît CanetTEST_IMG="$TEST_DIR/1.raw" _make_test_img $size
69c7fc5bc2SBenoît CanetTEST_IMG="$TEST_DIR/2.raw" _make_test_img $size
70c7fc5bc2SBenoît CanetTEST_IMG="$TEST_DIR/3.raw" _make_test_img $size
71c7fc5bc2SBenoît Canet
72c7fc5bc2SBenoît Canetecho
73c7fc5bc2SBenoît Canetecho "== writing images =="
74c7fc5bc2SBenoît Canet
75c7fc5bc2SBenoît Canet$QEMU_IO -c "open -o $quorum" -c "write -P 0x32 0 $size" | _filter_qemu_io
76c7fc5bc2SBenoît Canet
77c7fc5bc2SBenoît Canetecho
78c7fc5bc2SBenoît Canetecho "== checking quorum write =="
79c7fc5bc2SBenoît Canet
80c7fc5bc2SBenoît Canet$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/1.raw" | _filter_qemu_io
81c7fc5bc2SBenoît Canet$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io
82c7fc5bc2SBenoît Canet$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/3.raw" | _filter_qemu_io
83c7fc5bc2SBenoît Canet
84c7fc5bc2SBenoît Canetecho
85c7fc5bc2SBenoît Canetecho "== corrupting image =="
86c7fc5bc2SBenoît Canet
87c7fc5bc2SBenoît Canet$QEMU_IO -c "write -P 0x42 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io
88c7fc5bc2SBenoît Canet
89c7fc5bc2SBenoît Canetecho
90c7fc5bc2SBenoît Canetecho "== checking quorum correction =="
91c7fc5bc2SBenoît Canet
92c7fc5bc2SBenoît Canet$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io
93c7fc5bc2SBenoît Canet
94c7fc5bc2SBenoît Canetecho
95*6141f3bdSMax Reitzecho "== checking mixed reference/option specification =="
96*6141f3bdSMax Reitz
97*6141f3bdSMax Reitzrun_qemu -drive "file=$TEST_DIR/2.raw,format=$IMGFMT,if=none,id=drive2" <<EOF
98*6141f3bdSMax Reitz{ "execute": "qmp_capabilities" }
99*6141f3bdSMax Reitz{ "execute": "blockdev-add",
100*6141f3bdSMax Reitz    "arguments": {
101*6141f3bdSMax Reitz        "options": {
102*6141f3bdSMax Reitz            "driver": "quorum",
103*6141f3bdSMax Reitz            "id": "drive0-quorum",
104*6141f3bdSMax Reitz            "vote-threshold": 2,
105*6141f3bdSMax Reitz            "children": [
106*6141f3bdSMax Reitz                {
107*6141f3bdSMax Reitz                    "driver": "raw",
108*6141f3bdSMax Reitz                    "file": {
109*6141f3bdSMax Reitz                        "driver": "file",
110*6141f3bdSMax Reitz                        "filename": "$TEST_DIR/1.raw"
111*6141f3bdSMax Reitz                    }
112*6141f3bdSMax Reitz                },
113*6141f3bdSMax Reitz                "drive2",
114*6141f3bdSMax Reitz                {
115*6141f3bdSMax Reitz                    "driver": "raw",
116*6141f3bdSMax Reitz                    "file": {
117*6141f3bdSMax Reitz                        "driver": "file",
118*6141f3bdSMax Reitz                        "filename": "$TEST_DIR/3.raw"
119*6141f3bdSMax Reitz                    }
120*6141f3bdSMax Reitz                }
121*6141f3bdSMax Reitz            ]
122*6141f3bdSMax Reitz        }
123*6141f3bdSMax Reitz    }
124*6141f3bdSMax Reitz}
125*6141f3bdSMax Reitz{ "execute": "human-monitor-command",
126*6141f3bdSMax Reitz    "arguments": {
127*6141f3bdSMax Reitz        "command-line": 'qemu-io drive0-quorum "read -P 0x32 0 $size"'
128*6141f3bdSMax Reitz    }
129*6141f3bdSMax Reitz}
130*6141f3bdSMax Reitz{ "execute": "quit" }
131*6141f3bdSMax ReitzEOF
132*6141f3bdSMax Reitz
133*6141f3bdSMax Reitzecho
134c7fc5bc2SBenoît Canetecho "== breaking quorum =="
135c7fc5bc2SBenoît Canet
136c7fc5bc2SBenoît Canet$QEMU_IO -c "write -P 0x41 0 $size" "$TEST_DIR/1.raw" | _filter_qemu_io
137c7fc5bc2SBenoît Canetecho
138c7fc5bc2SBenoît Canetecho "== checking that quorum is broken =="
139c7fc5bc2SBenoît Canet
140c7fc5bc2SBenoît Canet$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io
141c7fc5bc2SBenoît Canet
142c7fc5bc2SBenoît Canet
143c7fc5bc2SBenoît Canet# success, all done
144c7fc5bc2SBenoît Canetecho "*** done"
145c7fc5bc2SBenoît Canetrm -f $seq.full
146c7fc5bc2SBenoît Canetstatus=0
147