diff mbox series

[v1,8/8] iotests: 287: add qcow2 compression type test

Message ID 20200227072953.25445-9-dplotnikov@virtuozzo.com (mailing list archive)
State New, archived
Headers show
Series qcow2: Implement zstd cluster compression method | expand

Commit Message

Denis Plotnikov Feb. 27, 2020, 7:29 a.m. UTC
The test checks fulfilling qcow2 requiriements for the compression
type feature and zstd compression type operability.

Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
---
 tests/qemu-iotests/287     | 123 +++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/287.out |  41 +++++++++++++
 tests/qemu-iotests/group   |   1 +
 3 files changed, 165 insertions(+)
 create mode 100755 tests/qemu-iotests/287
 create mode 100644 tests/qemu-iotests/287.out

Comments

Vladimir Sementsov-Ogievskiy Feb. 27, 2020, 10:29 a.m. UTC | #1
27.02.2020 10:29, Denis Plotnikov wrote:
> The test checks fulfilling qcow2 requiriements for the compression
> type feature and zstd compression type operability.
> 
> Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
> ---
>   tests/qemu-iotests/287     | 123 +++++++++++++++++++++++++++++++++++++
>   tests/qemu-iotests/287.out |  41 +++++++++++++
>   tests/qemu-iotests/group   |   1 +
>   3 files changed, 165 insertions(+)
>   create mode 100755 tests/qemu-iotests/287
>   create mode 100644 tests/qemu-iotests/287.out
> 
> diff --git a/tests/qemu-iotests/287 b/tests/qemu-iotests/287
> new file mode 100755
> index 0000000000..41b916f690
> --- /dev/null
> +++ b/tests/qemu-iotests/287
> @@ -0,0 +1,123 @@
> +#!/usr/bin/env bash
> +#
> +# Test case for an image using zstd compression
> +#
> +# Copyright (c) 2020 Virtuozzo International GmbH
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 2 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +#
> +
> +# creator
> +owner=dplotnikov@virtuozzo.com
> +
> +seq="$(basename $0)"
> +echo "QA output created by $seq"
> +
> +status=1	# failure is the default!
> +
> +_cleanup()
> +{
> +	_cleanup_test_img
> +}
> +trap "_cleanup; exit \$status" 0 1 2 3 15
> +
> +# standard environment
> +. ./common.rc
> +. ./common.filter
> +
> +# This tests qocw2-specific low-level functionality
> +_supported_fmt qcow2
> +_supported_proto file
> +_supported_os Linux
> +
> +P=`echo "$QEMU_PROG" | sed "s/qemu-system-x86_64//"`
> +
> +grep "CONFIG_ZSTD=y" "$P"../config-host.mak >/dev/null
> +RES=$?

Hmm. This will not work for other architectures and for
out of tree builds. Also, it checks config but not current
binary (they may be out of sync, or even unrelated).

Probably better try to create image with zstd compression type
and handle expected error.


> +if (($RES)); then
> +    _notrun "ZSTD is disabled in the current configuration"
> +fi
> +
> +# Test: when compression is zlib the incompatible is unset
> +echo
> +echo "=== Testing compression type incompatible bit setting for zlib ==="
> +echo
> +
> +_make_test_img 64M
> +$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
> +
> +# Test: when compression differs from zlib the incompatible bit is set
> +echo
> +echo "=== Testing compression type incompatible bit setting for zstd ==="
> +echo
> +
> +IMGOPTS='compression_type=zstd' _make_test_img 64M
> +$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
> +
> +# Test: an image can't be openned if compression type is zlib and

opened

> +#       incompatible feature compression type is set
> +echo
> +echo "=== Testing zlib with incompatible bit set  ==="
> +echo
> +
> +IMGOPTS='compression_type=zlib' _make_test_img 64M
> +$PYTHON qcow2.py "$TEST_IMG" set-feature-bit incompatible 3
> +# to make sure the bit was actually set
> +$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
> +$QEMU_IMG info "$TEST_IMG" 2>1 1>/dev/null
> +if (($?==0)); then
> +    echo "Error: The image openned successfully. The image must not be openned"
> +fi

may be better to instead keep error output and just check it..

> +
> +# Test: an image can't be openned if compression type is NOT zlib and
> +#       incompatible feature compression type is UNSET
> +echo
> +echo "=== Testing zstd with incompatible bit unset  ==="
> +echo
> +
> +IMGOPTS='compression_type=zstd' _make_test_img 64M
> +$PYTHON qcow2.py "$TEST_IMG" set-header incompatible_features 0
> +# to make sure the bit was actually unset
> +$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
> +$QEMU_IMG info "$TEST_IMG" 2>1 1>/dev/null
> +if (($?==0)); then
> +    echo "Error: The image openned successfully. The image must not be openned"
> +fi
> +# Test: check compression type values
> +echo
> +echo "=== Testing compression type values  ==="
> +echo
> +# zlib=0
> +IMGOPTS='compression_type=zlib' _make_test_img 64M
> +od -j104 -N1 -An -vtu1 "$TEST_IMG"
> +
> +# zstd=1
> +IMGOPTS='compression_type=zstd' _make_test_img 64M
> +od -j104 -N1 -An -vtu1 "$TEST_IMG"
> +
> +# Test: using zstd compression, write to and read from an image
> +echo
> +echo "=== Testing reading and writing with zstd ==="
> +echo
> +
> +CLUSTER_SIZE=65536
> +IMGOPTS='compression_type=zstd' _make_test_img 64M
> +$QEMU_IO -c "write -c 0 64k " "$TEST_IMG" | _filter_qemu_io
> +$QEMU_IO -c "read -v 0 10 " "$TEST_IMG" | _filter_qemu_io
> +$QEMU_IO -c "read -v 65530 8" "$TEST_IMG" | _filter_qemu_io

Hmm output depends on default pattern. Better use "write -c -P 0x11 0 64k"
  (or any pattern you want), to make it explicit.

> +
> +# success, all done
> +echo "*** done"
> +rm -f $seq.full
> +status=0
> diff --git a/tests/qemu-iotests/287.out b/tests/qemu-iotests/287.out
> new file mode 100644
> index 0000000000..4218254ce0
> --- /dev/null
> +++ b/tests/qemu-iotests/287.out
> @@ -0,0 +1,41 @@
> +QA output created by 287
> +
> +=== Testing compression type incompatible bit setting for zlib ===
> +
> +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
> +incompatible_features     []
> +
> +=== Testing compression type incompatible bit setting for zstd ===
> +
> +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 compression_type=zstd
> +incompatible_features     [3]
> +
> +=== Testing zlib with incompatible bit set  ===
> +
> +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
> +incompatible_features     [3]
> +
> +=== Testing zstd with incompatible bit unset  ===
> +
> +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 compression_type=zstd
> +incompatible_features     []
> +
> +=== Testing compression type values  ===
> +
> +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
> +   0
> +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 compression_type=zstd
> +   1
> +
> +=== Testing reading and writing with zstd ===
> +
> +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 compression_type=zstd
> +wrote 65536/65536 bytes at offset 0
> +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
> +00000000:  cd cd cd cd cd cd cd cd cd cd  ..........
> +read 10/10 bytes at offset 0
> +10 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
> +0000fffa:  cd cd cd cd cd cd 00 00  ........
> +read 8/8 bytes at offset 65530
> +8 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
> +*** done
> diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
> index 0317667695..5edbadef40 100644
> --- a/tests/qemu-iotests/group
> +++ b/tests/qemu-iotests/group
> @@ -293,3 +293,4 @@
>   283 auto quick
>   284 rw
>   286 rw quick
> +287 auto quick
>
Denis Plotnikov Feb. 28, 2020, 8:23 a.m. UTC | #2
On 27.02.2020 13:29, Vladimir Sementsov-Ogievskiy wrote:
> 27.02.2020 10:29, Denis Plotnikov wrote:
>> The test checks fulfilling qcow2 requiriements for the compression
>> type feature and zstd compression type operability.
>>
>> Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
>> ---
>>   tests/qemu-iotests/287     | 123 +++++++++++++++++++++++++++++++++++++
>>   tests/qemu-iotests/287.out |  41 +++++++++++++
>>   tests/qemu-iotests/group   |   1 +
>>   3 files changed, 165 insertions(+)
>>   create mode 100755 tests/qemu-iotests/287
>>   create mode 100644 tests/qemu-iotests/287.out
>>
>> diff --git a/tests/qemu-iotests/287 b/tests/qemu-iotests/287
>> new file mode 100755
>> index 0000000000..41b916f690
>> --- /dev/null
>> +++ b/tests/qemu-iotests/287
>> @@ -0,0 +1,123 @@
>> +#!/usr/bin/env bash
>> +#
>> +# Test case for an image using zstd compression
>> +#
>> +# Copyright (c) 2020 Virtuozzo International GmbH
>> +#
>> +# This program is free software; you can redistribute it and/or modify
>> +# it under the terms of the GNU General Public License as published by
>> +# the Free Software Foundation; either version 2 of the License, or
>> +# (at your option) any later version.
>> +#
>> +# This program is distributed in the hope that it will be useful,
>> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
>> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> +# GNU General Public License for more details.
>> +#
>> +# You should have received a copy of the GNU General Public License
>> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
>> +#
>> +
>> +# creator
>> +owner=dplotnikov@virtuozzo.com
>> +
>> +seq="$(basename $0)"
>> +echo "QA output created by $seq"
>> +
>> +status=1    # failure is the default!
>> +
>> +_cleanup()
>> +{
>> +    _cleanup_test_img
>> +}
>> +trap "_cleanup; exit \$status" 0 1 2 3 15
>> +
>> +# standard environment
>> +. ./common.rc
>> +. ./common.filter
>> +
>> +# This tests qocw2-specific low-level functionality
>> +_supported_fmt qcow2
>> +_supported_proto file
>> +_supported_os Linux
>> +
>> +P=`echo "$QEMU_PROG" | sed "s/qemu-system-x86_64//"`
>> +
>> +grep "CONFIG_ZSTD=y" "$P"../config-host.mak >/dev/null
>> +RES=$?
>
> Hmm. This will not work for other architectures and for
> out of tree builds. Also, it checks config but not current
> binary (they may be out of sync, or even unrelated).
>
> Probably better try to create image with zstd compression type
> and handle expected error.
What if the error is "unable to create an image with zstd", although it 
has to be?
I think the best way is to ask qemu binary whether it supports zstd, but 
it doesn't available by now (should be?)

Is there any other way to make sure that the std compression test has to 
be executed?
>
>
>> +if (($RES)); then
>> +    _notrun "ZSTD is disabled in the current configuration"
>> +fi
>> +
>> +# Test: when compression is zlib the incompatible is unset
>> +echo
>> +echo "=== Testing compression type incompatible bit setting for zlib 
>> ==="
>> +echo
>> +
>> +_make_test_img 64M
>> +$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
>> +
>> +# Test: when compression differs from zlib the incompatible bit is set
>> +echo
>> +echo "=== Testing compression type incompatible bit setting for zstd 
>> ==="
>> +echo
>> +
>> +IMGOPTS='compression_type=zstd' _make_test_img 64M
>> +$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
>> +
>> +# Test: an image can't be openned if compression type is zlib and
>
> opened
>
>> +#       incompatible feature compression type is set
>> +echo
>> +echo "=== Testing zlib with incompatible bit set  ==="
>> +echo
>> +
>> +IMGOPTS='compression_type=zlib' _make_test_img 64M
>> +$PYTHON qcow2.py "$TEST_IMG" set-feature-bit incompatible 3
>> +# to make sure the bit was actually set
>> +$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
>> +$QEMU_IMG info "$TEST_IMG" 2>1 1>/dev/null
>> +if (($?==0)); then
>> +    echo "Error: The image openned successfully. The image must not 
>> be openned"
>> +fi
>
> may be better to instead keep error output and just check it..
I add the explicit message to reduce the investigating time of what 
happened and what should it be.
If it isn't that important I'd rather leave it as is.
>
>> +
>> +# Test: an image can't be openned if compression type is NOT zlib and
>> +#       incompatible feature compression type is UNSET
>> +echo
>> +echo "=== Testing zstd with incompatible bit unset  ==="
>> +echo
>> +
>> +IMGOPTS='compression_type=zstd' _make_test_img 64M
>> +$PYTHON qcow2.py "$TEST_IMG" set-header incompatible_features 0
>> +# to make sure the bit was actually unset
>> +$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
>> +$QEMU_IMG info "$TEST_IMG" 2>1 1>/dev/null
>> +if (($?==0)); then
>> +    echo "Error: The image openned successfully. The image must not 
>> be openned"
>> +fi
>> +# Test: check compression type values
>> +echo
>> +echo "=== Testing compression type values  ==="
>> +echo
>> +# zlib=0
>> +IMGOPTS='compression_type=zlib' _make_test_img 64M
>> +od -j104 -N1 -An -vtu1 "$TEST_IMG"
>> +
>> +# zstd=1
>> +IMGOPTS='compression_type=zstd' _make_test_img 64M
>> +od -j104 -N1 -An -vtu1 "$TEST_IMG"
>> +
>> +# Test: using zstd compression, write to and read from an image
>> +echo
>> +echo "=== Testing reading and writing with zstd ==="
>> +echo
>> +
>> +CLUSTER_SIZE=65536
>> +IMGOPTS='compression_type=zstd' _make_test_img 64M
>> +$QEMU_IO -c "write -c 0 64k " "$TEST_IMG" | _filter_qemu_io
>> +$QEMU_IO -c "read -v 0 10 " "$TEST_IMG" | _filter_qemu_io
>> +$QEMU_IO -c "read -v 65530 8" "$TEST_IMG" | _filter_qemu_io
>
> Hmm output depends on default pattern. Better use "write -c -P 0x11 0 
> 64k"
>  (or any pattern you want), to make it explicit.
Good suggestion, I'll change that
>
>> +
>> +# success, all done
>> +echo "*** done"
>> +rm -f $seq.full
>> +status=0
>> diff --git a/tests/qemu-iotests/287.out b/tests/qemu-iotests/287.out
>> new file mode 100644
>> index 0000000000..4218254ce0
>> --- /dev/null
>> +++ b/tests/qemu-iotests/287.out
>> @@ -0,0 +1,41 @@
>> +QA output created by 287
>> +
>> +=== Testing compression type incompatible bit setting for zlib ===
>> +
>> +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
>> +incompatible_features     []
>> +
>> +=== Testing compression type incompatible bit setting for zstd ===
>> +
>> +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 
>> compression_type=zstd
>> +incompatible_features     [3]
>> +
>> +=== Testing zlib with incompatible bit set  ===
>> +
>> +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
>> +incompatible_features     [3]
>> +
>> +=== Testing zstd with incompatible bit unset  ===
>> +
>> +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 
>> compression_type=zstd
>> +incompatible_features     []
>> +
>> +=== Testing compression type values  ===
>> +
>> +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
>> +   0
>> +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 
>> compression_type=zstd
>> +   1
>> +
>> +=== Testing reading and writing with zstd ===
>> +
>> +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 
>> compression_type=zstd
>> +wrote 65536/65536 bytes at offset 0
>> +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
>> +00000000:  cd cd cd cd cd cd cd cd cd cd  ..........
>> +read 10/10 bytes at offset 0
>> +10 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
>> +0000fffa:  cd cd cd cd cd cd 00 00  ........
>> +read 8/8 bytes at offset 65530
>> +8 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
>> +*** done
>> diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
>> index 0317667695..5edbadef40 100644
>> --- a/tests/qemu-iotests/group
>> +++ b/tests/qemu-iotests/group
>> @@ -293,3 +293,4 @@
>>   283 auto quick
>>   284 rw
>>   286 rw quick
>> +287 auto quick
>>
>
>
Vladimir Sementsov-Ogievskiy Feb. 28, 2020, 8:32 a.m. UTC | #3
28.02.2020 11:23, Denis Plotnikov wrote:
> 
> 
> On 27.02.2020 13:29, Vladimir Sementsov-Ogievskiy wrote:
>> 27.02.2020 10:29, Denis Plotnikov wrote:
>>> The test checks fulfilling qcow2 requiriements for the compression
>>> type feature and zstd compression type operability.
>>>
>>> Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
>>> ---
>>>   tests/qemu-iotests/287     | 123 +++++++++++++++++++++++++++++++++++++
>>>   tests/qemu-iotests/287.out |  41 +++++++++++++
>>>   tests/qemu-iotests/group   |   1 +
>>>   3 files changed, 165 insertions(+)
>>>   create mode 100755 tests/qemu-iotests/287
>>>   create mode 100644 tests/qemu-iotests/287.out
>>>
>>> diff --git a/tests/qemu-iotests/287 b/tests/qemu-iotests/287
>>> new file mode 100755
>>> index 0000000000..41b916f690
>>> --- /dev/null
>>> +++ b/tests/qemu-iotests/287
>>> @@ -0,0 +1,123 @@
>>> +#!/usr/bin/env bash
>>> +#
>>> +# Test case for an image using zstd compression
>>> +#
>>> +# Copyright (c) 2020 Virtuozzo International GmbH
>>> +#
>>> +# This program is free software; you can redistribute it and/or modify
>>> +# it under the terms of the GNU General Public License as published by
>>> +# the Free Software Foundation; either version 2 of the License, or
>>> +# (at your option) any later version.
>>> +#
>>> +# This program is distributed in the hope that it will be useful,
>>> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
>>> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>>> +# GNU General Public License for more details.
>>> +#
>>> +# You should have received a copy of the GNU General Public License
>>> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
>>> +#
>>> +
>>> +# creator
>>> +owner=dplotnikov@virtuozzo.com
>>> +
>>> +seq="$(basename $0)"
>>> +echo "QA output created by $seq"
>>> +
>>> +status=1    # failure is the default!
>>> +
>>> +_cleanup()
>>> +{
>>> +    _cleanup_test_img
>>> +}
>>> +trap "_cleanup; exit \$status" 0 1 2 3 15
>>> +
>>> +# standard environment
>>> +. ./common.rc
>>> +. ./common.filter
>>> +
>>> +# This tests qocw2-specific low-level functionality
>>> +_supported_fmt qcow2
>>> +_supported_proto file
>>> +_supported_os Linux
>>> +
>>> +P=`echo "$QEMU_PROG" | sed "s/qemu-system-x86_64//"`
>>> +
>>> +grep "CONFIG_ZSTD=y" "$P"../config-host.mak >/dev/null
>>> +RES=$?
>>
>> Hmm. This will not work for other architectures and for
>> out of tree builds. Also, it checks config but not current
>> binary (they may be out of sync, or even unrelated).
>>
>> Probably better try to create image with zstd compression type
>> and handle expected error.
> What if the error is "unable to create an image with zstd", although it has to be?

With such message test should fail. I expect something like "unknown option" error in case of not built in zstd, and I think it's OK to check such message and skip the test.

> I think the best way is to ask qemu binary whether it supports zstd, but it doesn't available by now (should be?)

And in this case the problem is the same: what if it will say that it doesn't support it, although it should support? We can't check such things anyway.

> 
> Is there any other way to make sure that the std compression test has to be executed?
>>
>>
>>> +if (($RES)); then
>>> +    _notrun "ZSTD is disabled in the current configuration"
>>> +fi
>>> +
>>> +# Test: when compression is zlib the incompatible is unset
>>> +echo
>>> +echo "=== Testing compression type incompatible bit setting for zlib ==="
>>> +echo
>>> +
>>> +_make_test_img 64M
>>> +$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
>>> +
>>> +# Test: when compression differs from zlib the incompatible bit is set
>>> +echo
>>> +echo "=== Testing compression type incompatible bit setting for zstd ==="
>>> +echo
>>> +
>>> +IMGOPTS='compression_type=zstd' _make_test_img 64M
>>> +$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
>>> +
>>> +# Test: an image can't be openned if compression type is zlib and
>>
>> opened
>>
>>> +#       incompatible feature compression type is set
>>> +echo
>>> +echo "=== Testing zlib with incompatible bit set  ==="
>>> +echo
>>> +
>>> +IMGOPTS='compression_type=zlib' _make_test_img 64M
>>> +$PYTHON qcow2.py "$TEST_IMG" set-feature-bit incompatible 3
>>> +# to make sure the bit was actually set
>>> +$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
>>> +$QEMU_IMG info "$TEST_IMG" 2>1 1>/dev/null
>>> +if (($?==0)); then
>>> +    echo "Error: The image openned successfully. The image must not be openned"
>>> +fi
>>
>> may be better to instead keep error output and just check it..
> I add the explicit message to reduce the investigating time of what happened and what should it be.
> If it isn't that important I'd rather leave it as is.

of course, up to you

>>
>>> +
>>> +# Test: an image can't be openned if compression type is NOT zlib and
>>> +#       incompatible feature compression type is UNSET
>>> +echo
>>> +echo "=== Testing zstd with incompatible bit unset  ==="
>>> +echo
>>> +
>>> +IMGOPTS='compression_type=zstd' _make_test_img 64M
>>> +$PYTHON qcow2.py "$TEST_IMG" set-header incompatible_features 0
>>> +# to make sure the bit was actually unset
>>> +$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
>>> +$QEMU_IMG info "$TEST_IMG" 2>1 1>/dev/null
>>> +if (($?==0)); then
>>> +    echo "Error: The image openned successfully. The image must not be openned"
>>> +fi
>>> +# Test: check compression type values
>>> +echo
>>> +echo "=== Testing compression type values  ==="
>>> +echo
>>> +# zlib=0
>>> +IMGOPTS='compression_type=zlib' _make_test_img 64M
>>> +od -j104 -N1 -An -vtu1 "$TEST_IMG"
>>> +
>>> +# zstd=1
>>> +IMGOPTS='compression_type=zstd' _make_test_img 64M
>>> +od -j104 -N1 -An -vtu1 "$TEST_IMG"
>>> +
>>> +# Test: using zstd compression, write to and read from an image
>>> +echo
>>> +echo "=== Testing reading and writing with zstd ==="
>>> +echo
>>> +
>>> +CLUSTER_SIZE=65536
>>> +IMGOPTS='compression_type=zstd' _make_test_img 64M
>>> +$QEMU_IO -c "write -c 0 64k " "$TEST_IMG" | _filter_qemu_io
>>> +$QEMU_IO -c "read -v 0 10 " "$TEST_IMG" | _filter_qemu_io
>>> +$QEMU_IO -c "read -v 65530 8" "$TEST_IMG" | _filter_qemu_io
>>
>> Hmm output depends on default pattern. Better use "write -c -P 0x11 0 64k"
>>  (or any pattern you want), to make it explicit.
> Good suggestion, I'll change that
>>
>>> +
>>> +# success, all done
>>> +echo "*** done"
>>> +rm -f $seq.full
>>> +status=0
>>> diff --git a/tests/qemu-iotests/287.out b/tests/qemu-iotests/287.out
>>> new file mode 100644
>>> index 0000000000..4218254ce0
>>> --- /dev/null
>>> +++ b/tests/qemu-iotests/287.out
>>> @@ -0,0 +1,41 @@
>>> +QA output created by 287
>>> +
>>> +=== Testing compression type incompatible bit setting for zlib ===
>>> +
>>> +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
>>> +incompatible_features     []
>>> +
>>> +=== Testing compression type incompatible bit setting for zstd ===
>>> +
>>> +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 compression_type=zstd
>>> +incompatible_features     [3]
>>> +
>>> +=== Testing zlib with incompatible bit set  ===
>>> +
>>> +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
>>> +incompatible_features     [3]
>>> +
>>> +=== Testing zstd with incompatible bit unset  ===
>>> +
>>> +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 compression_type=zstd
>>> +incompatible_features     []
>>> +
>>> +=== Testing compression type values  ===
>>> +
>>> +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
>>> +   0
>>> +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 compression_type=zstd
>>> +   1
>>> +
>>> +=== Testing reading and writing with zstd ===
>>> +
>>> +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 compression_type=zstd
>>> +wrote 65536/65536 bytes at offset 0
>>> +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
>>> +00000000:  cd cd cd cd cd cd cd cd cd cd  ..........
>>> +read 10/10 bytes at offset 0
>>> +10 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
>>> +0000fffa:  cd cd cd cd cd cd 00 00  ........
>>> +read 8/8 bytes at offset 65530
>>> +8 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
>>> +*** done
>>> diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
>>> index 0317667695..5edbadef40 100644
>>> --- a/tests/qemu-iotests/group
>>> +++ b/tests/qemu-iotests/group
>>> @@ -293,3 +293,4 @@
>>>   283 auto quick
>>>   284 rw
>>>   286 rw quick
>>> +287 auto quick
>>>
>>
>>
>
diff mbox series

Patch

diff --git a/tests/qemu-iotests/287 b/tests/qemu-iotests/287
new file mode 100755
index 0000000000..41b916f690
--- /dev/null
+++ b/tests/qemu-iotests/287
@@ -0,0 +1,123 @@ 
+#!/usr/bin/env bash
+#
+# Test case for an image using zstd compression
+#
+# Copyright (c) 2020 Virtuozzo International GmbH
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+# creator
+owner=dplotnikov@virtuozzo.com
+
+seq="$(basename $0)"
+echo "QA output created by $seq"
+
+status=1	# failure is the default!
+
+_cleanup()
+{
+	_cleanup_test_img
+}
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+# standard environment
+. ./common.rc
+. ./common.filter
+
+# This tests qocw2-specific low-level functionality
+_supported_fmt qcow2
+_supported_proto file
+_supported_os Linux
+
+P=`echo "$QEMU_PROG" | sed "s/qemu-system-x86_64//"`
+
+grep "CONFIG_ZSTD=y" "$P"../config-host.mak >/dev/null
+RES=$?
+if (($RES)); then
+    _notrun "ZSTD is disabled in the current configuration"
+fi
+
+# Test: when compression is zlib the incompatible is unset
+echo
+echo "=== Testing compression type incompatible bit setting for zlib ==="
+echo
+
+_make_test_img 64M
+$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
+
+# Test: when compression differs from zlib the incompatible bit is set
+echo
+echo "=== Testing compression type incompatible bit setting for zstd ==="
+echo
+
+IMGOPTS='compression_type=zstd' _make_test_img 64M
+$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
+
+# Test: an image can't be openned if compression type is zlib and
+#       incompatible feature compression type is set
+echo
+echo "=== Testing zlib with incompatible bit set  ==="
+echo
+
+IMGOPTS='compression_type=zlib' _make_test_img 64M
+$PYTHON qcow2.py "$TEST_IMG" set-feature-bit incompatible 3
+# to make sure the bit was actually set
+$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
+$QEMU_IMG info "$TEST_IMG" 2>1 1>/dev/null
+if (($?==0)); then
+    echo "Error: The image openned successfully. The image must not be openned"
+fi
+
+# Test: an image can't be openned if compression type is NOT zlib and
+#       incompatible feature compression type is UNSET
+echo
+echo "=== Testing zstd with incompatible bit unset  ==="
+echo
+
+IMGOPTS='compression_type=zstd' _make_test_img 64M
+$PYTHON qcow2.py "$TEST_IMG" set-header incompatible_features 0
+# to make sure the bit was actually unset
+$PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
+$QEMU_IMG info "$TEST_IMG" 2>1 1>/dev/null
+if (($?==0)); then
+    echo "Error: The image openned successfully. The image must not be openned"
+fi
+# Test: check compression type values
+echo
+echo "=== Testing compression type values  ==="
+echo
+# zlib=0
+IMGOPTS='compression_type=zlib' _make_test_img 64M
+od -j104 -N1 -An -vtu1 "$TEST_IMG"
+
+# zstd=1
+IMGOPTS='compression_type=zstd' _make_test_img 64M
+od -j104 -N1 -An -vtu1 "$TEST_IMG"
+
+# Test: using zstd compression, write to and read from an image
+echo
+echo "=== Testing reading and writing with zstd ==="
+echo
+
+CLUSTER_SIZE=65536
+IMGOPTS='compression_type=zstd' _make_test_img 64M
+$QEMU_IO -c "write -c 0 64k " "$TEST_IMG" | _filter_qemu_io
+$QEMU_IO -c "read -v 0 10 " "$TEST_IMG" | _filter_qemu_io
+$QEMU_IO -c "read -v 65530 8" "$TEST_IMG" | _filter_qemu_io
+
+# success, all done
+echo "*** done"
+rm -f $seq.full
+status=0
diff --git a/tests/qemu-iotests/287.out b/tests/qemu-iotests/287.out
new file mode 100644
index 0000000000..4218254ce0
--- /dev/null
+++ b/tests/qemu-iotests/287.out
@@ -0,0 +1,41 @@ 
+QA output created by 287
+
+=== Testing compression type incompatible bit setting for zlib ===
+
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
+incompatible_features     []
+
+=== Testing compression type incompatible bit setting for zstd ===
+
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 compression_type=zstd
+incompatible_features     [3]
+
+=== Testing zlib with incompatible bit set  ===
+
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
+incompatible_features     [3]
+
+=== Testing zstd with incompatible bit unset  ===
+
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 compression_type=zstd
+incompatible_features     []
+
+=== Testing compression type values  ===
+
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
+   0
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 compression_type=zstd
+   1
+
+=== Testing reading and writing with zstd ===
+
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 compression_type=zstd
+wrote 65536/65536 bytes at offset 0
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+00000000:  cd cd cd cd cd cd cd cd cd cd  ..........
+read 10/10 bytes at offset 0
+10 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+0000fffa:  cd cd cd cd cd cd 00 00  ........
+read 8/8 bytes at offset 65530
+8 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+*** done
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
index 0317667695..5edbadef40 100644
--- a/tests/qemu-iotests/group
+++ b/tests/qemu-iotests/group
@@ -293,3 +293,4 @@ 
 283 auto quick
 284 rw
 286 rw quick
+287 auto quick