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/>.
23 owner
=dplotnikov@virtuozzo.com
26 echo "QA output created by $seq"
28 status
=1 # failure is the default!
30 # standard environment
34 # This tests qocw2-specific low-level functionality
36 _supported_proto
file fuse
38 _unsupported_imgopts
'compat=0.10' data_file
40 COMPR_IMG
="$TEST_IMG.compressed"
41 RAND_FILE
="$TEST_DIR/rand_data"
46 _rm_test_img
"$COMPR_IMG"
49 trap "_cleanup; exit \$status" 0 1 2 3 15
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"
61 echo "=== Testing compression type incompatible bit setting for zlib ==="
63 _make_test_img
-o compression_type
=zlib
64M
64 _qcow2_dump_header
--no-filter-compression |
grep incompatible_features
67 echo "=== Testing compression type incompatible bit setting for zstd ==="
69 _make_test_img
-o compression_type
=zstd
64M
70 _qcow2_dump_header
--no-filter-compression |
grep incompatible_features
73 echo "=== Testing zlib with incompatible bit set ==="
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."
85 echo "=== Testing zstd with incompatible bit unset ==="
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."
97 echo "=== Testing compression type values ==="
100 _make_test_img
-o compression_type
=zlib
64M
101 peek_file_be
"$TEST_IMG" 104 1
105 _make_test_img
-o compression_type
=zstd
64M
106 peek_file_be
"$TEST_IMG" 104 1
110 echo "=== Testing simple reading and writing with zstd ==="
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
120 echo "=== Testing adjacent clusters reading and writing with zstd ==="
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
132 echo "=== Testing incompressible cluster processing with zstd ==="
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"