osdep: protect qemu/osdep.h with extern "C"
[qemu/ar7.git] / tests / qemu-iotests / 310
blob9d9c928c4b3fcb08f6e0743b8366053e92fbe0f6
1 #!/usr/bin/env python3
2 # group: rw quick
4 # Copy-on-read tests using a COR filter with a bottom node
6 # Copyright (C) 2018 Red Hat, Inc.
7 # Copyright (c) 2020 Virtuozzo International 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 iotests
24 from iotests import log, qemu_img, qemu_io_silent
26 # Need backing file support
27 iotests.script_initialize(supported_fmts=['qcow2'],
28                           supported_platforms=['linux'])
30 log('')
31 log('=== Copy-on-read across nodes ===')
32 log('')
34 # This test is similar to the 216 one by Max Reitz <mreitz@redhat.com>
35 # The difference is that this test case involves a bottom node to the
36 # COR filter driver.
38 with iotests.FilePath('base.img') as base_img_path, \
39      iotests.FilePath('mid.img') as mid_img_path, \
40      iotests.FilePath('top.img') as top_img_path, \
41      iotests.VM() as vm:
43     log('--- Setting up images ---')
44     log('')
46     assert qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') == 0
47     assert qemu_io_silent(base_img_path, '-c', 'write -P 1 0M 1M') == 0
48     assert qemu_io_silent(base_img_path, '-c', 'write -P 1 3M 1M') == 0
49     assert qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path,
50                     '-F', iotests.imgfmt, mid_img_path) == 0
51     assert qemu_io_silent(mid_img_path,  '-c', 'write -P 3 2M 1M') == 0
52     assert qemu_io_silent(mid_img_path,  '-c', 'write -P 3 4M 1M') == 0
53     assert qemu_img('create', '-f', iotests.imgfmt, '-b', mid_img_path,
54                     '-F', iotests.imgfmt, top_img_path) == 0
55     assert qemu_io_silent(top_img_path,  '-c', 'write -P 2 1M 1M') == 0
57 #      0 1 2 3 4
58 # top    2
59 # mid      3   3
60 # base 1     1
62     log('Done')
64     log('')
65     log('--- Doing COR ---')
66     log('')
68     vm.launch()
70     log(vm.qmp('blockdev-add',
71                node_name='node0',
72                driver='copy-on-read',
73                bottom='node2',
74                file={
75                    'driver': iotests.imgfmt,
76                    'file': {
77                        'driver': 'file',
78                        'filename': top_img_path
79                    },
80                    'backing': {
81                        'node-name': 'node2',
82                        'driver': iotests.imgfmt,
83                        'file': {
84                            'driver': 'file',
85                            'filename': mid_img_path
86                        },
87                        'backing': {
88                            'driver': iotests.imgfmt,
89                            'file': {
90                                'driver': 'file',
91                                'filename': base_img_path
92                            }
93                        },
94                    }
95                }))
97     # Trigger COR
98     log(vm.qmp('human-monitor-command',
99                command_line='qemu-io node0 "read 0 5M"'))
101     vm.shutdown()
103     log('')
104     log('--- Checking COR result ---')
105     log('')
107     # Detach backing to check that we can read the data from the top level now
108     assert qemu_img('rebase', '-u', '-b', '', '-f', iotests.imgfmt,
109                     top_img_path) == 0
111     assert qemu_io_silent(top_img_path,  '-c', 'read -P 0 0 1M') == 0
112     assert qemu_io_silent(top_img_path,  '-c', 'read -P 2 1M 1M') == 0
113     assert qemu_io_silent(top_img_path,  '-c', 'read -P 3 2M 1M') == 0
114     assert qemu_io_silent(top_img_path,  '-c', 'read -P 0 3M 1M') == 0
115     assert qemu_io_silent(top_img_path,  '-c', 'read -P 3 4M 1M') == 0
117     log('Done')