3 # Tests for drive-backup
5 # Copyright (C) 2013 Red Hat, Inc.
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 from iotests
import qemu_img
, qemu_io
, create_image
28 backing_img
= os
.path
.join(iotests
.test_dir
, 'backing.img')
29 test_img
= os
.path
.join(iotests
.test_dir
, 'test.img')
30 target_img
= os
.path
.join(iotests
.test_dir
, 'target.img')
32 class TestSyncModesNoneAndTop(iotests
.QMPTestCase
):
33 image_len
= 64 * 1024 * 1024 # MB
36 create_image(backing_img
, TestSyncModesNoneAndTop
.image_len
)
37 qemu_img('create', '-f', iotests
.imgfmt
, '-o', 'backing_file=%s' % backing_img
, test_img
)
38 qemu_io('-c', 'write -P0x41 0 512', test_img
)
39 qemu_io('-c', 'write -P0xd5 1M 32k', test_img
)
40 qemu_io('-c', 'write -P0xdc 32M 124k', test_img
)
41 qemu_io('-c', 'write -P0xdc 67043328 64k', test_img
)
42 self
.vm
= iotests
.VM().add_drive(test_img
)
48 os
.remove(backing_img
)
54 def test_complete_top(self
):
55 self
.assert_no_active_block_jobs()
56 result
= self
.vm
.qmp('drive-backup', device
='drive0', sync
='top',
57 format
=iotests
.imgfmt
, target
=target_img
)
58 self
.assert_qmp(result
, 'return', {})
60 self
.wait_until_completed(check_offset
=False)
62 self
.assert_no_active_block_jobs()
64 self
.assertTrue(iotests
.compare_images(test_img
, target_img
),
65 'target image does not match source after backup')
67 def test_cancel_sync_none(self
):
68 self
.assert_no_active_block_jobs()
70 result
= self
.vm
.qmp('drive-backup', device
='drive0',
71 sync
='none', target
=target_img
)
72 self
.assert_qmp(result
, 'return', {})
74 self
.vm
.hmp_qemu_io('drive0', 'write -P0x5e 0 512')
75 self
.vm
.hmp_qemu_io('drive0', 'aio_flush')
76 # Verify that the original contents exist in the target image.
78 event
= self
.cancel_and_wait()
79 self
.assert_qmp(event
, 'data/type', 'backup')
83 self
.assertEqual(-1, qemu_io('-c', 'read -P0x41 0 512', target_img
).find("verification failed"))
86 if __name__
== '__main__':
87 iotests
.main(supported_fmts
=['qcow2', 'qed'])