osdep: protect qemu/osdep.h with extern "C"
[qemu/ar7.git] / tests / qemu-iotests / 313
bloba75655b7ef0403990ee72f3d9d652bef0cbce551
1 #!/usr/bin/env bash
2 # group: rw auto quick
4 # Test for the regression fixed in commit c8bf9a9169
6 # Copyright (C) 2020 Igalia, S.L.
7 # Author: Alberto Garcia <berto@igalia.com>
8 # Based on a test case by Maxim Levitsky <mlevitsk@redhat.com>
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 # creator
25 owner=berto@igalia.com
27 seq=`basename $0`
28 echo "QA output created by $seq"
30 status=1 # failure is the default!
32 _cleanup()
34 _cleanup_test_img
36 trap "_cleanup; exit \$status" 0 1 2 3 15
38 # get standard environment, filters and checks
39 . ./common.rc
40 . ./common.filter
42 _supported_fmt qcow2
43 _supported_proto file
44 _supported_os Linux
45 _unsupported_imgopts cluster_size refcount_bits extended_l2 compat=0.10 data_file
47 # The cluster size must be at least the granularity of the mirror job (4KB)
48 # Note that larger cluster sizes will produce very large images (several GBs)
49 cluster_size=4096
50 refcount_bits=64 # Make it equal to the L2 entry size for convenience
51 options="cluster_size=${cluster_size},refcount_bits=${refcount_bits}"
53 # Number of refcount entries per refcount blocks
54 ref_entries=$(( ${cluster_size} * 8 / ${refcount_bits} ))
56 # Number of data clusters needed to fill a refcount block
57 # Equals ${ref_entries} minus two (one L2 table and one refcount block)
58 data_clusters_per_refblock=$(( ${ref_entries} - 2 ))
60 # Number of entries in the refcount cache
61 ref_blocks=4
63 # Write enough data clusters to fill the refcount cache and allocate
64 # one more refcount block.
65 # Subtract 3 clusters from the total: qcow2 header, refcount table, L1 table
66 total_data_clusters=$(( ${data_clusters_per_refblock} * ${ref_blocks} + 1 - 3 ))
68 # Total size to write in bytes
69 total_size=$(( ${total_data_clusters} * ${cluster_size} ))
71 echo
72 echo '### Create the image'
73 echo
74 TEST_IMG_FILE=$TEST_IMG.base _make_test_img -o $options $total_size | _filter_img_create_size
76 echo
77 echo '### Write data to allocate more refcount blocks than the cache can hold'
78 echo
79 $QEMU_IO -c "write -P 1 0 $total_size" $TEST_IMG.base | _filter_qemu_io
81 echo
82 echo '### Create an overlay'
83 echo
84 _make_test_img -F $IMGFMT -b $TEST_IMG.base -o $options | _filter_img_create_size
86 echo
87 echo '### Fill the overlay with zeroes'
88 echo
89 $QEMU_IO -c "write -z 0 $total_size" $TEST_IMG | _filter_qemu_io
91 echo
92 echo '### Commit changes to the base image'
93 echo
94 $QEMU_IMG commit $TEST_IMG
96 echo
97 echo '### Check the base image'
98 echo
99 $QEMU_IMG check $TEST_IMG.base
101 # success, all done
102 echo "*** done"
103 rm -f $seq.full
104 status=0