summaryrefslogtreecommitdiffstats
path: root/tests/qemu-iotests/030
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@linux.vnet.ibm.com>2012-04-25 16:51:04 +0100
committerLuiz Capitulino <lcapitulino@redhat.com>2012-04-27 11:44:50 -0300
commite425306a27ef02b6ef19408d588974953f0f28c0 (patch)
tree192e4ad3f3aae22767cf1ed49d20643c820cc0f8 /tests/qemu-iotests/030
parentc83c66c3b58893a4dc056e272822beb88fe9ec7f (diff)
downloadhqemu-e425306a27ef02b6ef19408d588974953f0f28c0.zip
hqemu-e425306a27ef02b6ef19408d588974953f0f28c0.tar.gz
qemu-iotests: add block-stream speed value test case
Add tests to exercise the InvalidParameter 'speed' error code path, as well as the regular success case for setting the speed. The block-stream 'speed' parameter allows the speed limit of the job to be applied immediately when the job starts instead of issuing a separate block-job-set-speed command later. If the parameter has an invalid value we expect to get an error and the job is not created. It turns out that cancelling a block job is a common operation in these test cases, let's extract a cancel_and_wait() function instead of duplicating the QMP commands. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Acked-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Diffstat (limited to 'tests/qemu-iotests/030')
-rwxr-xr-xtests/qemu-iotests/03085
1 files changed, 69 insertions, 16 deletions
diff --git a/tests/qemu-iotests/030 b/tests/qemu-iotests/030
index 978fd82..38abc2c 100755
--- a/tests/qemu-iotests/030
+++ b/tests/qemu-iotests/030
@@ -32,6 +32,21 @@ class ImageStreamingTestCase(iotests.QMPTestCase):
result = self.vm.qmp('query-block-jobs')
self.assert_qmp(result, 'return', [])
+ def cancel_and_wait(self, drive='drive0'):
+ '''Cancel a block job and wait for it to finish'''
+ result = self.vm.qmp('block-job-cancel', device=drive)
+ self.assert_qmp(result, 'return', {})
+
+ cancelled = False
+ while not cancelled:
+ for event in self.vm.get_qmp_events(wait=True):
+ if event['event'] == 'BLOCK_JOB_CANCELLED':
+ self.assert_qmp(event, 'data/type', 'stream')
+ self.assert_qmp(event, 'data/device', drive)
+ cancelled = True
+
+ self.assert_no_active_streams()
+
class TestSingleDrive(ImageStreamingTestCase):
image_len = 1 * 1024 * 1024 # MB
@@ -97,21 +112,8 @@ class TestStreamStop(ImageStreamingTestCase):
events = self.vm.get_qmp_events(wait=False)
self.assertEqual(events, [], 'unexpected QMP event: %s' % events)
- self.vm.qmp('block-job-cancel', device='drive0')
- self.assert_qmp(result, 'return', {})
+ self.cancel_and_wait()
- cancelled = False
- while not cancelled:
- for event in self.vm.get_qmp_events(wait=True):
- if event['event'] == 'BLOCK_JOB_CANCELLED':
- self.assert_qmp(event, 'data/type', 'stream')
- self.assert_qmp(event, 'data/device', 'drive0')
- cancelled = True
-
- self.assert_no_active_streams()
-
-# This is a short performance test which is not run by default.
-# Invoke "IMGFMT=qed ./030 TestSetSpeed.perf_test_set_speed"
class TestSetSpeed(ImageStreamingTestCase):
image_len = 80 * 1024 * 1024 # MB
@@ -126,13 +128,15 @@ class TestSetSpeed(ImageStreamingTestCase):
os.remove(test_img)
os.remove(backing_img)
- def perf_test_set_speed(self):
+ # This is a short performance test which is not run by default.
+ # Invoke "IMGFMT=qed ./030 TestSetSpeed.perf_test_throughput"
+ def perf_test_throughput(self):
self.assert_no_active_streams()
result = self.vm.qmp('block-stream', device='drive0')
self.assert_qmp(result, 'return', {})
- result = self.vm.qmp('block-job-set-speed', device='drive0', value=8 * 1024 * 1024)
+ result = self.vm.qmp('block-job-set-speed', device='drive0', speed=8 * 1024 * 1024)
self.assert_qmp(result, 'return', {})
completed = False
@@ -147,5 +151,54 @@ class TestSetSpeed(ImageStreamingTestCase):
self.assert_no_active_streams()
+ def test_set_speed(self):
+ self.assert_no_active_streams()
+
+ result = self.vm.qmp('block-stream', device='drive0')
+ self.assert_qmp(result, 'return', {})
+
+ # Default speed is 0
+ result = self.vm.qmp('query-block-jobs')
+ self.assert_qmp(result, 'return[0]/device', 'drive0')
+ self.assert_qmp(result, 'return[0]/speed', 0)
+
+ result = self.vm.qmp('block-job-set-speed', device='drive0', speed=8 * 1024 * 1024)
+ self.assert_qmp(result, 'return', {})
+
+ # Ensure the speed we set was accepted
+ result = self.vm.qmp('query-block-jobs')
+ self.assert_qmp(result, 'return[0]/device', 'drive0')
+ self.assert_qmp(result, 'return[0]/speed', 8 * 1024 * 1024)
+
+ self.cancel_and_wait()
+
+ # Check setting speed in block-stream works
+ result = self.vm.qmp('block-stream', device='drive0', speed=4 * 1024 * 1024)
+ self.assert_qmp(result, 'return', {})
+
+ result = self.vm.qmp('query-block-jobs')
+ self.assert_qmp(result, 'return[0]/device', 'drive0')
+ self.assert_qmp(result, 'return[0]/speed', 4 * 1024 * 1024)
+
+ self.cancel_and_wait()
+
+ def test_set_speed_invalid(self):
+ self.assert_no_active_streams()
+
+ result = self.vm.qmp('block-stream', device='drive0', speed=-1)
+ self.assert_qmp(result, 'error/class', 'InvalidParameter')
+ self.assert_qmp(result, 'error/data/name', 'speed')
+
+ self.assert_no_active_streams()
+
+ result = self.vm.qmp('block-stream', device='drive0')
+ self.assert_qmp(result, 'return', {})
+
+ result = self.vm.qmp('block-job-set-speed', device='drive0', speed=-1)
+ self.assert_qmp(result, 'error/class', 'InvalidParameter')
+ self.assert_qmp(result, 'error/data/name', 'speed')
+
+ self.cancel_and_wait()
+
if __name__ == '__main__':
iotests.main(supported_fmts=['qcow2', 'qed'])
OpenPOWER on IntegriCloud