@@ -21,7 +21,8 @@
import time
import os
import iotests
-from iotests import qemu_img, qemu_io
+from iotests import qemu_img, qemu_io, qemu_img_pipe
+import json
backing_img = os.path.join(iotests.test_dir, 'backing.img')
mid_img = os.path.join(iotests.test_dir, 'mid.img')
@@ -956,6 +957,52 @@ class TestSetSpeed(iotests.QMPTestCase):
self.cancel_and_wait(resume=True)
+class TestCompressed(iotests.QMPTestCase):
+
+ def setUp(self):
+ qemu_img('create', '-f', iotests.imgfmt, backing_img, '1M')
+ qemu_img('create', '-f', iotests.imgfmt, '-o',
+ 'backing_file=%s' % backing_img, mid_img)
+ qemu_img('create', '-f', iotests.imgfmt, '-o',
+ 'backing_file=%s' % mid_img, test_img)
+ qemu_io('-c', 'write -P 0x1 0 512k', backing_img)
+ self.vm = iotests.VM().add_drive(test_img, "backing.node-name=mid," +
+ "backing.backing.node-name=base")
+ self.vm.launch()
+
+ def tearDown(self):
+ self.vm.shutdown()
+ os.remove(test_img)
+ os.remove(mid_img)
+ os.remove(backing_img)
+
+ def test_stream_compress(self):
+ self.assert_no_active_block_jobs()
+
+ result = self.vm.qmp('block-stream', device='mid', job_id='stream-mid')
+ self.assert_qmp(result, 'return', {})
+
+ self.wait_until_completed(drive='stream-mid')
+ for event in self.vm.get_qmp_events(wait=True):
+ if event['event'] == 'BLOCK_JOB_COMPLETED':
+ self.dictpath(event, 'data/device')
+ self.assert_qmp_absent(event, 'data/error')
+
+ result = self.vm.qmp('block-stream', device='drive0', base=mid_img,
+ job_id='stream-top', compress=True)
+ self.assert_qmp(result, 'return', {})
+
+ self.wait_until_completed(drive='stream-top')
+ self.assert_no_active_block_jobs()
+ self.vm.shutdown()
+
+ top = json.loads(qemu_img_pipe('info', '--output=json', test_img))
+ mid = json.loads(qemu_img_pipe('info', '--output=json', mid_img))
+ base = json.loads(qemu_img_pipe('info', '--output=json', backing_img))
+
+ self.assertEqual(mid['actual-size'], base['actual-size'])
+ self.assertLess(top['actual-size'], mid['actual-size'])
+
if __name__ == '__main__':
iotests.main(supported_fmts=['qcow2', 'qed'],
supported_protocols=['file'])
@@ -1,5 +1,5 @@
-...........................
+............................
----------------------------------------------------------------------
-Ran 27 tests
+Ran 28 tests
OK
Add a test case to the iotest #030 that checks 'compress' option for a block-stream job. Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com> --- tests/qemu-iotests/030 | 49 +++++++++++++++++++++++++++++++++++++++++++++- tests/qemu-iotests/030.out | 4 ++-- 2 files changed, 50 insertions(+), 3 deletions(-)