summaryrefslogtreecommitdiffstats
path: root/tests/qemu-iotests/303
blob: a8cc6a23dfe746dd2e89bcfbc55307b70a21b303 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
# group: rw quick
#
# Test for dumping of qcow2 image metadata
#
# Copyright (c) 2020 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 subprocess
from iotests import qemu_img_create, qemu_io_log, file_path, log, \
        verify_qcow2_zstd_compression

iotests.script_initialize(supported_fmts=['qcow2'],
                          unsupported_imgopts=['refcount_bits', 'compat'])
verify_qcow2_zstd_compression()

disk = file_path('disk')
chunk = 1024 * 1024


def create_bitmap(bitmap_number, disabled):
    granularity = 1 << (14 + bitmap_number)
    bitmap_name = 'bitmap-' + str(bitmap_number)
    args = ['bitmap', '--add', '-g', f'{granularity}', '-f', iotests.imgfmt,
            disk, bitmap_name]
    if disabled:
        args.append('--disable')

    iotests.qemu_img(*args)


def write_to_disk(offset, size):
    write = f'write {offset} {size}'
    qemu_io_log('-c', write, disk)


def add_bitmap(num, begin, end, disabled):
    log(f'Add bitmap {num}')
    create_bitmap(num, disabled)
    for i in range(begin, end):
        write_to_disk((i) * chunk, chunk)
    log('')


def test(compression_type: str, json_output: bool) -> None:
    qemu_img_create('-f', iotests.imgfmt,
                    '-o', f'compression_type={compression_type}',
                    disk, '10M')
    add_bitmap(1, 0, 6, False)
    add_bitmap(2, 6, 8, True)

    cmd = ['./qcow2.py', disk, 'dump-header']
    if json_output:
        cmd.append('-j')

    subprocess.run(cmd)


test('zlib', False)
test('zstd', True)