s390x: Move diagnose 308 subcodes and rcs into ipl.h
[qemu/ar7.git] / tests / qemu-iotests / 260
blob30c0de380dc7f097841e9d8b31625592ac270a7b
1 #!/usr/bin/env python3
3 # Tests for temporary external snapshot when we have bitmaps.
5 # Copyright (c) 2019 Virtuozzo International GmbH. All rights reserved.
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.
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.
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/>.
21 import iotests
22 from iotests import qemu_img_create, file_path, log, filter_qmp_event
24 iotests.verify_image_format(supported_fmts=['qcow2'])
26 base, top = file_path('base', 'top')
27 size = 64 * 1024 * 3
30 def print_bitmap(msg, vm):
31     result = vm.qmp('query-block')['return'][0]
32     if 'dirty-bitmaps' in result:
33         bitmap = result['dirty-bitmaps'][0]
34         log('{}: name={} dirty-clusters={}'.format(msg, bitmap['name'],
35             bitmap['count'] // 64 // 1024))
36     else:
37         log(msg + ': not found')
40 def test(persistent, restart):
41     assert persistent or not restart
42     log("\nTestcase {}persistent {} restart\n".format(
43             '' if persistent else 'non-', 'with' if restart else 'without'))
45     qemu_img_create('-f', iotests.imgfmt, base, str(size))
47     vm = iotests.VM().add_drive(base)
48     vm.launch()
50     vm.qmp_log('block-dirty-bitmap-add', node='drive0', name='bitmap0',
51                persistent=persistent)
52     vm.hmp_qemu_io('drive0', 'write 0 64K')
53     print_bitmap('initial bitmap', vm)
55     vm.qmp_log('blockdev-snapshot-sync', device='drive0', snapshot_file=top,
56                format=iotests.imgfmt, filters=[iotests.filter_qmp_testfiles])
57     vm.hmp_qemu_io('drive0', 'write 64K 512')
58     print_bitmap('check that no bitmaps are in snapshot', vm)
60     if restart:
61         log("... Restart ...")
62         vm.shutdown()
63         vm = iotests.VM().add_drive(top)
64         vm.launch()
66     vm.qmp_log('block-commit', device='drive0', top=top,
67                filters=[iotests.filter_qmp_testfiles])
68     ev = vm.events_wait((('BLOCK_JOB_READY', None),
69                          ('BLOCK_JOB_COMPLETED', None)))
70     log(filter_qmp_event(ev))
71     if (ev['event'] == 'BLOCK_JOB_COMPLETED'):
72         vm.shutdown()
73         log(vm.get_log())
74         exit()
76     vm.qmp_log('block-job-complete', device='drive0')
77     ev = vm.event_wait('BLOCK_JOB_COMPLETED')
78     log(filter_qmp_event(ev))
79     print_bitmap('check bitmap after commit', vm)
81     vm.hmp_qemu_io('drive0', 'write 128K 64K')
82     print_bitmap('check updated bitmap', vm)
84     vm.shutdown()
87 test(persistent=False, restart=False)
88 test(persistent=True, restart=False)
89 test(persistent=True, restart=True)