xref: /openbmc/qemu/tests/qemu-iotests/304 (revision 8e49197c)
1#!/usr/bin/env python3
2#
3# Tests dirty-bitmap backup with unaligned bitmap granularity
4#
5# Copyright (c) 2020 Proxmox Server Solutions
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19#
20# owner=s.reiter@proxmox.com
21
22import iotests
23from iotests import qemu_img_create, qemu_img_log, file_path
24
25iotests.script_initialize(supported_fmts=['qcow2'],
26                          supported_protocols=['file'])
27
28test_img = file_path('test.qcow2')
29target_img = file_path('target.qcow2')
30
31# unaligned by one byte
32image_len = 4097
33bitmap_granularity = 4096
34
35qemu_img_create('-f', iotests.imgfmt, test_img, str(image_len))
36
37# create VM
38vm = iotests.VM().add_drive(test_img)
39vm.launch()
40
41# write to the entire image
42vm.hmp_qemu_io('drive0', 'write -P0x16 0 4096');
43vm.hmp_qemu_io('drive0', 'write -P0x17 4096 1');
44
45# do backup and wait for completion
46vm.qmp('drive-backup', **{
47    'device': 'drive0',
48    'sync': 'full',
49    'target': target_img
50})
51
52event = vm.event_wait(name='BLOCK_JOB_COMPLETED',
53                      match={'data': {'device': 'drive0'}},
54                      timeout=5.0)
55
56# shutdown to sync images
57vm.shutdown()
58
59# backup succeeded, check if image is correct
60qemu_img_log('compare', test_img, target_img)
61