s390x: Move diagnose 308 subcodes and rcs into ipl.h
[qemu/ar7.git] / tests / qemu-iotests / 171
blob341064a1c6bddac786488a86f3f96f8711f7a6e6
1 #!/usr/bin/env bash
3 # Test 'offset' and 'size' options of the raw driver. Make sure we can't
4 # (or can) read and write outside of the image size.
6 # Copyright (C) 2016 Red Hat, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # creator
23 owner=tgolembi@redhat.com
25 seq=`basename $0`
26 echo "QA output created by $seq"
28 status=1 # failure is the default!
30 _cleanup()
32 _cleanup_test_img
34 trap "_cleanup; exit \$status" 0 1 2 3 15
36 # get standard environment, filters and checks
37 . ./common.rc
38 . ./common.filter
40 _supported_fmt raw
41 _supported_proto file
42 _supported_os Linux
45 # Create JSON with options
46 img_json() {
47 printf %s 'json:{"driver":"raw", '
48 printf %s "\"offset\":\"$img_offset\", "
49 if [ "$img_size" -ne -1 ] ; then
50 printf %s "\"size\":\"$img_size\", "
52 printf %s '"file": {'
53 printf %s '"driver":"file", '
54 printf %s "\"filename\":\"$TEST_IMG\" "
55 printf %s "} }"
58 do_general_test() {
59 if [ "$img_size" -ge 0 ] ; then
60 test_size=$img_size
61 else
62 test_size=$((size-img_offset))
65 echo
66 echo "write to image"
67 $QEMU_IO -c "write -P 0x0a 0 $test_size" "$(img_json)" | _filter_qemu_io
69 echo
70 echo "read the image"
71 $QEMU_IO -c "read -P 0x0a 0 $test_size" "$(img_json)" | _filter_qemu_io
73 echo
74 echo "check that offset is respected"
75 $QEMU_IO -c "read -v $((img_offset-2)) 4" $TEST_IMG | _filter_qemu_io
77 echo
78 echo "write before image boundary"
79 $QEMU_IO -c "write $((test_size-1)) 1" "$(img_json)" | _filter_qemu_io
81 echo
82 echo "write across image boundary"
83 $QEMU_IO -c "write $((test_size-1)) 2" "$(img_json)" | _filter_qemu_io
85 echo
86 echo "write at image boundary"
87 $QEMU_IO -c "write $test_size 1" "$(img_json)" | _filter_qemu_io
89 echo
90 echo "write after image boundary"
91 $QEMU_IO -c "write $((test_size+512)) 1" "$(img_json)" | _filter_qemu_io
93 echo
94 echo "writev before/after image boundary"
95 $QEMU_IO -c "writev $((test_size-512)) 512 512" "$(img_json)" | _filter_qemu_io
97 echo
98 echo "read before image boundary"
99 $QEMU_IO -c "read $((test_size-1)) 1" "$(img_json)" | _filter_qemu_io
101 echo
102 echo "read across image boundary"
103 $QEMU_IO -c "read $((test_size-1)) 2" "$(img_json)" | _filter_qemu_io
105 echo
106 echo "read at image boundary"
107 $QEMU_IO -c "read $test_size 1" "$(img_json)" | _filter_qemu_io
109 echo
110 echo "read after image boundary"
111 $QEMU_IO -c "read $((test_size+512)) 1" "$(img_json)" | _filter_qemu_io
113 echo
114 echo "readv before/after image boundary"
115 $QEMU_IO -c "readv $((test_size-512)) 512 512" "$(img_json)" | _filter_qemu_io
117 echo
118 echo "fill image with pattern"
119 $QEMU_IO -c "write -P 0x0a 0 $size" $TEST_IMG | _filter_qemu_io
121 echo
122 echo "write zeroes and check"
123 $QEMU_IO -c "write -z 0 512" "$(img_json)" | _filter_qemu_io
124 $QEMU_IO -c "read -v $((img_offset-2)) 4" $TEST_IMG | _filter_qemu_io
126 echo
127 echo "write zeroes across image boundary"
128 $QEMU_IO -c "write -z $((test_size-1)) 2" "$(img_json)" | _filter_qemu_io
130 echo
131 echo "write zeroes at image boundary and check"
132 $QEMU_IO -c "write -z $((test_size-2)) 2" "$(img_json)" | _filter_qemu_io
133 $QEMU_IO -c "read -v $((img_offset+test_size-2)) 2" $TEST_IMG | _filter_qemu_io
134 $QEMU_IO -c "read -v $((img_offset+test_size)) 2" $TEST_IMG | _filter_qemu_io
136 echo
137 echo "fill image with pattern"
138 $QEMU_IO -c "write -P 0x0a 0 $size" $TEST_IMG | _filter_qemu_io
140 echo
141 echo "discard and check"
142 $QEMU_IO -c "discard 0 512" "$(img_json)" | _filter_qemu_io
143 $QEMU_IO -c "read -v $((img_offset-2)) 4" $TEST_IMG | _filter_qemu_io
145 echo
146 echo "discard across image boundary"
147 $QEMU_IO -c "discard $((test_size-1)) 2" "$(img_json)" | _filter_qemu_io
149 echo
150 echo "discard at image boundary and check"
151 $QEMU_IO -c "discard $((test_size-2)) 2" "$(img_json)" | _filter_qemu_io
152 $QEMU_IO -c "read -v $((img_offset+test_size-2)) 2" $TEST_IMG | _filter_qemu_io
153 $QEMU_IO -c "read -v $((img_offset+test_size)) 2" $TEST_IMG | _filter_qemu_io
156 echo
157 echo "== test 'offset' option =="
158 size=4096
159 img_offset=512
160 img_size=-1
161 _make_test_img $size
162 do_general_test
163 _cleanup_test_img
165 echo
166 echo "== test 'offset' and 'size' options =="
167 size=4096
168 img_offset=512
169 img_size=2048
170 _make_test_img $size
171 do_general_test
172 _cleanup_test_img
174 echo
175 echo "== test misaligned 'offset' =="
176 size=4096
177 img_offset=10
178 img_size=2048
179 _make_test_img $size
180 do_general_test
181 _cleanup_test_img
183 echo
184 echo "== test reopen =="
185 size=4096
186 img_offset=512
187 img_size=512
188 _make_test_img $size
190 $QEMU_IO "$(img_json)" <<EOT
191 write -P 0x0a 0 512
192 write -P 0x0a 511 1
193 write -P 0x0a 512 1
194 reopen -o driver=raw,offset=1536,size=1024
195 write -P 0x0a 0 1024
196 write -P 0x0a 1023 1
197 write -P 0x0a 1024 1
199 ) | _filter_qemu_io
200 echo "checking boundaries"
201 $QEMU_IO -c "read -v 510 4" $TEST_IMG | _filter_qemu_io
202 $QEMU_IO -c "read -v 1022 4" $TEST_IMG | _filter_qemu_io
203 $QEMU_IO -c "read -v 1534 4" $TEST_IMG | _filter_qemu_io
204 $QEMU_IO -c "read -v 2558 4" $TEST_IMG | _filter_qemu_io
205 _cleanup_test_img
207 # success, all done
208 echo
209 echo "*** done"
210 rm -f $seq.full
211 status=0