287 (4757B)
1 #!/usr/bin/env bash 2 # group: auto quick 3 # 4 # Test case for an image using zstd compression 5 # 6 # Copyright (c) 2020 Virtuozzo International GmbH 7 # 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. 12 # 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. 17 # 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/>. 20 # 21 22 # creator 23 owner=dplotnikov@virtuozzo.com 24 25 seq="$(basename $0)" 26 echo "QA output created by $seq" 27 28 status=1 # failure is the default! 29 30 # standard environment 31 . ./common.rc 32 . ./common.filter 33 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 39 40 COMPR_IMG="$TEST_IMG.compressed" 41 RAND_FILE="$TEST_DIR/rand_data" 42 43 _cleanup() 44 { 45 _cleanup_test_img 46 _rm_test_img "$COMPR_IMG" 47 rm -f "$RAND_FILE" 48 } 49 trap "_cleanup; exit \$status" 0 1 2 3 15 50 51 # for all the cases 52 CLUSTER_SIZE=65536 53 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" 58 fi 59 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 65 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 71 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 79 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." 82 fi 83 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 91 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." 94 fi 95 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 103 104 # zstd=1 105 _make_test_img -o compression_type=zstd 64M 106 peek_file_be "$TEST_IMG" 104 1 107 echo 108 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 118 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 126 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 130 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 139 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 143 144 $QEMU_IMG convert -O $IMGFMT -c \ 145 -o "$(_optstr_add "$IMGOPTS" "compression_type=zstd")" "$TEST_IMG" \ 146 "$COMPR_IMG" | _filter_qemu_io 147 148 $QEMU_IMG compare "$TEST_IMG" "$COMPR_IMG" 149 150 # success, all done 151 echo "*** done" 152 rm -f $seq.full 153 status=0