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/>.
22 owner
=dplotnikov@virtuozzo.com
25 echo "QA output created by $seq"
27 status
=1 # failure is the default!
29 # standard environment
33 # This tests qocw2-specific low-level functionality
35 _supported_proto
file fuse
37 _unsupported_imgopts
'compat=0.10' data_file
39 COMPR_IMG
="$TEST_IMG.compressed"
40 RAND_FILE
="$TEST_DIR/rand_data"
45 _rm_test_img
"$COMPR_IMG"
48 trap "_cleanup; exit \$status" 0 1 2 3 15
53 # Check if we can run this test.
54 output
=$
(_make_test_img
-o 'compression_type=zstd' 64M
; _cleanup_test_img
)
55 if echo "$output" |
grep -q "Invalid parameter 'zstd'"; then
56 _notrun
"ZSTD is disabled"
60 echo "=== Testing compression type incompatible bit setting for zlib ==="
62 _make_test_img
-o compression_type
=zlib
64M
63 $PYTHON qcow2.py
"$TEST_IMG" dump-header |
grep incompatible_features
66 echo "=== Testing compression type incompatible bit setting for zstd ==="
68 _make_test_img
-o compression_type
=zstd
64M
69 $PYTHON qcow2.py
"$TEST_IMG" dump-header |
grep incompatible_features
72 echo "=== Testing zlib with incompatible bit set ==="
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."
84 echo "=== Testing zstd with incompatible bit unset ==="
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."
96 echo "=== Testing compression type values ==="
99 _make_test_img
-o compression_type
=zlib
64M
100 peek_file_be
"$TEST_IMG" 104 1
104 _make_test_img
-o compression_type
=zstd
64M
105 peek_file_be
"$TEST_IMG" 104 1
109 echo "=== Testing simple reading and writing with zstd ==="
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
119 echo "=== Testing adjacent clusters reading and writing with zstd ==="
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
131 echo "=== Testing incompressible cluster processing with zstd ==="
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"