提交 8b9a30ca 编写于 作者: F Fam Zheng 提交者: Kevin Wolf

qemu-iotests: Test BLOCK_JOB_READY event for 0Kb image active commit

There should be a BLOCK_JOB_READY event with active commit, regardless
of image length. Let's test the 0 length image case, and make sure it
goes through the ready->complete process.
Signed-off-by: NFam Zheng <famz@redhat.com>
Reviewed-by: NEric Blake <eblake@redhat.com>
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
上级 9e48b025
...@@ -35,12 +35,13 @@ test_img = os.path.join(iotests.test_dir, 'test.img') ...@@ -35,12 +35,13 @@ test_img = os.path.join(iotests.test_dir, 'test.img')
class ImageCommitTestCase(iotests.QMPTestCase): class ImageCommitTestCase(iotests.QMPTestCase):
'''Abstract base class for image commit test cases''' '''Abstract base class for image commit test cases'''
def run_commit_test(self, top, base): def run_commit_test(self, top, base, need_ready=False):
self.assert_no_active_block_jobs() self.assert_no_active_block_jobs()
result = self.vm.qmp('block-commit', device='drive0', top=top, base=base) result = self.vm.qmp('block-commit', device='drive0', top=top, base=base)
self.assert_qmp(result, 'return', {}) self.assert_qmp(result, 'return', {})
completed = False completed = False
ready = False
while not completed: while not completed:
for event in self.vm.get_qmp_events(wait=True): for event in self.vm.get_qmp_events(wait=True):
if event['event'] == 'BLOCK_JOB_COMPLETED': if event['event'] == 'BLOCK_JOB_COMPLETED':
...@@ -48,8 +49,11 @@ class ImageCommitTestCase(iotests.QMPTestCase): ...@@ -48,8 +49,11 @@ class ImageCommitTestCase(iotests.QMPTestCase):
self.assert_qmp(event, 'data/device', 'drive0') self.assert_qmp(event, 'data/device', 'drive0')
self.assert_qmp(event, 'data/offset', self.image_len) self.assert_qmp(event, 'data/offset', self.image_len)
self.assert_qmp(event, 'data/len', self.image_len) self.assert_qmp(event, 'data/len', self.image_len)
if need_ready:
self.assertTrue(ready, "Expecting BLOCK_JOB_COMPLETED event")
completed = True completed = True
elif event['event'] == 'BLOCK_JOB_READY': elif event['event'] == 'BLOCK_JOB_READY':
ready = True
self.assert_qmp(event, 'data/type', 'commit') self.assert_qmp(event, 'data/type', 'commit')
self.assert_qmp(event, 'data/device', 'drive0') self.assert_qmp(event, 'data/device', 'drive0')
self.assert_qmp(event, 'data/len', self.image_len) self.assert_qmp(event, 'data/len', self.image_len)
...@@ -63,7 +67,7 @@ class TestSingleDrive(ImageCommitTestCase): ...@@ -63,7 +67,7 @@ class TestSingleDrive(ImageCommitTestCase):
test_len = 1 * 1024 * 256 test_len = 1 * 1024 * 256
def setUp(self): def setUp(self):
iotests.create_image(backing_img, TestSingleDrive.image_len) 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' % backing_img, mid_img)
qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % mid_img, test_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) qemu_io('-c', 'write -P 0xab 0 524288', backing_img)
...@@ -105,7 +109,7 @@ class TestSingleDrive(ImageCommitTestCase): ...@@ -105,7 +109,7 @@ class TestSingleDrive(ImageCommitTestCase):
self.assert_qmp(result, 'error/desc', 'Base \'badfile\' not found') self.assert_qmp(result, 'error/desc', 'Base \'badfile\' not found')
def test_top_is_active(self): def test_top_is_active(self):
self.run_commit_test(test_img, backing_img) 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 0xab 0 524288', backing_img).find("verification failed"))
self.assertEqual(-1, qemu_io('-c', 'read -P 0xef 524288 524288', backing_img).find("verification failed")) self.assertEqual(-1, qemu_io('-c', 'read -P 0xef 524288 524288', backing_img).find("verification failed"))
...@@ -238,6 +242,8 @@ class TestSetSpeed(ImageCommitTestCase): ...@@ -238,6 +242,8 @@ class TestSetSpeed(ImageCommitTestCase):
self.cancel_and_wait(resume=True) self.cancel_and_wait(resume=True)
class TestActiveZeroLengthImage(TestSingleDrive):
image_len = 0
if __name__ == '__main__': if __name__ == '__main__':
iotests.main(supported_fmts=['qcow2', 'qed']) iotests.main(supported_fmts=['qcow2', 'qed'])
................ ........................
---------------------------------------------------------------------- ----------------------------------------------------------------------
Ran 16 tests Ran 24 tests
OK OK
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册