Merge tag 'qemu-macppc-20230206' of https://github.com/mcayland/qemu into staging
[qemu.git] / tests / qemu-iotests / 240
blob9b281e1dc036c4248c991163a9352dac450b97d9
1 #!/usr/bin/env python3
2 # group: quick
4 # Test hot plugging and unplugging with iothreads
6 # Copyright (C) 2019 Igalia, S.L.
7 # Author: Alberto Garcia <berto@igalia.com>
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/>.
22 import iotests
23 import os
25 nbd_sock = iotests.file_path('nbd.sock', base_dir=iotests.sock_dir)
27 class TestCase(iotests.QMPTestCase):
28     test_driver = "null-co"
30     def required_drivers(self):
31         return [self.test_driver]
33     @iotests.skip_if_unsupported(required_drivers)
34     def setUp(self):
35         self.vm = iotests.VM()
36         self.vm.launch()
38     def tearDown(self):
39         self.vm.shutdown()
41     def test1(self):
42         iotests.log('==Unplug a SCSI disk and then plug it again==')
43         self.vm.qmp_log('blockdev-add', driver='null-co', read_zeroes=True, node_name='hd0')
44         self.vm.qmp_log('object-add', qom_type='iothread', id="iothread0")
45         self.vm.qmp_log('device_add', id='scsi0', driver='virtio-scsi', iothread='iothread0', filters=[iotests.filter_qmp_virtio_scsi])
46         self.vm.qmp_log('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0')
47         self.vm.qmp_log('device_del', id='scsi-hd0')
48         self.vm.event_wait('DEVICE_DELETED')
49         self.vm.qmp_log('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0')
50         self.vm.qmp_log('device_del', id='scsi-hd0')
51         self.vm.event_wait('DEVICE_DELETED')
52         self.vm.qmp_log('blockdev-del', node_name='hd0')
54     def test2(self):
55         iotests.log('==Attach two SCSI disks using the same block device and the same iothread==')
56         self.vm.qmp_log('blockdev-add', driver='null-co', read_zeroes=True, node_name='hd0', read_only=True)
57         self.vm.qmp_log('object-add', qom_type='iothread', id="iothread0")
58         self.vm.qmp_log('device_add', id='scsi0', driver='virtio-scsi', iothread='iothread0', filters=[iotests.filter_qmp_virtio_scsi])
60         self.vm.qmp_log('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0')
61         self.vm.qmp_log('device_add', id='scsi-hd1', driver='scsi-hd', drive='hd0')
62         self.vm.qmp_log('device_del', id='scsi-hd0')
63         self.vm.event_wait('DEVICE_DELETED')
64         self.vm.qmp_log('device_del', id='scsi-hd1')
65         self.vm.event_wait('DEVICE_DELETED')
66         self.vm.qmp_log('blockdev-del', node_name='hd0')
68     def test3(self):
69         iotests.log('==Attach two SCSI disks using the same block device but different iothreads==')
71         self.vm.qmp_log('blockdev-add', driver='null-co', read_zeroes=True, node_name='hd0', read_only=True)
73         self.vm.qmp_log('object-add', qom_type='iothread', id="iothread0")
74         self.vm.qmp_log('object-add', qom_type='iothread', id="iothread1")
76         self.vm.qmp_log('device_add', id='scsi0', driver='virtio-scsi', iothread='iothread0', filters=[iotests.filter_qmp_virtio_scsi])
77         self.vm.qmp_log('device_add', id='scsi1', driver='virtio-scsi', iothread='iothread1', filters=[iotests.filter_qmp_virtio_scsi])
79         self.vm.qmp_log('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0', bus="scsi0.0")
80         self.vm.qmp_log('device_add', id='scsi-hd1', driver='scsi-hd', drive='hd0', bus="scsi1.0")
82         self.vm.qmp_log('device_del', id='scsi-hd0')
83         self.vm.event_wait('DEVICE_DELETED')
84         self.vm.qmp_log('device_add', id='scsi-hd1', driver='scsi-hd', drive='hd0', bus="scsi1.0")
86         self.vm.qmp_log('device_del', id='scsi-hd1')
87         self.vm.event_wait('DEVICE_DELETED')
88         self.vm.qmp_log('blockdev-del', node_name='hd0')
90     def test4(self):
91         iotests.log('==Attach a SCSI disks using the same block device as a NBD server==')
93         self.vm.qmp_log('blockdev-add', driver='null-co', read_zeroes=True, node_name='hd0', read_only=True)
95         self.vm.qmp_log('nbd-server-start',
96                         filters=[iotests.filter_qmp_testfiles],
97                         addr={'type':'unix', 'data':{'path':nbd_sock}})
99         self.vm.qmp_log('nbd-server-add', device='hd0')
101         self.vm.qmp_log('object-add', qom_type='iothread', id="iothread0")
102         self.vm.qmp_log('device_add', id='scsi0', driver='virtio-scsi', iothread='iothread0', filters=[iotests.filter_qmp_virtio_scsi])
103         self.vm.qmp_log('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0')
105 if __name__ == '__main__':
106     iotests.activate_logging()
107     iotests.main()