1*903cb1bfSPhilippe Mathieu-Daudé#!/usr/bin/env python3 28ca92f3cSFam Zheng# 38ca92f3cSFam Zheng# Tests for drive-mirror with source size unaligned to granularity 48ca92f3cSFam Zheng# 58ca92f3cSFam Zheng# Copyright (C) 2016 Red Hat, Inc. 68ca92f3cSFam Zheng# 78ca92f3cSFam Zheng# This program is free software; you can redistribute it and/or modify 88ca92f3cSFam Zheng# it under the terms of the GNU General Public License as published by 98ca92f3cSFam Zheng# the Free Software Foundation; either version 2 of the License, or 108ca92f3cSFam Zheng# (at your option) any later version. 118ca92f3cSFam Zheng# 128ca92f3cSFam Zheng# This program is distributed in the hope that it will be useful, 138ca92f3cSFam Zheng# but WITHOUT ANY WARRANTY; without even the implied warranty of 148ca92f3cSFam Zheng# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 158ca92f3cSFam Zheng# GNU General Public License for more details. 168ca92f3cSFam Zheng# 178ca92f3cSFam Zheng# You should have received a copy of the GNU General Public License 188ca92f3cSFam Zheng# along with this program. If not, see <http://www.gnu.org/licenses/>. 198ca92f3cSFam Zheng# 208ca92f3cSFam Zheng 218ca92f3cSFam Zhengimport os 228ca92f3cSFam Zhengimport iotests 238ca92f3cSFam Zhengfrom iotests import qemu_img 248ca92f3cSFam Zheng 258ca92f3cSFam Zhengtest_img = os.path.join(iotests.test_dir, 'test.img') 268ca92f3cSFam Zhengtarget_img = os.path.join(iotests.test_dir, 'target.img') 278ca92f3cSFam Zheng 288ca92f3cSFam Zhengclass TestUnaligned(iotests.QMPTestCase): 298ca92f3cSFam Zheng def setUp(self): 308ca92f3cSFam Zheng qemu_img('create', '-f', iotests.imgfmt, test_img, '512') 318ca92f3cSFam Zheng self.vm = iotests.VM().add_drive(test_img) 328ca92f3cSFam Zheng self.vm.launch() 338ca92f3cSFam Zheng 348ca92f3cSFam Zheng def tearDown(self): 358ca92f3cSFam Zheng self.vm.shutdown() 368ca92f3cSFam Zheng os.remove(test_img) 378ca92f3cSFam Zheng try: 388ca92f3cSFam Zheng os.remove(target_img) 398ca92f3cSFam Zheng except OSError: 408ca92f3cSFam Zheng pass 418ca92f3cSFam Zheng 428ca92f3cSFam Zheng def test_unaligned(self): 438ca92f3cSFam Zheng result = self.vm.qmp('drive-mirror', device='drive0', sync='full', 448ca92f3cSFam Zheng granularity=65536, target=target_img) 458ca92f3cSFam Zheng self.complete_and_wait() 468ca92f3cSFam Zheng self.vm.shutdown() 478ca92f3cSFam Zheng self.assertEqual(iotests.image_size(test_img), iotests.image_size(target_img), 488ca92f3cSFam Zheng "Target size doesn't match source when granularity when unaligend") 498ca92f3cSFam Zheng 508ca92f3cSFam Zheng def test_unaligned_with_update(self): 518ca92f3cSFam Zheng result = self.vm.qmp('drive-mirror', device='drive0', sync='full', 528ca92f3cSFam Zheng granularity=65536, target=target_img) 538ca92f3cSFam Zheng self.wait_ready() 548ca92f3cSFam Zheng self.vm.hmp_qemu_io('drive0', 'write 0 512') 558ca92f3cSFam Zheng self.complete_and_wait(wait_ready=False) 568ca92f3cSFam Zheng self.vm.shutdown() 578ca92f3cSFam Zheng self.assertEqual(iotests.image_size(test_img), iotests.image_size(target_img), 588ca92f3cSFam Zheng "Target size doesn't match source when granularity when unaligend") 598ca92f3cSFam Zheng 608ca92f3cSFam Zheng 618ca92f3cSFam Zhengif __name__ == '__main__': 62103cbc77SMax Reitz iotests.main(supported_fmts=['raw', 'qcow2'], 63103cbc77SMax Reitz supported_protocols=['file']) 64