hw/arm/sbsa-ref: Remove unnecessary check for secure_sysmem == NULL
[qemu/ar7.git] / tests / qemu-iotests / 216
blob3c0ae54b4450b7ce684c45f64768f6d3c8837ec5
1 #!/usr/bin/env python
3 # Copy-on-read tests using a COR filter node
5 # Copyright (C) 2018 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 # Creator/Owner: Max Reitz <mreitz@redhat.com>
22 import iotests
23 from iotests import log, qemu_img, qemu_io_silent
25 # Need backing file support
26 iotests.verify_image_format(supported_fmts=['qcow2', 'qcow', 'qed', 'vmdk'])
27 iotests.verify_platform(['linux'])
29 log('')
30 log('=== Copy-on-read across nodes ===')
31 log('')
33 # The old copy-on-read mechanism without a filter node cannot request
34 # WRITE_UNCHANGED permissions for its child. Therefore it just tries
35 # to sneak its write by the usual permission system and holds its
36 # fingers crossed. However, that sneaking does not work so well when
37 # there is a filter node in the way: That will receive the write
38 # request and re-issue a new one to its child, which this time is a
39 # proper write request that will make the permission system cough --
40 # unless there is someone at the top (like a guest device) that has
41 # requested write permissions.
43 # A COR filter node, however, can request the proper permissions for
44 # its child and therefore is not hit by this issue.
46 with iotests.FilePath('base.img') as base_img_path, \
47 iotests.FilePath('top.img') as top_img_path, \
48 iotests.VM() as vm:
50 log('--- Setting up images ---')
51 log('')
53 assert qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') == 0
54 assert qemu_io_silent(base_img_path, '-c', 'write -P 1 0M 1M') == 0
55 assert qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path,
56 top_img_path) == 0
57 assert qemu_io_silent(top_img_path, '-c', 'write -P 2 1M 1M') == 0
59 log('Done')
61 log('')
62 log('--- Doing COR ---')
63 log('')
65 # Compare with e.g. the following:
66 # vm.add_drive_raw('if=none,node-name=node0,copy-on-read=on,driver=raw,' \
67 # 'file.driver=%s,file.file.filename=%s' %
68 # (iotests.imgfmt, top_img_path))
69 # (Remove the blockdev-add instead.)
70 # ((Not tested here because it hits an assertion in the permission
71 # system.))
73 vm.launch()
75 log(vm.qmp('blockdev-add',
76 node_name='node0',
77 driver='copy-on-read',
78 file={
79 'driver': 'raw',
80 'file': {
81 'driver': 'copy-on-read',
82 'file': {
83 'driver': 'raw',
84 'file': {
85 'driver': iotests.imgfmt,
86 'file': {
87 'driver': 'file',
88 'filename': top_img_path
90 'backing': {
91 'driver': iotests.imgfmt,
92 'file': {
93 'driver': 'file',
94 'filename': base_img_path
102 # Trigger COR
103 log(vm.qmp('human-monitor-command',
104 command_line='qemu-io node0 "read 0 64M"'))
106 vm.shutdown()
108 log('')
109 log('--- Checking COR result ---')
110 log('')
112 assert qemu_io_silent(base_img_path, '-c', 'discard 0 64M') == 0
113 assert qemu_io_silent(top_img_path, '-c', 'read -P 1 0M 1M') == 0
114 assert qemu_io_silent(top_img_path, '-c', 'read -P 2 1M 1M') == 0
116 log('Done')