From 05b4cd5d3c20c9d7a75f0533b57b9c1c3d06e6e7 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Thu, 7 Sep 2017 10:50:00 +0200 Subject: qemu-iotests: Add missing -machine accel=qtest A basic set of qemu options is initialised in ./common: export QEMU_OPTIONS="-nodefaults -machine accel=qtest" However, two test cases (172 and 186) overwrite QEMU_OPTIONS and neglect to manually set '-machine accel=qtest'. Add the missing option for 172. 186 probably only copied the code from 172, it doesn't actually need to overwrite QEMU_OPTIONS, so remove that in 186. Signed-off-by: Kevin Wolf Tested-by: Cornelia Huck Reviewed-by: Cornelia Huck --- tests/qemu-iotests/172 | 2 +- tests/qemu-iotests/186 | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/qemu-iotests/172 b/tests/qemu-iotests/172 index 826d6fe..02c5f79 100755 --- a/tests/qemu-iotests/172 +++ b/tests/qemu-iotests/172 @@ -56,7 +56,7 @@ function do_run_qemu() done fi echo quit - ) | $QEMU -nographic -monitor stdio -serial none "$@" + ) | $QEMU -machine accel=qtest -nographic -monitor stdio -serial none "$@" echo } diff --git a/tests/qemu-iotests/186 b/tests/qemu-iotests/186 index 2b9f618..44cc01e 100755 --- a/tests/qemu-iotests/186 +++ b/tests/qemu-iotests/186 @@ -56,15 +56,15 @@ function do_run_qemu() done fi echo quit - ) | $QEMU -S -nodefaults -display none -device virtio-scsi-pci -monitor stdio "$@" 2>&1 + ) | $QEMU -S -display none -device virtio-scsi-pci -monitor stdio "$@" 2>&1 echo } function check_info_block() { echo "info block" | - QEMU_OPTIONS="" do_run_qemu "$@" | _filter_win32 | _filter_hmp | - _filter_qemu | _filter_generated_node_ids + do_run_qemu "$@" | _filter_win32 | _filter_hmp | _filter_qemu | + _filter_generated_node_ids } -- cgit v1.1 From f1d5516ab583130157852fe475f96fd7cce227c3 Mon Sep 17 00:00:00 2001 From: Cornelia Huck Date: Wed, 13 Sep 2017 11:10:36 +0200 Subject: iotests: use -ccw on s390x for 040, 139, and 182 The default cpu model on s390x does not provide zPCI, which is not yet wired up on tcg. Moreover, virtio-ccw is the standard on s390x, so use the -ccw instead of the -pci versions of virtio devices on s390x. Reviewed-by: Kevin Wolf Signed-off-by: Cornelia Huck Reviewed-by: QingFeng Hao Signed-off-by: Kevin Wolf --- tests/qemu-iotests/040 | 6 +++++- tests/qemu-iotests/139 | 12 ++++++++++-- tests/qemu-iotests/182 | 13 +++++++++++-- 3 files changed, 26 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/qemu-iotests/040 b/tests/qemu-iotests/040 index 95b7510..c284d08 100755 --- a/tests/qemu-iotests/040 +++ b/tests/qemu-iotests/040 @@ -82,7 +82,11 @@ class TestSingleDrive(ImageCommitTestCase): qemu_io('-f', 'raw', '-c', 'write -P 0xab 0 524288', backing_img) qemu_io('-f', iotests.imgfmt, '-c', 'write -P 0xef 524288 524288', mid_img) self.vm = iotests.VM().add_drive(test_img, "node-name=top,backing.node-name=mid,backing.backing.node-name=base", interface="none") - self.vm.add_device("virtio-scsi-pci") + if iotests.qemu_default_machine == 's390-ccw-virtio': + self.vm.add_device("virtio-scsi-ccw") + else: + self.vm.add_device("virtio-scsi-pci") + self.vm.add_device("scsi-hd,id=scsi0,drive=drive0") self.vm.launch() diff --git a/tests/qemu-iotests/139 b/tests/qemu-iotests/139 index 50cf40f..f8f0280 100644 --- a/tests/qemu-iotests/139 +++ b/tests/qemu-iotests/139 @@ -25,13 +25,21 @@ import time base_img = os.path.join(iotests.test_dir, 'base.img') new_img = os.path.join(iotests.test_dir, 'new.img') +if iotests.qemu_default_machine == 's390-ccw-virtio': + default_virtio_blk = 'virtio-blk-ccw' +else: + default_virtio_blk = 'virtio-blk-pci' class TestBlockdevDel(iotests.QMPTestCase): def setUp(self): iotests.qemu_img('create', '-f', iotests.imgfmt, base_img, '1M') self.vm = iotests.VM() - self.vm.add_device("virtio-scsi-pci,id=virtio-scsi") + if iotests.qemu_default_machine == 's390-ccw-virtio': + self.vm.add_device("virtio-scsi-ccw,id=virtio-scsi") + else: + self.vm.add_device("virtio-scsi-pci,id=virtio-scsi") + self.vm.launch() def tearDown(self): @@ -87,7 +95,7 @@ class TestBlockdevDel(iotests.QMPTestCase): self.checkBlockDriverState(node, expect_error) # Add a device model - def addDeviceModel(self, device, backend, driver = 'virtio-blk-pci'): + def addDeviceModel(self, device, backend, driver = default_virtio_blk): result = self.vm.qmp('device_add', id = device, driver = driver, drive = backend) self.assert_qmp(result, 'return', {}) diff --git a/tests/qemu-iotests/182 b/tests/qemu-iotests/182 index 7ecbb22..2e078ce 100755 --- a/tests/qemu-iotests/182 +++ b/tests/qemu-iotests/182 @@ -45,17 +45,26 @@ _supported_os Linux size=32M +case "$QEMU_DEFAULT_MACHINE" in + s390-ccw-virtio) + virtioblk=virtio-blk-ccw + ;; + *) + virtioblk=virtio-blk-pci + ;; +esac + _make_test_img $size echo "Starting QEMU" _launch_qemu -drive file=$TEST_IMG,if=none,id=drive0,file.locking=on \ - -device virtio-blk-pci,drive=drive0 + -device $virtioblk,drive=drive0 echo echo "Starting a second QEMU using the same image should fail" echo 'quit' | $QEMU -monitor stdio \ -drive file=$TEST_IMG,if=none,id=drive0,file.locking=on \ - -device virtio-blk-pci,drive=drive0 2>&1 | _filter_testdir 2>&1 | + -device $virtioblk,drive=drive0 2>&1 | _filter_testdir 2>&1 | _filter_qemu | sed -e '/falling back to POSIX file/d' \ -e '/locks can be lost unexpectedly/d' -- cgit v1.1 From 75f02ed53a0dd7fff641de5c73566ee9abe4cf94 Mon Sep 17 00:00:00 2001 From: Cornelia Huck Date: Wed, 13 Sep 2017 11:10:37 +0200 Subject: iotests: use -ccw on s390x for 051 The default cpu model on s390x does not provide zPCI, which is not yet wired up on tcg. Moreover, virtio-ccw is the standard on s390x, so use the -ccw instead of the -pci versions of virtio devices on s390x. Signed-off-by: Cornelia Huck Reviewed-by: QingFeng Hao Reviewed-by: David Hildenbrand Reviewed-by: Thomas Huth Signed-off-by: Kevin Wolf --- tests/qemu-iotests/051 | 12 +++++++++++- tests/qemu-iotests/051.out | 2 +- tests/qemu-iotests/051.pc.out | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/qemu-iotests/051 b/tests/qemu-iotests/051 index c8cfc76..dba8816 100755 --- a/tests/qemu-iotests/051 +++ b/tests/qemu-iotests/051 @@ -103,7 +103,17 @@ echo echo === Device without drive === echo -run_qemu -device virtio-scsi-pci -device scsi-hd +case "$QEMU_DEFAULT_MACHINE" in + s390-ccw-virtio) + virtio_scsi=virtio-scsi-ccw + ;; + *) + virtio_scsi=virtio-scsi-pci + ;; +esac + +run_qemu -device $virtio_scsi -device scsi-hd | + sed -e "s/$virtio_scsi/VIRTIO_SCSI/" echo echo === Overriding backing file === diff --git a/tests/qemu-iotests/051.out b/tests/qemu-iotests/051.out index 4d3b1ff..e3c6eab 100644 --- a/tests/qemu-iotests/051.out +++ b/tests/qemu-iotests/051.out @@ -49,7 +49,7 @@ QEMU_PROG: -drive file=TEST_DIR/t.qcow2,driver=qcow2,format=qcow2: Cannot specif === Device without drive === -Testing: -device virtio-scsi-pci -device scsi-hd +Testing: -device VIRTIO_SCSI -device scsi-hd QEMU X.Y.Z monitor - type 'help' for more information (qemu) QEMU_PROG: -device scsi-hd: drive property not set diff --git a/tests/qemu-iotests/051.pc.out b/tests/qemu-iotests/051.pc.out index 762fb9f..f2c5622 100644 --- a/tests/qemu-iotests/051.pc.out +++ b/tests/qemu-iotests/051.pc.out @@ -49,7 +49,7 @@ QEMU_PROG: -drive file=TEST_DIR/t.qcow2,driver=qcow2,format=qcow2: Cannot specif === Device without drive === -Testing: -device virtio-scsi-pci -device scsi-hd +Testing: -device VIRTIO_SCSI -device scsi-hd QEMU X.Y.Z monitor - type 'help' for more information (qemu) QEMU_PROG: -device scsi-hd: drive property not set -- cgit v1.1 From b1149c1a2ad8eaecca08e78f677513672ff3d627 Mon Sep 17 00:00:00 2001 From: Cornelia Huck Date: Wed, 13 Sep 2017 11:10:38 +0200 Subject: iotests: use virtio aliases for 067 The default cpu model on s390x does not provide zPCI, which is not yet wired up on tcg. Moreover, virtio-ccw is the standard on s390x. Using virtio-scsi will implicitly pick the right device, so just switch to that for simplicity. Signed-off-by: Cornelia Huck Reviewed-by: QingFeng Hao Reviewed-by: David Hildenbrand Reviewed-by: Thomas Huth Signed-off-by: Kevin Wolf --- tests/qemu-iotests/067 | 2 +- tests/qemu-iotests/067.out | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/qemu-iotests/067 b/tests/qemu-iotests/067 index 5d4ca4b..ee9595f 100755 --- a/tests/qemu-iotests/067 +++ b/tests/qemu-iotests/067 @@ -141,7 +141,7 @@ echo echo === Empty drive with -device and device_del === echo -run_qemu -device virtio-scsi-pci -device scsi-cd,id=cd0 < Date: Fri, 15 Sep 2017 13:45:26 +0800 Subject: iotests: Print full path of bad output if mismatch So it is easier to copy paste the path. Signed-off-by: Fam Zheng Signed-off-by: Kevin Wolf --- tests/qemu-iotests/check | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/qemu-iotests/check b/tests/qemu-iotests/check index d504b6e..4583a0c 100755 --- a/tests/qemu-iotests/check +++ b/tests/qemu-iotests/check @@ -353,7 +353,7 @@ do else echo " - output mismatch (see $seq.out.bad)" mv $tmp.out $seq.out.bad - $diff -w "$reference" $seq.out.bad + $diff -w "$reference" $(realpath $seq.out.bad) err=true fi fi -- cgit v1.1 From f3adefb2cea1c63b7b198acaef5e40eb4b2d2d39 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Fri, 22 Sep 2017 14:50:12 +0200 Subject: qemu-io: Drop write permissions before read-only reopen qemu-io provides a 'reopen' command that allows switching from writable to read-only access. We need to make sure that we don't try to keep write permissions to a BlockBackend that becomes read-only, otherwise things are going to fail. This requires a bdrv_drain() call because otherwise in-flight AIO write requests could issue new internal requests while the permission has already gone away, which would cause assertion failures. Draining the queue doesn't break AIO requests in any new way, bdrv_reopen() would drain it anyway only a few lines later. Signed-off-by: Kevin Wolf Reviewed-by: Fam Zheng --- tests/qemu-iotests/187.out | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/qemu-iotests/187.out b/tests/qemu-iotests/187.out index 68fb944..30b987f7 100644 --- a/tests/qemu-iotests/187.out +++ b/tests/qemu-iotests/187.out @@ -12,7 +12,7 @@ Start from read-write wrote 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -write failed: Operation not permitted +Block node is read-only wrote 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) *** done -- cgit v1.1 From 3fb23e07516aae13d1ba566740c1c81ae12184b7 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Fri, 15 Sep 2017 18:56:41 +0200 Subject: qemu-iotests: Test change-backing-file command This involves a temporary read-write reopen if the backing file link in the middle of a backing file chain should be changed and is therefore a good test for the latest bdrv_reopen() vs. op blockers fixes. Signed-off-by: Kevin Wolf --- tests/qemu-iotests/195 | 92 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/195.out | 78 +++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 171 insertions(+) create mode 100755 tests/qemu-iotests/195 create mode 100644 tests/qemu-iotests/195.out (limited to 'tests') diff --git a/tests/qemu-iotests/195 b/tests/qemu-iotests/195 new file mode 100755 index 0000000..05a239c --- /dev/null +++ b/tests/qemu-iotests/195 @@ -0,0 +1,92 @@ +#!/bin/bash +# +# Test change-backing-file command +# +# Copyright (C) 2017 Red Hat, Inc. +# +# 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 . +# + +# creator +owner=kwolf@redhat.com + +seq=`basename $0` +echo "QA output created by $seq" + +here=`pwd` +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img + rm -f "$TEST_IMG.mid" +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt qcow2 +_supported_proto file +_supported_os Linux + +function do_run_qemu() +{ + echo Testing: "$@" | _filter_imgfmt + $QEMU -nographic -qmp-pretty stdio -serial none "$@" + echo +} + +function run_qemu() +{ + do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp \ + | _filter_qemu_io | _filter_generated_node_ids +} + +size=64M +TEST_IMG="$TEST_IMG.base" _make_test_img $size +TEST_IMG="$TEST_IMG.mid" _make_test_img -b "$TEST_IMG.base" +_make_test_img -b "$TEST_IMG.mid" + +echo +echo "Change backing file of mid (opened read-only)" +echo + +run_qemu -drive if=none,file="$TEST_IMG",backing.node-name=mid < Date: Mon, 25 Sep 2017 17:55:29 +0300 Subject: iotests: fix 181: enable postcopy-ram capability on target Migration capabilities should be enabled on both source and destination qemu processes. Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Kevin Wolf --- tests/qemu-iotests/181 | 2 ++ tests/qemu-iotests/181.out | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/qemu-iotests/181 b/tests/qemu-iotests/181 index 0333dda..0c91e8f 100755 --- a/tests/qemu-iotests/181 +++ b/tests/qemu-iotests/181 @@ -93,7 +93,9 @@ echo # Slow down migration so much that it definitely won't finish before we can # switch to postcopy +# Enable postcopy-ram capability both on source and destination silent=yes +_send_qemu_cmd $dest 'migrate_set_capability postcopy-ram on' "(qemu)" _send_qemu_cmd $src 'migrate_set_speed 4k' "(qemu)" _send_qemu_cmd $src 'migrate_set_capability postcopy-ram on' "(qemu)" _send_qemu_cmd $src "migrate -d unix:${MIG_SOCKET}" "(qemu)" diff --git a/tests/qemu-iotests/181.out b/tests/qemu-iotests/181.out index 6534ba2..d58c6a9 100644 --- a/tests/qemu-iotests/181.out +++ b/tests/qemu-iotests/181.out @@ -20,7 +20,6 @@ read 65536/65536 bytes at offset 0 === Do some I/O on the destination === -QEMU X.Y.Z monitor - type 'help' for more information (qemu) qemu-io disk "read -P 0x55 0 64k" read 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -- cgit v1.1 From 4ffca8904a350460cdaa6304ea8c9b9c693d2d91 Mon Sep 17 00:00:00 2001 From: Pavel Butsykin Date: Mon, 18 Sep 2017 15:42:27 +0300 Subject: qemu-img: add --shrink flag for resize The flag is additional precaution against data loss. Perhaps in the future the operation shrink without this flag will be blocked for all formats, but for now we need to maintain compatibility with raw. Signed-off-by: Pavel Butsykin Reviewed-by: Max Reitz Reviewed-by: John Snow Message-id: 20170918124230.8152-2-pbutsykin@virtuozzo.com [mreitz: Added a missing space to a warning] Signed-off-by: Max Reitz --- tests/qemu-iotests/102 | 4 ++-- tests/qemu-iotests/106 | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/qemu-iotests/102 b/tests/qemu-iotests/102 index 87db1bb..d7ad8d9 100755 --- a/tests/qemu-iotests/102 +++ b/tests/qemu-iotests/102 @@ -54,7 +54,7 @@ _make_test_img $IMG_SIZE $QEMU_IO -c 'write 0 64k' "$TEST_IMG" | _filter_qemu_io # Remove data cluster from image (first cluster: image header, second: reftable, # third: refblock, fourth: L1 table, fifth: L2 table) -$QEMU_IMG resize -f raw "$TEST_IMG" $((5 * 64 * 1024)) +$QEMU_IMG resize -f raw --shrink "$TEST_IMG" $((5 * 64 * 1024)) $QEMU_IO -c map "$TEST_IMG" $QEMU_IMG map "$TEST_IMG" @@ -69,7 +69,7 @@ $QEMU_IO -c 'write 0 64k' "$TEST_IMG" | _filter_qemu_io qemu_comm_method=monitor _launch_qemu -drive if=none,file="$TEST_IMG",id=drv0 -$QEMU_IMG resize -f raw "$TEST_IMG" $((5 * 64 * 1024)) +$QEMU_IMG resize -f raw --shrink "$TEST_IMG" $((5 * 64 * 1024)) _send_qemu_cmd $QEMU_HANDLE 'qemu-io drv0 map' 'allocated' \ | sed -e 's/^(qemu).*qemu-io drv0 map...$/(qemu) qemu-io drv0 map/' diff --git a/tests/qemu-iotests/106 b/tests/qemu-iotests/106 index 3264957..bfe71f4 100755 --- a/tests/qemu-iotests/106 +++ b/tests/qemu-iotests/106 @@ -83,7 +83,7 @@ echo '=== Testing image shrinking ===' for growth_mode in falloc full off; do echo echo "--- growth_mode=$growth_mode ---" - $QEMU_IMG resize -f "$IMGFMT" --preallocation=$growth_mode "$TEST_IMG" -${GROWTH_SIZE}K + $QEMU_IMG resize -f "$IMGFMT" --shrink --preallocation=$growth_mode "$TEST_IMG" -${GROWTH_SIZE}K done # success, all done -- cgit v1.1 From fefac70d2a4c2bfb895fdcf2bdc5baf1253eeb74 Mon Sep 17 00:00:00 2001 From: Pavel Butsykin Date: Mon, 18 Sep 2017 15:42:30 +0300 Subject: qemu-iotests: add shrinking image test Signed-off-by: Pavel Butsykin Reviewed-by: Max Reitz Reviewed-by: John Snow Message-id: 20170918124230.8152-5-pbutsykin@virtuozzo.com Signed-off-by: Max Reitz --- tests/qemu-iotests/163 | 170 +++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/163.out | 5 ++ tests/qemu-iotests/group | 1 + 3 files changed, 176 insertions(+) create mode 100644 tests/qemu-iotests/163 create mode 100644 tests/qemu-iotests/163.out (limited to 'tests') diff --git a/tests/qemu-iotests/163 b/tests/qemu-iotests/163 new file mode 100644 index 0000000..4038423 --- /dev/null +++ b/tests/qemu-iotests/163 @@ -0,0 +1,170 @@ +#!/usr/bin/env python +# +# Tests for shrinking images +# +# Copyright (c) 2016-2017 Parallels 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 . +# + +import os, random, iotests, struct, qcow2 +from iotests import qemu_img, qemu_io, image_size + +test_img = os.path.join(iotests.test_dir, 'test.img') +check_img = os.path.join(iotests.test_dir, 'check.img') + +def size_to_int(str): + suff = ['B', 'K', 'M', 'G', 'T'] + return int(str[:-1]) * 1024**suff.index(str[-1:]) + +class ShrinkBaseClass(iotests.QMPTestCase): + image_len = '128M' + shrink_size = '10M' + chunk_size = '16M' + refcount_bits = '16' + + def __qcow2_check(self, filename): + entry_bits = 3 + entry_size = 1 << entry_bits + l1_mask = 0x00fffffffffffe00 + div_roundup = lambda n, d: (n + d - 1) / d + + def split_by_n(data, n): + for x in xrange(0, len(data), n): + yield struct.unpack('>Q', data[x:x + n])[0] & l1_mask + + def check_l1_table(h, l1_data): + l1_list = list(split_by_n(l1_data, entry_size)) + real_l1_size = div_roundup(h.size, + 1 << (h.cluster_bits*2 - entry_size)) + used, unused = l1_list[:real_l1_size], l1_list[real_l1_size:] + + self.assertTrue(len(used) != 0, "Verifying l1 table content") + self.assertFalse(any(unused), "Verifying l1 table content") + + def check_reftable(fd, h, reftable): + for offset in split_by_n(reftable, entry_size): + if offset != 0: + fd.seek(offset) + cluster = fd.read(1 << h.cluster_bits) + self.assertTrue(any(cluster), "Verifying reftable content") + + with open(filename, "rb") as fd: + h = qcow2.QcowHeader(fd) + + fd.seek(h.l1_table_offset) + l1_table = fd.read(h.l1_size << entry_bits) + + fd.seek(h.refcount_table_offset) + reftable = fd.read(h.refcount_table_clusters << h.cluster_bits) + + check_l1_table(h, l1_table) + check_reftable(fd, h, reftable) + + def __raw_check(self, filename): + pass + + image_check = { + 'qcow2' : __qcow2_check, + 'raw' : __raw_check + } + + def setUp(self): + if iotests.imgfmt == 'raw': + qemu_img('create', '-f', iotests.imgfmt, test_img, self.image_len) + qemu_img('create', '-f', iotests.imgfmt, check_img, + self.shrink_size) + else: + qemu_img('create', '-f', iotests.imgfmt, + '-o', 'cluster_size=' + self.cluster_size + + ',refcount_bits=' + self.refcount_bits, + test_img, self.image_len) + qemu_img('create', '-f', iotests.imgfmt, + '-o', 'cluster_size=%s'% self.cluster_size, + check_img, self.shrink_size) + qemu_io('-c', 'write -P 0xff 0 ' + self.shrink_size, check_img) + + def tearDown(self): + os.remove(test_img) + os.remove(check_img) + + def image_verify(self): + self.assertEqual(image_size(test_img), image_size(check_img), + "Verifying image size") + self.image_check[iotests.imgfmt](self, test_img) + + if iotests.imgfmt == 'raw': + return + self.assertEqual(qemu_img('check', test_img), 0, + "Verifying image corruption") + + def test_empty_image(self): + qemu_img('resize', '-f', iotests.imgfmt, '--shrink', test_img, + self.shrink_size) + + self.assertEqual( + qemu_io('-c', 'read -P 0x00 %s'%self.shrink_size, test_img), + qemu_io('-c', 'read -P 0x00 %s'%self.shrink_size, check_img), + "Verifying image content") + + self.image_verify() + + def test_sequential_write(self): + for offs in range(0, size_to_int(self.image_len), + size_to_int(self.chunk_size)): + qemu_io('-c', 'write -P 0xff %d %s' % (offs, self.chunk_size), + test_img) + + qemu_img('resize', '-f', iotests.imgfmt, '--shrink', test_img, + self.shrink_size) + + self.assertEqual(qemu_img("compare", test_img, check_img), 0, + "Verifying image content") + + self.image_verify() + + def test_random_write(self): + offs_list = range(0, size_to_int(self.image_len), + size_to_int(self.chunk_size)) + random.shuffle(offs_list) + for offs in offs_list: + qemu_io('-c', 'write -P 0xff %d %s' % (offs, self.chunk_size), + test_img) + + qemu_img('resize', '-f', iotests.imgfmt, '--shrink', test_img, + self.shrink_size) + + self.assertEqual(qemu_img("compare", test_img, check_img), 0, + "Verifying image content") + + self.image_verify() + +class TestShrink512(ShrinkBaseClass): + image_len = '3M' + shrink_size = '1M' + chunk_size = '256K' + cluster_size = '512' + refcount_bits = '64' + +class TestShrink64K(ShrinkBaseClass): + cluster_size = '64K' + +class TestShrink1M(ShrinkBaseClass): + cluster_size = '1M' + refcount_bits = '1' + +ShrinkBaseClass = None + +if __name__ == '__main__': + iotests.main(supported_fmts=['raw', 'qcow2']) diff --git a/tests/qemu-iotests/163.out b/tests/qemu-iotests/163.out new file mode 100644 index 0000000..dae404e --- /dev/null +++ b/tests/qemu-iotests/163.out @@ -0,0 +1,5 @@ +......... +---------------------------------------------------------------------- +Ran 9 tests + +OK diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 108339c..cdccee3 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -166,6 +166,7 @@ 159 rw auto quick 160 rw auto quick 162 auto quick +163 rw auto quick 165 rw auto quick 170 rw auto quick 171 rw auto quick -- cgit v1.1