[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH 2/2] iotests: Add test cases for drive-mirror "detec
From: |
Fam Zheng |
Subject: |
[Qemu-block] [PATCH 2/2] iotests: Add test cases for drive-mirror "detect-zeroes" option |
Date: |
Mon, 8 Jun 2015 15:06:25 +0800 |
Signed-off-by: Fam Zheng <address@hidden>
---
tests/qemu-iotests/132 | 26 +++++++++++++++++++++++---
tests/qemu-iotests/132.out | 4 ++--
tests/qemu-iotests/iotests.py | 7 +++++++
3 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/tests/qemu-iotests/132 b/tests/qemu-iotests/132
index f53ef6e..e506490 100644
--- a/tests/qemu-iotests/132
+++ b/tests/qemu-iotests/132
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Test mirror with unmap
+# Test mirror with unmap and zero source clusters
#
# Copyright (C) 2015 Red Hat, Inc.
#
@@ -21,7 +21,7 @@
import time
import os
import iotests
-from iotests import qemu_img, qemu_io
+from iotests import qemu_img, qemu_io, qemu_img_map
test_img = os.path.join(iotests.test_dir, 'test.img')
target_img = os.path.join(iotests.test_dir, 'target.img')
@@ -55,5 +55,25 @@ class TestSingleDrive(iotests.QMPTestCase):
self.assertTrue(iotests.compare_images(test_img, target_img),
'target image does not match source after mirroring')
+ def test_detect_zeroes(self):
+ self.vm.hmp_qemu_io('drive0', 'write -P 0 0 2M')
+ result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
+ target=target_img, detect_zeroes=True)
+ self.assert_qmp(result, 'return', {})
+ self.complete_and_wait('drive0')
+ self.vm.shutdown()
+ m = qemu_img_map(target_img)
+ self.assertTrue(m[0]["zero"])
+
+ def test_no_detect_zeroes(self):
+ self.vm.hmp_qemu_io('drive0', 'write -P 0 0 2M')
+ result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
+ target=target_img, detect_zeroes=False)
+ self.assert_qmp(result, 'return', {})
+ self.complete_and_wait('drive0')
+ self.vm.shutdown()
+ m = qemu_img_map(target_img)
+ self.assertFalse(m[0]["zero"])
+
if __name__ == '__main__':
- iotests.main(supported_fmts=['raw', 'qcow2'])
+ iotests.main(supported_fmts=['qcow2'])
diff --git a/tests/qemu-iotests/132.out b/tests/qemu-iotests/132.out
index ae1213e..8d7e996 100644
--- a/tests/qemu-iotests/132.out
+++ b/tests/qemu-iotests/132.out
@@ -1,5 +1,5 @@
-.
+...
----------------------------------------------------------------------
-Ran 1 tests
+Ran 3 tests
OK
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 8615b10..2ddc735 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -27,6 +27,7 @@ sys.path.append(os.path.join(os.path.dirname(__file__), '..',
'..', 'scripts', '
import qmp
import qtest
import struct
+import json
__all__ = ['imgfmt', 'imgproto', 'test_dir' 'qemu_img', 'qemu_io',
'VM', 'QMPTestCase', 'notrun', 'main']
@@ -58,6 +59,12 @@ def qemu_img_pipe(*args):
'''Run qemu-img and return its output'''
return subprocess.Popen(qemu_img_args + list(args),
stdout=subprocess.PIPE).communicate()[0]
+def qemu_img_map(*args):
+ '''Run qemu-img map and return the result parsed from the json formated
+ output '''
+ output = qemu_img_pipe(*(['map', '--output=json'] + list(args)))
+ return json.loads(output)
+
def qemu_io(*args):
'''Run qemu-io and return the stdout data'''
args = qemu_io_args + list(args)
--
2.4.2
[Qemu-block] [PATCH 2/2] iotests: Add test cases for drive-mirror "detect-zeroes" option,
Fam Zheng <=