Philippe Mathieu-Daudé | 903cb1b | 2020-01-30 17:32:23 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Vladimir Sementsov-Ogievskiy | 9dd003a | 2021-01-16 16:44:19 +0300 | [diff] [blame] | 2 | # group: rw quick |
Fam Zheng | c615091 | 2015-06-08 13:56:13 +0800 | [diff] [blame] | 3 | # |
| 4 | # Test mirror with unmap |
| 5 | # |
| 6 | # Copyright (C) 2015 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 | |
| 22 | import time |
| 23 | import os |
| 24 | import iotests |
| 25 | from iotests import qemu_img, qemu_io |
| 26 | |
| 27 | test_img = os.path.join(iotests.test_dir, 'test.img') |
| 28 | target_img = os.path.join(iotests.test_dir, 'target.img') |
| 29 | |
| 30 | class TestSingleDrive(iotests.QMPTestCase): |
| 31 | image_len = 2 * 1024 * 1024 # MB |
| 32 | |
| 33 | def setUp(self): |
| 34 | # Write data to the image so we can compare later |
| 35 | qemu_img('create', '-f', iotests.imgfmt, test_img, str(TestSingleDrive.image_len)) |
| 36 | qemu_io('-f', iotests.imgfmt, '-c', 'write -P0x5d 0 2M', test_img) |
| 37 | |
| 38 | self.vm = iotests.VM().add_drive(test_img, 'discard=unmap') |
| 39 | self.vm.launch() |
| 40 | |
| 41 | def tearDown(self): |
| 42 | self.vm.shutdown() |
| 43 | os.remove(test_img) |
| 44 | try: |
| 45 | os.remove(target_img) |
| 46 | except OSError: |
| 47 | pass |
| 48 | |
| 49 | def test_mirror_discard(self): |
| 50 | result = self.vm.qmp('drive-mirror', device='drive0', sync='full', |
| 51 | target=target_img) |
| 52 | self.assert_qmp(result, 'return', {}) |
| 53 | self.vm.hmp_qemu_io('drive0', 'discard 0 64k') |
| 54 | self.complete_and_wait('drive0') |
| 55 | self.vm.shutdown() |
| 56 | self.assertTrue(iotests.compare_images(test_img, target_img), |
| 57 | 'target image does not match source after mirroring') |
| 58 | |
| 59 | if __name__ == '__main__': |
Max Reitz | 103cbc7 | 2019-09-02 21:33:18 +0200 | [diff] [blame] | 60 | iotests.main(supported_fmts=['raw', 'qcow2'], |
| 61 | supported_protocols=['file']) |