diff mbox

[v9,10/11] qemu-iotests: test overlapping block-stream operations

Message ID 2483f3f1b677752d0f77da8628b0216bd4a26d3f.1459776815.git.berto@igalia.com (mailing list archive)
State New, archived
Headers show

Commit Message

Alberto Garcia April 4, 2016, 1:44 p.m. UTC
This test case checks that it's not possible to perform two
block-stream operations if there are nodes involved in both.

Signed-off-by: Alberto Garcia <berto@igalia.com>
---
 tests/qemu-iotests/030     | 60 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/030.out |  4 ++--
 2 files changed, 62 insertions(+), 2 deletions(-)

Comments

Max Reitz April 27, 2016, 1:48 p.m. UTC | #1
On 04.04.2016 15:44, Alberto Garcia wrote:
> This test case checks that it's not possible to perform two
> block-stream operations if there are nodes involved in both.
> 
> Signed-off-by: Alberto Garcia <berto@igalia.com>
> ---
>  tests/qemu-iotests/030     | 60 ++++++++++++++++++++++++++++++++++++++++++++++
>  tests/qemu-iotests/030.out |  4 ++--
>  2 files changed, 62 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/qemu-iotests/030 b/tests/qemu-iotests/030
> index 1c53f80..6348872 100755
> --- a/tests/qemu-iotests/030
> +++ b/tests/qemu-iotests/030
> @@ -145,6 +145,66 @@ class TestSingleDrive(iotests.QMPTestCase):
>          self.assert_qmp(result, 'error/class', 'GenericError')
>  
>  
> +class TestMultipleOps(iotests.QMPTestCase):
> +    num_imgs = 9 # It must be > 5 or some tests will break
> +    image_len = num_imgs * 1024 * 1024
> +    imgs = []
> +
> +    def setUp(self):
> +        opts = []
> +        self.imgs = []
> +
> +        # Initialize file names and command-line options
> +        for i in range(self.num_imgs):
> +            img_depth = self.num_imgs - i - 1
> +            opts.append("backing." * img_depth + "node-name=node%d" % i)
> +            self.imgs.append(os.path.join(iotests.test_dir, 'img-%d.img' % i))
> +
> +        # Create all images
> +        iotests.create_image(self.imgs[0], self.image_len)
> +        for i in range(1, self.num_imgs):
> +            qemu_img('create', '-f', iotests.imgfmt,
> +                     '-o', 'backing_file=%s' % self.imgs[i-1], self.imgs[i])
> +
> +        # Put data into some images so there's something to copy
> +        for i in range(1, self.num_imgs, 2):
> +            qemu_io('-f', iotests.imgfmt,
> +                    '-c', 'write -P %d %d %d' % (i, i*1024*1024, 1024*1024),
> +                    self.imgs[i])
> +
> +        # Attach the drive to the VM
> +        self.vm = iotests.VM()
> +        self.vm.add_drive("blkdebug::" + self.imgs[-1], ','.join(opts))

Any special reason for blkdebug? For me it works just fine without.

With or without:

Reviewed-by: Max Reitz <mreitz@redhat.com>

> +        self.vm.launch()
> +
> +    def tearDown(self):
> +        self.vm.shutdown()
> +        for img in self.imgs:
> +            os.remove(img)
> +
> +    # Test that it's not possible to perform two block-stream
> +    # operations if there are nodes involved in both.
> +    def test_overlapping(self):
> +        self.assert_no_active_block_jobs()
> +
> +        # Set a speed limit to make sure that this job blocks the rest
> +        result = self.vm.qmp('block-stream', device='node4', base=self.imgs[0], speed=32768)
> +        self.assert_qmp(result, 'return', {})
> +
> +        result = self.vm.qmp('block-stream', device='node5', base=self.imgs[1])
> +        self.assert_qmp(result, 'error/class', 'GenericError')
> +
> +        result = self.vm.qmp('block-stream', device='node3', base=self.imgs[2])
> +        self.assert_qmp(result, 'error/class', 'GenericError')
> +
> +        result = self.vm.qmp('block-stream', device='node4')
> +        self.assert_qmp(result, 'error/class', 'GenericError')
> +
> +        self.wait_until_completed(drive='node4')
> +        self.assert_no_active_block_jobs()
> +
> +        self.vm.shutdown()
> +
>  class TestSmallerBackingFile(iotests.QMPTestCase):
>      backing_len = 1 * 1024 * 1024 # MB
>      image_len = 2 * backing_len
> diff --git a/tests/qemu-iotests/030.out b/tests/qemu-iotests/030.out
> index 96961ed..b6f2576 100644
> --- a/tests/qemu-iotests/030.out
> +++ b/tests/qemu-iotests/030.out
> @@ -1,5 +1,5 @@
> -...............
> +................
>  ----------------------------------------------------------------------
> -Ran 15 tests
> +Ran 16 tests
>  
>  OK
>
Alberto Garcia April 27, 2016, 3:02 p.m. UTC | #2
On Wed 27 Apr 2016 03:48:26 PM CEST, Max Reitz wrote:
>> +        # Attach the drive to the VM
>> +        self.vm = iotests.VM()
>> +        self.vm.add_drive("blkdebug::" + self.imgs[-1], ','.join(opts))
>
> Any special reason for blkdebug? For me it works just fine without.

Oh, I think it's just a remainder from previous tests that did use
blkdebug. I'll remove it.

Berto
diff mbox

Patch

diff --git a/tests/qemu-iotests/030 b/tests/qemu-iotests/030
index 1c53f80..6348872 100755
--- a/tests/qemu-iotests/030
+++ b/tests/qemu-iotests/030
@@ -145,6 +145,66 @@  class TestSingleDrive(iotests.QMPTestCase):
         self.assert_qmp(result, 'error/class', 'GenericError')
 
 
+class TestMultipleOps(iotests.QMPTestCase):
+    num_imgs = 9 # It must be > 5 or some tests will break
+    image_len = num_imgs * 1024 * 1024
+    imgs = []
+
+    def setUp(self):
+        opts = []
+        self.imgs = []
+
+        # Initialize file names and command-line options
+        for i in range(self.num_imgs):
+            img_depth = self.num_imgs - i - 1
+            opts.append("backing." * img_depth + "node-name=node%d" % i)
+            self.imgs.append(os.path.join(iotests.test_dir, 'img-%d.img' % i))
+
+        # Create all images
+        iotests.create_image(self.imgs[0], self.image_len)
+        for i in range(1, self.num_imgs):
+            qemu_img('create', '-f', iotests.imgfmt,
+                     '-o', 'backing_file=%s' % self.imgs[i-1], self.imgs[i])
+
+        # Put data into some images so there's something to copy
+        for i in range(1, self.num_imgs, 2):
+            qemu_io('-f', iotests.imgfmt,
+                    '-c', 'write -P %d %d %d' % (i, i*1024*1024, 1024*1024),
+                    self.imgs[i])
+
+        # Attach the drive to the VM
+        self.vm = iotests.VM()
+        self.vm.add_drive("blkdebug::" + self.imgs[-1], ','.join(opts))
+        self.vm.launch()
+
+    def tearDown(self):
+        self.vm.shutdown()
+        for img in self.imgs:
+            os.remove(img)
+
+    # Test that it's not possible to perform two block-stream
+    # operations if there are nodes involved in both.
+    def test_overlapping(self):
+        self.assert_no_active_block_jobs()
+
+        # Set a speed limit to make sure that this job blocks the rest
+        result = self.vm.qmp('block-stream', device='node4', base=self.imgs[0], speed=32768)
+        self.assert_qmp(result, 'return', {})
+
+        result = self.vm.qmp('block-stream', device='node5', base=self.imgs[1])
+        self.assert_qmp(result, 'error/class', 'GenericError')
+
+        result = self.vm.qmp('block-stream', device='node3', base=self.imgs[2])
+        self.assert_qmp(result, 'error/class', 'GenericError')
+
+        result = self.vm.qmp('block-stream', device='node4')
+        self.assert_qmp(result, 'error/class', 'GenericError')
+
+        self.wait_until_completed(drive='node4')
+        self.assert_no_active_block_jobs()
+
+        self.vm.shutdown()
+
 class TestSmallerBackingFile(iotests.QMPTestCase):
     backing_len = 1 * 1024 * 1024 # MB
     image_len = 2 * backing_len
diff --git a/tests/qemu-iotests/030.out b/tests/qemu-iotests/030.out
index 96961ed..b6f2576 100644
--- a/tests/qemu-iotests/030.out
+++ b/tests/qemu-iotests/030.out
@@ -1,5 +1,5 @@ 
-...............
+................
 ----------------------------------------------------------------------
-Ran 15 tests
+Ran 16 tests
 
 OK