ipxe: update binaries
[qemu/ar7.git] / tests / qemu-iotests / 287
blobf98a4cadc1283ec6694ef0745db56f2ea9549678
1 #!/usr/bin/env bash
3 # Test case for an image using zstd compression
5 # Copyright (c) 2020 Virtuozzo International GmbH
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # creator
22 owner=dplotnikov@virtuozzo.com
24 seq="$(basename $0)"
25 echo "QA output created by $seq"
27 status=1 # failure is the default!
29 # standard environment
30 . ./common.rc
31 . ./common.filter
33 # This tests qocw2-specific low-level functionality
34 _supported_fmt qcow2
35 _supported_proto file
36 _supported_os Linux
37 _unsupported_imgopts 'compat=0.10' data_file
39 COMPR_IMG="$TEST_IMG.compressed"
40 RAND_FILE="$TEST_DIR/rand_data"
42 _cleanup()
44 _cleanup_test_img
45 _rm_test_img "$COMPR_IMG"
46 rm -f "$RAND_FILE"
48 trap "_cleanup; exit \$status" 0 1 2 3 15
50 # for all the cases
51 CLUSTER_SIZE=65536
53 # Check if we can run this test.
54 if IMGOPTS='compression_type=zstd' _make_test_img 64M |
55 grep "Invalid parameter 'zstd'"; then
56 _notrun "ZSTD is disabled"
59 echo
60 echo "=== Testing compression type incompatible bit setting for zlib ==="
61 echo
62 _make_test_img -o compression_type=zlib 64M
63 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
65 echo
66 echo "=== Testing compression type incompatible bit setting for zstd ==="
67 echo
68 _make_test_img -o compression_type=zstd 64M
69 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
71 echo
72 echo "=== Testing zlib with incompatible bit set ==="
73 echo
74 _make_test_img -o compression_type=zlib 64M
75 $PYTHON qcow2.py "$TEST_IMG" set-feature-bit incompatible 3
76 # to make sure the bit was actually set
77 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
79 if $QEMU_IMG info "$TEST_IMG" >/dev/null 2>&1 ; then
80 echo "Error: The image opened successfully. The image must not be opened."
83 echo
84 echo "=== Testing zstd with incompatible bit unset ==="
85 echo
86 _make_test_img -o compression_type=zstd 64M
87 $PYTHON qcow2.py "$TEST_IMG" set-header incompatible_features 0
88 # to make sure the bit was actually unset
89 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
91 if $QEMU_IMG info "$TEST_IMG" >/dev/null 2>&1 ; then
92 echo "Error: The image opened successfully. The image must not be opened."
95 echo
96 echo "=== Testing compression type values ==="
97 echo
98 # zlib=0
99 _make_test_img -o compression_type=zlib 64M
100 peek_file_be "$TEST_IMG" 104 1
101 echo
103 # zstd=1
104 _make_test_img -o compression_type=zstd 64M
105 peek_file_be "$TEST_IMG" 104 1
106 echo
108 echo
109 echo "=== Testing simple reading and writing with zstd ==="
110 echo
111 _make_test_img -o compression_type=zstd 64M
112 $QEMU_IO -c "write -c -P 0xAC 64K 64K " "$TEST_IMG" | _filter_qemu_io
113 $QEMU_IO -c "read -P 0xAC 64K 64K " "$TEST_IMG" | _filter_qemu_io
114 # read on the cluster boundaries
115 $QEMU_IO -c "read -v 131070 8 " "$TEST_IMG" | _filter_qemu_io
116 $QEMU_IO -c "read -v 65534 8" "$TEST_IMG" | _filter_qemu_io
118 echo
119 echo "=== Testing adjacent clusters reading and writing with zstd ==="
120 echo
121 _make_test_img -o compression_type=zstd 64M
122 $QEMU_IO -c "write -c -P 0xAB 0 64K " "$TEST_IMG" | _filter_qemu_io
123 $QEMU_IO -c "write -c -P 0xAC 64K 64K " "$TEST_IMG" | _filter_qemu_io
124 $QEMU_IO -c "write -c -P 0xAD 128K 64K " "$TEST_IMG" | _filter_qemu_io
126 $QEMU_IO -c "read -P 0xAB 0 64k " "$TEST_IMG" | _filter_qemu_io
127 $QEMU_IO -c "read -P 0xAC 64K 64k " "$TEST_IMG" | _filter_qemu_io
128 $QEMU_IO -c "read -P 0xAD 128K 64k " "$TEST_IMG" | _filter_qemu_io
130 echo
131 echo "=== Testing incompressible cluster processing with zstd ==="
132 echo
133 # create a 2M image and fill it with 1M likely incompressible data
134 # and 1M compressible data
135 dd if=/dev/urandom of="$RAND_FILE" bs=1M count=1 seek=1
136 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS_NO_FMT" \
137 $QEMU_IO -f raw -c "write -P 0xFA 0 1M" "$RAND_FILE" | _filter_qemu_io
139 $QEMU_IMG convert -f raw -O $IMGFMT -c \
140 -o "$(_optstr_add "$IMGOPTS" "compression_type=zlib")" "$RAND_FILE" \
141 "$TEST_IMG" | _filter_qemu_io
143 $QEMU_IMG convert -O $IMGFMT -c \
144 -o "$(_optstr_add "$IMGOPTS" "compression_type=zstd")" "$TEST_IMG" \
145 "$COMPR_IMG" | _filter_qemu_io
147 $QEMU_IMG compare "$TEST_IMG" "$COMPR_IMG"
149 # success, all done
150 echo "*** done"
151 rm -f $seq.full
152 status=0