Merge tag 'v9.0.0-rc3'
[qemu/ar7.git] / tests / qemu-iotests / tests / stream-unaligned-prefetch
blob546db1d36980fc9fd53cc02325e04f0b4ee30cf6
1 #!/usr/bin/env python3
2 # group: rw quick
4 # Test what happens when a stream job does an unaligned prefetch read
5 # which requires padding while having a NULL qiov.
7 # Copyright (C) Proxmox Server Solutions GmbH
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/>.
23 import os
24 import iotests
25 from iotests import imgfmt, qemu_img_create, qemu_io, QMPTestCase
27 image_size = 1 * 1024 * 1024
28 cluster_size = 64 * 1024
29 base = os.path.join(iotests.test_dir, 'base.img')
30 top = os.path.join(iotests.test_dir, 'top.img')
32 class TestStreamUnalignedPrefetch(QMPTestCase):
33     def setUp(self) -> None:
34         """
35         Create two images:
36         - base image {base} with {cluster_size // 2} bytes allocated
37         - top image {top} without any data allocated and coarser
38           cluster size
40         Attach a compress filter for the top image, because that
41         requires that the request alignment is the top image's cluster
42         size.
43         """
44         qemu_img_create('-f', imgfmt,
45                         '-o', 'cluster_size={}'.format(cluster_size // 2),
46                         base, str(image_size))
47         qemu_io('-c', f'write 0 {cluster_size // 2}', base)
48         qemu_img_create('-f', imgfmt,
49                         '-o', 'cluster_size={}'.format(cluster_size),
50                         top, str(image_size))
52         self.vm = iotests.VM()
53         self.vm.add_blockdev(self.vm.qmp_to_opts({
54             'driver': imgfmt,
55             'node-name': 'base',
56             'file': {
57                 'driver': 'file',
58                 'filename': base
59             }
60         }))
61         self.vm.add_blockdev(self.vm.qmp_to_opts({
62             'driver': 'compress',
63             'node-name': 'compress-top',
64             'file': {
65                 'driver': imgfmt,
66                 'node-name': 'top',
67                 'file': {
68                     'driver': 'file',
69                     'filename': top
70                 },
71                 'backing': 'base'
72             }
73         }))
74         self.vm.launch()
76     def tearDown(self) -> None:
77         self.vm.shutdown()
78         os.remove(top)
79         os.remove(base)
81     def test_stream_unaligned_prefetch(self) -> None:
82         self.vm.cmd('block-stream', job_id='stream', device='compress-top')
85 if __name__ == '__main__':
86     iotests.main(supported_fmts=['qcow2'], supported_protocols=['file'])