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