mirror of
https://github.com/qemu/qemu.git
synced 2024-11-26 12:23:36 +08:00
qemu-iotests: Improve and make use of QMPTestCase.wait_until_completed()
This eliminates code duplication. Signed-off-by: Fam Zheng <famz@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
d1db760d7b
commit
9974ad40bf
@ -50,15 +50,7 @@ class TestSingleDrive(iotests.QMPTestCase):
|
||||
result = self.vm.qmp('block-stream', device='drive0')
|
||||
self.assert_qmp(result, 'return', {})
|
||||
|
||||
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/type', 'stream')
|
||||
self.assert_qmp(event, 'data/device', 'drive0')
|
||||
self.assert_qmp(event, 'data/offset', self.image_len)
|
||||
self.assert_qmp(event, 'data/len', self.image_len)
|
||||
completed = True
|
||||
self.wait_until_completed()
|
||||
|
||||
self.assert_no_active_block_jobs()
|
||||
self.vm.shutdown()
|
||||
@ -89,15 +81,7 @@ class TestSingleDrive(iotests.QMPTestCase):
|
||||
self.assert_qmp(result, 'return', {})
|
||||
|
||||
self.vm.resume_drive('drive0')
|
||||
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/type', 'stream')
|
||||
self.assert_qmp(event, 'data/device', 'drive0')
|
||||
self.assert_qmp(event, 'data/offset', self.image_len)
|
||||
self.assert_qmp(event, 'data/len', self.image_len)
|
||||
completed = True
|
||||
self.wait_until_completed()
|
||||
|
||||
self.assert_no_active_block_jobs()
|
||||
self.vm.shutdown()
|
||||
@ -112,15 +96,7 @@ class TestSingleDrive(iotests.QMPTestCase):
|
||||
result = self.vm.qmp('block-stream', device='drive0', base=mid_img)
|
||||
self.assert_qmp(result, 'return', {})
|
||||
|
||||
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/type', 'stream')
|
||||
self.assert_qmp(event, 'data/device', 'drive0')
|
||||
self.assert_qmp(event, 'data/offset', self.image_len)
|
||||
self.assert_qmp(event, 'data/len', self.image_len)
|
||||
completed = True
|
||||
self.wait_until_completed()
|
||||
|
||||
self.assert_no_active_block_jobs()
|
||||
self.vm.shutdown()
|
||||
@ -152,15 +128,7 @@ class TestSmallerBackingFile(iotests.QMPTestCase):
|
||||
result = self.vm.qmp('block-stream', device='drive0')
|
||||
self.assert_qmp(result, 'return', {})
|
||||
|
||||
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/type', 'stream')
|
||||
self.assert_qmp(event, 'data/device', 'drive0')
|
||||
self.assert_qmp(event, 'data/offset', self.image_len)
|
||||
self.assert_qmp(event, 'data/len', self.image_len)
|
||||
completed = True
|
||||
self.wait_until_completed()
|
||||
|
||||
self.assert_no_active_block_jobs()
|
||||
self.vm.shutdown()
|
||||
@ -442,15 +410,7 @@ class TestSetSpeed(iotests.QMPTestCase):
|
||||
result = self.vm.qmp('block-job-set-speed', device='drive0', speed=8 * 1024 * 1024)
|
||||
self.assert_qmp(result, 'return', {})
|
||||
|
||||
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/type', 'stream')
|
||||
self.assert_qmp(event, 'data/device', 'drive0')
|
||||
self.assert_qmp(event, 'data/offset', self.image_len)
|
||||
self.assert_qmp(event, 'data/len', self.image_len)
|
||||
completed = True
|
||||
self.wait_until_completed()
|
||||
|
||||
self.assert_no_active_block_jobs()
|
||||
|
||||
|
@ -57,14 +57,7 @@ class TestSyncModesNoneAndTop(iotests.QMPTestCase):
|
||||
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.wait_until_completed(check_offset=False)
|
||||
|
||||
self.assert_no_active_block_jobs()
|
||||
self.vm.shutdown()
|
||||
|
@ -257,7 +257,7 @@ class QMPTestCase(unittest.TestCase):
|
||||
self.assert_no_active_block_jobs()
|
||||
return result
|
||||
|
||||
def wait_until_completed(self, drive='drive0'):
|
||||
def wait_until_completed(self, drive='drive0', check_offset=True):
|
||||
'''Wait for a block job to finish, returning the event'''
|
||||
completed = False
|
||||
while not completed:
|
||||
@ -265,7 +265,8 @@ class QMPTestCase(unittest.TestCase):
|
||||
if event['event'] == 'BLOCK_JOB_COMPLETED':
|
||||
self.assert_qmp(event, 'data/device', drive)
|
||||
self.assert_qmp_absent(event, 'data/error')
|
||||
self.assert_qmp(event, 'data/offset', self.image_len)
|
||||
if check_offset:
|
||||
self.assert_qmp(event, 'data/offset', self.image_len)
|
||||
self.assert_qmp(event, 'data/len', self.image_len)
|
||||
completed = True
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user