clock: Define and use new clock_display_freq()
[qemu/ar7.git] / tests / qemu-iotests / 305
blob5a415eb2a47587e016e250cdfd8cf3a047b97886
1 #!/usr/bin/env bash
3 # Test the handling of errors in write requests with multiple allocations
5 # Copyright (C) 2020 Igalia, S.L.
6 # Author: Alberto Garcia <berto@igalia.com>
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/>.
22 # creator
23 owner=berto@igalia.com
25 seq=`basename $0`
26 echo "QA output created by $seq"
28 status=1 # failure is the default!
30 _cleanup()
32 _cleanup_test_img
34 trap "_cleanup; exit \$status" 0 1 2 3 15
36 # get standard environment, filters and checks
37 . ./common.rc
38 . ./common.filter
40 _supported_fmt qcow2
41 _supported_proto file fuse
42 _supported_os Linux
43 _unsupported_imgopts cluster_size refcount_bits extended_l2 compat=0.10 data_file
45 echo '### Create the image'
46 _make_test_img -o refcount_bits=64,cluster_size=1k 1M
48 # The reference counts of the clusters for the first 123k of this
49 # write request are stored in the first refcount block. The last
50 # cluster (guest offset 123k) is referenced in the second refcount
51 # block.
52 echo '### Fill the first refcount block and one data cluster from the second'
53 $QEMU_IO -c 'write 0 124k' "$TEST_IMG" | _filter_qemu_io
55 echo '### Discard two of the last data clusters, leave one in the middle'
56 $QEMU_IO -c 'discard 121k 1k' "$TEST_IMG" | _filter_qemu_io
57 $QEMU_IO -c 'discard 123k 1k' "$TEST_IMG" | _filter_qemu_io
59 echo '### Corrupt the offset of the second refcount block'
60 refcount_table_offset=$(peek_file_be "$TEST_IMG" 48 8)
61 poke_file "$TEST_IMG" $(($refcount_table_offset+14)) "\x06"
63 # This tries to allocate the two clusters discarded earlier (guest
64 # offsets 121k and 123k). Their reference counts are in the first and
65 # second refcount blocks respectively, but only the first one can be
66 # allocated correctly because the second entry of the refcount table
67 # is corrupted.
68 echo '### Try to allocate the discarded clusters again'
69 $QEMU_IO -c 'write 121k 3k' "$TEST_IMG" | _filter_qemu_io
71 # success, all done
72 echo "*** done"
73 rm -f $seq.full
74 status=0