diff mbox

[4/4] iotests: Skip read and write in 040 for length=0

Message ID 1405117387-25539-5-git-send-email-mreitz@redhat.com
State New
Headers show

Commit Message

Max Reitz July 11, 2014, 10:23 p.m. UTC
Do not prevent to actually do a meaningful comparison after the commit
in case the backing image has a length of zero: The reason qemu-io does
not return "verification failed" in these tests is simply that it
returns "I/O error" instead. Therefore, it's better to skip these
comparisons instead of pretending they'd be useful.

Furthermore, do not write anything to the backing file in case its
length should be zero: As of "block: Correct bs->growable", raw images
are growable which means the backing file will no longer have a length
of zero after something has been written to it. Thus the write operation
should be skipped in order to actually test a commit operation on a
zero-length backing file.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 tests/qemu-iotests/040 | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
diff mbox

Patch

diff --git a/tests/qemu-iotests/040 b/tests/qemu-iotests/040
index f1e16c1..4accd3e 100755
--- a/tests/qemu-iotests/040
+++ b/tests/qemu-iotests/040
@@ -78,7 +78,8 @@  class TestSingleDrive(ImageCommitTestCase):
         iotests.create_image(backing_img, self.image_len)
         qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % backing_img, mid_img)
         qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % mid_img, test_img)
-        qemu_io('-c', 'write -P 0xab 0 524288', backing_img)
+        if self.image_len > 0:
+            qemu_io('-c', 'write -P 0xab 0 524288', backing_img)
         qemu_io('-c', 'write -P 0xef 524288 524288', mid_img)
         self.vm = iotests.VM().add_drive(test_img)
         self.vm.launch()
@@ -91,8 +92,9 @@  class TestSingleDrive(ImageCommitTestCase):
 
     def test_commit(self):
         self.run_commit_test(mid_img, backing_img)
-        self.assertEqual(-1, qemu_io('-c', 'read -P 0xab 0 524288', backing_img).find("verification failed"))
-        self.assertEqual(-1, qemu_io('-c', 'read -P 0xef 524288 524288', backing_img).find("verification failed"))
+        if self.image_len > 0:
+            self.assertEqual(-1, qemu_io('-c', 'read -P 0xab 0 524288', backing_img).find("verification failed"))
+            self.assertEqual(-1, qemu_io('-c', 'read -P 0xef 524288 524288', backing_img).find("verification failed"))
 
     def test_device_not_found(self):
         result = self.vm.qmp('block-commit', device='nonexistent', top='%s' % mid_img)
@@ -118,13 +120,15 @@  class TestSingleDrive(ImageCommitTestCase):
 
     def test_top_is_active(self):
         self.run_commit_test(test_img, backing_img, need_ready=True)
-        self.assertEqual(-1, qemu_io('-c', 'read -P 0xab 0 524288', backing_img).find("verification failed"))
-        self.assertEqual(-1, qemu_io('-c', 'read -P 0xef 524288 524288', backing_img).find("verification failed"))
+        if self.image_len > 0:
+            self.assertEqual(-1, qemu_io('-c', 'read -P 0xab 0 524288', backing_img).find("verification failed"))
+            self.assertEqual(-1, qemu_io('-c', 'read -P 0xef 524288 524288', backing_img).find("verification failed"))
 
     def test_top_is_default_active(self):
         self.run_default_commit_test()
-        self.assertEqual(-1, qemu_io('-c', 'read -P 0xab 0 524288', backing_img).find("verification failed"))
-        self.assertEqual(-1, qemu_io('-c', 'read -P 0xef 524288 524288', backing_img).find("verification failed"))
+        if self.image_len > 0:
+            self.assertEqual(-1, qemu_io('-c', 'read -P 0xab 0 524288', backing_img).find("verification failed"))
+            self.assertEqual(-1, qemu_io('-c', 'read -P 0xef 524288 524288', backing_img).find("verification failed"))
 
     def test_top_and_base_reversed(self):
         self.assert_no_active_block_jobs()