From patchwork Fri Jul 26 18:05:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Main X-Patchwork-Id: 262226 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3A7732C00EE for ; Sat, 27 Jul 2013 04:06:45 +1000 (EST) Received: from localhost ([::1]:46870 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2mPb-0004y7-3b for incoming@patchwork.ozlabs.org; Fri, 26 Jul 2013 14:06:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44789) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2mP4-0004sh-Hb for qemu-devel@nongnu.org; Fri, 26 Jul 2013 14:06:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V2mP1-0001Zk-BL for qemu-devel@nongnu.org; Fri, 26 Jul 2013 14:06:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:2553) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2mP1-0001Zd-4j for qemu-devel@nongnu.org; Fri, 26 Jul 2013 14:06:07 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r6QI66VC019202 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 26 Jul 2013 14:06:06 -0400 Received: from arnold.mains.com (ovpn-113-23.phx2.redhat.com [10.3.113.23]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r6QI5c61024747; Fri, 26 Jul 2013 14:06:05 -0400 From: Ian Main To: qemu-devel@nongnu.org Date: Fri, 26 Jul 2013 11:05:32 -0700 Message-Id: <1374861932-32270-3-git-send-email-imain@redhat.com> In-Reply-To: <1374861932-32270-1-git-send-email-imain@redhat.com> References: <1374861932-32270-1-git-send-email-imain@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, famz@redhat.com, rjones@redhat.com, Ian Main , stefanha@redhat.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH V8 2/2] Add tests for sync modes 'TOP' and 'NONE' 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 This patch adds tests for sync modes top and none. Test for 'TOP' is separated out as it requires a backing file. Also added a test for invalid format. Signed-off-by: Ian Main --- tests/qemu-iotests/055 | 26 +++++++++++++-- tests/qemu-iotests/055.out | 4 +-- tests/qemu-iotests/056 | 74 +++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/056.out | 5 +++ tests/qemu-iotests/group | 1 + tests/qemu-iotests/iotests.py | 5 +++ 6 files changed, 111 insertions(+), 4 deletions(-) create mode 100755 tests/qemu-iotests/056 create mode 100644 tests/qemu-iotests/056.out diff --git a/tests/qemu-iotests/055 b/tests/qemu-iotests/055 index c66f8db..ff7d22c 100755 --- a/tests/qemu-iotests/055 +++ b/tests/qemu-iotests/055 @@ -23,7 +23,7 @@ import time import os import iotests -from iotests import qemu_img, qemu_io +from iotests import qemu_img, qemu_io, create_image test_img = os.path.join(iotests.test_dir, 'test.img') target_img = os.path.join(iotests.test_dir, 'target.img') @@ -34,7 +34,7 @@ class TestSingleDrive(iotests.QMPTestCase): def setUp(self): # Write data to the image so we can compare later qemu_img('create', '-f', iotests.imgfmt, test_img, str(TestSingleDrive.image_len)) - qemu_io('-c', 'write -P0x5d 0 64k', test_img) + qemu_io('-c', 'write -P0x41 0 512', test_img) qemu_io('-c', 'write -P0xd5 1M 32k', test_img) qemu_io('-c', 'write -P0xdc 32M 124k', test_img) qemu_io('-c', 'write -P0xdc 67043328 64k', test_img) @@ -60,6 +60,22 @@ class TestSingleDrive(iotests.QMPTestCase): event = self.cancel_and_wait() self.assert_qmp(event, 'data/type', 'backup') + def test_cancel_sync_none(self): + self.assert_no_active_block_jobs() + + result = self.vm.qmp('drive-backup', device='drive0', + sync='none', target=target_img) + self.assert_qmp(result, 'return', {}) + time.sleep(1) + self.vm.hmp_qemu_io('drive0', 'write -P0x5e 0 512') + self.vm.hmp_qemu_io('drive0', 'aio_flush') + time.sleep(1) + # Verify that the original contents exist in the target image. + self.assertEqual(-1, qemu_io('-c', 'read -P0x41 0 512', target_img).find("verification failed")) + + event = self.cancel_and_wait() + self.assert_qmp(event, 'data/type', 'backup') + def test_pause(self): self.assert_no_active_block_jobs() @@ -97,6 +113,12 @@ class TestSingleDrive(iotests.QMPTestCase): target=target_img, sync='full', mode='existing') self.assert_qmp(result, 'error/class', 'GenericError') + def test_invalid_format(self): + result = self.vm.qmp('drive-backup', device='drive0', + target=target_img, sync='full', + format='spaghetti-noodles') + self.assert_qmp(result, 'error/class', 'GenericError') + def test_device_not_found(self): result = self.vm.qmp('drive-backup', device='nonexistent', target=target_img, sync='full') diff --git a/tests/qemu-iotests/055.out b/tests/qemu-iotests/055.out index fa16b5c..96961ed 100644 --- a/tests/qemu-iotests/055.out +++ b/tests/qemu-iotests/055.out @@ -1,5 +1,5 @@ -............. +............... ---------------------------------------------------------------------- -Ran 13 tests +Ran 15 tests OK diff --git a/tests/qemu-iotests/056 b/tests/qemu-iotests/056 new file mode 100755 index 0000000..a0a3f02 --- /dev/null +++ b/tests/qemu-iotests/056 @@ -0,0 +1,74 @@ +#!/usr/bin/env python +# +# Tests for drive-backup +# +# Copyright (C) 2013 Red Hat, Inc. +# +# Based on 041. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import time +import os +import iotests +from iotests import qemu_img, qemu_io, create_image + +backing_img = os.path.join(iotests.test_dir, 'backing.img') +test_img = os.path.join(iotests.test_dir, 'test.img') +target_img = os.path.join(iotests.test_dir, 'target.img') + +class TestSyncModeTop(iotests.QMPTestCase): + image_len = 2 * 1024 * 1024 # MB + + def setUp(self): + create_image(backing_img, TestSyncModeTop.image_len) + qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % backing_img, test_img) + qemu_io('-c', 'write -P0x5d 0 64k', test_img) + qemu_io('-c', 'write -P0xd5 1M 32k', test_img) + qemu_io('-c', 'write -P0xdc 32M 124k', test_img) + self.vm = iotests.VM().add_drive(test_img) + self.vm.launch() + + def tearDown(self): + self.vm.shutdown() + os.remove(test_img) + os.remove(backing_img) + try: + os.remove(target_img) + except OSError: + pass + + def test_complete_top(self): + self.assert_no_active_block_jobs() + result = self.vm.qmp('drive-backup', device='drive0', sync='top', + 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.assert_no_active_block_jobs() + self.vm.shutdown() + self.assertTrue(iotests.compare_images(test_img, target_img), + 'target image does not match source after backup') + +if __name__ == '__main__': + iotests.main(supported_fmts=['qcow2', 'qed']) diff --git a/tests/qemu-iotests/056.out b/tests/qemu-iotests/056.out new file mode 100644 index 0000000..ae1213e --- /dev/null +++ b/tests/qemu-iotests/056.out @@ -0,0 +1,5 @@ +. +---------------------------------------------------------------------- +Ran 1 tests + +OK diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index fdc6ed1..b1d03c7 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -62,3 +62,4 @@ 053 rw auto 054 rw auto 055 rw auto +056 rw auto backing diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index b028a89..33ad0ec 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -95,6 +95,11 @@ class VM(object): self._num_drives += 1 return self + def hmp_qemu_io(self, drive, cmd): + '''Write to a given drive using an HMP command''' + return self.qmp('human-monitor-command', + command_line='qemu-io %s "%s"' % (drive, cmd)) + def add_fd(self, fd, fdset, opaque, opts=''): '''Pass a file descriptor to the VM''' options = ['fd=%d' % fd,