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