MAINTAINERS: Add include/hw/timer/tmu012.h to the SH4 R2D section
[qemu/kevin.git] / tests / qemu-iotests / 314
blob96d7b4d2581fdbece748676a8d1a266e5da0f204
1 #!/usr/bin/env bash
2 # group: rw backing auto quick
4 # Test qemu-img rebase with compression
6 # Copyright (c) 2023 Virtuozzo International GmbH.
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=andrey.drobyshev@virtuozzo.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
33 _rm_test_img "$TEST_IMG.base"
34 _rm_test_img "$TEST_IMG.itmd"
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
46 # Want the size divisible by 2 and 3
47 size=$(( 48 * 1024 * 1024 ))
48 half_size=$(( size / 2 ))
49 third_size=$(( size / 3 ))
51 # 1. "qemu-img rebase -c" should refuse working with any format which doesn't
52 # support compression. We only check "-f raw" here.
53 echo
54 echo "=== Testing compressed rebase format compatibility ==="
55 echo
57 $QEMU_IMG create -f raw "$TEST_IMG" "$size" | _filter_img_create
58 $QEMU_IMG rebase -c -f raw -b "" "$TEST_IMG"
60 # 2. Write the 1st half of $size to backing file (compressed), 2nd half -- to
61 # the top image (also compressed). Rebase the top image onto no backing file,
62 # with compression (i.e. "qemu-img -c -b ''"). Check that the resulting image
63 # has the written data preserved, and "qemu-img check" reports 100% clusters
64 # as compressed.
65 echo
66 echo "=== Testing rebase with compression onto no backing file ==="
67 echo
69 TEST_IMG="$TEST_IMG.base" _make_test_img $size
70 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT $size
72 $QEMU_IO -c "write -c -P 0xaa 0 $half_size" "$TEST_IMG.base" | _filter_qemu_io
73 $QEMU_IO -c "write -c -P 0xbb $half_size $half_size" "$TEST_IMG" \
74 | _filter_qemu_io
76 $QEMU_IMG rebase -c -f $IMGFMT -b "" "$TEST_IMG"
78 $QEMU_IO -c "read -P 0xaa 0 $half_size" "$TEST_IMG" | _filter_qemu_io
79 $QEMU_IO -c "read -P 0xbb $half_size $half_size" "$TEST_IMG" | _filter_qemu_io
81 $QEMU_IMG check "$TEST_IMG" | _filter_testdir
83 # 3. Same as the previous one, but with raw backing file (hence write to
84 # the backing is uncompressed).
85 echo
86 echo "=== Testing rebase with compression with raw backing file ==="
87 echo
89 $QEMU_IMG create -f raw "$TEST_IMG.base" "$half_size" | _filter_img_create
90 _make_test_img -b "$TEST_IMG.base" -F raw $size
92 $QEMU_IO -f raw -c "write -P 0xaa 0 $half_size" "$TEST_IMG.base" \
93 | _filter_qemu_io
94 $QEMU_IO -c "write -c -P 0xbb $half_size $half_size" \
95 "$TEST_IMG" | _filter_qemu_io
97 $QEMU_IMG rebase -c -f $IMGFMT -b "" "$TEST_IMG"
99 $QEMU_IO -c "read -P 0xaa 0 $half_size" "$TEST_IMG" | _filter_qemu_io
100 $QEMU_IO -c "read -P 0xbb $half_size $half_size" "$TEST_IMG" | _filter_qemu_io
102 $QEMU_IMG check "$TEST_IMG" | _filter_testdir
104 # 4. Create a backing chain base<--itmd<--img, filling 1st, 2nd and 3rd
105 # thirds of them, respectively (with compression). Rebase img onto base,
106 # effectively deleting itmd from the chain, and check that written data is
107 # preserved in the resulting image. Also check that "qemu-img check" reports
108 # 100% clusters as compressed.
109 echo
110 echo "=== Testing compressed rebase removing single delta from the chain ==="
111 echo
113 TEST_IMG="$TEST_IMG.base" _make_test_img $size
114 TEST_IMG="$TEST_IMG.itmd" _make_test_img -b "$TEST_IMG.base" -F $IMGFMT $size
115 _make_test_img -b "$TEST_IMG.itmd" -F $IMGFMT $size
117 $QEMU_IO -c "write -c -P 0xaa 0 $third_size" \
118 "$TEST_IMG.base" | _filter_qemu_io
119 $QEMU_IO -c "write -c -P 0xbb $third_size $third_size" \
120 "$TEST_IMG.itmd" | _filter_qemu_io
121 $QEMU_IO -c "write -c -P 0xcc $((third_size * 2 )) $third_size" \
122 "$TEST_IMG" | _filter_qemu_io
124 $QEMU_IMG rebase -c -f $IMGFMT -b "$TEST_IMG.base" -F $IMGFMT "$TEST_IMG"
126 $QEMU_IO -c "read -P 0xaa 0 $third_size" "$TEST_IMG" | _filter_qemu_io
127 $QEMU_IO -c "read -P 0xbb $third_size $third_size" \
128 "$TEST_IMG" | _filter_qemu_io
129 $QEMU_IO -c "read -P 0xcc $(( third_size * 2 )) $third_size" \
130 "$TEST_IMG" | _filter_qemu_io
132 $QEMU_IMG check "$TEST_IMG" | _filter_testdir
134 # 5. Create one-cluster backing and overlay images, and fill only the first
135 # (half - 1) bytes of the backing with data (uncompressed). Rebase the
136 # overlay onto no backing file with compression. Check that data is still
137 # read correctly, and that cluster is now really compressed ("qemu-img check"
138 # reports 100% clusters as compressed.
139 echo
140 echo "=== Testing compressed rebase with unaligned unmerged data ==="
141 echo
143 CLUSTER_SIZE=65536
145 TEST_IMG="$TEST_IMG.base" _make_test_img $CLUSTER_SIZE
146 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT $CLUSTER_SIZE
148 $QEMU_IO -c "write -P 0xaa 0 $(( CLUSTER_SIZE / 2 - 1 ))" $TEST_IMG.base \
149 | _filter_qemu_io
151 $QEMU_IMG rebase -c -f $IMGFMT -b "" "$TEST_IMG"
153 $QEMU_IO -c "read -P 0xaa 0 $(( CLUSTER_SIZE / 2 - 1 ))" "$TEST_IMG" \
154 | _filter_qemu_io
155 $QEMU_IO -c \
156 "read -P 0x00 $(( CLUSTER_SIZE / 2 - 1 )) $(( CLUSTER_SIZE / 2 + 1 ))" \
157 "$TEST_IMG" | _filter_qemu_io
159 $QEMU_IMG check "$TEST_IMG" | _filter_testdir
161 # success, all done
162 echo
163 echo '*** done'
164 rm -f $seq.full
165 status=0