From patchwork Wed May 6 04:52:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 468581 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 966291402B5 for ; Wed, 6 May 2015 14:53:16 +1000 (AEST) Received: from localhost ([::1]:42960 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YprKc-0001d3-Oa for incoming@patchwork.ozlabs.org; Wed, 06 May 2015 00:53:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49696) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YprK2-0000Ul-FY for qemu-devel@nongnu.org; Wed, 06 May 2015 00:52:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YprK1-00045J-E1 for qemu-devel@nongnu.org; Wed, 06 May 2015 00:52:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59521) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YprK1-000452-7i; Wed, 06 May 2015 00:52:37 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t464qaeh022454 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 6 May 2015 00:52:36 -0400 Received: from ad.nay.redhat.com (dhcp-14-137.nay.redhat.com [10.66.14.137]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t464qCRc028497; Wed, 6 May 2015 00:52:33 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 6 May 2015 12:52:07 +0800 Message-Id: <1430887928-18189-6-git-send-email-famz@redhat.com> In-Reply-To: <1430887928-18189-1-git-send-email-famz@redhat.com> References: <1430887928-18189-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , qemu-block@nongnu.org, Stefan Hajnoczi , pbonzini@redhat.com, jsnow@redhat.com, wangxiaolong@ucloud.cn Subject: [Qemu-devel] [PATCH v2 5/6] qemu-iotests: Add test case for mirror with unmap 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 checks that the discard on mirror source that effectively zeroes data is also reflected by the data of target. Signed-off-by: Fam Zheng Reviewed-by: John Snow --- tests/qemu-iotests/131 | 59 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/131.out | 5 ++++ tests/qemu-iotests/group | 1 + 3 files changed, 65 insertions(+) create mode 100644 tests/qemu-iotests/131 create mode 100644 tests/qemu-iotests/131.out diff --git a/tests/qemu-iotests/131 b/tests/qemu-iotests/131 new file mode 100644 index 0000000..f53ef6e --- /dev/null +++ b/tests/qemu-iotests/131 @@ -0,0 +1,59 @@ +#!/usr/bin/env python +# +# Test mirror with unmap +# +# Copyright (C) 2015 Red Hat, Inc. +# +# 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 + +test_img = os.path.join(iotests.test_dir, 'test.img') +target_img = os.path.join(iotests.test_dir, 'target.img') + +class TestSingleDrive(iotests.QMPTestCase): + image_len = 2 * 1024 * 1024 # MB + + 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('-f', iotests.imgfmt, '-c', 'write -P0x5d 0 2M', test_img) + + self.vm = iotests.VM().add_drive(test_img, 'discard=unmap') + self.vm.launch() + + def tearDown(self): + self.vm.shutdown() + os.remove(test_img) + try: + os.remove(target_img) + except OSError: + pass + + def test_mirror_discard(self): + result = self.vm.qmp('drive-mirror', device='drive0', sync='full', + target=target_img) + self.assert_qmp(result, 'return', {}) + self.vm.hmp_qemu_io('drive0', 'discard 0 64k') + self.complete_and_wait('drive0') + self.vm.shutdown() + self.assertTrue(iotests.compare_images(test_img, target_img), + 'target image does not match source after mirroring') + +if __name__ == '__main__': + iotests.main(supported_fmts=['raw', 'qcow2']) diff --git a/tests/qemu-iotests/131.out b/tests/qemu-iotests/131.out new file mode 100644 index 0000000..ae1213e --- /dev/null +++ b/tests/qemu-iotests/131.out @@ -0,0 +1,5 @@ +. +---------------------------------------------------------------------- +Ran 1 tests + +OK diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 6ca3466..34b16cb 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -128,3 +128,4 @@ 128 rw auto quick 129 rw auto quick 130 rw auto quick +131 rw auto quick