diff mbox

[V6,2/3] Add tests for sync modes 'TOP' and 'NONE'

Message ID 1374530960-22031-3-git-send-email-imain@redhat.com
State New
Headers show

Commit Message

Ian Main July 22, 2013, 10:09 p.m. UTC
This patch adds tests for sync modes top and none.  Also added are tests
for invalid and missing formats.

Signed-off-by: Ian Main <imain@redhat.com>
---
 tests/qemu-iotests/055        | 108 +++++++++++++++++++++++++++++++++++++-----
 tests/qemu-iotests/055.out    |   4 +-
 tests/qemu-iotests/group      |   2 +-
 tests/qemu-iotests/iotests.py |   5 ++
 4 files changed, 103 insertions(+), 16 deletions(-)

Comments

Kevin Wolf July 24, 2013, 11:19 a.m. UTC | #1
Am 23.07.2013 um 00:09 hat Ian Main geschrieben:
> This patch adds tests for sync modes top and none.  Also added are tests
> for invalid and missing formats.
> 
> Signed-off-by: Ian Main <imain@redhat.com>
> ---
>  tests/qemu-iotests/055        | 108 +++++++++++++++++++++++++++++++++++++-----
>  tests/qemu-iotests/055.out    |   4 +-
>  tests/qemu-iotests/group      |   2 +-
>  tests/qemu-iotests/iotests.py |   5 ++
>  4 files changed, 103 insertions(+), 16 deletions(-)

> @@ -127,7 +202,8 @@ class TestSetSpeed(iotests.QMPTestCase):
>          self.assert_qmp(result, 'return[0]/device', 'drive0')
>          self.assert_qmp(result, 'return[0]/speed', 0)
>  
> -        result = self.vm.qmp('block-job-set-speed', device='drive0', speed=8 * 1024 * 1024)
> +        result = self.vm.qmp('block-job-set-speed', device='drive0',
> +                             speed=8 * 1024 * 1024)

Forgot adding sync?

>          self.assert_qmp(result, 'return', {})
>  
>          # Ensure the speed we set was accepted

> @@ -285,4 +367,4 @@ class TestSingleTransaction(iotests.QMPTestCase):
>          self.assert_no_active_block_jobs()
>  
>  if __name__ == '__main__':
> -    iotests.main(supported_fmts=['raw', 'qcow2'])
> +    iotests.main(supported_fmts=['qcow2', 'qed'])

Not good. Can we split the test in a part that can be run by raw, and a
separate part that uses backing files?

Kevin
Ian Main July 24, 2013, 6:02 p.m. UTC | #2
On Wed, Jul 24, 2013 at 01:19:18PM +0200, Kevin Wolf wrote:
> Am 23.07.2013 um 00:09 hat Ian Main geschrieben:
> > This patch adds tests for sync modes top and none.  Also added are tests
> > for invalid and missing formats.
> > 
> > Signed-off-by: Ian Main <imain@redhat.com>
> > ---
> >  tests/qemu-iotests/055        | 108 +++++++++++++++++++++++++++++++++++++-----
> >  tests/qemu-iotests/055.out    |   4 +-
> >  tests/qemu-iotests/group      |   2 +-
> >  tests/qemu-iotests/iotests.py |   5 ++
> >  4 files changed, 103 insertions(+), 16 deletions(-)
> 
> > @@ -127,7 +202,8 @@ class TestSetSpeed(iotests.QMPTestCase):
> >          self.assert_qmp(result, 'return[0]/device', 'drive0')
> >          self.assert_qmp(result, 'return[0]/speed', 0)
> >  
> > -        result = self.vm.qmp('block-job-set-speed', device='drive0', speed=8 * 1024 * 1024)
> > +        result = self.vm.qmp('block-job-set-speed', device='drive0',
> > +                             speed=8 * 1024 * 1024)
> 
> Forgot adding sync?

Sync defaults to FULL which I think is intended here.  IIRC it was just
a long line fix.
 
> >          self.assert_qmp(result, 'return', {})
> >  
> >          # Ensure the speed we set was accepted
> 
> > @@ -285,4 +367,4 @@ class TestSingleTransaction(iotests.QMPTestCase):
> >          self.assert_no_active_block_jobs()
> >  
> >  if __name__ == '__main__':
> > -    iotests.main(supported_fmts=['raw', 'qcow2'])
> > +    iotests.main(supported_fmts=['qcow2', 'qed'])
> 
> Not good. Can we split the test in a part that can be run by raw, and a
> separate part that uses backing files?

If that is what is needed, sure.

	Ian

> Kevin
diff mbox

Patch

diff --git a/tests/qemu-iotests/055 b/tests/qemu-iotests/055
index c66f8db..5abe0ab 100755
--- a/tests/qemu-iotests/055
+++ b/tests/qemu-iotests/055
@@ -23,8 +23,9 @@ 
 import time
 import os
 import iotests
-from iotests import qemu_img, qemu_io
+from iotests import qemu_img, qemu_io, create_image
 
+backing_img = os.path.join(iotests.test_dir, 'backing.img')
 test_img = os.path.join(iotests.test_dir, 'test.img')
 target_img = os.path.join(iotests.test_dir, 'target.img')
 
@@ -34,7 +35,7 @@  class TestSingleDrive(iotests.QMPTestCase):
     def setUp(self):
         # Write data to the image so we can compare later
         qemu_img('create', '-f', iotests.imgfmt, test_img, str(TestSingleDrive.image_len))
-        qemu_io('-c', 'write -P0x5d 0 64k', test_img)
+        qemu_io('-c', 'write -P0x41 0 512', test_img)
         qemu_io('-c', 'write -P0xd5 1M 32k', test_img)
         qemu_io('-c', 'write -P0xdc 32M 124k', test_img)
         qemu_io('-c', 'write -P0xdc 67043328 64k', test_img)
@@ -54,17 +55,35 @@  class TestSingleDrive(iotests.QMPTestCase):
         self.assert_no_active_block_jobs()
 
         result = self.vm.qmp('drive-backup', device='drive0',
-                             target=target_img, sync='full')
+                             target=target_img, format=iotests.imgfmt,
+                             sync='full')
         self.assert_qmp(result, 'return', {})
 
         event = self.cancel_and_wait()
         self.assert_qmp(event, 'data/type', 'backup')
 
+    def test_cancel_sync_none(self):
+        self.assert_no_active_block_jobs()
+
+        result = self.vm.qmp('drive-backup', device='drive0',
+                             sync='none', format='raw', target=target_img)
+        self.assert_qmp(result, 'return', {})
+        time.sleep(1)
+        self.vm.hmp_qemu_io('drive0', 'write -P0x5e 0 512')
+        self.vm.hmp_qemu_io('drive0', 'aio_flush')
+        time.sleep(1)
+        # Verify that the original contents exist in the target image.
+        self.assertEqual(-1, qemu_io('-c', 'read -P0x41 0 512', target_img).find("verification failed"))
+
+        event = self.cancel_and_wait()
+        self.assert_qmp(event, 'data/type', 'backup')
+
     def test_pause(self):
         self.assert_no_active_block_jobs()
 
         result = self.vm.qmp('drive-backup', device='drive0',
-                             target=target_img, sync='full')
+                             target=target_img, format=iotests.imgfmt,
+                             sync='full')
         self.assert_qmp(result, 'return', {})
 
         result = self.vm.qmp('block-job-pause', device='drive0')
@@ -89,19 +108,74 @@  class TestSingleDrive(iotests.QMPTestCase):
 
     def test_medium_not_found(self):
         result = self.vm.qmp('drive-backup', device='ide1-cd0',
-                             target=target_img, sync='full')
+                             target=target_img, format=iotests.imgfmt,
+                             sync='full')
         self.assert_qmp(result, 'error/class', 'GenericError')
 
     def test_image_not_found(self):
         result = self.vm.qmp('drive-backup', device='drive0',
-                             target=target_img, sync='full', mode='existing')
+                             target=target_img, sync='full',
+                             format=iotests.imgfmt, mode='existing')
+        self.assert_qmp(result, 'error/class', 'GenericError')
+
+    def test_invalid_format(self):
+        result = self.vm.qmp('drive-backup', device='drive0',
+                             target=target_img, sync='full',
+                             format='spaghetti-noodles')
+        self.assert_qmp(result, 'error/class', 'GenericError')
+
+    def test_missing_format(self):
+        result = self.vm.qmp('drive-backup', device='drive0',
+                             target=target_img, sync='full')
         self.assert_qmp(result, 'error/class', 'GenericError')
 
     def test_device_not_found(self):
         result = self.vm.qmp('drive-backup', device='nonexistent',
-                             target=target_img, sync='full')
+                             target=target_img, sync='full',
+                             format=iotests.imgfmt)
         self.assert_qmp(result, 'error/class', 'DeviceNotFound')
 
+class TestSyncModeTop(iotests.QMPTestCase):
+    image_len = 2 * 1024 * 1024 # MB
+
+    def setUp(self):
+        create_image(backing_img, TestSyncModeTop.image_len)
+        qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % backing_img, test_img)
+        qemu_io('-c', 'write -P0x5d 0 64k', test_img)
+        qemu_io('-c', 'write -P0xd5 1M 32k', test_img)
+        qemu_io('-c', 'write -P0xdc 32M 124k', test_img)
+        self.vm = iotests.VM().add_drive(test_img)
+        self.vm.launch()
+
+    def tearDown(self):
+        self.vm.shutdown()
+        os.remove(test_img)
+        os.remove(backing_img)
+        try:
+            os.remove(target_img)
+        except OSError:
+            pass
+
+    def test_complete_top(self):
+        self.assert_no_active_block_jobs()
+        result = self.vm.qmp('drive-backup', device='drive0', sync='top',
+                             format=iotests.imgfmt, target=target_img)
+        self.assert_qmp(result, 'return', {})
+
+        # Custom completed check as we are not copying all data.
+        completed = False
+        while not completed:
+            for event in self.vm.get_qmp_events(wait=True):
+                if event['event'] == 'BLOCK_JOB_COMPLETED':
+                    self.assert_qmp(event, 'data/device', 'drive0')
+                    self.assert_qmp_absent(event, 'data/error')
+                    completed = True
+
+        self.assert_no_active_block_jobs()
+        self.vm.shutdown()
+        self.assertTrue(iotests.compare_images(test_img, target_img),
+                        'target image does not match source after backup')
+
 class TestSetSpeed(iotests.QMPTestCase):
     image_len = 80 * 1024 * 1024 # MB
 
@@ -119,7 +193,8 @@  class TestSetSpeed(iotests.QMPTestCase):
         self.assert_no_active_block_jobs()
 
         result = self.vm.qmp('drive-backup', device='drive0',
-                             target=target_img, sync='full')
+                             format=iotests.imgfmt, target=target_img,
+                             sync='full')
         self.assert_qmp(result, 'return', {})
 
         # Default speed is 0
@@ -127,7 +202,8 @@  class TestSetSpeed(iotests.QMPTestCase):
         self.assert_qmp(result, 'return[0]/device', 'drive0')
         self.assert_qmp(result, 'return[0]/speed', 0)
 
-        result = self.vm.qmp('block-job-set-speed', device='drive0', speed=8 * 1024 * 1024)
+        result = self.vm.qmp('block-job-set-speed', device='drive0',
+                             speed=8 * 1024 * 1024)
         self.assert_qmp(result, 'return', {})
 
         # Ensure the speed we set was accepted
@@ -140,7 +216,8 @@  class TestSetSpeed(iotests.QMPTestCase):
 
         # Check setting speed in drive-backup works
         result = self.vm.qmp('drive-backup', device='drive0',
-                             target=target_img, sync='full', speed=4*1024*1024)
+                             format=iotests.imgfmt, target=target_img,
+                             sync='full', speed=4*1024*1024)
         self.assert_qmp(result, 'return', {})
 
         result = self.vm.qmp('query-block-jobs')
@@ -154,13 +231,15 @@  class TestSetSpeed(iotests.QMPTestCase):
         self.assert_no_active_block_jobs()
 
         result = self.vm.qmp('drive-backup', device='drive0',
-                             target=target_img, sync='full', speed=-1)
+                             format=iotests.imgfmt, target=target_img,
+                             sync='full', speed=-1)
         self.assert_qmp(result, 'error/class', 'GenericError')
 
         self.assert_no_active_block_jobs()
 
         result = self.vm.qmp('drive-backup', device='drive0',
-                             target=target_img, sync='full')
+                             format=iotests.imgfmt, target=target_img,
+                             sync='full')
         self.assert_qmp(result, 'return', {})
 
         result = self.vm.qmp('block-job-set-speed', device='drive0', speed=-1)
@@ -196,6 +275,7 @@  class TestSingleTransaction(iotests.QMPTestCase):
         result = self.vm.qmp('transaction', actions=[{
                 'type': 'drive-backup',
                 'data': { 'device': 'drive0',
+                          'format': iotests.imgfmt,
                           'target': target_img,
                           'sync': 'full' },
             }
@@ -211,6 +291,7 @@  class TestSingleTransaction(iotests.QMPTestCase):
         result = self.vm.qmp('transaction', actions=[{
                 'type': 'drive-backup',
                 'data': { 'device': 'drive0',
+                          'format': iotests.imgfmt,
                           'target': target_img,
                           'sync': 'full' },
             }
@@ -241,6 +322,7 @@  class TestSingleTransaction(iotests.QMPTestCase):
         result = self.vm.qmp('transaction', actions=[{
                 'type': 'drive-backup',
                 'data': { 'device': 'ide1-cd0',
+                          'format': iotests.imgfmt,
                           'target': target_img,
                           'sync': 'full' },
             }
@@ -285,4 +367,4 @@  class TestSingleTransaction(iotests.QMPTestCase):
         self.assert_no_active_block_jobs()
 
 if __name__ == '__main__':
-    iotests.main(supported_fmts=['raw', 'qcow2'])
+    iotests.main(supported_fmts=['qcow2', 'qed'])
diff --git a/tests/qemu-iotests/055.out b/tests/qemu-iotests/055.out
index fa16b5c..52d796e 100644
--- a/tests/qemu-iotests/055.out
+++ b/tests/qemu-iotests/055.out
@@ -1,5 +1,5 @@ 
-.............
+.................
 ----------------------------------------------------------------------
-Ran 13 tests
+Ran 17 tests
 
 OK
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
index fdc6ed1..d3c3f61 100644
--- a/tests/qemu-iotests/group
+++ b/tests/qemu-iotests/group
@@ -61,4 +61,4 @@ 
 052 rw auto backing
 053 rw auto
 054 rw auto
-055 rw auto
+055 rw auto backing
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index b028a89..33ad0ec 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -95,6 +95,11 @@  class VM(object):
         self._num_drives += 1
         return self
 
+    def hmp_qemu_io(self, drive, cmd):
+        '''Write to a given drive using an HMP command'''
+        return self.qmp('human-monitor-command',
+                        command_line='qemu-io %s "%s"' % (drive, cmd))
+
     def add_fd(self, fd, fdset, opaque, opts=''):
         '''Pass a file descriptor to the VM'''
         options = ['fd=%d' % fd,