xref: /openbmc/qemu/tests/qemu-iotests/026 (revision 52280eac)
1#!/bin/bash
2#
3# qcow2 error path testing
4#
5# Copyright (C) 2010 Red Hat, Inc.
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19#
20
21# creator
22owner=kwolf@redhat.com
23
24seq=`basename $0`
25echo "QA output created by $seq"
26
27here=`pwd`
28tmp=/tmp/$$
29status=1	# failure is the default!
30
31_cleanup()
32{
33	_cleanup_test_img
34    rm $TEST_DIR/blkdebug.conf
35}
36trap "_cleanup; exit \$status" 0 1 2 3 15
37
38# get standard environment, filters and checks
39. ./common.rc
40. ./common.filter
41. ./common.pattern
42
43# Currently only qcow2 supports rebasing
44_supported_fmt qcow2
45_supported_os Linux
46
47
48echo "Errors while writing 128 kB"
49echo
50
51CLUSTER_SIZE=1024
52
53BLKDBG_TEST_IMG="blkdebug:$TEST_DIR/blkdebug.conf:$TEST_IMG"
54
55for event in \
56    l1_update \
57    \
58    l2_load \
59    l2_update \
60    l2_alloc.write \
61    \
62    write_aio \
63    \
64    refblock_load \
65    refblock_update_part \
66    refblock_alloc \
67    \
68    cluster_alloc \
69
70do
71
72for errno in 5 28; do
73for imm in off; do
74for once in on off; do
75for vmstate in "" "-b"; do
76
77cat > $TEST_DIR/blkdebug.conf <<EOF
78[inject-error]
79event = "$event"
80errno = "$errno"
81immediately = "$imm"
82once ="$once"
83EOF
84
85_make_test_img 1G
86
87echo
88echo "Event: $event; errno: $errno; imm: $imm; once: $once; write $vmstate"
89$QEMU_IO -c "write $vmstate 0 128k " $BLKDBG_TEST_IMG | _filter_qemu_io
90
91# l2_load is not called on allocation, so issue a second write
92# Reads are another path to trigger l2_load, so do a read, too
93if [ "$event" == "l2_load" ]; then
94    $QEMU_IO -c "write $vmstate 0 128k " $BLKDBG_TEST_IMG | _filter_qemu_io
95    $QEMU_IO -c "read $vmstate 0 128k " $BLKDBG_TEST_IMG | _filter_qemu_io
96fi
97
98$QEMU_IMG check $TEST_IMG 2>&1 | grep -v "refcount=1 reference=0"
99
100done
101done
102done
103done
104done
105
106
107echo
108echo === Refcout table growth tests ===
109echo
110CLUSTER_SIZE=512
111
112
113for event in \
114    refblock_alloc.hookup \
115    refblock_alloc.write \
116    refblock_alloc.write_blocks \
117    refblock_alloc.write_table \
118    refblock_alloc.switch_table \
119
120do
121
122# This one takes a while, so let's test only one error code (ENOSPC should
123# never be generated by qemu, so it's probably a good choice)
124for errno in 28; do
125for imm in off; do
126for once in on off; do
127for vmstate in "" "-b"; do
128
129cat > $TEST_DIR/blkdebug.conf <<EOF
130[inject-error]
131event = "$event"
132errno = "$errno"
133immediately = "$imm"
134once = "$once"
135EOF
136
137_make_test_img 1G
138
139echo
140echo "Event: $event; errno: $errno; imm: $imm; once: $once; write $vmstate"
141$QEMU_IO -c "write $vmstate 0 64M" $BLKDBG_TEST_IMG | _filter_qemu_io
142
143$QEMU_IMG check $TEST_IMG 2>&1 | grep -v "refcount=1 reference=0"
144
145done
146done
147done
148done
149done
150
151echo
152echo === L1 growth tests ===
153echo
154CLUSTER_SIZE=1024
155
156
157for event in \
158    l1_grow.alloc_table \
159    l1_grow.write_table \
160    l1_grow.activate_table \
161
162do
163
164for errno in 5 28; do
165for imm in off; do
166for once in on off; do
167
168cat > $TEST_DIR/blkdebug.conf <<EOF
169[inject-error]
170event = "$event"
171errno = "$errno"
172immediately = "$imm"
173once = "$once"
174EOF
175
176_make_test_img 1G
177
178echo
179echo "Event: $event; errno: $errno; imm: $imm; once: $once"
180$QEMU_IO -c "write -b 0 64k" $BLKDBG_TEST_IMG | _filter_qemu_io
181
182$QEMU_IMG check $TEST_IMG 2>&1 | grep -v "refcount=1 reference=0"
183
184done
185done
186done
187done
188
189# success, all done
190echo "*** done"
191rm -f $seq.full
192status=0
193