qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-block] [PATCH v2 3/3] iotests: Add test cases for drive-mirror "de


From: Fam Zheng
Subject: [Qemu-block] [PATCH v2 3/3] iotests: Add test cases for drive-mirror "detect-zeroes" option
Date: Mon, 8 Jun 2015 18:34:22 +0800

Signed-off-by: Fam Zheng <address@hidden>
---
 tests/qemu-iotests/132        | 28 +++++++++++++++++++++++++---
 tests/qemu-iotests/132.out    |  4 ++--
 tests/qemu-iotests/iotests.py |  7 +++++++
 3 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/tests/qemu-iotests/132 b/tests/qemu-iotests/132
index f53ef6e..a4a4f01 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,27 @@ class TestSingleDrive(iotests.QMPTestCase):
         self.assertTrue(iotests.compare_images(test_img, target_img),
                         'target image does not match source after mirroring')
 
+    def do_detect_zeroes_test(self, detect_zeroes, unmap):
+        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=detect_zeroes,
+                             unmap=unmap)
+        self.assert_qmp(result, 'return', {})
+        self.complete_and_wait('drive0')
+        self.vm.shutdown()
+        return qemu_img_map(target_img)
+
+    def test_detect_zeroes(self):
+        m = self.do_detect_zeroes_test(detect_zeroes=True, unmap=False);
+        self.assertTrue(m[0]["zero"])
+
+    def test_detect_zeroes_unmap(self):
+        m = self.do_detect_zeroes_test(detect_zeroes=True, unmap=True);
+        self.assertTrue(m[0]["zero"])
+
+    def test_no_detect_zeroes(self):
+        m = self.do_detect_zeroes_test(detect_zeroes=False, unmap=False);
+        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..89968f3 100644
--- a/tests/qemu-iotests/132.out
+++ b/tests/qemu-iotests/132.out
@@ -1,5 +1,5 @@
-.
+....
 ----------------------------------------------------------------------
-Ran 1 tests
+Ran 4 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]