xics/spapr: Detect old KVM XICS on POWER9 hosts
[qemu/ar7.git] / tests / qemu-iotests / 214
blob21ec8a2ad839739c4557a50d98655266e3357ce1
1 #!/usr/bin/env bash
3 # Test qcow2 image compression
5 # Copyright (C) 2018 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 seq=$(basename "$0")
23 echo "QA output created by $seq"
25 status=1 # failure is the default!
27 _cleanup()
29 _cleanup_test_img
31 trap "_cleanup; exit \$status" 0 1 2 3 15
33 # get standard environment, filters and checks
34 . ./common.rc
35 . ./common.filter
37 _supported_fmt qcow2
38 _supported_proto file
40 # Repairing the corrupted image requires qemu-img check to store a
41 # refcount up to 3, which requires at least two refcount bits.
42 _unsupported_imgopts 'refcount_bits=1[^0-9]'
45 echo
46 echo "=== Corrupted size field in compressed cluster descriptor ==="
47 echo
48 # Create an empty image and fill half of it with compressed data.
49 # The L2 entries of the two compressed clusters are located at
50 # 0x800000 and 0x800008, their original values are 0x4008000000a00000
51 # and 0x4008000000a00802 (5 sectors for compressed data each).
52 _make_test_img 8M -o cluster_size=2M
53 $QEMU_IO -c "write -c -P 0x11 0 2M" -c "write -c -P 0x11 2M 2M" "$TEST_IMG" \
54 2>&1 | _filter_qemu_io | _filter_testdir
56 # Reduce size of compressed data to 4 sectors: this corrupts the image.
57 poke_file "$TEST_IMG" $((0x800000)) "\x40\x06"
58 $QEMU_IO -c "read -P 0x11 0 4M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
60 # 'qemu-img check' however doesn't see anything wrong because it
61 # doesn't try to decompress the data and the refcounts are consistent.
62 # TODO: update qemu-img so this can be detected.
63 _check_test_img
65 # Increase size of compressed data to the maximum (8192 sectors).
66 # This makes QEMU read more data (8192 sectors instead of 5, host
67 # addresses [0xa00000, 0xdfffff]), but the decompression algorithm
68 # stops once we have enough to restore the uncompressed cluster, so
69 # the rest of the data is ignored.
70 poke_file "$TEST_IMG" $((0x800000)) "\x7f\xfe"
71 # Do it also for the second compressed cluster (L2 entry at 0x800008).
72 # In this case the compressed data would span 3 host clusters
73 # (host addresses: [0xa00802, 0xe00801])
74 poke_file "$TEST_IMG" $((0x800008)) "\x7f\xfe"
76 # Here the image is too small so we're asking QEMU to read beyond the
77 # end of the image.
78 $QEMU_IO -c "read -P 0x11 0 4M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
79 # But if we grow the image we won't be reading beyond its end anymore.
80 $QEMU_IO -c "write -P 0x22 4M 4M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
81 $QEMU_IO -c "read -P 0x11 0 4M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
83 # The refcount data is however wrong because due to the increased size
84 # of the compressed data it now reaches the following host clusters.
85 # This can be repaired by qemu-img check by increasing the refcount of
86 # those clusters.
87 # TODO: update qemu-img to correct the compressed cluster size instead.
88 _check_test_img -r all
89 $QEMU_IO -c "read -P 0x11 0 4M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
90 $QEMU_IO -c "read -P 0x22 4M 4M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
92 # success, all done
93 echo '*** done'
94 rm -f $seq.full
95 status=0