From patchwork Wed Apr 25 15:51:04 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 155016 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B4D6EB6FC8 for ; Thu, 26 Apr 2012 01:52:57 +1000 (EST) Received: from localhost ([::1]:39855 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SN4WV-00042o-M7 for incoming@patchwork.ozlabs.org; Wed, 25 Apr 2012 11:52:55 -0400 Received: from eggs.gnu.org ([208.118.235.92]:41043) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SN4VJ-0000Rz-1K for qemu-devel@nongnu.org; Wed, 25 Apr 2012 11:51:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SN4VD-0003O9-Aq for qemu-devel@nongnu.org; Wed, 25 Apr 2012 11:51:40 -0400 Received: from e06smtp17.uk.ibm.com ([195.75.94.113]:45613) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SN4VD-0003MC-1K for qemu-devel@nongnu.org; Wed, 25 Apr 2012 11:51:35 -0400 Received: from /spool/local by e06smtp17.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 25 Apr 2012 16:51:31 +0100 Received: from d06nrmr1806.portsmouth.uk.ibm.com (9.149.39.193) by e06smtp17.uk.ibm.com (192.168.101.147) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 25 Apr 2012 16:51:29 +0100 Received: from d06av10.portsmouth.uk.ibm.com (d06av10.portsmouth.uk.ibm.com [9.149.37.251]) by d06nrmr1806.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q3PFpThf2695382 for ; Wed, 25 Apr 2012 16:51:29 +0100 Received: from d06av10.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q3PFmS27012574 for ; Wed, 25 Apr 2012 11:48:28 -0400 Received: from localhost ([9.145.156.72]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q3PFmRVg012559; Wed, 25 Apr 2012 11:48:28 -0400 From: Stefan Hajnoczi To: Date: Wed, 25 Apr 2012 16:51:04 +0100 Message-Id: <1335369064-27600-6-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1335369064-27600-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1335369064-27600-1-git-send-email-stefanha@linux.vnet.ibm.com> x-cbid: 12042515-0542-0000-0000-000001A5534B X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.75.94.113 Cc: Kevin Wolf , Paolo Bonzini , Eric Blake , Stefan Hajnoczi , Luiz Capitulino Subject: [Qemu-devel] [PATCH v4 5/5] qemu-iotests: add block-stream speed value test case X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Acked-by: Kevin Wolf --- tests/qemu-iotests/030 | 85 +++++++++++++++++++++++++++++++++++--------- tests/qemu-iotests/030.out | 4 +-- 2 files changed, 71 insertions(+), 18 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']) diff --git a/tests/qemu-iotests/030.out b/tests/qemu-iotests/030.out index 8d7e996..914e373 100644 --- a/tests/qemu-iotests/030.out +++ b/tests/qemu-iotests/030.out @@ -1,5 +1,5 @@ -... +..... ---------------------------------------------------------------------- -Ran 3 tests +Ran 5 tests OK