From patchwork Tue May 28 15:11:36 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 246890 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 550992C02BD for ; Wed, 29 May 2013 01:12:49 +1000 (EST) Received: from localhost ([::1]:55718 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UhLZv-0008Og-Bz for incoming@patchwork.ozlabs.org; Tue, 28 May 2013 11:12:47 -0400 Received: from eggs.gnu.org ([208.118.235.92]:37039) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UhLZ7-0008HA-HY for qemu-devel@nongnu.org; Tue, 28 May 2013 11:12:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UhLYz-0001Cn-1S for qemu-devel@nongnu.org; Tue, 28 May 2013 11:11:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58469) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UhLYy-0001Cb-Og for qemu-devel@nongnu.org; Tue, 28 May 2013 11:11:48 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r4SFBm0V012969 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 28 May 2013 11:11:48 -0400 Received: from localhost (ovpn-112-25.ams2.redhat.com [10.36.112.25]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r4SFBlat026035; Tue, 28 May 2013 11:11:47 -0400 From: Stefan Hajnoczi To: Date: Tue, 28 May 2013 17:11:36 +0200 Message-Id: <1369753897-15140-4-git-send-email-stefanha@redhat.com> In-Reply-To: <1369753897-15140-1-git-send-email-stefanha@redhat.com> References: <1369753897-15140-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 3/4] qemu-iotests: make compare_images() common 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 The iotests.compare_images() function returns True if two image files have the identical data. Previously this was implemented by converting images to raw and then comparing their contents using Python. Since "qemu-img compare" is now available and is more efficient, switch to it. This function will be reused by the 'drive-backup' test case. Suggested-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi --- tests/qemu-iotests/041 | 41 ++++++++++------------------------------- tests/qemu-iotests/iotests.py | 5 +++++ 2 files changed, 15 insertions(+), 31 deletions(-) diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 index c4ce75e..7702074 100755 --- a/tests/qemu-iotests/041 +++ b/tests/qemu-iotests/041 @@ -80,27 +80,6 @@ class ImageMirroringTestCase(iotests.QMPTestCase): i = i + 512 file.close() - def compare_images(self, img1, img2): - try: - qemu_img('convert', '-f', iotests.imgfmt, '-O', 'raw', img1, img1 + '.raw') - qemu_img('convert', '-f', iotests.imgfmt, '-O', 'raw', img2, img2 + '.raw') - file1 = open(img1 + '.raw', 'r') - file2 = open(img2 + '.raw', 'r') - return file1.read() == file2.read() - finally: - if file1 is not None: - file1.close() - if file2 is not None: - file2.close() - try: - os.remove(img1 + '.raw') - except OSError: - pass - try: - os.remove(img2 + '.raw') - except OSError: - pass - class TestSingleDrive(ImageMirroringTestCase): image_len = 1 * 1024 * 1024 # MB @@ -130,7 +109,7 @@ class TestSingleDrive(ImageMirroringTestCase): result = self.vm.qmp('query-block') self.assert_qmp(result, 'return[0]/inserted/file', target_img) self.vm.shutdown() - self.assertTrue(self.compare_images(test_img, target_img), + self.assertTrue(iotests.compare_images(test_img, target_img), 'target image does not match source after mirroring') def test_cancel(self): @@ -156,7 +135,7 @@ class TestSingleDrive(ImageMirroringTestCase): result = self.vm.qmp('query-block') self.assert_qmp(result, 'return[0]/inserted/file', test_img) self.vm.shutdown() - self.assertTrue(self.compare_images(test_img, target_img), + self.assertTrue(iotests.compare_images(test_img, target_img), 'target image does not match source after mirroring') def test_pause(self): @@ -182,7 +161,7 @@ class TestSingleDrive(ImageMirroringTestCase): self.complete_and_wait() self.vm.shutdown() - self.assertTrue(self.compare_images(test_img, target_img), + self.assertTrue(iotests.compare_images(test_img, target_img), 'target image does not match source after mirroring') def test_small_buffer(self): @@ -197,7 +176,7 @@ class TestSingleDrive(ImageMirroringTestCase): result = self.vm.qmp('query-block') self.assert_qmp(result, 'return[0]/inserted/file', target_img) self.vm.shutdown() - self.assertTrue(self.compare_images(test_img, target_img), + self.assertTrue(iotests.compare_images(test_img, target_img), 'target image does not match source after mirroring') def test_small_buffer2(self): @@ -213,7 +192,7 @@ class TestSingleDrive(ImageMirroringTestCase): result = self.vm.qmp('query-block') self.assert_qmp(result, 'return[0]/inserted/file', target_img) self.vm.shutdown() - self.assertTrue(self.compare_images(test_img, target_img), + self.assertTrue(iotests.compare_images(test_img, target_img), 'target image does not match source after mirroring') def test_large_cluster(self): @@ -229,7 +208,7 @@ class TestSingleDrive(ImageMirroringTestCase): result = self.vm.qmp('query-block') self.assert_qmp(result, 'return[0]/inserted/file', target_img) self.vm.shutdown() - self.assertTrue(self.compare_images(test_img, target_img), + self.assertTrue(iotests.compare_images(test_img, target_img), 'target image does not match source after mirroring') def test_medium_not_found(self): @@ -256,7 +235,7 @@ class TestMirrorNoBacking(ImageMirroringTestCase): def compare_images(self, img1, img2): self.create_image(target_backing_img, TestMirrorNoBacking.image_len) - return ImageMirroringTestCase.compare_images(self, img1, img2) + return iotests.compare_images(img1, img2) def setUp(self): self.create_image(backing_img, TestMirrorNoBacking.image_len) @@ -353,7 +332,7 @@ class TestMirrorResized(ImageMirroringTestCase): result = self.vm.qmp('query-block') self.assert_qmp(result, 'return[0]/inserted/file', target_img) self.vm.shutdown() - self.assertTrue(self.compare_images(test_img, target_img), + self.assertTrue(iotests.compare_images(test_img, target_img), 'target image does not match source after mirroring') def test_complete_full(self): @@ -367,7 +346,7 @@ class TestMirrorResized(ImageMirroringTestCase): result = self.vm.qmp('query-block') self.assert_qmp(result, 'return[0]/inserted/file', target_img) self.vm.shutdown() - self.assertTrue(self.compare_images(test_img, target_img), + self.assertTrue(iotests.compare_images(test_img, target_img), 'target image does not match source after mirroring') class TestReadErrors(ImageMirroringTestCase): @@ -487,7 +466,7 @@ new_state = "1" # Detach blkdebug to compare images successfully qemu_img('rebase', '-f', iotests.imgfmt, '-u', '-b', backing_img, test_img) - self.assertTrue(self.compare_images(test_img, target_img), + self.assertTrue(iotests.compare_images(test_img, target_img), 'target image does not match source after mirroring') def test_stop_read(self): diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index bc9c71b..733b82b 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -51,6 +51,11 @@ def qemu_io(*args): args = qemu_io_args + list(args) return subprocess.Popen(args, stdout=subprocess.PIPE).communicate()[0] +def compare_images(img1, img2): + '''Return True if two image files are identical''' + return qemu_img('compare', '-f', imgfmt, + '-F', imgfmt, img1, img2) == 0 + class VM(object): '''A QEMU VM'''