4 # Test mirror with unmap
6 # Copyright (C) 2015 Red Hat, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 from iotests import qemu_img, qemu_io
27 test_img = os.path.join(iotests.test_dir, 'test.img')
28 target_img = os.path.join(iotests.test_dir, 'target.img')
30 class TestSingleDrive(iotests.QMPTestCase):
31 image_len = 2 * 1024 * 1024 # MB
34 # Write data to the image so we can compare later
35 qemu_img('create', '-f', iotests.imgfmt, test_img, str(TestSingleDrive.image_len))
36 qemu_io('-f', iotests.imgfmt, '-c', 'write -P0x5d 0 2M', test_img)
38 self.vm = iotests.VM().add_drive(test_img, 'discard=unmap')
49 def test_mirror_discard(self):
50 result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
52 self.assert_qmp(result, 'return', {})
53 self.vm.hmp_qemu_io('drive0', 'discard 0 64k')
54 self.complete_and_wait('drive0')
56 self.assertTrue(iotests.compare_images(test_img, target_img),
57 'target image does not match source after mirroring')
59 if __name__ == '__main__':
60 iotests.main(supported_fmts=['raw', 'qcow2'],
61 supported_protocols=['file'])