From: Kevin Wolf <kwolf@redhat.com>
To: anthony@codemonkey.ws
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 05/10] qemu-iotests: make compare_images() common
Date: Tue, 4 Jun 2013 14:45:35 +0200 [thread overview]
Message-ID: <1370349940-4703-6-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1370349940-4703-1-git-send-email-kwolf@redhat.com>
From: Stefan Hajnoczi <stefanha@redhat.com>
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 <kwolf@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
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'''
--
1.8.1.4
next prev parent reply other threads:[~2013-06-04 12:46 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-04 12:45 [Qemu-devel] [PULL 00/10] Block patches Kevin Wolf
2013-06-04 12:45 ` [Qemu-devel] [PULL 01/10] qemu-iotests: fix 054 cluster size help output Kevin Wolf
2013-06-04 12:45 ` [Qemu-devel] [PULL 02/10] block: add block driver read only whitelist Kevin Wolf
2013-06-04 12:45 ` [Qemu-devel] [PULL 03/10] qemu-iotests: make assert_no_active_block_jobs() common Kevin Wolf
2013-06-04 12:45 ` [Qemu-devel] [PULL 04/10] qemu-iotests: make cancel_and_wait() common Kevin Wolf
2013-06-04 12:45 ` Kevin Wolf [this message]
2013-06-04 12:45 ` [Qemu-devel] [PULL 06/10] qemu-iotests: make create_image() common Kevin Wolf
2013-06-04 12:45 ` [Qemu-devel] [PULL 07/10] block: drop bs_snapshots global variable Kevin Wolf
2013-06-04 12:45 ` [Qemu-devel] [PULL 08/10] block: move snapshot code in block.c to block/snapshot.c Kevin Wolf
2013-06-04 12:45 ` [Qemu-devel] [PULL 09/10] block: move qmp and info dump related code to block/qapi.c Kevin Wolf
2013-06-04 12:45 ` [Qemu-devel] [PULL 10/10] block: dump snapshot and image info to specified output Kevin Wolf
2013-06-17 21:17 ` [Qemu-devel] [PULL 00/10] Block patches Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1370349940-4703-6-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).