macio: Eliminate macio_init_child_obj()
[qemu/ar7.git] / tests / qemu-iotests / 281
blob0bf973bca69c40891bff768f115aa5eebf2a9774
1 #!/usr/bin/env python3
3 # Test cases for blockdev + IOThread interactions
5 # Copyright (C) 2019 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/>.
21 import os
22 import iotests
23 from iotests import qemu_img
25 image_len = 64 * 1024 * 1024
27 # Test for RHBZ#1782175
28 class TestDirtyBitmapIOThread(iotests.QMPTestCase):
29     drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
30     images = { 'drive0': drive0_img }
32     def setUp(self):
33         for name in self.images:
34             qemu_img('create', '-f', iotests.imgfmt,
35                      self.images[name], str(image_len))
37         self.vm = iotests.VM()
38         self.vm.add_object('iothread,id=iothread0')
40         for name in self.images:
41             self.vm.add_blockdev('driver=file,filename=%s,node-name=file_%s'
42                                  % (self.images[name], name))
43             self.vm.add_blockdev('driver=qcow2,file=file_%s,node-name=%s'
44                                  % (name, name))
46         self.vm.launch()
47         self.vm.qmp('x-blockdev-set-iothread',
48                     node_name='drive0', iothread='iothread0',
49                     force=True)
51     def tearDown(self):
52         self.vm.shutdown()
53         for name in self.images:
54             os.remove(self.images[name])
56     def test_add_dirty_bitmap(self):
57         result = self.vm.qmp(
58             'block-dirty-bitmap-add',
59             node='drive0',
60             name='bitmap1',
61             persistent=True,
62         )
64         self.assert_qmp(result, 'return', {})
67 # Test for RHBZ#1746217 & RHBZ#1773517
68 class TestNBDMirrorIOThread(iotests.QMPTestCase):
69     nbd_sock = os.path.join(iotests.sock_dir, 'nbd.sock')
70     drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
71     mirror_img = os.path.join(iotests.test_dir, 'mirror.img')
72     images = { 'drive0': drive0_img, 'mirror': mirror_img }
74     def setUp(self):
75         for name in self.images:
76             qemu_img('create', '-f', iotests.imgfmt,
77                      self.images[name], str(image_len))
79         self.vm_src = iotests.VM(path_suffix='src')
80         self.vm_src.add_object('iothread,id=iothread0')
81         self.vm_src.add_blockdev('driver=file,filename=%s,node-name=file0'
82                           % (self.drive0_img))
83         self.vm_src.add_blockdev('driver=qcow2,file=file0,node-name=drive0')
84         self.vm_src.launch()
85         self.vm_src.qmp('x-blockdev-set-iothread',
86                         node_name='drive0', iothread='iothread0',
87                         force=True)
89         self.vm_tgt = iotests.VM(path_suffix='tgt')
90         self.vm_tgt.add_object('iothread,id=iothread0')
91         self.vm_tgt.add_blockdev('driver=file,filename=%s,node-name=file0'
92                           % (self.mirror_img))
93         self.vm_tgt.add_blockdev('driver=qcow2,file=file0,node-name=drive0')
94         self.vm_tgt.launch()
95         self.vm_tgt.qmp('x-blockdev-set-iothread',
96                         node_name='drive0', iothread='iothread0',
97                         force=True)
99     def tearDown(self):
100         self.vm_src.shutdown()
101         self.vm_tgt.shutdown()
102         for name in self.images:
103             os.remove(self.images[name])
105     def test_nbd_mirror(self):
106         result = self.vm_tgt.qmp(
107             'nbd-server-start',
108             addr={
109                 'type': 'unix',
110                 'data': { 'path': self.nbd_sock }
111             }
112         )
113         self.assert_qmp(result, 'return', {})
115         result = self.vm_tgt.qmp(
116             'nbd-server-add',
117             device='drive0',
118             writable=True
119         )
120         self.assert_qmp(result, 'return', {})
122         result = self.vm_src.qmp(
123             'drive-mirror',
124             device='drive0',
125             target='nbd+unix:///drive0?socket=' + self.nbd_sock,
126             sync='full',
127             mode='existing',
128             speed=64*1024*1024,
129             job_id='j1'
130         )
131         self.assert_qmp(result, 'return', {})
133         self.vm_src.event_wait(name="BLOCK_JOB_READY")
136 # Test for RHBZ#1779036
137 class TestExternalSnapshotAbort(iotests.QMPTestCase):
138     drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
139     snapshot_img = os.path.join(iotests.test_dir, 'snapshot.img')
140     images = { 'drive0': drive0_img, 'snapshot': snapshot_img }
142     def setUp(self):
143         for name in self.images:
144             qemu_img('create', '-f', iotests.imgfmt,
145                      self.images[name], str(image_len))
147         self.vm = iotests.VM()
148         self.vm.add_object('iothread,id=iothread0')
149         self.vm.add_blockdev('driver=file,filename=%s,node-name=file0'
150                           % (self.drive0_img))
151         self.vm.add_blockdev('driver=qcow2,file=file0,node-name=drive0')
152         self.vm.launch()
153         self.vm.qmp('x-blockdev-set-iothread',
154                     node_name='drive0', iothread='iothread0',
155                     force=True)
157     def tearDown(self):
158         self.vm.shutdown()
159         for name in self.images:
160             os.remove(self.images[name])
162     def test_external_snapshot_abort(self):
163         # Use a two actions transaction with a bogus values on the second
164         # one to trigger an abort of the transaction.
165         result = self.vm.qmp('transaction', actions=[
166             {
167                 'type': 'blockdev-snapshot-sync',
168                 'data': { 'node-name': 'drive0',
169                           'snapshot-file': self.snapshot_img,
170                           'snapshot-node-name': 'snap1',
171                           'mode': 'absolute-paths',
172                           'format': 'qcow2' }
173             },
174             {
175                 'type': 'blockdev-snapshot-sync',
176                 'data': { 'node-name': 'drive0',
177                           'snapshot-file': '/fakesnapshot',
178                           'snapshot-node-name': 'snap2',
179                           'mode': 'absolute-paths',
180                           'format': 'qcow2' }
181             },
182         ])
184         # Crashes on failure, we expect this error.
185         self.assert_qmp(result, 'error/class', 'GenericError')
188 # Test for RHBZ#1782111
189 class TestBlockdevBackupAbort(iotests.QMPTestCase):
190     drive0_img = os.path.join(iotests.test_dir, 'drive0.img')
191     drive1_img = os.path.join(iotests.test_dir, 'drive1.img')
192     snap0_img = os.path.join(iotests.test_dir, 'snap0.img')
193     snap1_img = os.path.join(iotests.test_dir, 'snap1.img')
194     images = { 'drive0': drive0_img,
195                'drive1': drive1_img,
196                'snap0': snap0_img,
197                'snap1': snap1_img }
199     def setUp(self):
200         for name in self.images:
201             qemu_img('create', '-f', iotests.imgfmt,
202                      self.images[name], str(image_len))
204         self.vm = iotests.VM()
205         self.vm.add_object('iothread,id=iothread0')
206         self.vm.add_device('virtio-scsi,iothread=iothread0')
208         for name in self.images:
209             self.vm.add_blockdev('driver=file,filename=%s,node-name=file_%s'
210                                  % (self.images[name], name))
211             self.vm.add_blockdev('driver=qcow2,file=file_%s,node-name=%s'
212                                  % (name, name))
214         self.vm.add_device('scsi-hd,drive=drive0')
215         self.vm.add_device('scsi-hd,drive=drive1')
216         self.vm.launch()
218     def tearDown(self):
219         self.vm.shutdown()
220         for name in self.images:
221             os.remove(self.images[name])
223     def test_blockdev_backup_abort(self):
224         # Use a two actions transaction with a bogus values on the second
225         # one to trigger an abort of the transaction.
226         result = self.vm.qmp('transaction', actions=[
227             {
228                 'type': 'blockdev-backup',
229                 'data': { 'device': 'drive0',
230                           'target': 'snap0',
231                           'sync': 'full',
232                           'job-id': 'j1' }
233             },
234             {
235                 'type': 'blockdev-backup',
236                 'data': { 'device': 'drive1',
237                           'target': 'snap1',
238                           'sync': 'full' }
239             },
240         ])
242         # Hangs on failure, we expect this error.
243         self.assert_qmp(result, 'error/class', 'GenericError')
245 if __name__ == '__main__':
246     iotests.main(supported_fmts=['qcow2'],
247                  supported_protocols=['file'])