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