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