qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 2/4] qemu-iotests: make cancel_and_wait() common
Date: Wed, 29 May 2013 11:54:56 +0200	[thread overview]
Message-ID: <20130529095456.GD3521@dhcp-200-207.str.redhat.com> (raw)
In-Reply-To: <1369753897-15140-3-git-send-email-stefanha@redhat.com>

Am 28.05.2013 um 17:11 hat Stefan Hajnoczi geschrieben:
> The cancel_and_wait() function has been duplicated in 030 and 041.  Move
> it into iotests.py and let it return the event so tests can perform
> additional asserts.
> 
> Note that 041's cancel_and_wait(wait_ready=True) is replaced by
> wait_ready_and_cancel(), which uses the new wait_ready() and
> cancel_and_wait() underneath.
> 
> Suggested-by: Kevin Wolf <kwolf@redhat.com>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>

> diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041
> index ff89427..c4ce75e 100755
> --- a/tests/qemu-iotests/041
> +++ b/tests/qemu-iotests/041
> @@ -32,46 +32,28 @@ target_img = os.path.join(iotests.test_dir, 'target.img')
>  class ImageMirroringTestCase(iotests.QMPTestCase):
>      '''Abstract base class for image mirroring test cases'''
>  
> -    def cancel_and_wait(self, drive='drive0', wait_ready=True):
> -        '''Cancel a block job and wait for it to finish'''
> -        if wait_ready:
> -            ready = False
> -            while not ready:
> -                for event in self.vm.get_qmp_events(wait=True):
> -                    if event['event'] == 'BLOCK_JOB_READY':
> -                        self.assert_qmp(event, 'data/type', 'mirror')
> -                        self.assert_qmp(event, 'data/device', drive)
> -                        ready = True
> -
> -        result = self.vm.qmp('block-job-cancel', device=drive,
> -                             force=not wait_ready)
> -        self.assert_qmp(result, 'return', {})
> -
> -        cancelled = False
> -        while not cancelled:
> +    def wait_ready(self, drive='drive0'):
> +        '''Wait until a block job BLOCK_JOB_READY event'''
> +        ready = False
> +        while not ready:
>              for event in self.vm.get_qmp_events(wait=True):
> -                if event['event'] == 'BLOCK_JOB_COMPLETED' or \
> -                   event['event'] == 'BLOCK_JOB_CANCELLED':
> +                if event['event'] == 'BLOCK_JOB_READY':
>                      self.assert_qmp(event, 'data/type', 'mirror')
>                      self.assert_qmp(event, 'data/device', drive)
> -                    if wait_ready:
> -                        self.assertEquals(event['event'], 'BLOCK_JOB_COMPLETED')
> -                        self.assert_qmp(event, 'data/offset', self.image_len)
> -                        self.assert_qmp(event, 'data/len', self.image_len)
> -                    cancelled = True
> +                    ready = True

Why don't you just move the whole function including the wait_ready
parameter? It doesn't do any harm to other callers that don't need the
feature, and will likely be useful for other test cases later.

Kevin

  reply	other threads:[~2013-05-29  9:55 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-28 15:11 [Qemu-devel] [PATCH 0/4] qemu-iotests: reduce iotests.py code duplication Stefan Hajnoczi
2013-05-28 15:11 ` [Qemu-devel] [PATCH 1/4] qemu-iotests: make assert_no_active_block_jobs() common Stefan Hajnoczi
2013-05-28 15:11 ` [Qemu-devel] [PATCH 2/4] qemu-iotests: make cancel_and_wait() common Stefan Hajnoczi
2013-05-29  9:54   ` Kevin Wolf [this message]
2013-05-29 11:02     ` Stefan Hajnoczi
2013-05-28 15:11 ` [Qemu-devel] [PATCH 3/4] qemu-iotests: make compare_images() common Stefan Hajnoczi
2013-05-28 15:11 ` [Qemu-devel] [PATCH 4/4] qemu-iotests: make create_image() common Stefan Hajnoczi
2013-05-29  5:29 ` [Qemu-devel] [PATCH 0/4] qemu-iotests: reduce iotests.py code duplication Fam Zheng
2013-05-29  7:51   ` Stefan Hajnoczi
2013-05-29 10:04 ` Kevin Wolf
2013-05-29 11:56 ` Kevin Wolf

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=20130529095456.GD3521@dhcp-200-207.str.redhat.com \
    --to=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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).