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/>.
23 owner
=tgolembi@redhat.com
26 echo "QA output created by $seq"
28 status
=1 # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
36 # get standard environment, filters and checks
45 # Create JSON with options
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\", "
53 printf %s
'"driver":"file", '
54 printf %s
"\"filename\":\"$TEST_IMG\" "
59 if [ "$img_size" -ge 0 ] ; then
62 test_size
=$
((size-img_offset
))
67 $QEMU_IO -c "write -P 0x0a 0 $test_size" "$(img_json)" | _filter_qemu_io
71 $QEMU_IO -c "read -P 0x0a 0 $test_size" "$(img_json)" | _filter_qemu_io
74 echo "check that offset is respected"
75 $QEMU_IO -c "read -v $((img_offset-2)) 4" $TEST_IMG | _filter_qemu_io
78 echo "write before image boundary"
79 $QEMU_IO -c "write $((test_size-1)) 1" "$(img_json)" | _filter_qemu_io
82 echo "write across image boundary"
83 $QEMU_IO -c "write $((test_size-1)) 2" "$(img_json)" | _filter_qemu_io
86 echo "write at image boundary"
87 $QEMU_IO -c "write $test_size 1" "$(img_json)" | _filter_qemu_io
90 echo "write after image boundary"
91 $QEMU_IO -c "write $((test_size+512)) 1" "$(img_json)" | _filter_qemu_io
94 echo "writev before/after image boundary"
95 $QEMU_IO -c "writev $((test_size-512)) 512 512" "$(img_json)" | _filter_qemu_io
98 echo "read before image boundary"
99 $QEMU_IO -c "read $((test_size-1)) 1" "$(img_json)" | _filter_qemu_io
102 echo "read across image boundary"
103 $QEMU_IO -c "read $((test_size-1)) 2" "$(img_json)" | _filter_qemu_io
106 echo "read at image boundary"
107 $QEMU_IO -c "read $test_size 1" "$(img_json)" | _filter_qemu_io
110 echo "read after image boundary"
111 $QEMU_IO -c "read $((test_size+512)) 1" "$(img_json)" | _filter_qemu_io
114 echo "readv before/after image boundary"
115 $QEMU_IO -c "readv $((test_size-512)) 512 512" "$(img_json)" | _filter_qemu_io
118 echo "fill image with pattern"
119 $QEMU_IO -c "write -P 0x0a 0 $size" $TEST_IMG | _filter_qemu_io
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
127 echo "write zeroes across image boundary"
128 $QEMU_IO -c "write -z $((test_size-1)) 2" "$(img_json)" | _filter_qemu_io
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
137 echo "fill image with pattern"
138 $QEMU_IO -c "write -P 0x0a 0 $size" $TEST_IMG | _filter_qemu_io
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
146 echo "discard across image boundary"
147 $QEMU_IO -c "discard $((test_size-1)) 2" "$(img_json)" | _filter_qemu_io
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
157 echo "== test 'offset' option =="
166 echo "== test 'offset' and 'size' options =="
175 echo "== test misaligned 'offset' =="
184 echo "== test reopen =="
190 $QEMU_IO "$(img_json)" <<EOT
194 reopen -o driver=raw,offset=1536,size=1024
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