diff mbox series

[v11,3/3] qemu-img info: bitmaps extension new test 239

Message ID 1548942405-760115-4-git-send-email-andrey.shinkevich@virtuozzo.com (mailing list archive)
State New, archived
Headers show
Series qemu-img info lists bitmap directory entries | expand

Commit Message

Andrey Shinkevich Jan. 31, 2019, 1:46 p.m. UTC
A new test file 239 added to the qemu-iotests set. It checks
the output format of 'qemu-img info' for bitmaps extension of
qcow2 specific information.

Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
---
 tests/qemu-iotests/239     |  74 ++++++++++++++++++++++++++
 tests/qemu-iotests/239.out | 130 +++++++++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/group   |   1 +
 3 files changed, 205 insertions(+)
 create mode 100755 tests/qemu-iotests/239
 create mode 100644 tests/qemu-iotests/239.out

Comments

Vladimir Sementsov-Ogievskiy Feb. 1, 2019, 3:57 p.m. UTC | #1
31.01.2019 16:46, Andrey Shinkevich wrote:
> A new test file 239 added to the qemu-iotests set. It checks
> the output format of 'qemu-img info' for bitmaps extension of
> qcow2 specific information.
> 
> Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
> ---
>   tests/qemu-iotests/239     |  74 ++++++++++++++++++++++++++
>   tests/qemu-iotests/239.out | 130 +++++++++++++++++++++++++++++++++++++++++++++
>   tests/qemu-iotests/group   |   1 +
>   3 files changed, 205 insertions(+)
>   create mode 100755 tests/qemu-iotests/239
>   create mode 100644 tests/qemu-iotests/239.out
> 
> diff --git a/tests/qemu-iotests/239 b/tests/qemu-iotests/239
> new file mode 100755
> index 0000000..bee7943
> --- /dev/null
> +++ b/tests/qemu-iotests/239
> @@ -0,0 +1,74 @@
> +#!/usr/bin/env python
> +#
> +# Test for qcow2 bitmap printed information
> +#
> +# Copyright (c) 2018 Virtuozzo International GmbH
> +#
> +# 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 <http://www.gnu.org/licenses/>.
> +#
> +
> +import iotests
> +import json
> +from iotests import qemu_img_create, qemu_io, qemu_img_pipe, \
> +                    file_path, log
> +
> +iotests.verify_image_format(supported_fmts=['qcow2'])
> +
> +disk = file_path('disk')
> +chunk = 256
> +
> +def print_bitmap():
> +    log('qemu-img info dump:\n')
> +    iotests.img_info_log(disk, extra_args=['--force-share'])
> +    result = json.loads(qemu_img_pipe('info', '--force-share',
> +                                      '--output=json', disk))
> +    if 'bitmaps' in result['format-specific']['data']:
> +        bitmaps = result['format-specific']['data']['bitmaps']
> +        log('The same bitmaps in JSON format:')
> +        log(bitmaps, indent=2)
> +    else:
> +        log('No bitmap in JSON format output')
> +
> +def add_bitmap(bitmap_number, persistent, disabled):
> +    granularity = 2**(13 + bitmap_number)
> +    bitmap_name = 'bitmap-' + str(bitmap_number-1)
> +    vm = iotests.VM().add_drive(disk)
> +    vm.launch()
> +    vm.qmp_log('block-dirty-bitmap-add', node='drive0', name=bitmap_name,
> +               granularity=granularity, persistent=persistent,
> +               disabled=disabled)
> +    vm.shutdown()
> +
> +def write_to_disk(offset, size):
> +    write = 'write {} {}K'.format(offset, size)

I think, you meant {}K {}K. On the other hand, if you want to work with 256K chunks,
I think, better is to define chunk as
chunk = 256 * 1024

> +    qemu_io('-f', iotests.imgfmt, '-c', write, disk)

Hmm, interesting, it's a common preactice to give -f iotests.imgfmt to qemu_io(),
but in reality it's not needed, as qemu_io() automatically set this flag, this
parameter will be passed twice. So, it would be good to fix it in all iotests,
handle '-f' properly in qemu_io(), and I think, in qemu-io utility too, forbid
multiple -f option.

So, here let's use
qemu_io('-c', write, disk)

> +    log('Write ' + str(size) + 'K to disk at offset ' + str(hex(offset)))

hmm, you just do qemu-io output by hand. better log() what qemu_io() returns
with appropriate filters, look in iotest 149

> +
> +
> +qemu_img_create('-f', iotests.imgfmt, disk, '1M')
> +
> +for num in range(1, 4):

good to log('Test {}'.format(num)) here

> +    disabled = False
> +    if num == 2:
> +        disabled = True
> +    add_bitmap(num, bool(num-1), disabled)

more clear: num > 1

> +    write_to_disk((num-1)*chunk, chunk)

Hm, actually this don't change test output, as we don't see dirty bits through
new API. However, it make sense anyway, to be closer to real-life.

> +    print_bitmap()
> +    log('')
> +
> +vm = iotests.VM().add_drive(disk)
> +vm.launch()
> +log('Checking \"in-use\" flag...')

don't back-slash double quotes, it's not needed, as you are inside single quotes.

> +print_bitmap()

I'd prefere to use '--force-share' only for this case, when it's really needed.

> +vm.shutdown()
> diff --git a/tests/qemu-iotests/239.out b/tests/qemu-iotests/239.out
Kevin Wolf Feb. 1, 2019, 5:14 p.m. UTC | #2
Am 31.01.2019 um 14:46 hat Andrey Shinkevich geschrieben:
> A new test file 239 added to the qemu-iotests set. It checks
> the output format of 'qemu-img info' for bitmaps extension of
> qcow2 specific information.
> 
> Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>

239 is already taken, so please rename this one. I usually search the
mailing list for "239.out" etc. until I find a number that nobody has
used even in a patch series yet.

Kevin
Eric Blake Feb. 1, 2019, 5:23 p.m. UTC | #3
On 1/31/19 7:46 AM, Andrey Shinkevich wrote:
> A new test file 239 added to the qemu-iotests set. It checks
> the output format of 'qemu-img info' for bitmaps extension of
> qcow2 specific information.
> 
> Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
> ---
>  tests/qemu-iotests/239     |  74 ++++++++++++++++++++++++++
>  tests/qemu-iotests/239.out | 130 +++++++++++++++++++++++++++++++++++++++++++++
>  tests/qemu-iotests/group   |   1 +
>  3 files changed, 205 insertions(+)
>  create mode 100755 tests/qemu-iotests/239
>  create mode 100644 tests/qemu-iotests/239.out

Kevin just sent a pull request with 239 consumed for something else (a
test for dmg; also consumed 240); I don't mind renumbering the test as
242 or later as part of staging if we are happy with this version of the
test.  But I also see that Vladimir had some suggestions, so I wouldn't
be surprised if you want to send a v12.

> 
> diff --git a/tests/qemu-iotests/239 b/tests/qemu-iotests/239
> new file mode 100755
> index 0000000..bee7943
> --- /dev/null
> +++ b/tests/qemu-iotests/239
> @@ -0,0 +1,74 @@
> +#!/usr/bin/env python
> +#
> +# Test for qcow2 bitmap printed information
> +#
> +# Copyright (c) 2018 Virtuozzo International GmbH

Want to claim 2019?


> +def add_bitmap(bitmap_number, persistent, disabled):
> +    granularity = 2**(13 + bitmap_number)
> +    bitmap_name = 'bitmap-' + str(bitmap_number-1)
> +    vm = iotests.VM().add_drive(disk)
> +    vm.launch()
> +    vm.qmp_log('block-dirty-bitmap-add', node='drive0', name=bitmap_name,
> +               granularity=granularity, persistent=persistent,
> +               disabled=disabled)
> +    vm.shutdown()
> +
> +def write_to_disk(offset, size):
> +    write = 'write {} {}K'.format(offset, size)
> +    qemu_io('-f', iotests.imgfmt, '-c', write, disk)
> +    log('Write ' + str(size) + 'K to disk at offset ' + str(hex(offset)))
> +
> +
> +qemu_img_create('-f', iotests.imgfmt, disk, '1M')
> +
> +for num in range(1, 4):
> +    disabled = False
> +    if num == 2:
> +        disabled = True
> +    add_bitmap(num, bool(num-1), disabled)

I don't know the pythonic way of coercing a bool value out of a check
for whether another value is a particular integer; but I see that you
did it in two different styles.  I don't know if this works, but it
would at least look more consistent:

add_bitmap(num, bool(num == 1), bool(num == 2))

> +    write_to_disk((num-1)*chunk, chunk)

Does PEP8 want spaces around those operators?

> +    print_bitmap()
> +    log('')
> +
> +vm = iotests.VM().add_drive(disk)
> +vm.launch()
> +log('Checking \"in-use\" flag...')
> +print_bitmap()
> +vm.shutdown()

The test output looks like reasonable coverage.
Tested-by: Eric Blake <eblake@redhat.com>
Kevin Wolf Feb. 1, 2019, 5:34 p.m. UTC | #4
Am 01.02.2019 um 18:23 hat Eric Blake geschrieben:
> On 1/31/19 7:46 AM, Andrey Shinkevich wrote:
> > A new test file 239 added to the qemu-iotests set. It checks
> > the output format of 'qemu-img info' for bitmaps extension of
> > qcow2 specific information.
> > 
> > Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
> > ---
> >  tests/qemu-iotests/239     |  74 ++++++++++++++++++++++++++
> >  tests/qemu-iotests/239.out | 130 +++++++++++++++++++++++++++++++++++++++++++++
> >  tests/qemu-iotests/group   |   1 +
> >  3 files changed, 205 insertions(+)
> >  create mode 100755 tests/qemu-iotests/239
> >  create mode 100644 tests/qemu-iotests/239.out
> 
> Kevin just sent a pull request with 239 consumed for something else (a
> test for dmg; also consumed 240); I don't mind renumbering the test as
> 242 or later as part of staging if we are happy with this version of the
> test.  But I also see that Vladimir had some suggestions, so I wouldn't
> be surprised if you want to send a v12.
> 
> > 
> > diff --git a/tests/qemu-iotests/239 b/tests/qemu-iotests/239
> > new file mode 100755
> > index 0000000..bee7943
> > --- /dev/null
> > +++ b/tests/qemu-iotests/239
> > @@ -0,0 +1,74 @@
> > +#!/usr/bin/env python
> > +#
> > +# Test for qcow2 bitmap printed information
> > +#
> > +# Copyright (c) 2018 Virtuozzo International GmbH
> 
> Want to claim 2019?
> 
> 
> > +def add_bitmap(bitmap_number, persistent, disabled):
> > +    granularity = 2**(13 + bitmap_number)
> > +    bitmap_name = 'bitmap-' + str(bitmap_number-1)
> > +    vm = iotests.VM().add_drive(disk)
> > +    vm.launch()
> > +    vm.qmp_log('block-dirty-bitmap-add', node='drive0', name=bitmap_name,
> > +               granularity=granularity, persistent=persistent,
> > +               disabled=disabled)
> > +    vm.shutdown()
> > +
> > +def write_to_disk(offset, size):
> > +    write = 'write {} {}K'.format(offset, size)
> > +    qemu_io('-f', iotests.imgfmt, '-c', write, disk)
> > +    log('Write ' + str(size) + 'K to disk at offset ' + str(hex(offset)))
> > +
> > +
> > +qemu_img_create('-f', iotests.imgfmt, disk, '1M')
> > +
> > +for num in range(1, 4):
> > +    disabled = False
> > +    if num == 2:
> > +        disabled = True
> > +    add_bitmap(num, bool(num-1), disabled)
> 
> I don't know the pythonic way of coercing a bool value out of a check
> for whether another value is a particular integer; but I see that you
> did it in two different styles.  I don't know if this works, but it
> would at least look more consistent:
> 
> add_bitmap(num, bool(num == 1), bool(num == 2))

Hm...

    >>> num = 0
    >>> type(num == 2)
    <class 'bool'>

Why all the bool() calls when the result of == is already a bool?

Kevin
Vladimir Sementsov-Ogievskiy Feb. 4, 2019, 7:53 a.m. UTC | #5
01.02.2019 20:14, Kevin Wolf wrote:
> Am 31.01.2019 um 14:46 hat Andrey Shinkevich geschrieben:
>> A new test file 239 added to the qemu-iotests set. It checks
>> the output format of 'qemu-img info' for bitmaps extension of
>> qcow2 specific information.
>>
>> Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
> 
> 239 is already taken, so please rename this one. I usually search the
> mailing list for "239.out" etc. until I find a number that nobody has
> used even in a patch series yet.
> 
> Kevin
> 

Interesting, wasn't it considered to give meaningful names to iotest files?
like migrate.bitmaps or qemu-img.qcow2-bitmaps, namespace.test? And then
we'll be able to ./check -qcow2 qemu-img.*. And all these conflicts in list
will be resolved
Kevin Wolf Feb. 4, 2019, 9:36 a.m. UTC | #6
Am 04.02.2019 um 08:53 hat Vladimir Sementsov-Ogievskiy geschrieben:
> 01.02.2019 20:14, Kevin Wolf wrote:
> > Am 31.01.2019 um 14:46 hat Andrey Shinkevich geschrieben:
> >> A new test file 239 added to the qemu-iotests set. It checks
> >> the output format of 'qemu-img info' for bitmaps extension of
> >> qcow2 specific information.
> >>
> >> Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
> > 
> > 239 is already taken, so please rename this one. I usually search the
> > mailing list for "239.out" etc. until I find a number that nobody has
> > used even in a patch series yet.
> > 
> > Kevin
> > 
> 
> Interesting, wasn't it considered to give meaningful names to iotest files?
> like migrate.bitmaps or qemu-img.qcow2-bitmaps, namespace.test? And then
> we'll be able to ./check -qcow2 qemu-img.*. And all these conflicts in list
> will be resolved

You're not the first one to suggest this, and I don't think people ever
fundamentally objected to the idea. But noone implemented it either -
the current system is ugly, but it does kind of work in practice and
renaming files in the repo always comes with some cost like 'git blame'
and 'git log' stopping at the rename by default.

Kevin
diff mbox series

Patch

diff --git a/tests/qemu-iotests/239 b/tests/qemu-iotests/239
new file mode 100755
index 0000000..bee7943
--- /dev/null
+++ b/tests/qemu-iotests/239
@@ -0,0 +1,74 @@ 
+#!/usr/bin/env python
+#
+# Test for qcow2 bitmap printed information
+#
+# Copyright (c) 2018 Virtuozzo International GmbH
+#
+# 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 <http://www.gnu.org/licenses/>.
+#
+
+import iotests
+import json
+from iotests import qemu_img_create, qemu_io, qemu_img_pipe, \
+                    file_path, log
+
+iotests.verify_image_format(supported_fmts=['qcow2'])
+
+disk = file_path('disk')
+chunk = 256
+
+def print_bitmap():
+    log('qemu-img info dump:\n')
+    iotests.img_info_log(disk, extra_args=['--force-share'])
+    result = json.loads(qemu_img_pipe('info', '--force-share',
+                                      '--output=json', disk))
+    if 'bitmaps' in result['format-specific']['data']:
+        bitmaps = result['format-specific']['data']['bitmaps']
+        log('The same bitmaps in JSON format:')
+        log(bitmaps, indent=2)
+    else:
+        log('No bitmap in JSON format output')
+
+def add_bitmap(bitmap_number, persistent, disabled):
+    granularity = 2**(13 + bitmap_number)
+    bitmap_name = 'bitmap-' + str(bitmap_number-1)
+    vm = iotests.VM().add_drive(disk)
+    vm.launch()
+    vm.qmp_log('block-dirty-bitmap-add', node='drive0', name=bitmap_name,
+               granularity=granularity, persistent=persistent,
+               disabled=disabled)
+    vm.shutdown()
+
+def write_to_disk(offset, size):
+    write = 'write {} {}K'.format(offset, size)
+    qemu_io('-f', iotests.imgfmt, '-c', write, disk)
+    log('Write ' + str(size) + 'K to disk at offset ' + str(hex(offset)))
+
+
+qemu_img_create('-f', iotests.imgfmt, disk, '1M')
+
+for num in range(1, 4):
+    disabled = False
+    if num == 2:
+        disabled = True
+    add_bitmap(num, bool(num-1), disabled)
+    write_to_disk((num-1)*chunk, chunk)
+    print_bitmap()
+    log('')
+
+vm = iotests.VM().add_drive(disk)
+vm.launch()
+log('Checking \"in-use\" flag...')
+print_bitmap()
+vm.shutdown()
diff --git a/tests/qemu-iotests/239.out b/tests/qemu-iotests/239.out
new file mode 100644
index 0000000..0abcac7
--- /dev/null
+++ b/tests/qemu-iotests/239.out
@@ -0,0 +1,130 @@ 
+{"execute": "block-dirty-bitmap-add", "arguments": {"disabled": false, "granularity": 16384, "name": "bitmap-0", "node": "drive0", "persistent": false}}
+{"return": {}}
+Write 256K to disk at offset 0x0
+qemu-img info dump:
+
+image: TEST_IMG
+file format: IMGFMT
+virtual size: 1.0M (1048576 bytes)
+cluster_size: 65536
+Format specific information:
+    compat: 1.1
+    lazy refcounts: false
+    refcount bits: 16
+    corrupt: false
+
+No bitmap in JSON format output
+
+{"execute": "block-dirty-bitmap-add", "arguments": {"disabled": true, "granularity": 32768, "name": "bitmap-1", "node": "drive0", "persistent": true}}
+{"return": {}}
+Write 256K to disk at offset 0x100
+qemu-img info dump:
+
+image: TEST_IMG
+file format: IMGFMT
+virtual size: 1.0M (1048576 bytes)
+cluster_size: 65536
+Format specific information:
+    compat: 1.1
+    lazy refcounts: false
+    bitmaps:
+        [0]:
+            flags:
+            name: bitmap-1
+            granularity: 32768
+    refcount bits: 16
+    corrupt: false
+
+The same bitmaps in JSON format:
+[
+  {
+    "flags": [],
+    "granularity": 32768,
+    "name": "bitmap-1"
+  }
+]
+
+{"execute": "block-dirty-bitmap-add", "arguments": {"disabled": false, "granularity": 65536, "name": "bitmap-2", "node": "drive0", "persistent": true}}
+{"return": {}}
+Write 256K to disk at offset 0x200
+qemu-img info dump:
+
+image: TEST_IMG
+file format: IMGFMT
+virtual size: 1.0M (1048576 bytes)
+cluster_size: 65536
+Format specific information:
+    compat: 1.1
+    lazy refcounts: false
+    bitmaps:
+        [0]:
+            flags:
+            name: bitmap-1
+            granularity: 32768
+        [1]:
+            flags:
+                [0]: auto
+            name: bitmap-2
+            granularity: 65536
+    refcount bits: 16
+    corrupt: false
+
+The same bitmaps in JSON format:
+[
+  {
+    "flags": [],
+    "granularity": 32768,
+    "name": "bitmap-1"
+  },
+  {
+    "flags": [
+      "auto"
+    ],
+    "granularity": 65536,
+    "name": "bitmap-2"
+  }
+]
+
+Checking "in-use" flag...
+qemu-img info dump:
+
+image: TEST_IMG
+file format: IMGFMT
+virtual size: 1.0M (1048576 bytes)
+cluster_size: 65536
+Format specific information:
+    compat: 1.1
+    lazy refcounts: false
+    bitmaps:
+        [0]:
+            flags:
+                [0]: in-use
+            name: bitmap-1
+            granularity: 32768
+        [1]:
+            flags:
+                [0]: in-use
+                [1]: auto
+            name: bitmap-2
+            granularity: 65536
+    refcount bits: 16
+    corrupt: false
+
+The same bitmaps in JSON format:
+[
+  {
+    "flags": [
+      "in-use"
+    ],
+    "granularity": 32768,
+    "name": "bitmap-1"
+  },
+  {
+    "flags": [
+      "in-use",
+      "auto"
+    ],
+    "granularity": 65536,
+    "name": "bitmap-2"
+  }
+]
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
index 0f1c3f9..3e310c7 100644
--- a/tests/qemu-iotests/group
+++ b/tests/qemu-iotests/group
@@ -235,3 +235,4 @@ 
 235 auto quick
 236 auto quick
 238 auto quick
+239 rw auto quick