1*e8f6ea6fSKevin Wolf#!/bin/bash 2*e8f6ea6fSKevin Wolf# 3*e8f6ea6fSKevin Wolf# Test parallels and file image creation 4*e8f6ea6fSKevin Wolf# 5*e8f6ea6fSKevin Wolf# Copyright (C) 2018 Red Hat, Inc. 6*e8f6ea6fSKevin Wolf# 7*e8f6ea6fSKevin Wolf# This program is free software; you can redistribute it and/or modify 8*e8f6ea6fSKevin Wolf# it under the terms of the GNU General Public License as published by 9*e8f6ea6fSKevin Wolf# the Free Software Foundation; either version 2 of the License, or 10*e8f6ea6fSKevin Wolf# (at your option) any later version. 11*e8f6ea6fSKevin Wolf# 12*e8f6ea6fSKevin Wolf# This program is distributed in the hope that it will be useful, 13*e8f6ea6fSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 14*e8f6ea6fSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*e8f6ea6fSKevin Wolf# GNU General Public License for more details. 16*e8f6ea6fSKevin Wolf# 17*e8f6ea6fSKevin Wolf# You should have received a copy of the GNU General Public License 18*e8f6ea6fSKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 19*e8f6ea6fSKevin Wolf# 20*e8f6ea6fSKevin Wolf 21*e8f6ea6fSKevin Wolf# creator 22*e8f6ea6fSKevin Wolfowner=kwolf@redhat.com 23*e8f6ea6fSKevin Wolf 24*e8f6ea6fSKevin Wolfseq=`basename $0` 25*e8f6ea6fSKevin Wolfecho "QA output created by $seq" 26*e8f6ea6fSKevin Wolf 27*e8f6ea6fSKevin Wolfhere=`pwd` 28*e8f6ea6fSKevin Wolfstatus=1 # failure is the default! 29*e8f6ea6fSKevin Wolf 30*e8f6ea6fSKevin Wolf# get standard environment, filters and checks 31*e8f6ea6fSKevin Wolf. ./common.rc 32*e8f6ea6fSKevin Wolf. ./common.filter 33*e8f6ea6fSKevin Wolf 34*e8f6ea6fSKevin Wolf_supported_fmt parallels 35*e8f6ea6fSKevin Wolf_supported_proto file 36*e8f6ea6fSKevin Wolf_supported_os Linux 37*e8f6ea6fSKevin Wolf 38*e8f6ea6fSKevin Wolffunction do_run_qemu() 39*e8f6ea6fSKevin Wolf{ 40*e8f6ea6fSKevin Wolf echo Testing: "$@" 41*e8f6ea6fSKevin Wolf $QEMU -nographic -qmp stdio -serial none "$@" 42*e8f6ea6fSKevin Wolf echo 43*e8f6ea6fSKevin Wolf} 44*e8f6ea6fSKevin Wolf 45*e8f6ea6fSKevin Wolffunction run_qemu() 46*e8f6ea6fSKevin Wolf{ 47*e8f6ea6fSKevin Wolf do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \ 48*e8f6ea6fSKevin Wolf | _filter_qemu | _filter_imgfmt \ 49*e8f6ea6fSKevin Wolf | _filter_actual_image_size 50*e8f6ea6fSKevin Wolf} 51*e8f6ea6fSKevin Wolf 52*e8f6ea6fSKevin Wolfecho 53*e8f6ea6fSKevin Wolfecho "=== Successful image creation (defaults) ===" 54*e8f6ea6fSKevin Wolfecho 55*e8f6ea6fSKevin Wolf 56*e8f6ea6fSKevin Wolfsize=$((128 * 1024 * 1024)) 57*e8f6ea6fSKevin Wolf 58*e8f6ea6fSKevin Wolfrun_qemu <<EOF 59*e8f6ea6fSKevin Wolf{ "execute": "qmp_capabilities" } 60*e8f6ea6fSKevin Wolf{ "execute": "x-blockdev-create", 61*e8f6ea6fSKevin Wolf "arguments": { 62*e8f6ea6fSKevin Wolf "driver": "file", 63*e8f6ea6fSKevin Wolf "filename": "$TEST_IMG", 64*e8f6ea6fSKevin Wolf "size": 0 65*e8f6ea6fSKevin Wolf } 66*e8f6ea6fSKevin Wolf} 67*e8f6ea6fSKevin Wolf{ "execute": "blockdev-add", 68*e8f6ea6fSKevin Wolf "arguments": { 69*e8f6ea6fSKevin Wolf "driver": "file", 70*e8f6ea6fSKevin Wolf "node-name": "imgfile", 71*e8f6ea6fSKevin Wolf "filename": "$TEST_IMG" 72*e8f6ea6fSKevin Wolf } 73*e8f6ea6fSKevin Wolf} 74*e8f6ea6fSKevin Wolf{ "execute": "x-blockdev-create", 75*e8f6ea6fSKevin Wolf "arguments": { 76*e8f6ea6fSKevin Wolf "driver": "$IMGFMT", 77*e8f6ea6fSKevin Wolf "file": "imgfile", 78*e8f6ea6fSKevin Wolf "size": $size 79*e8f6ea6fSKevin Wolf } 80*e8f6ea6fSKevin Wolf} 81*e8f6ea6fSKevin Wolf{ "execute": "quit" } 82*e8f6ea6fSKevin WolfEOF 83*e8f6ea6fSKevin Wolf 84*e8f6ea6fSKevin Wolf_img_info --format-specific | _filter_img_info --format-specific 85*e8f6ea6fSKevin Wolf 86*e8f6ea6fSKevin Wolfecho 87*e8f6ea6fSKevin Wolfecho "=== Successful image creation (explicit defaults) ===" 88*e8f6ea6fSKevin Wolfecho 89*e8f6ea6fSKevin Wolf 90*e8f6ea6fSKevin Wolf# Choose a different size to show that we got a new image 91*e8f6ea6fSKevin Wolfsize=$((64 * 1024 * 1024)) 92*e8f6ea6fSKevin Wolf 93*e8f6ea6fSKevin Wolfrun_qemu <<EOF 94*e8f6ea6fSKevin Wolf{ "execute": "qmp_capabilities" } 95*e8f6ea6fSKevin Wolf{ "execute": "x-blockdev-create", 96*e8f6ea6fSKevin Wolf "arguments": { 97*e8f6ea6fSKevin Wolf "driver": "file", 98*e8f6ea6fSKevin Wolf "filename": "$TEST_IMG", 99*e8f6ea6fSKevin Wolf "size": 0 100*e8f6ea6fSKevin Wolf } 101*e8f6ea6fSKevin Wolf} 102*e8f6ea6fSKevin Wolf{ "execute": "x-blockdev-create", 103*e8f6ea6fSKevin Wolf "arguments": { 104*e8f6ea6fSKevin Wolf "driver": "$IMGFMT", 105*e8f6ea6fSKevin Wolf "file": { 106*e8f6ea6fSKevin Wolf "driver": "file", 107*e8f6ea6fSKevin Wolf "filename": "$TEST_IMG" 108*e8f6ea6fSKevin Wolf }, 109*e8f6ea6fSKevin Wolf "size": $size, 110*e8f6ea6fSKevin Wolf "cluster-size": 1048576 111*e8f6ea6fSKevin Wolf } 112*e8f6ea6fSKevin Wolf} 113*e8f6ea6fSKevin Wolf{ "execute": "quit" } 114*e8f6ea6fSKevin WolfEOF 115*e8f6ea6fSKevin Wolf 116*e8f6ea6fSKevin Wolf_img_info --format-specific | _filter_img_info --format-specific 117*e8f6ea6fSKevin Wolf 118*e8f6ea6fSKevin Wolfecho 119*e8f6ea6fSKevin Wolfecho "=== Successful image creation (with non-default options) ===" 120*e8f6ea6fSKevin Wolfecho 121*e8f6ea6fSKevin Wolf 122*e8f6ea6fSKevin Wolf# Choose a different size to show that we got a new image 123*e8f6ea6fSKevin Wolfsize=$((32 * 1024 * 1024)) 124*e8f6ea6fSKevin Wolf 125*e8f6ea6fSKevin Wolfrun_qemu <<EOF 126*e8f6ea6fSKevin Wolf{ "execute": "qmp_capabilities" } 127*e8f6ea6fSKevin Wolf{ "execute": "x-blockdev-create", 128*e8f6ea6fSKevin Wolf "arguments": { 129*e8f6ea6fSKevin Wolf "driver": "file", 130*e8f6ea6fSKevin Wolf "filename": "$TEST_IMG", 131*e8f6ea6fSKevin Wolf "size": 0 132*e8f6ea6fSKevin Wolf } 133*e8f6ea6fSKevin Wolf} 134*e8f6ea6fSKevin Wolf{ "execute": "x-blockdev-create", 135*e8f6ea6fSKevin Wolf "arguments": { 136*e8f6ea6fSKevin Wolf "driver": "$IMGFMT", 137*e8f6ea6fSKevin Wolf "file": { 138*e8f6ea6fSKevin Wolf "driver": "file", 139*e8f6ea6fSKevin Wolf "filename": "$TEST_IMG" 140*e8f6ea6fSKevin Wolf }, 141*e8f6ea6fSKevin Wolf "size": $size, 142*e8f6ea6fSKevin Wolf "cluster-size": 65536 143*e8f6ea6fSKevin Wolf } 144*e8f6ea6fSKevin Wolf} 145*e8f6ea6fSKevin Wolf{ "execute": "quit" } 146*e8f6ea6fSKevin WolfEOF 147*e8f6ea6fSKevin Wolf 148*e8f6ea6fSKevin Wolf_img_info --format-specific | _filter_img_info --format-specific 149*e8f6ea6fSKevin Wolf 150*e8f6ea6fSKevin Wolfecho 151*e8f6ea6fSKevin Wolfecho "=== Invalid BlockdevRef ===" 152*e8f6ea6fSKevin Wolfecho 153*e8f6ea6fSKevin Wolf 154*e8f6ea6fSKevin Wolfrun_qemu <<EOF 155*e8f6ea6fSKevin Wolf{ "execute": "qmp_capabilities" } 156*e8f6ea6fSKevin Wolf{ "execute": "x-blockdev-create", 157*e8f6ea6fSKevin Wolf "arguments": { 158*e8f6ea6fSKevin Wolf "driver": "$IMGFMT", 159*e8f6ea6fSKevin Wolf "file": "this doesn't exist", 160*e8f6ea6fSKevin Wolf "size": $size 161*e8f6ea6fSKevin Wolf } 162*e8f6ea6fSKevin Wolf} 163*e8f6ea6fSKevin Wolf{ "execute": "quit" } 164*e8f6ea6fSKevin WolfEOF 165*e8f6ea6fSKevin Wolf 166*e8f6ea6fSKevin Wolfecho 167*e8f6ea6fSKevin Wolfecho "=== Zero size ===" 168*e8f6ea6fSKevin Wolfecho 169*e8f6ea6fSKevin Wolf 170*e8f6ea6fSKevin Wolfrun_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF 171*e8f6ea6fSKevin Wolf{ "execute": "qmp_capabilities" } 172*e8f6ea6fSKevin Wolf{ "execute": "x-blockdev-create", 173*e8f6ea6fSKevin Wolf "arguments": { 174*e8f6ea6fSKevin Wolf "driver": "$IMGFMT", 175*e8f6ea6fSKevin Wolf "file": "node0", 176*e8f6ea6fSKevin Wolf "size": 0 177*e8f6ea6fSKevin Wolf } 178*e8f6ea6fSKevin Wolf} 179*e8f6ea6fSKevin Wolf{ "execute": "quit" } 180*e8f6ea6fSKevin WolfEOF 181*e8f6ea6fSKevin Wolf 182*e8f6ea6fSKevin Wolf_img_info | _filter_img_info 183*e8f6ea6fSKevin Wolf 184*e8f6ea6fSKevin Wolfecho 185*e8f6ea6fSKevin Wolfecho "=== Maximum size ===" 186*e8f6ea6fSKevin Wolfecho 187*e8f6ea6fSKevin Wolf 188*e8f6ea6fSKevin Wolfrun_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF 189*e8f6ea6fSKevin Wolf{ "execute": "qmp_capabilities" } 190*e8f6ea6fSKevin Wolf{ "execute": "x-blockdev-create", 191*e8f6ea6fSKevin Wolf "arguments": { 192*e8f6ea6fSKevin Wolf "driver": "$IMGFMT", 193*e8f6ea6fSKevin Wolf "file": "node0", 194*e8f6ea6fSKevin Wolf "size": 4503599627369984 195*e8f6ea6fSKevin Wolf } 196*e8f6ea6fSKevin Wolf} 197*e8f6ea6fSKevin Wolf{ "execute": "quit" } 198*e8f6ea6fSKevin WolfEOF 199*e8f6ea6fSKevin Wolf 200*e8f6ea6fSKevin Wolf_img_info | _filter_img_info 201*e8f6ea6fSKevin Wolf 202*e8f6ea6fSKevin Wolfecho 203*e8f6ea6fSKevin Wolfecho "=== Invalid sizes ===" 204*e8f6ea6fSKevin Wolfecho 205*e8f6ea6fSKevin Wolf 206*e8f6ea6fSKevin Wolf# TODO Negative image sizes aren't handled correctly, but this is a problem 207*e8f6ea6fSKevin Wolf# with QAPI's implementation of the 'size' type and affects other commands as 208*e8f6ea6fSKevin Wolf# well. Once this is fixed, we may want to add a test case here. 209*e8f6ea6fSKevin Wolf 210*e8f6ea6fSKevin Wolf# 1. Misaligned image size 211*e8f6ea6fSKevin Wolf# 2. 2^64 - 512 212*e8f6ea6fSKevin Wolf# 3. 2^63 = 8 EB (qemu-img enforces image sizes less than this) 213*e8f6ea6fSKevin Wolf# 4. 2^63 - 512 (generally valid, but with the image header the file will 214*e8f6ea6fSKevin Wolf# exceed 63 bits) 215*e8f6ea6fSKevin Wolf# 5. 2^52 (512 bytes more than maximum image size) 216*e8f6ea6fSKevin Wolf 217*e8f6ea6fSKevin Wolfrun_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF 218*e8f6ea6fSKevin Wolf{ "execute": "qmp_capabilities" } 219*e8f6ea6fSKevin Wolf{ "execute": "x-blockdev-create", 220*e8f6ea6fSKevin Wolf "arguments": { 221*e8f6ea6fSKevin Wolf "driver": "$IMGFMT", 222*e8f6ea6fSKevin Wolf "file": "node0", 223*e8f6ea6fSKevin Wolf "size": 1234 224*e8f6ea6fSKevin Wolf } 225*e8f6ea6fSKevin Wolf} 226*e8f6ea6fSKevin Wolf{ "execute": "x-blockdev-create", 227*e8f6ea6fSKevin Wolf "arguments": { 228*e8f6ea6fSKevin Wolf "driver": "$IMGFMT", 229*e8f6ea6fSKevin Wolf "file": "node0", 230*e8f6ea6fSKevin Wolf "size": 18446744073709551104 231*e8f6ea6fSKevin Wolf } 232*e8f6ea6fSKevin Wolf} 233*e8f6ea6fSKevin Wolf{ "execute": "x-blockdev-create", 234*e8f6ea6fSKevin Wolf "arguments": { 235*e8f6ea6fSKevin Wolf "driver": "$IMGFMT", 236*e8f6ea6fSKevin Wolf "file": "node0", 237*e8f6ea6fSKevin Wolf "size": 9223372036854775808 238*e8f6ea6fSKevin Wolf } 239*e8f6ea6fSKevin Wolf} 240*e8f6ea6fSKevin Wolf{ "execute": "x-blockdev-create", 241*e8f6ea6fSKevin Wolf "arguments": { 242*e8f6ea6fSKevin Wolf "driver": "$IMGFMT", 243*e8f6ea6fSKevin Wolf "file": "node0", 244*e8f6ea6fSKevin Wolf "size": 9223372036854775296 245*e8f6ea6fSKevin Wolf } 246*e8f6ea6fSKevin Wolf} 247*e8f6ea6fSKevin Wolf{ "execute": "x-blockdev-create", 248*e8f6ea6fSKevin Wolf "arguments": { 249*e8f6ea6fSKevin Wolf "driver": "$IMGFMT", 250*e8f6ea6fSKevin Wolf "file": "node0", 251*e8f6ea6fSKevin Wolf "size": 4503599627370497 252*e8f6ea6fSKevin Wolf } 253*e8f6ea6fSKevin Wolf} 254*e8f6ea6fSKevin Wolf{ "execute": "quit" } 255*e8f6ea6fSKevin WolfEOF 256*e8f6ea6fSKevin Wolf 257*e8f6ea6fSKevin Wolfecho 258*e8f6ea6fSKevin Wolfecho "=== Invalid cluster size ===" 259*e8f6ea6fSKevin Wolfecho 260*e8f6ea6fSKevin Wolf 261*e8f6ea6fSKevin Wolfrun_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF 262*e8f6ea6fSKevin Wolf{ "execute": "qmp_capabilities" } 263*e8f6ea6fSKevin Wolf{ "execute": "x-blockdev-create", 264*e8f6ea6fSKevin Wolf "arguments": { 265*e8f6ea6fSKevin Wolf "driver": "$IMGFMT", 266*e8f6ea6fSKevin Wolf "file": "node0", 267*e8f6ea6fSKevin Wolf "size": 67108864, 268*e8f6ea6fSKevin Wolf "cluster-size": 1234 269*e8f6ea6fSKevin Wolf } 270*e8f6ea6fSKevin Wolf} 271*e8f6ea6fSKevin Wolf{ "execute": "x-blockdev-create", 272*e8f6ea6fSKevin Wolf "arguments": { 273*e8f6ea6fSKevin Wolf "driver": "$IMGFMT", 274*e8f6ea6fSKevin Wolf "file": "node0", 275*e8f6ea6fSKevin Wolf "size": 67108864, 276*e8f6ea6fSKevin Wolf "cluster-size": 128 277*e8f6ea6fSKevin Wolf } 278*e8f6ea6fSKevin Wolf} 279*e8f6ea6fSKevin Wolf{ "execute": "x-blockdev-create", 280*e8f6ea6fSKevin Wolf "arguments": { 281*e8f6ea6fSKevin Wolf "driver": "$IMGFMT", 282*e8f6ea6fSKevin Wolf "file": "node0", 283*e8f6ea6fSKevin Wolf "size": 67108864, 284*e8f6ea6fSKevin Wolf "cluster-size": 4294967296 285*e8f6ea6fSKevin Wolf } 286*e8f6ea6fSKevin Wolf} 287*e8f6ea6fSKevin Wolf{ "execute": "x-blockdev-create", 288*e8f6ea6fSKevin Wolf "arguments": { 289*e8f6ea6fSKevin Wolf "driver": "$IMGFMT", 290*e8f6ea6fSKevin Wolf "file": "node0", 291*e8f6ea6fSKevin Wolf "size": 67108864, 292*e8f6ea6fSKevin Wolf "cluster-size": 9223372036854775808 293*e8f6ea6fSKevin Wolf } 294*e8f6ea6fSKevin Wolf} 295*e8f6ea6fSKevin Wolf{ "execute": "x-blockdev-create", 296*e8f6ea6fSKevin Wolf "arguments": { 297*e8f6ea6fSKevin Wolf "driver": "$IMGFMT", 298*e8f6ea6fSKevin Wolf "file": "node0", 299*e8f6ea6fSKevin Wolf "size": 67108864, 300*e8f6ea6fSKevin Wolf "cluster-size": 18446744073709551104 301*e8f6ea6fSKevin Wolf } 302*e8f6ea6fSKevin Wolf} 303*e8f6ea6fSKevin Wolf{ "execute": "x-blockdev-create", 304*e8f6ea6fSKevin Wolf "arguments": { 305*e8f6ea6fSKevin Wolf "driver": "$IMGFMT", 306*e8f6ea6fSKevin Wolf "file": "node0", 307*e8f6ea6fSKevin Wolf "size": 67108864, 308*e8f6ea6fSKevin Wolf "cluster-size": 0 309*e8f6ea6fSKevin Wolf } 310*e8f6ea6fSKevin Wolf} 311*e8f6ea6fSKevin Wolf{ "execute": "x-blockdev-create", 312*e8f6ea6fSKevin Wolf "arguments": { 313*e8f6ea6fSKevin Wolf "driver": "$IMGFMT", 314*e8f6ea6fSKevin Wolf "file": "node0", 315*e8f6ea6fSKevin Wolf "size": 281474976710656, 316*e8f6ea6fSKevin Wolf "cluster-size": 512 317*e8f6ea6fSKevin Wolf } 318*e8f6ea6fSKevin Wolf} 319*e8f6ea6fSKevin Wolf{ "execute": "quit" } 320*e8f6ea6fSKevin WolfEOF 321*e8f6ea6fSKevin Wolf 322*e8f6ea6fSKevin Wolf 323*e8f6ea6fSKevin Wolf# success, all done 324*e8f6ea6fSKevin Wolfecho "*** done" 325*e8f6ea6fSKevin Wolfrm -f $seq.full 326*e8f6ea6fSKevin Wolfstatus=0 327