17c477526SPhilippe Mathieu-Daudé#!/usr/bin/env python3 29dd003a9SVladimir Sementsov-Ogievskiy# group: rw quick 3cb73747eSMax Reitz# 4cb73747eSMax Reitz# Test VPC and file image creation 5cb73747eSMax Reitz# 6cb73747eSMax Reitz# Copyright (C) 2019 Red Hat, Inc. 7cb73747eSMax Reitz# 8cb73747eSMax Reitz# This program is free software; you can redistribute it and/or modify 9cb73747eSMax Reitz# it under the terms of the GNU General Public License as published by 10cb73747eSMax Reitz# the Free Software Foundation; either version 2 of the License, or 11cb73747eSMax Reitz# (at your option) any later version. 12cb73747eSMax Reitz# 13cb73747eSMax Reitz# This program is distributed in the hope that it will be useful, 14cb73747eSMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of 15cb73747eSMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16cb73747eSMax Reitz# GNU General Public License for more details. 17cb73747eSMax Reitz# 18cb73747eSMax Reitz# You should have received a copy of the GNU General Public License 19cb73747eSMax Reitz# along with this program. If not, see <http://www.gnu.org/licenses/>. 20cb73747eSMax Reitz# 21cb73747eSMax Reitz 22cb73747eSMax Reitzimport iotests 23cb73747eSMax Reitzfrom iotests import imgfmt 24cb73747eSMax Reitz 25cb73747eSMax Reitz 26cb73747eSMax Reitz# Successful image creation (defaults) 27cb73747eSMax Reitzdef implicit_defaults(vm, file_path): 28cb73747eSMax Reitz iotests.log("=== Successful image creation (defaults) ===") 29cb73747eSMax Reitz iotests.log("") 30cb73747eSMax Reitz 31cb73747eSMax Reitz # 8 heads, 964 cyls/head, 17 secs/cyl 32cb73747eSMax Reitz # (Close to 64 MB) 33cb73747eSMax Reitz size = 8 * 964 * 17 * 512 34cb73747eSMax Reitz 35de1ff674SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 36cb73747eSMax Reitz 'file': 'protocol-node', 37cb73747eSMax Reitz 'size': size }) 38cb73747eSMax Reitz 39cb73747eSMax Reitz 40cb73747eSMax Reitz# Successful image creation (explicit defaults) 41cb73747eSMax Reitzdef explicit_defaults(vm, file_path): 42cb73747eSMax Reitz iotests.log("=== Successful image creation (explicit defaults) ===") 43cb73747eSMax Reitz iotests.log("") 44cb73747eSMax Reitz 45cb73747eSMax Reitz # 16 heads, 964 cyls/head, 17 secs/cyl 46cb73747eSMax Reitz # (Close to 128 MB) 47cb73747eSMax Reitz size = 16 * 964 * 17 * 512 48cb73747eSMax Reitz 49de1ff674SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 50cb73747eSMax Reitz 'file': 'protocol-node', 51cb73747eSMax Reitz 'size': size, 52cb73747eSMax Reitz 'subformat': 'dynamic', 53cb73747eSMax Reitz 'force-size': False }) 54cb73747eSMax Reitz 55cb73747eSMax Reitz 56cb73747eSMax Reitz# Successful image creation (non-default options) 57cb73747eSMax Reitzdef non_defaults(vm, file_path): 58cb73747eSMax Reitz iotests.log("=== Successful image creation (non-default options) ===") 59cb73747eSMax Reitz iotests.log("") 60cb73747eSMax Reitz 61cb73747eSMax Reitz # Not representable in CHS (fine with force-size=True) 62cb73747eSMax Reitz size = 1048576 63cb73747eSMax Reitz 64de1ff674SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 65cb73747eSMax Reitz 'file': 'protocol-node', 66cb73747eSMax Reitz 'size': size, 67cb73747eSMax Reitz 'subformat': 'fixed', 68cb73747eSMax Reitz 'force-size': True }) 69cb73747eSMax Reitz 70cb73747eSMax Reitz 71cb73747eSMax Reitz# Size not representable in CHS with force-size=False 72cb73747eSMax Reitzdef non_chs_size_without_force(vm, file_path): 73cb73747eSMax Reitz iotests.log("=== Size not representable in CHS ===") 74cb73747eSMax Reitz iotests.log("") 75cb73747eSMax Reitz 76cb73747eSMax Reitz # Not representable in CHS (will not work with force-size=False) 77cb73747eSMax Reitz size = 1048576 78cb73747eSMax Reitz 79de1ff674SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 80cb73747eSMax Reitz 'file': 'protocol-node', 81cb73747eSMax Reitz 'size': size, 82cb73747eSMax Reitz 'force-size': False }) 83cb73747eSMax Reitz 84cb73747eSMax Reitz 85cb73747eSMax Reitz# Zero size 86cb73747eSMax Reitzdef zero_size(vm, file_path): 87cb73747eSMax Reitz iotests.log("=== Zero size===") 88cb73747eSMax Reitz iotests.log("") 89cb73747eSMax Reitz 90de1ff674SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 91cb73747eSMax Reitz 'file': 'protocol-node', 92cb73747eSMax Reitz 'size': 0 }) 93cb73747eSMax Reitz 94cb73747eSMax Reitz 95cb73747eSMax Reitz# Maximum CHS size 96cb73747eSMax Reitzdef maximum_chs_size(vm, file_path): 97cb73747eSMax Reitz iotests.log("=== Maximum CHS size===") 98cb73747eSMax Reitz iotests.log("") 99cb73747eSMax Reitz 100de1ff674SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 101cb73747eSMax Reitz 'file': 'protocol-node', 102cb73747eSMax Reitz 'size': 16 * 65535 * 255 * 512 }) 103cb73747eSMax Reitz 104cb73747eSMax Reitz 105cb73747eSMax Reitz# Actual maximum size 106cb73747eSMax Reitzdef maximum_size(vm, file_path): 107cb73747eSMax Reitz iotests.log("=== Actual maximum size===") 108cb73747eSMax Reitz iotests.log("") 109cb73747eSMax Reitz 110de1ff674SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 111cb73747eSMax Reitz 'file': 'protocol-node', 112cb73747eSMax Reitz 'size': 0xff000000 * 512, 113cb73747eSMax Reitz 'force-size': True }) 114cb73747eSMax Reitz 115cb73747eSMax Reitz 116cb73747eSMax Reitzdef main(): 117cb73747eSMax Reitz for test_func in [implicit_defaults, explicit_defaults, non_defaults, 118cb73747eSMax Reitz non_chs_size_without_force, zero_size, maximum_chs_size, 119cb73747eSMax Reitz maximum_size]: 120cb73747eSMax Reitz 121cb73747eSMax Reitz with iotests.FilePath('t.vpc') as file_path, \ 122cb73747eSMax Reitz iotests.VM() as vm: 123cb73747eSMax Reitz 124cb73747eSMax Reitz vm.launch() 125cb73747eSMax Reitz 126cb73747eSMax Reitz iotests.log('--- Creating empty file ---') 127de1ff674SKevin Wolf vm.blockdev_create({ 'driver': 'file', 128cb73747eSMax Reitz 'filename': file_path, 129cb73747eSMax Reitz 'size': 0 }) 130cb73747eSMax Reitz 131cb73747eSMax Reitz vm.qmp_log('blockdev-add', driver='file', filename=file_path, 132cb73747eSMax Reitz node_name='protocol-node', 133cb73747eSMax Reitz filters=[iotests.filter_qmp_testfiles]) 134cb73747eSMax Reitz iotests.log('') 135cb73747eSMax Reitz 136cb73747eSMax Reitz print_info = test_func(vm, file_path) 137cb73747eSMax Reitz iotests.log('') 138cb73747eSMax Reitz 139cb73747eSMax Reitz vm.shutdown() 140*8f685ac3SJohn Snow iotests.img_info_log(file_path, check=False) 141cb73747eSMax Reitz 142cb73747eSMax Reitz 143cb73747eSMax Reitziotests.script_main(main, 144cb73747eSMax Reitz supported_fmts=['vpc'], 145cb73747eSMax Reitz supported_protocols=['file']) 146