xref: /openbmc/qemu/tests/qemu-iotests/152 (revision 8ca92f3c)
1*8ca92f3cSFam Zheng#!/usr/bin/env python
2*8ca92f3cSFam Zheng#
3*8ca92f3cSFam Zheng# Tests for drive-mirror with source size unaligned to granularity
4*8ca92f3cSFam Zheng#
5*8ca92f3cSFam Zheng# Copyright (C) 2016 Red Hat, Inc.
6*8ca92f3cSFam Zheng#
7*8ca92f3cSFam Zheng# This program is free software; you can redistribute it and/or modify
8*8ca92f3cSFam Zheng# it under the terms of the GNU General Public License as published by
9*8ca92f3cSFam Zheng# the Free Software Foundation; either version 2 of the License, or
10*8ca92f3cSFam Zheng# (at your option) any later version.
11*8ca92f3cSFam Zheng#
12*8ca92f3cSFam Zheng# This program is distributed in the hope that it will be useful,
13*8ca92f3cSFam Zheng# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*8ca92f3cSFam Zheng# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*8ca92f3cSFam Zheng# GNU General Public License for more details.
16*8ca92f3cSFam Zheng#
17*8ca92f3cSFam Zheng# You should have received a copy of the GNU General Public License
18*8ca92f3cSFam Zheng# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19*8ca92f3cSFam Zheng#
20*8ca92f3cSFam Zheng
21*8ca92f3cSFam Zhengimport os
22*8ca92f3cSFam Zhengimport iotests
23*8ca92f3cSFam Zhengfrom iotests import qemu_img
24*8ca92f3cSFam Zheng
25*8ca92f3cSFam Zhengtest_img = os.path.join(iotests.test_dir, 'test.img')
26*8ca92f3cSFam Zhengtarget_img = os.path.join(iotests.test_dir, 'target.img')
27*8ca92f3cSFam Zheng
28*8ca92f3cSFam Zhengclass TestUnaligned(iotests.QMPTestCase):
29*8ca92f3cSFam Zheng    def setUp(self):
30*8ca92f3cSFam Zheng        qemu_img('create', '-f', iotests.imgfmt, test_img, '512')
31*8ca92f3cSFam Zheng        self.vm = iotests.VM().add_drive(test_img)
32*8ca92f3cSFam Zheng        self.vm.launch()
33*8ca92f3cSFam Zheng
34*8ca92f3cSFam Zheng    def tearDown(self):
35*8ca92f3cSFam Zheng        self.vm.shutdown()
36*8ca92f3cSFam Zheng        os.remove(test_img)
37*8ca92f3cSFam Zheng        try:
38*8ca92f3cSFam Zheng            os.remove(target_img)
39*8ca92f3cSFam Zheng        except OSError:
40*8ca92f3cSFam Zheng            pass
41*8ca92f3cSFam Zheng
42*8ca92f3cSFam Zheng    def test_unaligned(self):
43*8ca92f3cSFam Zheng        result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
44*8ca92f3cSFam Zheng                             granularity=65536, target=target_img)
45*8ca92f3cSFam Zheng        self.complete_and_wait()
46*8ca92f3cSFam Zheng        self.vm.shutdown()
47*8ca92f3cSFam Zheng        self.assertEqual(iotests.image_size(test_img), iotests.image_size(target_img),
48*8ca92f3cSFam Zheng                         "Target size doesn't match source when granularity when unaligend")
49*8ca92f3cSFam Zheng
50*8ca92f3cSFam Zheng    def test_unaligned_with_update(self):
51*8ca92f3cSFam Zheng        result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
52*8ca92f3cSFam Zheng                             granularity=65536, target=target_img)
53*8ca92f3cSFam Zheng        self.wait_ready()
54*8ca92f3cSFam Zheng        self.vm.hmp_qemu_io('drive0', 'write 0 512')
55*8ca92f3cSFam Zheng        self.complete_and_wait(wait_ready=False)
56*8ca92f3cSFam Zheng        self.vm.shutdown()
57*8ca92f3cSFam Zheng        self.assertEqual(iotests.image_size(test_img), iotests.image_size(target_img),
58*8ca92f3cSFam Zheng                         "Target size doesn't match source when granularity when unaligend")
59*8ca92f3cSFam Zheng
60*8ca92f3cSFam Zheng
61*8ca92f3cSFam Zhengif __name__ == '__main__':
62*8ca92f3cSFam Zheng    iotests.main(supported_fmts=['raw', 'qcow2'])
63