aboutsummaryrefslogtreecommitdiff
path: root/tests/qemu-iotests/171
blob: 341064a1c6bddac786488a86f3f96f8711f7a6e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/env bash
#
# Test 'offset' and 'size' options of the raw driver. Make sure we can't
# (or can) read and write outside of the image size.
#
# Copyright (C) 2016 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

# creator
owner=tgolembi@redhat.com

seq=`basename $0`
echo "QA output created by $seq"

status=1	# failure is the default!

_cleanup()
{
    _cleanup_test_img
}
trap "_cleanup; exit \$status" 0 1 2 3 15

# get standard environment, filters and checks
. ./common.rc
. ./common.filter

_supported_fmt raw
_supported_proto file
_supported_os Linux


# Create JSON with options
img_json() {
    printf %s 'json:{"driver":"raw", '
    printf %s "\"offset\":\"$img_offset\", "
    if [ "$img_size" -ne -1 ] ; then
        printf %s "\"size\":\"$img_size\", "
    fi
    printf %s '"file": {'
    printf %s   '"driver":"file", '
    printf %s   "\"filename\":\"$TEST_IMG\" "
    printf %s "} }"
}

do_general_test() {
    if [ "$img_size" -ge 0 ] ; then
        test_size=$img_size
    else
        test_size=$((size-img_offset))
    fi

    echo
    echo "write to image"
    $QEMU_IO -c "write -P 0x0a 0 $test_size" "$(img_json)" | _filter_qemu_io

    echo
    echo "read the image"
    $QEMU_IO -c "read -P 0x0a 0 $test_size" "$(img_json)" | _filter_qemu_io

    echo
    echo "check that offset is respected"
    $QEMU_IO -c "read -v $((img_offset-2)) 4" $TEST_IMG | _filter_qemu_io

    echo
    echo "write before image boundary"
    $QEMU_IO -c "write $((test_size-1)) 1" "$(img_json)" | _filter_qemu_io

    echo
    echo "write across image boundary"
    $QEMU_IO -c "write $((test_size-1)) 2" "$(img_json)" | _filter_qemu_io

    echo
    echo "write at image boundary"
    $QEMU_IO -c "write $test_size 1" "$(img_json)" | _filter_qemu_io

    echo
    echo "write after image boundary"
    $QEMU_IO -c "write $((test_size+512)) 1" "$(img_json)" | _filter_qemu_io

    echo
    echo "writev before/after image boundary"
    $QEMU_IO -c "writev $((test_size-512)) 512 512" "$(img_json)" | _filter_qemu_io

    echo
    echo "read before image boundary"
    $QEMU_IO -c "read $((test_size-1)) 1" "$(img_json)" | _filter_qemu_io

    echo
    echo "read across image boundary"
    $QEMU_IO -c "read $((test_size-1)) 2" "$(img_json)" | _filter_qemu_io

    echo
    echo "read at image boundary"
    $QEMU_IO -c "read $test_size 1" "$(img_json)" | _filter_qemu_io

    echo
    echo "read after image boundary"
    $QEMU_IO -c "read $((test_size+512)) 1" "$(img_json)" | _filter_qemu_io

    echo
    echo "readv before/after image boundary"
    $QEMU_IO -c "readv $((test_size-512)) 512 512" "$(img_json)" | _filter_qemu_io

    echo
    echo "fill image with pattern"
    $QEMU_IO -c "write -P 0x0a 0 $size" $TEST_IMG | _filter_qemu_io

    echo
    echo "write zeroes and check"
    $QEMU_IO -c "write -z 0 512" "$(img_json)" | _filter_qemu_io
    $QEMU_IO -c "read -v $((img_offset-2)) 4" $TEST_IMG | _filter_qemu_io

    echo
    echo "write zeroes across image boundary"
    $QEMU_IO -c "write -z $((test_size-1)) 2" "$(img_json)" | _filter_qemu_io

    echo
    echo "write zeroes at image boundary and check"
    $QEMU_IO -c "write -z $((test_size-2)) 2" "$(img_json)" | _filter_qemu_io
    $QEMU_IO -c "read -v $((img_offset+test_size-2)) 2" $TEST_IMG | _filter_qemu_io
    $QEMU_IO -c "read -v $((img_offset+test_size)) 2" $TEST_IMG | _filter_qemu_io

    echo
    echo "fill image with pattern"
    $QEMU_IO -c "write -P 0x0a 0 $size" $TEST_IMG | _filter_qemu_io

    echo
    echo "discard and check"
    $QEMU_IO -c "discard 0 512" "$(img_json)" | _filter_qemu_io
    $QEMU_IO -c "read -v $((img_offset-2)) 4" $TEST_IMG | _filter_qemu_io

    echo
    echo "discard across image boundary"
    $QEMU_IO -c "discard $((test_size-1)) 2" "$(img_json)" | _filter_qemu_io

    echo
    echo "discard at image boundary and check"
    $QEMU_IO -c "discard $((test_size-2)) 2" "$(img_json)" | _filter_qemu_io
    $QEMU_IO -c "read -v $((img_offset+test_size-2)) 2" $TEST_IMG | _filter_qemu_io
    $QEMU_IO -c "read -v $((img_offset+test_size)) 2" $TEST_IMG | _filter_qemu_io
}

echo
echo "== test 'offset' option =="
size=4096
img_offset=512
img_size=-1
_make_test_img $size
do_general_test
_cleanup_test_img

echo
echo "== test 'offset' and 'size' options =="
size=4096
img_offset=512
img_size=2048
_make_test_img $size
do_general_test
_cleanup_test_img

echo
echo "== test misaligned 'offset' =="
size=4096
img_offset=10
img_size=2048
_make_test_img $size
do_general_test
_cleanup_test_img

echo
echo "== test reopen =="
size=4096
img_offset=512
img_size=512
_make_test_img $size
(
$QEMU_IO "$(img_json)"  <<EOT
write -P 0x0a 0 512
write -P 0x0a 511 1
write -P 0x0a 512 1
reopen -o driver=raw,offset=1536,size=1024
write -P 0x0a 0 1024
write -P 0x0a 1023 1
write -P 0x0a 1024 1
EOT
) | _filter_qemu_io
echo "checking boundaries"
$QEMU_IO -c "read -v 510 4" $TEST_IMG | _filter_qemu_io
$QEMU_IO -c "read -v 1022 4" $TEST_IMG | _filter_qemu_io
$QEMU_IO -c "read -v 1534 4" $TEST_IMG | _filter_qemu_io
$QEMU_IO -c "read -v 2558 4" $TEST_IMG | _filter_qemu_io
_cleanup_test_img

# success, all done
echo
echo "*** done"
rm -f $seq.full
status=0