1*a1144c0dSKevin Wolf#!/bin/bash 2*a1144c0dSKevin Wolf# 3*a1144c0dSKevin Wolf# Test count_contiguous_clusters in qcow2 4*a1144c0dSKevin Wolf# 5*a1144c0dSKevin Wolf# Copyright (C) 2013 Red Hat, Inc. 6*a1144c0dSKevin Wolf# 7*a1144c0dSKevin Wolf# This program is free software; you can redistribute it and/or modify 8*a1144c0dSKevin Wolf# it under the terms of the GNU General Public License as published by 9*a1144c0dSKevin Wolf# the Free Software Foundation; either version 2 of the License, or 10*a1144c0dSKevin Wolf# (at your option) any later version. 11*a1144c0dSKevin Wolf# 12*a1144c0dSKevin Wolf# This program is distributed in the hope that it will be useful, 13*a1144c0dSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 14*a1144c0dSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*a1144c0dSKevin Wolf# GNU General Public License for more details. 16*a1144c0dSKevin Wolf# 17*a1144c0dSKevin Wolf# You should have received a copy of the GNU General Public License 18*a1144c0dSKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 19*a1144c0dSKevin Wolf# 20*a1144c0dSKevin Wolf 21*a1144c0dSKevin Wolf# creator 22*a1144c0dSKevin Wolfowner=kwolf@redhat.com 23*a1144c0dSKevin Wolf 24*a1144c0dSKevin Wolfseq=`basename $0` 25*a1144c0dSKevin Wolfecho "QA output created by $seq" 26*a1144c0dSKevin Wolf 27*a1144c0dSKevin Wolfhere=`pwd` 28*a1144c0dSKevin Wolftmp=/tmp/$$ 29*a1144c0dSKevin Wolfstatus=1 # failure is the default! 30*a1144c0dSKevin Wolf 31*a1144c0dSKevin Wolf_cleanup() 32*a1144c0dSKevin Wolf{ 33*a1144c0dSKevin Wolf _cleanup_test_img 34*a1144c0dSKevin Wolf} 35*a1144c0dSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 36*a1144c0dSKevin Wolf 37*a1144c0dSKevin Wolf# get standard environment, filters and checks 38*a1144c0dSKevin Wolf. ./common.rc 39*a1144c0dSKevin Wolf. ./common.filter 40*a1144c0dSKevin Wolf 41*a1144c0dSKevin Wolf_supported_fmt qcow2 42*a1144c0dSKevin Wolf_supported_proto generic 43*a1144c0dSKevin Wolf_supported_os Linux 44*a1144c0dSKevin Wolf 45*a1144c0dSKevin WolfCLUSTER_SIZE=64k 46*a1144c0dSKevin Wolfsize=128M 47*a1144c0dSKevin Wolf 48*a1144c0dSKevin Wolfecho 49*a1144c0dSKevin Wolfecho "== creating backing file ==" 50*a1144c0dSKevin Wolf 51*a1144c0dSKevin WolfTEST_IMG="$TEST_IMG.base" _make_test_img $size 52*a1144c0dSKevin Wolf 53*a1144c0dSKevin Wolf_make_test_img -b "$TEST_IMG.base" 54*a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0xa5 0 $size" "$TEST_IMG.base" | _filter_qemu_io 55*a1144c0dSKevin Wolf 56*a1144c0dSKevin Wolfecho 57*a1144c0dSKevin Wolfecho "== normal -> unallocated ==" 58*a1144c0dSKevin Wolf 59*a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x11 0 0x10000" "$TEST_IMG" | _filter_qemu_io 60*a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x11 0x10000 0x10000" "$TEST_IMG.base" | _filter_qemu_io 61*a1144c0dSKevin Wolf 62*a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0x11 0 0x20000" "$TEST_IMG" | _filter_qemu_io 63*a1144c0dSKevin Wolf 64*a1144c0dSKevin Wolfecho 65*a1144c0dSKevin Wolfecho "== normal -> compressed ==" 66*a1144c0dSKevin Wolf 67*a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x22 0x20000 0x10000" "$TEST_IMG" | _filter_qemu_io 68*a1144c0dSKevin Wolf$QEMU_IO -c "write -c -P 0x22 0x30000 0x10000" "$TEST_IMG" | _filter_qemu_io 69*a1144c0dSKevin Wolf 70*a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0x22 0x20000 0x20000" "$TEST_IMG" | _filter_qemu_io 71*a1144c0dSKevin Wolf 72*a1144c0dSKevin Wolfecho 73*a1144c0dSKevin Wolfecho "== normal -> zero ==" 74*a1144c0dSKevin Wolf 75*a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x33 0x40000 0x20000" "$TEST_IMG" | _filter_qemu_io 76*a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x33 0x40000 0x20000" "$TEST_IMG.base" | _filter_qemu_io 77*a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0 0x40000 0x10000" "$TEST_IMG" | _filter_qemu_io 78*a1144c0dSKevin Wolf$QEMU_IO -c "write -z 0x50000 0x10000" "$TEST_IMG" | _filter_qemu_io 79*a1144c0dSKevin Wolf 80*a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0 0x40000 0x20000" "$TEST_IMG" | _filter_qemu_io 81*a1144c0dSKevin Wolf 82*a1144c0dSKevin Wolfecho 83*a1144c0dSKevin Wolfecho 84*a1144c0dSKevin Wolfecho "== unallocated -> normal ==" 85*a1144c0dSKevin Wolf 86*a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x44 0x60000 0x10000" "$TEST_IMG.base" | _filter_qemu_io 87*a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x44 0x70000 0x10000" "$TEST_IMG" | _filter_qemu_io 88*a1144c0dSKevin Wolf 89*a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0x44 0x60000 0x20000" "$TEST_IMG" | _filter_qemu_io 90*a1144c0dSKevin Wolf 91*a1144c0dSKevin Wolfecho 92*a1144c0dSKevin Wolfecho "== unallocated -> compressed ==" 93*a1144c0dSKevin Wolf 94*a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x55 0x80000 0x10000" "$TEST_IMG.base" | _filter_qemu_io 95*a1144c0dSKevin Wolf$QEMU_IO -c "write -c -P 0x55 0x90000 0x10000" "$TEST_IMG" | _filter_qemu_io 96*a1144c0dSKevin Wolf 97*a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0x55 0x80000 0x20000" "$TEST_IMG" | _filter_qemu_io 98*a1144c0dSKevin Wolf 99*a1144c0dSKevin Wolfecho 100*a1144c0dSKevin Wolfecho "== unallocated -> zero ==" 101*a1144c0dSKevin Wolf 102*a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x66 0xa0000 0x20000" "$TEST_IMG.base" | _filter_qemu_io 103*a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0 0xa0000 0x10000" "$TEST_IMG.base" | _filter_qemu_io 104*a1144c0dSKevin Wolf$QEMU_IO -c "write -z 0xb0000 0x10000" "$TEST_IMG" | _filter_qemu_io 105*a1144c0dSKevin Wolf 106*a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0 0xa0000 0x20000" "$TEST_IMG" | _filter_qemu_io 107*a1144c0dSKevin Wolf 108*a1144c0dSKevin Wolfecho 109*a1144c0dSKevin Wolfecho 110*a1144c0dSKevin Wolfecho "== compressed -> normal ==" 111*a1144c0dSKevin Wolf 112*a1144c0dSKevin Wolf$QEMU_IO -c "write -c -P 0x77 0xc0000 0x10000" "$TEST_IMG" | _filter_qemu_io 113*a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x77 0xd0000 0x10000" "$TEST_IMG" | _filter_qemu_io 114*a1144c0dSKevin Wolf 115*a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0x77 0xc0000 0x20000" "$TEST_IMG" | _filter_qemu_io 116*a1144c0dSKevin Wolf 117*a1144c0dSKevin Wolfecho 118*a1144c0dSKevin Wolfecho "== compressed -> unallocated ==" 119*a1144c0dSKevin Wolf 120*a1144c0dSKevin Wolf$QEMU_IO -c "write -c -P 0x88 0xe0000 0x10000" "$TEST_IMG" | _filter_qemu_io 121*a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x88 0xf0000 0x10000" "$TEST_IMG.base" | _filter_qemu_io 122*a1144c0dSKevin Wolf 123*a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0x88 0xe0000 0x20000" "$TEST_IMG" | _filter_qemu_io 124*a1144c0dSKevin Wolf 125*a1144c0dSKevin Wolfecho 126*a1144c0dSKevin Wolfecho "== compressed -> zero ==" 127*a1144c0dSKevin Wolf 128*a1144c0dSKevin Wolf$QEMU_IO -c "write -c -P 0 0x100000 0x10000" "$TEST_IMG" | _filter_qemu_io 129*a1144c0dSKevin Wolf$QEMU_IO -c "write -c -P 0x99 0x110000 0x10000" "$TEST_IMG" | _filter_qemu_io 130*a1144c0dSKevin Wolf$QEMU_IO -c "write -z 0x110000 0x10000" "$TEST_IMG" | _filter_qemu_io 131*a1144c0dSKevin Wolf 132*a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0 0x100000 0x20000" "$TEST_IMG" | _filter_qemu_io 133*a1144c0dSKevin Wolf 134*a1144c0dSKevin Wolfecho 135*a1144c0dSKevin Wolfecho 136*a1144c0dSKevin Wolfecho "== zero -> normal ==" 137*a1144c0dSKevin Wolf 138*a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0xaa 0x120000 0x10000" "$TEST_IMG" | _filter_qemu_io 139*a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0 0x130000 0x10000" "$TEST_IMG" | _filter_qemu_io 140*a1144c0dSKevin Wolf$QEMU_IO -c "write -z 0x120000 0x10000" "$TEST_IMG" | _filter_qemu_io 141*a1144c0dSKevin Wolf 142*a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0 0x120000 0x20000" "$TEST_IMG" | _filter_qemu_io 143*a1144c0dSKevin Wolf 144*a1144c0dSKevin Wolfecho 145*a1144c0dSKevin Wolfecho "== zero -> unallocated ==" 146*a1144c0dSKevin Wolf 147*a1144c0dSKevin Wolf$QEMU_IO -c "write -z 0x140000 0x10000" "$TEST_IMG" | _filter_qemu_io 148*a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0 0x150000 0x10000" "$TEST_IMG.base" | _filter_qemu_io 149*a1144c0dSKevin Wolf 150*a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0 0x140000 0x20000" "$TEST_IMG" | _filter_qemu_io 151*a1144c0dSKevin Wolf 152*a1144c0dSKevin Wolfecho 153*a1144c0dSKevin Wolfecho "== zero -> compressed ==" 154*a1144c0dSKevin Wolf 155*a1144c0dSKevin Wolf$QEMU_IO -c "write -c -P 0 0x170000 0x10000" "$TEST_IMG" | _filter_qemu_io 156*a1144c0dSKevin Wolf$QEMU_IO -c "write -z 0x160000 0x10000" "$TEST_IMG" | _filter_qemu_io 157*a1144c0dSKevin Wolf 158*a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0 0x160000 0x20000" "$TEST_IMG" | _filter_qemu_io 159*a1144c0dSKevin Wolf 160*a1144c0dSKevin Wolf 161*a1144c0dSKevin Wolf_check_test_img 162*a1144c0dSKevin Wolf 163*a1144c0dSKevin Wolf# success, all done 164*a1144c0dSKevin Wolfecho "*** done" 165*a1144c0dSKevin Wolfrm -f $seq.full 166*a1144c0dSKevin Wolfstatus=0 167