[v5,4/4] tests/qemu-iotests: add case for block-stream compress
diff mbox series

Message ID 1571603828-185910-5-git-send-email-andrey.shinkevich@virtuozzo.com
State New
Headers show
Series
  • qcow2: advanced compression options
Related show

Commit Message

Andrey Shinkevich Oct. 20, 2019, 8:37 p.m. UTC
Add a case to the iotest #030 that tests the 'compress' option for a
block-stream job.

Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
---
 tests/qemu-iotests/030     | 34 +++++++++++++++++++++++++++++++++-
 tests/qemu-iotests/030.out |  4 ++--
 2 files changed, 35 insertions(+), 3 deletions(-)

Comments

Max Reitz Oct. 22, 2019, 9:28 a.m. UTC | #1
On 20.10.19 22:37, Andrey Shinkevich wrote:
> Add a case to the iotest #030 that tests the 'compress' option for a
> block-stream job.
> 
> Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
> ---
>  tests/qemu-iotests/030     | 34 +++++++++++++++++++++++++++++++++-
>  tests/qemu-iotests/030.out |  4 ++--
>  2 files changed, 35 insertions(+), 3 deletions(-)
> 
> diff --git a/tests/qemu-iotests/030 b/tests/qemu-iotests/030
> index f3766f2..f33fd21 100755
> --- a/tests/qemu-iotests/030
> +++ b/tests/qemu-iotests/030
> @@ -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,37 @@ class TestSetSpeed(iotests.QMPTestCase):
>  
>          self.cancel_and_wait(resume=True)
>  
> +class TestCompressed(iotests.QMPTestCase):
> +    allocated_clusters = 8
> +
> +    def setUp(self):
> +        qemu_img('create', '-f', iotests.imgfmt, backing_img, '1M')
> +        qemu_img('create', '-f', iotests.imgfmt, '-o',
> +                 'backing_file={}'.format(backing_img), test_img)
> +        cluster_size = 0x10000
> +        data_size = self.allocated_clusters * cluster_size
> +        qemu_io('-c', 'write -P 0x1 0 {}'.format(data_size), backing_img)
> +        self.vm = iotests.VM().add_drive(test_img, "compress=on")

I don’t think it makes sense to add a drive with compress=on to a VM.
If the VM writes to any cluster more than once, the request will fail.

> +        self.vm.launch()
> +
> +    def tearDown(self):
> +        self.vm.shutdown()
> +        os.remove(test_img)
> +        os.remove(backing_img)
> +
> +    def test_stream_compress(self):
> +        self.assert_no_active_block_jobs()
> +
> +        result = self.vm.qmp('block-stream', device='drive0')
> +        self.assert_qmp(result, 'return', {})

In this example, it’s actually even a bit worse: The VM might be aware
that it may only write to each cluster exactly once.  But if it writes
to any of the first eight clusters after the stream job as done so
(invisibly to the VM guest), it will get an error.

You could see that by adding a qemu-io write here and see that it fails.
 (In practice you won’t because the error goes to stdout and that is
lost in Python tests).

Max

> +        match = {'data': {'type': 'stream', 'device': 'drive0'}}
> +        self.vm.event_wait(name='BLOCK_JOB_COMPLETED', match=match)
> +        self.vm.shutdown()
> +
> +        top = json.loads(qemu_img_pipe('check', '--output=json', test_img))
> +        self.assertEqual(top['compressed-clusters'], self.allocated_clusters)
> +
>  if __name__ == '__main__':
>      iotests.main(supported_fmts=['qcow2', 'qed'],
>                   supported_protocols=['file'])
> diff --git a/tests/qemu-iotests/030.out b/tests/qemu-iotests/030.out
> index 6d9bee1..af8dac1 100644
> --- a/tests/qemu-iotests/030.out
> +++ b/tests/qemu-iotests/030.out
> @@ -1,5 +1,5 @@
> -...........................
> +............................
>  ----------------------------------------------------------------------
> -Ran 27 tests
> +Ran 28 tests
>  
>  OK
>

Patch
diff mbox series

diff --git a/tests/qemu-iotests/030 b/tests/qemu-iotests/030
index f3766f2..f33fd21 100755
--- a/tests/qemu-iotests/030
+++ b/tests/qemu-iotests/030
@@ -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,37 @@  class TestSetSpeed(iotests.QMPTestCase):
 
         self.cancel_and_wait(resume=True)
 
+class TestCompressed(iotests.QMPTestCase):
+    allocated_clusters = 8
+
+    def setUp(self):
+        qemu_img('create', '-f', iotests.imgfmt, backing_img, '1M')
+        qemu_img('create', '-f', iotests.imgfmt, '-o',
+                 'backing_file={}'.format(backing_img), test_img)
+        cluster_size = 0x10000
+        data_size = self.allocated_clusters * cluster_size
+        qemu_io('-c', 'write -P 0x1 0 {}'.format(data_size), backing_img)
+        self.vm = iotests.VM().add_drive(test_img, "compress=on")
+        self.vm.launch()
+
+    def tearDown(self):
+        self.vm.shutdown()
+        os.remove(test_img)
+        os.remove(backing_img)
+
+    def test_stream_compress(self):
+        self.assert_no_active_block_jobs()
+
+        result = self.vm.qmp('block-stream', device='drive0')
+        self.assert_qmp(result, 'return', {})
+
+        match = {'data': {'type': 'stream', 'device': 'drive0'}}
+        self.vm.event_wait(name='BLOCK_JOB_COMPLETED', match=match)
+        self.vm.shutdown()
+
+        top = json.loads(qemu_img_pipe('check', '--output=json', test_img))
+        self.assertEqual(top['compressed-clusters'], self.allocated_clusters)
+
 if __name__ == '__main__':
     iotests.main(supported_fmts=['qcow2', 'qed'],
                  supported_protocols=['file'])
diff --git a/tests/qemu-iotests/030.out b/tests/qemu-iotests/030.out
index 6d9bee1..af8dac1 100644
--- a/tests/qemu-iotests/030.out
+++ b/tests/qemu-iotests/030.out
@@ -1,5 +1,5 @@ 
-...........................
+............................
 ----------------------------------------------------------------------
-Ran 27 tests
+Ran 28 tests
 
 OK