xref: /openbmc/qemu/tests/qemu-iotests/304 (revision 0e324626)
11f3765b6SStefan Reiter#!/usr/bin/env python3
2*9dd003a9SVladimir Sementsov-Ogievskiy# group: rw quick
31f3765b6SStefan Reiter#
41f3765b6SStefan Reiter# Tests dirty-bitmap backup with unaligned bitmap granularity
51f3765b6SStefan Reiter#
61f3765b6SStefan Reiter# Copyright (c) 2020 Proxmox Server Solutions
71f3765b6SStefan Reiter#
81f3765b6SStefan Reiter# This program is free software; you can redistribute it and/or modify
91f3765b6SStefan Reiter# it under the terms of the GNU General Public License as published by
101f3765b6SStefan Reiter# the Free Software Foundation; either version 2 of the License, or
111f3765b6SStefan Reiter# (at your option) any later version.
121f3765b6SStefan Reiter#
131f3765b6SStefan Reiter# This program is distributed in the hope that it will be useful,
141f3765b6SStefan Reiter# but WITHOUT ANY WARRANTY; without even the implied warranty of
151f3765b6SStefan Reiter# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
161f3765b6SStefan Reiter# GNU General Public License for more details.
171f3765b6SStefan Reiter#
181f3765b6SStefan Reiter# You should have received a copy of the GNU General Public License
191f3765b6SStefan Reiter# along with this program.  If not, see <http://www.gnu.org/licenses/>.
201f3765b6SStefan Reiter#
211f3765b6SStefan Reiter# owner=s.reiter@proxmox.com
221f3765b6SStefan Reiter
231f3765b6SStefan Reiterimport iotests
241f3765b6SStefan Reiterfrom iotests import qemu_img_create, qemu_img_log, file_path
251f3765b6SStefan Reiter
261f3765b6SStefan Reiteriotests.script_initialize(supported_fmts=['qcow2'],
271f3765b6SStefan Reiter                          supported_protocols=['file'])
281f3765b6SStefan Reiter
291f3765b6SStefan Reitertest_img = file_path('test.qcow2')
301f3765b6SStefan Reitertarget_img = file_path('target.qcow2')
311f3765b6SStefan Reiter
321f3765b6SStefan Reiter# unaligned by one byte
331f3765b6SStefan Reiterimage_len = 4097
341f3765b6SStefan Reiterbitmap_granularity = 4096
351f3765b6SStefan Reiter
361f3765b6SStefan Reiterqemu_img_create('-f', iotests.imgfmt, test_img, str(image_len))
371f3765b6SStefan Reiter
381f3765b6SStefan Reiter# create VM
391f3765b6SStefan Reitervm = iotests.VM().add_drive(test_img)
401f3765b6SStefan Reitervm.launch()
411f3765b6SStefan Reiter
421f3765b6SStefan Reiter# write to the entire image
431f3765b6SStefan Reitervm.hmp_qemu_io('drive0', 'write -P0x16 0 4096');
441f3765b6SStefan Reitervm.hmp_qemu_io('drive0', 'write -P0x17 4096 1');
451f3765b6SStefan Reiter
461f3765b6SStefan Reiter# do backup and wait for completion
471f3765b6SStefan Reitervm.qmp('drive-backup', **{
481f3765b6SStefan Reiter    'device': 'drive0',
491f3765b6SStefan Reiter    'sync': 'full',
501f3765b6SStefan Reiter    'target': target_img
511f3765b6SStefan Reiter})
521f3765b6SStefan Reiter
531f3765b6SStefan Reiterevent = vm.event_wait(name='BLOCK_JOB_COMPLETED',
541f3765b6SStefan Reiter                      match={'data': {'device': 'drive0'}},
551f3765b6SStefan Reiter                      timeout=5.0)
561f3765b6SStefan Reiter
571f3765b6SStefan Reiter# shutdown to sync images
581f3765b6SStefan Reitervm.shutdown()
591f3765b6SStefan Reiter
601f3765b6SStefan Reiter# backup succeeded, check if image is correct
611f3765b6SStefan Reiterqemu_img_log('compare', test_img, target_img)
62