xref: /openbmc/qemu/tests/qemu-iotests/152 (revision f7ccc3295b3d7c49d4a7a3d42242cd5b50111e35)
1#!/usr/bin/env python3
2# group: rw quick
3#
4# Tests for drive-mirror with source size unaligned to granularity
5#
6# Copyright (C) 2016 Red Hat, Inc.
7#
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.
12#
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.
17#
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/>.
20#
21
22import os
23import iotests
24from iotests import qemu_img
25
26test_img = os.path.join(iotests.test_dir, 'test.img')
27target_img = os.path.join(iotests.test_dir, 'target.img')
28
29class TestUnaligned(iotests.QMPTestCase):
30    def setUp(self):
31        qemu_img('create', '-f', iotests.imgfmt, test_img, '512')
32        self.vm = iotests.VM().add_drive(test_img)
33        self.vm.launch()
34
35    def tearDown(self):
36        self.vm.shutdown()
37        os.remove(test_img)
38        try:
39            os.remove(target_img)
40        except OSError:
41            pass
42
43    def test_unaligned(self):
44        result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
45                             granularity=65536, target=target_img)
46        self.assert_qmp(result, 'return', {})
47        self.complete_and_wait()
48        self.vm.shutdown()
49        self.assertEqual(iotests.image_size(test_img), iotests.image_size(target_img),
50                         "Target size doesn't match source when granularity when unaligend")
51
52    def test_unaligned_with_update(self):
53        result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
54                             granularity=65536, target=target_img)
55        self.assert_qmp(result, 'return', {})
56        self.wait_ready()
57        self.vm.hmp_qemu_io('drive0', 'write 0 512')
58        self.complete_and_wait(wait_ready=False)
59        self.vm.shutdown()
60        self.assertEqual(iotests.image_size(test_img), iotests.image_size(target_img),
61                         "Target size doesn't match source when granularity when unaligend")
62
63
64if __name__ == '__main__':
65    iotests.main(supported_fmts=['raw', 'qcow2'],
66                 supported_protocols=['file'])
67