osdep: protect qemu/osdep.h with extern "C"
[qemu/ar7.git] / tests / qemu-iotests / 171
blobd1d77f7013041177b0460a81e1a1354cf593847a
1 #!/usr/bin/env bash
2 # group: rw quick
4 # Test 'offset' and 'size' options of the raw driver. Make sure we can't
5 # (or can) read and write outside of the image size.
7 # Copyright (C) 2016 Red Hat, Inc.
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 # creator
24 owner=tgolembi@redhat.com
26 seq=`basename $0`
27 echo "QA output created by $seq"
29 status=1 # failure is the default!
31 _cleanup()
33 _cleanup_test_img
35 trap "_cleanup; exit \$status" 0 1 2 3 15
37 # get standard environment, filters and checks
38 . ./common.rc
39 . ./common.filter
41 _supported_fmt raw
42 _supported_proto file fuse
43 _supported_os Linux
46 # Create JSON with options
47 img_json() {
48 printf %s 'json:{"driver":"raw", '
49 printf %s "\"offset\":\"$img_offset\", "
50 if [ "$img_size" -ne -1 ] ; then
51 printf %s "\"size\":\"$img_size\", "
53 printf %s '"file": {'
54 printf %s '"driver":"file", '
55 printf %s "\"filename\":\"$TEST_IMG\" "
56 printf %s "} }"
59 do_general_test() {
60 if [ "$img_size" -ge 0 ] ; then
61 test_size=$img_size
62 else
63 test_size=$((size-img_offset))
66 echo
67 echo "write to image"
68 $QEMU_IO -c "write -P 0x0a 0 $test_size" "$(img_json)" | _filter_qemu_io
70 echo
71 echo "read the image"
72 $QEMU_IO -c "read -P 0x0a 0 $test_size" "$(img_json)" | _filter_qemu_io
74 echo
75 echo "check that offset is respected"
76 $QEMU_IO -c "read -v $((img_offset-2)) 4" $TEST_IMG | _filter_qemu_io
78 echo
79 echo "write before image boundary"
80 $QEMU_IO -c "write $((test_size-1)) 1" "$(img_json)" | _filter_qemu_io
82 echo
83 echo "write across image boundary"
84 $QEMU_IO -c "write $((test_size-1)) 2" "$(img_json)" | _filter_qemu_io
86 echo
87 echo "write at image boundary"
88 $QEMU_IO -c "write $test_size 1" "$(img_json)" | _filter_qemu_io
90 echo
91 echo "write after image boundary"
92 $QEMU_IO -c "write $((test_size+512)) 1" "$(img_json)" | _filter_qemu_io
94 echo
95 echo "writev before/after image boundary"
96 $QEMU_IO -c "writev $((test_size-512)) 512 512" "$(img_json)" | _filter_qemu_io
98 echo
99 echo "read before image boundary"
100 $QEMU_IO -c "read $((test_size-1)) 1" "$(img_json)" | _filter_qemu_io
102 echo
103 echo "read across image boundary"
104 $QEMU_IO -c "read $((test_size-1)) 2" "$(img_json)" | _filter_qemu_io
106 echo
107 echo "read at image boundary"
108 $QEMU_IO -c "read $test_size 1" "$(img_json)" | _filter_qemu_io
110 echo
111 echo "read after image boundary"
112 $QEMU_IO -c "read $((test_size+512)) 1" "$(img_json)" | _filter_qemu_io
114 echo
115 echo "readv before/after image boundary"
116 $QEMU_IO -c "readv $((test_size-512)) 512 512" "$(img_json)" | _filter_qemu_io
118 echo
119 echo "fill image with pattern"
120 $QEMU_IO -c "write -P 0x0a 0 $size" $TEST_IMG | _filter_qemu_io
122 echo
123 echo "write zeroes and check"
124 $QEMU_IO -c "write -z 0 512" "$(img_json)" | _filter_qemu_io
125 $QEMU_IO -c "read -v $((img_offset-2)) 4" $TEST_IMG | _filter_qemu_io
127 echo
128 echo "write zeroes across image boundary"
129 $QEMU_IO -c "write -z $((test_size-1)) 2" "$(img_json)" | _filter_qemu_io
131 echo
132 echo "write zeroes at image boundary and check"
133 $QEMU_IO -c "write -z $((test_size-2)) 2" "$(img_json)" | _filter_qemu_io
134 $QEMU_IO -c "read -v $((img_offset+test_size-2)) 2" $TEST_IMG | _filter_qemu_io
135 $QEMU_IO -c "read -v $((img_offset+test_size)) 2" $TEST_IMG | _filter_qemu_io
137 echo
138 echo "fill image with pattern"
139 $QEMU_IO -c "write -P 0x0a 0 $size" $TEST_IMG | _filter_qemu_io
141 echo
142 echo "discard and check"
143 $QEMU_IO -c "discard 0 512" "$(img_json)" | _filter_qemu_io
144 $QEMU_IO -c "read -v $((img_offset-2)) 4" $TEST_IMG | _filter_qemu_io
146 echo
147 echo "discard across image boundary"
148 $QEMU_IO -c "discard $((test_size-1)) 2" "$(img_json)" | _filter_qemu_io
150 echo
151 echo "discard at image boundary and check"
152 $QEMU_IO -c "discard $((test_size-2)) 2" "$(img_json)" | _filter_qemu_io
153 $QEMU_IO -c "read -v $((img_offset+test_size-2)) 2" $TEST_IMG | _filter_qemu_io
154 $QEMU_IO -c "read -v $((img_offset+test_size)) 2" $TEST_IMG | _filter_qemu_io
157 echo
158 echo "== test 'offset' option =="
159 size=4096
160 img_offset=512
161 img_size=-1
162 _make_test_img $size
163 do_general_test
164 _cleanup_test_img
166 echo
167 echo "== test 'offset' and 'size' options =="
168 size=4096
169 img_offset=512
170 img_size=2048
171 _make_test_img $size
172 do_general_test
173 _cleanup_test_img
175 echo
176 echo "== test misaligned 'offset' =="
177 size=4096
178 img_offset=10
179 img_size=2048
180 _make_test_img $size
181 do_general_test
182 _cleanup_test_img
184 echo
185 echo "== test reopen =="
186 size=4096
187 img_offset=512
188 img_size=512
189 _make_test_img $size
191 $QEMU_IO "$(img_json)" <<EOT
192 write -P 0x0a 0 512
193 write -P 0x0a 511 1
194 write -P 0x0a 512 1
195 reopen -o driver=raw,offset=1536,size=1024
196 write -P 0x0a 0 1024
197 write -P 0x0a 1023 1
198 write -P 0x0a 1024 1
200 ) | _filter_qemu_io
201 echo "checking boundaries"
202 $QEMU_IO -c "read -v 510 4" $TEST_IMG | _filter_qemu_io
203 $QEMU_IO -c "read -v 1022 4" $TEST_IMG | _filter_qemu_io
204 $QEMU_IO -c "read -v 1534 4" $TEST_IMG | _filter_qemu_io
205 $QEMU_IO -c "read -v 2558 4" $TEST_IMG | _filter_qemu_io
206 _cleanup_test_img
208 # success, all done
209 echo
210 echo "*** done"
211 rm -f $seq.full
212 status=0