xref: /openbmc/qemu/tests/qemu-iotests/026 (revision 1559e0d4)
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_proto generic
46_supported_os Linux
47
48
49echo "Errors while writing 128 kB"
50echo
51
52CLUSTER_SIZE=1024
53
54BLKDBG_TEST_IMG="blkdebug:$TEST_DIR/blkdebug.conf:$TEST_IMG"
55
56for event in \
57    l1_update \
58    \
59    l2_load \
60    l2_update \
61    l2_alloc.write \
62    \
63    write_aio \
64    \
65    refblock_load \
66    refblock_update_part \
67    refblock_alloc \
68    \
69    cluster_alloc \
70
71do
72
73for errno in 5 28; do
74for imm in off; do
75for once in on off; do
76for vmstate in "" "-b"; do
77
78cat > $TEST_DIR/blkdebug.conf <<EOF
79[inject-error]
80event = "$event"
81errno = "$errno"
82immediately = "$imm"
83once ="$once"
84EOF
85
86_make_test_img 1G
87
88echo
89echo "Event: $event; errno: $errno; imm: $imm; once: $once; write $vmstate"
90
91# We want to catch a simple L2 update, not the allocation of the first L2 table
92if [ "$event" == "l2_update" ]; then
93    $QEMU_IO -c "write $vmstate 0 512" $TEST_IMG > /dev/null 2>&1
94fi
95
96$QEMU_IO -c "write $vmstate 0 128k " $BLKDBG_TEST_IMG | _filter_qemu_io
97
98# l2_load is not called on allocation, so issue a second write
99# Reads are another path to trigger l2_load, so do a read, too
100if [ "$event" == "l2_load" ]; then
101    $QEMU_IO -c "write $vmstate 0 128k " $BLKDBG_TEST_IMG | _filter_qemu_io
102    $QEMU_IO -c "read $vmstate 0 128k " $BLKDBG_TEST_IMG | _filter_qemu_io
103fi
104
105_check_test_img 2>&1 | grep -v "refcount=1 reference=0"
106
107done
108done
109done
110done
111done
112
113
114echo
115echo === Refcout table growth tests ===
116echo
117CLUSTER_SIZE=512
118
119
120for event in \
121    refblock_alloc.hookup \
122    refblock_alloc.write \
123    refblock_alloc.write_blocks \
124    refblock_alloc.write_table \
125    refblock_alloc.switch_table \
126
127do
128
129# This one takes a while, so let's test only one error code (ENOSPC should
130# never be generated by qemu, so it's probably a good choice)
131for errno in 28; do
132for imm in off; do
133for once in on off; do
134for vmstate in "" "-b"; do
135
136cat > $TEST_DIR/blkdebug.conf <<EOF
137[inject-error]
138event = "$event"
139errno = "$errno"
140immediately = "$imm"
141once = "$once"
142EOF
143
144_make_test_img 1G
145
146echo
147echo "Event: $event; errno: $errno; imm: $imm; once: $once; write $vmstate"
148$QEMU_IO -c "write $vmstate 0 64M" $BLKDBG_TEST_IMG | _filter_qemu_io
149
150_check_test_img 2>&1 | grep -v "refcount=1 reference=0"
151
152done
153done
154done
155done
156done
157
158echo
159echo === L1 growth tests ===
160echo
161CLUSTER_SIZE=1024
162
163
164for event in \
165    l1_grow.alloc_table \
166    l1_grow.write_table \
167    l1_grow.activate_table \
168
169do
170
171for errno in 5 28; do
172for imm in off; do
173for once in on off; do
174
175cat > $TEST_DIR/blkdebug.conf <<EOF
176[inject-error]
177event = "$event"
178errno = "$errno"
179immediately = "$imm"
180once = "$once"
181EOF
182
183_make_test_img 1G
184
185echo
186echo "Event: $event; errno: $errno; imm: $imm; once: $once"
187$QEMU_IO -c "write -b 0 64k" $BLKDBG_TEST_IMG | _filter_qemu_io
188
189_check_test_img 2>&1 | grep -v "refcount=1 reference=0"
190
191done
192done
193done
194done
195
196# success, all done
197echo "*** done"
198rm -f $seq.full
199status=0
200