From patchwork Fri Apr 27 15:01:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 155507 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 55942B6FAB for ; Sat, 28 Apr 2012 01:23:27 +1000 (EST) Received: from localhost ([::1]:36069 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SNn13-0006T3-5R for incoming@patchwork.ozlabs.org; Fri, 27 Apr 2012 11:23:25 -0400 Received: from eggs.gnu.org ([208.118.235.92]:55857) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SNn0n-00060p-Jh for qemu-devel@nongnu.org; Fri, 27 Apr 2012 11:23:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SNn0i-0004qM-Ah for qemu-devel@nongnu.org; Fri, 27 Apr 2012 11:23:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58622) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SNn0i-0004q1-2O for qemu-devel@nongnu.org; Fri, 27 Apr 2012 11:23:04 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q3RFMwuO014768 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 27 Apr 2012 11:22:59 -0400 Received: from localhost (ovpn-116-78.ams2.redhat.com [10.36.116.78]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q3RF175E005540; Fri, 27 Apr 2012 11:01:09 -0400 From: Luiz Capitulino To: aliguori@us.ibm.com Date: Fri, 27 Apr 2012 12:01:00 -0300 Message-Id: <1335538861-24977-6-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1335538861-24977-1-git-send-email-lcapitulino@redhat.com> References: <1335538861-24977-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org, Stefan Hajnoczi Subject: [Qemu-devel] [PULL 5/6] 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 From: Stefan Hajnoczi 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 Signed-off-by: Luiz Capitulino --- 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