]>
Commit | Line | Data |
---|---|---|
11a82d14 | 1 | #!/usr/bin/env bash |
ccc47808 TG |
2 | # |
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. | |
5 | # | |
6 | # Copyright (C) 2016 Red Hat, Inc. | |
7 | # | |
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. | |
12 | # | |
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. | |
17 | # | |
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/>. | |
20 | # | |
21 | ||
22 | # creator | |
23 | [email protected] | |
24 | ||
25 | seq=`basename $0` | |
26 | echo "QA output created by $seq" | |
27 | ||
ccc47808 TG |
28 | status=1 # failure is the default! |
29 | ||
30 | _cleanup() | |
31 | { | |
32 | _cleanup_test_img | |
33 | } | |
34 | trap "_cleanup; exit \$status" 0 1 2 3 15 | |
35 | ||
36 | # get standard environment, filters and checks | |
37 | . ./common.rc | |
38 | . ./common.filter | |
39 | ||
40 | _supported_fmt raw | |
41 | _supported_proto file | |
42 | _supported_os Linux | |
43 | ||
44 | ||
45 | # Create JSON with options | |
46 | img_json() { | |
b43671f8 EB |
47 | printf %s 'json:{"driver":"raw", ' |
48 | printf %s "\"offset\":\"$img_offset\", " | |
ccc47808 | 49 | if [ "$img_size" -ne -1 ] ; then |
b43671f8 | 50 | printf %s "\"size\":\"$img_size\", " |
ccc47808 | 51 | fi |
b43671f8 EB |
52 | printf %s '"file": {' |
53 | printf %s '"driver":"file", ' | |
54 | printf %s "\"filename\":\"$TEST_IMG\" " | |
55 | printf %s "} }" | |
ccc47808 TG |
56 | } |
57 | ||
58 | do_general_test() { | |
59 | if [ "$img_size" -ge 0 ] ; then | |
60 | test_size=$img_size | |
61 | else | |
62 | test_size=$((size-img_offset)) | |
63 | fi | |
64 | ||
65 | echo | |
66 | echo "write to image" | |
67 | $QEMU_IO -c "write -P 0x0a 0 $test_size" "$(img_json)" | _filter_qemu_io | |
68 | ||
69 | echo | |
70 | echo "read the image" | |
71 | $QEMU_IO -c "read -P 0x0a 0 $test_size" "$(img_json)" | _filter_qemu_io | |
72 | ||
73 | echo | |
74 | echo "check that offset is respected" | |
75 | $QEMU_IO -c "read -v $((img_offset-2)) 4" $TEST_IMG | _filter_qemu_io | |
76 | ||
77 | echo | |
78 | echo "write before image boundary" | |
79 | $QEMU_IO -c "write $((test_size-1)) 1" "$(img_json)" | _filter_qemu_io | |
80 | ||
81 | echo | |
82 | echo "write across image boundary" | |
83 | $QEMU_IO -c "write $((test_size-1)) 2" "$(img_json)" | _filter_qemu_io | |
84 | ||
85 | echo | |
86 | echo "write at image boundary" | |
87 | $QEMU_IO -c "write $test_size 1" "$(img_json)" | _filter_qemu_io | |
88 | ||
89 | echo | |
90 | echo "write after image boundary" | |
91 | $QEMU_IO -c "write $((test_size+512)) 1" "$(img_json)" | _filter_qemu_io | |
92 | ||
93 | echo | |
94 | echo "writev before/after image boundary" | |
95 | $QEMU_IO -c "writev $((test_size-512)) 512 512" "$(img_json)" | _filter_qemu_io | |
96 | ||
97 | echo | |
98 | echo "read before image boundary" | |
99 | $QEMU_IO -c "read $((test_size-1)) 1" "$(img_json)" | _filter_qemu_io | |
100 | ||
101 | echo | |
102 | echo "read across image boundary" | |
103 | $QEMU_IO -c "read $((test_size-1)) 2" "$(img_json)" | _filter_qemu_io | |
104 | ||
105 | echo | |
106 | echo "read at image boundary" | |
107 | $QEMU_IO -c "read $test_size 1" "$(img_json)" | _filter_qemu_io | |
108 | ||
109 | echo | |
110 | echo "read after image boundary" | |
111 | $QEMU_IO -c "read $((test_size+512)) 1" "$(img_json)" | _filter_qemu_io | |
112 | ||
113 | echo | |
114 | echo "readv before/after image boundary" | |
115 | $QEMU_IO -c "readv $((test_size-512)) 512 512" "$(img_json)" | _filter_qemu_io | |
116 | ||
117 | echo | |
118 | echo "fill image with pattern" | |
119 | $QEMU_IO -c "write -P 0x0a 0 $size" $TEST_IMG | _filter_qemu_io | |
120 | ||
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 | |
125 | ||
126 | echo | |
127 | echo "write zeroes across image boundary" | |
128 | $QEMU_IO -c "write -z $((test_size-1)) 2" "$(img_json)" | _filter_qemu_io | |
129 | ||
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 | |
135 | ||
136 | echo | |
137 | echo "fill image with pattern" | |
138 | $QEMU_IO -c "write -P 0x0a 0 $size" $TEST_IMG | _filter_qemu_io | |
139 | ||
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 | |
144 | ||
145 | echo | |
146 | echo "discard across image boundary" | |
147 | $QEMU_IO -c "discard $((test_size-1)) 2" "$(img_json)" | _filter_qemu_io | |
148 | ||
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 | |
154 | } | |
155 | ||
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 | |
164 | ||
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 | |
173 | ||
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 | |
182 | ||
183 | echo | |
184 | echo "== test reopen ==" | |
185 | size=4096 | |
186 | img_offset=512 | |
187 | img_size=512 | |
188 | _make_test_img $size | |
189 | ( | |
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 | |
198 | EOT | |
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 | |
206 | ||
207 | # success, all done | |
208 | echo | |
209 | echo "*** done" | |
210 | rm -f $seq.full | |
211 | status=0 |