xref: /qemu/tests/qemu-iotests/303 (revision bf654b37e19eb43abca5b5b2a6eac21732b368ca)
1*bf654b37SAndrey Shinkevich#!/usr/bin/env python3
2*bf654b37SAndrey Shinkevich#
3*bf654b37SAndrey Shinkevich# Test for dumping of qcow2 image metadata
4*bf654b37SAndrey Shinkevich#
5*bf654b37SAndrey Shinkevich# Copyright (c) 2020 Virtuozzo International GmbH
6*bf654b37SAndrey Shinkevich#
7*bf654b37SAndrey Shinkevich# This program is free software; you can redistribute it and/or modify
8*bf654b37SAndrey Shinkevich# it under the terms of the GNU General Public License as published by
9*bf654b37SAndrey Shinkevich# the Free Software Foundation; either version 2 of the License, or
10*bf654b37SAndrey Shinkevich# (at your option) any later version.
11*bf654b37SAndrey Shinkevich#
12*bf654b37SAndrey Shinkevich# This program is distributed in the hope that it will be useful,
13*bf654b37SAndrey Shinkevich# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*bf654b37SAndrey Shinkevich# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*bf654b37SAndrey Shinkevich# GNU General Public License for more details.
16*bf654b37SAndrey Shinkevich#
17*bf654b37SAndrey Shinkevich# You should have received a copy of the GNU General Public License
18*bf654b37SAndrey Shinkevich# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19*bf654b37SAndrey Shinkevich#
20*bf654b37SAndrey Shinkevich
21*bf654b37SAndrey Shinkevichimport iotests
22*bf654b37SAndrey Shinkevichimport subprocess
23*bf654b37SAndrey Shinkevichfrom iotests import qemu_img_create, qemu_io, file_path, log, filter_qemu_io
24*bf654b37SAndrey Shinkevich
25*bf654b37SAndrey Shinkevichiotests.script_initialize(supported_fmts=['qcow2'])
26*bf654b37SAndrey Shinkevich
27*bf654b37SAndrey Shinkevichdisk = file_path('disk')
28*bf654b37SAndrey Shinkevichchunk = 1024 * 1024
29*bf654b37SAndrey Shinkevich
30*bf654b37SAndrey Shinkevich
31*bf654b37SAndrey Shinkevichdef create_bitmap(bitmap_number, disabled):
32*bf654b37SAndrey Shinkevich    granularity = 1 << (14 + bitmap_number)
33*bf654b37SAndrey Shinkevich    bitmap_name = 'bitmap-' + str(bitmap_number)
34*bf654b37SAndrey Shinkevich    args = ['bitmap', '--add', '-g', f'{granularity}', '-f', iotests.imgfmt,
35*bf654b37SAndrey Shinkevich            disk, bitmap_name]
36*bf654b37SAndrey Shinkevich    if disabled:
37*bf654b37SAndrey Shinkevich        args.append('--disable')
38*bf654b37SAndrey Shinkevich
39*bf654b37SAndrey Shinkevich    iotests.qemu_img_pipe(*args)
40*bf654b37SAndrey Shinkevich
41*bf654b37SAndrey Shinkevich
42*bf654b37SAndrey Shinkevichdef write_to_disk(offset, size):
43*bf654b37SAndrey Shinkevich    write = f'write {offset} {size}'
44*bf654b37SAndrey Shinkevich    log(qemu_io('-c', write, disk), filters=[filter_qemu_io])
45*bf654b37SAndrey Shinkevich
46*bf654b37SAndrey Shinkevich
47*bf654b37SAndrey Shinkevichdef add_bitmap(num, begin, end, disabled):
48*bf654b37SAndrey Shinkevich    log(f'Add bitmap {num}')
49*bf654b37SAndrey Shinkevich    create_bitmap(num, disabled)
50*bf654b37SAndrey Shinkevich    for i in range(begin, end):
51*bf654b37SAndrey Shinkevich        write_to_disk((i) * chunk, chunk)
52*bf654b37SAndrey Shinkevich    log('')
53*bf654b37SAndrey Shinkevich
54*bf654b37SAndrey Shinkevich
55*bf654b37SAndrey Shinkevichqemu_img_create('-f', iotests.imgfmt, disk, '10M')
56*bf654b37SAndrey Shinkevich
57*bf654b37SAndrey Shinkevichadd_bitmap(1, 0, 6, False)
58*bf654b37SAndrey Shinkevichadd_bitmap(2, 6, 8, True)
59*bf654b37SAndrey Shinkevichdump = ['qcow2.py', disk, 'dump-header']
60*bf654b37SAndrey Shinkevichsubprocess.run(dump)
61