1903cb1bfSPhilippe Mathieu-Daudé#!/usr/bin/env python3 29dd003a9SVladimir Sementsov-Ogievskiy# group: rw quick 3c6150917SFam Zheng# 4c6150917SFam Zheng# Test mirror with unmap 5c6150917SFam Zheng# 6c6150917SFam Zheng# Copyright (C) 2015 Red Hat, Inc. 7c6150917SFam Zheng# 8c6150917SFam Zheng# This program is free software; you can redistribute it and/or modify 9c6150917SFam Zheng# it under the terms of the GNU General Public License as published by 10c6150917SFam Zheng# the Free Software Foundation; either version 2 of the License, or 11c6150917SFam Zheng# (at your option) any later version. 12c6150917SFam Zheng# 13c6150917SFam Zheng# This program is distributed in the hope that it will be useful, 14c6150917SFam Zheng# but WITHOUT ANY WARRANTY; without even the implied warranty of 15c6150917SFam Zheng# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16c6150917SFam Zheng# GNU General Public License for more details. 17c6150917SFam Zheng# 18c6150917SFam Zheng# You should have received a copy of the GNU General Public License 19c6150917SFam Zheng# along with this program. If not, see <http://www.gnu.org/licenses/>. 20c6150917SFam Zheng# 21c6150917SFam Zheng 22c6150917SFam Zhengimport time 23c6150917SFam Zhengimport os 24c6150917SFam Zhengimport iotests 25c6150917SFam Zhengfrom iotests import qemu_img, qemu_io 26c6150917SFam Zheng 27c6150917SFam Zhengtest_img = os.path.join(iotests.test_dir, 'test.img') 28c6150917SFam Zhengtarget_img = os.path.join(iotests.test_dir, 'target.img') 29c6150917SFam Zheng 30c6150917SFam Zhengclass TestSingleDrive(iotests.QMPTestCase): 31c6150917SFam Zheng image_len = 2 * 1024 * 1024 # MB 32c6150917SFam Zheng 33c6150917SFam Zheng def setUp(self): 34c6150917SFam Zheng # Write data to the image so we can compare later 35c6150917SFam Zheng qemu_img('create', '-f', iotests.imgfmt, test_img, str(TestSingleDrive.image_len)) 36c6150917SFam Zheng qemu_io('-f', iotests.imgfmt, '-c', 'write -P0x5d 0 2M', test_img) 37c6150917SFam Zheng 38c6150917SFam Zheng self.vm = iotests.VM().add_drive(test_img, 'discard=unmap') 39c6150917SFam Zheng self.vm.launch() 40c6150917SFam Zheng 41c6150917SFam Zheng def tearDown(self): 42c6150917SFam Zheng self.vm.shutdown() 43c6150917SFam Zheng os.remove(test_img) 44c6150917SFam Zheng try: 45c6150917SFam Zheng os.remove(target_img) 46c6150917SFam Zheng except OSError: 47c6150917SFam Zheng pass 48c6150917SFam Zheng 49c6150917SFam Zheng def test_mirror_discard(self): 50*b6aed193SVladimir Sementsov-Ogievskiy self.vm.cmd('drive-mirror', device='drive0', sync='full', 51c6150917SFam Zheng target=target_img) 52c6150917SFam Zheng self.vm.hmp_qemu_io('drive0', 'discard 0 64k') 53c6150917SFam Zheng self.complete_and_wait('drive0') 54c6150917SFam Zheng self.vm.shutdown() 55c6150917SFam Zheng self.assertTrue(iotests.compare_images(test_img, target_img), 56c6150917SFam Zheng 'target image does not match source after mirroring') 57c6150917SFam Zheng 58c6150917SFam Zhengif __name__ == '__main__': 59103cbc77SMax Reitz iotests.main(supported_fmts=['raw', 'qcow2'], 60103cbc77SMax Reitz supported_protocols=['file']) 61