Merge tag 'qemu-macppc-20230206' of https://github.com/mcayland/qemu into staging
[qemu.git] / tests / qemu-iotests / 287
blob6414640b2121d6511d7dcb11cda126116856758a
1 #!/usr/bin/env bash
2 # group: auto quick
4 # Test case for an image using zstd compression
6 # Copyright (c) 2020 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=dplotnikov@virtuozzo.com
25 seq="$(basename $0)"
26 echo "QA output created by $seq"
28 status=1 # failure is the default!
30 # standard environment
31 . ./common.rc
32 . ./common.filter
34 # This tests qocw2-specific low-level functionality
35 _supported_fmt qcow2
36 _supported_proto file fuse
37 _supported_os Linux
38 _unsupported_imgopts 'compat=0.10' data_file
40 COMPR_IMG="$TEST_IMG.compressed"
41 RAND_FILE="$TEST_DIR/rand_data"
43 _cleanup()
45 _cleanup_test_img
46 _rm_test_img "$COMPR_IMG"
47 rm -f "$RAND_FILE"
49 trap "_cleanup; exit \$status" 0 1 2 3 15
51 # for all the cases
52 CLUSTER_SIZE=65536
54 # Check if we can run this test.
55 output=$(_make_test_img -o 'compression_type=zstd' 64M; _cleanup_test_img)
56 if echo "$output" | grep -q "Parameter 'compression-type' does not accept value 'zstd'"; then
57 _notrun "ZSTD is disabled"
60 echo
61 echo "=== Testing compression type incompatible bit setting for zlib ==="
62 echo
63 _make_test_img -o compression_type=zlib 64M
64 _qcow2_dump_header --no-filter-compression | grep incompatible_features
66 echo
67 echo "=== Testing compression type incompatible bit setting for zstd ==="
68 echo
69 _make_test_img -o compression_type=zstd 64M
70 _qcow2_dump_header --no-filter-compression | grep incompatible_features
72 echo
73 echo "=== Testing zlib with incompatible bit set ==="
74 echo
75 _make_test_img -o compression_type=zlib 64M
76 $PYTHON qcow2.py "$TEST_IMG" set-feature-bit incompatible 3
77 # to make sure the bit was actually set
78 _qcow2_dump_header --no-filter-compression | grep incompatible_features
80 if $QEMU_IMG info "$TEST_IMG" >/dev/null 2>&1 ; then
81 echo "Error: The image opened successfully. The image must not be opened."
84 echo
85 echo "=== Testing zstd with incompatible bit unset ==="
86 echo
87 _make_test_img -o compression_type=zstd 64M
88 $PYTHON qcow2.py "$TEST_IMG" set-header incompatible_features 0
89 # to make sure the bit was actually unset
90 _qcow2_dump_header --no-filter-compression | grep incompatible_features
92 if $QEMU_IMG info "$TEST_IMG" >/dev/null 2>&1 ; then
93 echo "Error: The image opened successfully. The image must not be opened."
96 echo
97 echo "=== Testing compression type values ==="
98 echo
99 # zlib=0
100 _make_test_img -o compression_type=zlib 64M
101 peek_file_be "$TEST_IMG" 104 1
102 echo
104 # zstd=1
105 _make_test_img -o compression_type=zstd 64M
106 peek_file_be "$TEST_IMG" 104 1
107 echo
109 echo
110 echo "=== Testing simple reading and writing with zstd ==="
111 echo
112 _make_test_img -o compression_type=zstd 64M
113 $QEMU_IO -c "write -c -P 0xAC 64K 64K " "$TEST_IMG" | _filter_qemu_io
114 $QEMU_IO -c "read -P 0xAC 64K 64K " "$TEST_IMG" | _filter_qemu_io
115 # read on the cluster boundaries
116 $QEMU_IO -c "read -v 131070 8 " "$TEST_IMG" | _filter_qemu_io
117 $QEMU_IO -c "read -v 65534 8" "$TEST_IMG" | _filter_qemu_io
119 echo
120 echo "=== Testing adjacent clusters reading and writing with zstd ==="
121 echo
122 _make_test_img -o compression_type=zstd 64M
123 $QEMU_IO -c "write -c -P 0xAB 0 64K " "$TEST_IMG" | _filter_qemu_io
124 $QEMU_IO -c "write -c -P 0xAC 64K 64K " "$TEST_IMG" | _filter_qemu_io
125 $QEMU_IO -c "write -c -P 0xAD 128K 64K " "$TEST_IMG" | _filter_qemu_io
127 $QEMU_IO -c "read -P 0xAB 0 64k " "$TEST_IMG" | _filter_qemu_io
128 $QEMU_IO -c "read -P 0xAC 64K 64k " "$TEST_IMG" | _filter_qemu_io
129 $QEMU_IO -c "read -P 0xAD 128K 64k " "$TEST_IMG" | _filter_qemu_io
131 echo
132 echo "=== Testing incompressible cluster processing with zstd ==="
133 echo
134 # create a 2M image and fill it with 1M likely incompressible data
135 # and 1M compressible data
136 dd if=/dev/urandom of="$RAND_FILE" bs=1M count=1 seek=1
137 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS_NO_FMT" \
138 $QEMU_IO -f raw -c "write -P 0xFA 0 1M" "$RAND_FILE" | _filter_qemu_io
140 $QEMU_IMG convert -f raw -O $IMGFMT -c \
141 -o "$(_optstr_add "$IMGOPTS" "compression_type=zlib")" "$RAND_FILE" \
142 "$TEST_IMG" | _filter_qemu_io
144 $QEMU_IMG convert -O $IMGFMT -c \
145 -o "$(_optstr_add "$IMGOPTS" "compression_type=zstd")" "$TEST_IMG" \
146 "$COMPR_IMG" | _filter_qemu_io
148 $QEMU_IMG compare "$TEST_IMG" "$COMPR_IMG"
150 # success, all done
151 echo "*** done"
152 rm -f $seq.full
153 status=0