hmp: Fail gracefully if chardev is already in use
[qemu/ar7.git] / tests / qemu-iotests / 246
blob59a216a839e9d0adebdd8d4d3d6ccb07090655b1
1 #!/usr/bin/env python3
3 # Test persistent bitmap resizing.
5 # Copyright (c) 2019 John Snow for Red Hat, Inc.
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/>.
20 # owner=jsnow@redhat.com
22 import iotests
23 from iotests import log
25 iotests.verify_image_format(supported_fmts=['qcow2'])
26 size = 64 * 1024 * 1024 * 1024
27 gran_small = 32 * 1024
28 gran_large = 128 * 1024
30 def query_bitmaps(vm):
31     res = vm.qmp("query-block")
32     return { "bitmaps": { device['device']: device.get('dirty-bitmaps', []) for
33                           device in res['return'] } }
35 with iotests.FilePath('img') as img_path, \
36      iotests.VM() as vm:
38     log('--- Preparing image & VM ---\n')
39     iotests.qemu_img_create('-f', iotests.imgfmt, img_path, str(size))
40     vm.add_drive(img_path)
43     log('--- 1st Boot (Establish Baseline Image) ---\n')
44     vm.launch()
46     log('\n--- Adding bitmaps Small, Medium, Large, and Transient ---\n')
47     vm.qmp_log("block-dirty-bitmap-add", node="drive0",
48                name="Small", granularity=gran_small, persistent=True)
49     vm.qmp_log("block-dirty-bitmap-add", node="drive0",
50                name="Medium", persistent=True)
51     vm.qmp_log("block-dirty-bitmap-add", node="drive0",
52                name="Large", granularity=gran_large, persistent=True)
53     vm.qmp_log("block-dirty-bitmap-add", node="drive0",
54                name="Transient", persistent=False)
56     log('--- Forcing flush of bitmaps to disk ---\n')
57     log(query_bitmaps(vm), indent=2)
58     vm.shutdown()
61     log('--- 2nd Boot (Grow Image) ---\n')
62     vm.launch()
63     log(query_bitmaps(vm), indent=2)
65     log('--- Adding new bitmap, growing image, and adding 2nd new bitmap ---')
66     vm.qmp_log("block-dirty-bitmap-add", node="drive0",
67                name="New", persistent=True)
68     vm.qmp_log("human-monitor-command",
69                command_line="block_resize drive0 70G")
70     vm.qmp_log("block-dirty-bitmap-add", node="drive0",
71                name="Newtwo", persistent=True)
72     log(query_bitmaps(vm), indent=2)
74     log('--- Forcing flush of bitmaps to disk ---\n')
75     vm.shutdown()
78     log('--- 3rd Boot (Shrink Image) ---\n')
79     vm.launch()
80     log(query_bitmaps(vm), indent=2)
82     log('--- Adding "NewB" bitmap, removing "New" bitmap ---')
83     vm.qmp_log("block-dirty-bitmap-add", node="drive0",
84                name="NewB", persistent=True)
85     vm.qmp_log("block-dirty-bitmap-remove", node="drive0",
86                name="New")
88     log('--- Truncating image ---\n')
89     vm.qmp_log("human-monitor-command",
90                command_line="block_resize drive0 50G")
92     log('--- Adding "NewC" bitmap, removing "NewTwo" bitmap ---')
93     vm.qmp_log("block-dirty-bitmap-add", node="drive0",
94                name="NewC", persistent=True)
95     vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="Newtwo")
97     log('--- Forcing flush of bitmaps to disk ---\n')
98     vm.shutdown()
101     log('--- 4th Boot (Verification and Cleanup) ---\n')
102     vm.launch()
103     log(query_bitmaps(vm), indent=2)
105     log('--- Removing all Bitmaps ---\n')
106     vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="Small")
107     vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="Medium")
108     vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="Large")
109     vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="NewB")
110     vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="NewC")
111     log(query_bitmaps(vm), indent=2)
113     log('\n--- Done ---')
114     vm.shutdown()