1*11a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env 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 Wolfstatus=1 # failure is the default! 28a1144c0dSKevin Wolf 29a1144c0dSKevin Wolf_cleanup() 30a1144c0dSKevin Wolf{ 31a1144c0dSKevin Wolf _cleanup_test_img 32a1144c0dSKevin Wolf} 33a1144c0dSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 34a1144c0dSKevin Wolf 35a1144c0dSKevin Wolf# get standard environment, filters and checks 36a1144c0dSKevin Wolf. ./common.rc 37a1144c0dSKevin Wolf. ./common.filter 38a1144c0dSKevin Wolf 39a1144c0dSKevin Wolf_supported_fmt qcow2 40a1144c0dSKevin Wolf_supported_proto generic 41a98f49f4SJeff Cody_unsupported_proto vxhs 42a1144c0dSKevin Wolf_supported_os Linux 43a1144c0dSKevin Wolf 44a1144c0dSKevin WolfCLUSTER_SIZE=64k 45a1144c0dSKevin Wolfsize=128M 46a1144c0dSKevin Wolf 47a1144c0dSKevin Wolfecho 48a1144c0dSKevin Wolfecho "== creating backing file ==" 49a1144c0dSKevin Wolf 50a1144c0dSKevin WolfTEST_IMG="$TEST_IMG.base" _make_test_img $size 51a1144c0dSKevin Wolf 52a1144c0dSKevin Wolf_make_test_img -b "$TEST_IMG.base" 53a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0xa5 0 $size" "$TEST_IMG.base" | _filter_qemu_io 54a1144c0dSKevin Wolf 55a1144c0dSKevin Wolfecho 56a1144c0dSKevin Wolfecho "== normal -> unallocated ==" 57a1144c0dSKevin Wolf 58a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x11 0 0x10000" "$TEST_IMG" | _filter_qemu_io 59a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x11 0x10000 0x10000" "$TEST_IMG.base" | _filter_qemu_io 60a1144c0dSKevin Wolf 61a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0x11 0 0x20000" "$TEST_IMG" | _filter_qemu_io 62a1144c0dSKevin Wolf 63a1144c0dSKevin Wolfecho 64a1144c0dSKevin Wolfecho "== normal -> compressed ==" 65a1144c0dSKevin Wolf 66a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x22 0x20000 0x10000" "$TEST_IMG" | _filter_qemu_io 67a1144c0dSKevin Wolf$QEMU_IO -c "write -c -P 0x22 0x30000 0x10000" "$TEST_IMG" | _filter_qemu_io 68a1144c0dSKevin Wolf 69a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0x22 0x20000 0x20000" "$TEST_IMG" | _filter_qemu_io 70a1144c0dSKevin Wolf 71a1144c0dSKevin Wolfecho 72a1144c0dSKevin Wolfecho "== normal -> zero ==" 73a1144c0dSKevin Wolf 74a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x33 0x40000 0x20000" "$TEST_IMG" | _filter_qemu_io 75a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x33 0x40000 0x20000" "$TEST_IMG.base" | _filter_qemu_io 76a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0 0x40000 0x10000" "$TEST_IMG" | _filter_qemu_io 77a1144c0dSKevin Wolf$QEMU_IO -c "write -z 0x50000 0x10000" "$TEST_IMG" | _filter_qemu_io 78a1144c0dSKevin Wolf 79a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0 0x40000 0x20000" "$TEST_IMG" | _filter_qemu_io 80a1144c0dSKevin Wolf 81a1144c0dSKevin Wolfecho 82a1144c0dSKevin Wolfecho 83a1144c0dSKevin Wolfecho "== unallocated -> normal ==" 84a1144c0dSKevin Wolf 85a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x44 0x60000 0x10000" "$TEST_IMG.base" | _filter_qemu_io 86a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x44 0x70000 0x10000" "$TEST_IMG" | _filter_qemu_io 87a1144c0dSKevin Wolf 88a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0x44 0x60000 0x20000" "$TEST_IMG" | _filter_qemu_io 89a1144c0dSKevin Wolf 90a1144c0dSKevin Wolfecho 91a1144c0dSKevin Wolfecho "== unallocated -> compressed ==" 92a1144c0dSKevin Wolf 93a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x55 0x80000 0x10000" "$TEST_IMG.base" | _filter_qemu_io 94a1144c0dSKevin Wolf$QEMU_IO -c "write -c -P 0x55 0x90000 0x10000" "$TEST_IMG" | _filter_qemu_io 95a1144c0dSKevin Wolf 96a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0x55 0x80000 0x20000" "$TEST_IMG" | _filter_qemu_io 97a1144c0dSKevin Wolf 98a1144c0dSKevin Wolfecho 99a1144c0dSKevin Wolfecho "== unallocated -> zero ==" 100a1144c0dSKevin Wolf 101a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x66 0xa0000 0x20000" "$TEST_IMG.base" | _filter_qemu_io 102a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0 0xa0000 0x10000" "$TEST_IMG.base" | _filter_qemu_io 103a1144c0dSKevin Wolf$QEMU_IO -c "write -z 0xb0000 0x10000" "$TEST_IMG" | _filter_qemu_io 104a1144c0dSKevin Wolf 105a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0 0xa0000 0x20000" "$TEST_IMG" | _filter_qemu_io 106a1144c0dSKevin Wolf 107a1144c0dSKevin Wolfecho 108a1144c0dSKevin Wolfecho 109a1144c0dSKevin Wolfecho "== compressed -> normal ==" 110a1144c0dSKevin Wolf 111a1144c0dSKevin Wolf$QEMU_IO -c "write -c -P 0x77 0xc0000 0x10000" "$TEST_IMG" | _filter_qemu_io 112a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x77 0xd0000 0x10000" "$TEST_IMG" | _filter_qemu_io 113a1144c0dSKevin Wolf 114a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0x77 0xc0000 0x20000" "$TEST_IMG" | _filter_qemu_io 115a1144c0dSKevin Wolf 116a1144c0dSKevin Wolfecho 117a1144c0dSKevin Wolfecho "== compressed -> unallocated ==" 118a1144c0dSKevin Wolf 119a1144c0dSKevin Wolf$QEMU_IO -c "write -c -P 0x88 0xe0000 0x10000" "$TEST_IMG" | _filter_qemu_io 120a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x88 0xf0000 0x10000" "$TEST_IMG.base" | _filter_qemu_io 121a1144c0dSKevin Wolf 122a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0x88 0xe0000 0x20000" "$TEST_IMG" | _filter_qemu_io 123a1144c0dSKevin Wolf 124a1144c0dSKevin Wolfecho 125a1144c0dSKevin Wolfecho "== compressed -> zero ==" 126a1144c0dSKevin Wolf 127a1144c0dSKevin Wolf$QEMU_IO -c "write -c -P 0 0x100000 0x10000" "$TEST_IMG" | _filter_qemu_io 128a1144c0dSKevin Wolf$QEMU_IO -c "write -c -P 0x99 0x110000 0x10000" "$TEST_IMG" | _filter_qemu_io 129a1144c0dSKevin Wolf$QEMU_IO -c "write -z 0x110000 0x10000" "$TEST_IMG" | _filter_qemu_io 130a1144c0dSKevin Wolf 131a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0 0x100000 0x20000" "$TEST_IMG" | _filter_qemu_io 132a1144c0dSKevin Wolf 133a1144c0dSKevin Wolfecho 134a1144c0dSKevin Wolfecho 135a1144c0dSKevin Wolfecho "== zero -> normal ==" 136a1144c0dSKevin Wolf 137a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0xaa 0x120000 0x10000" "$TEST_IMG" | _filter_qemu_io 138a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0 0x130000 0x10000" "$TEST_IMG" | _filter_qemu_io 139a1144c0dSKevin Wolf$QEMU_IO -c "write -z 0x120000 0x10000" "$TEST_IMG" | _filter_qemu_io 140a1144c0dSKevin Wolf 141a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0 0x120000 0x20000" "$TEST_IMG" | _filter_qemu_io 142a1144c0dSKevin Wolf 143a1144c0dSKevin Wolfecho 144a1144c0dSKevin Wolfecho "== zero -> unallocated ==" 145a1144c0dSKevin Wolf 146a1144c0dSKevin Wolf$QEMU_IO -c "write -z 0x140000 0x10000" "$TEST_IMG" | _filter_qemu_io 147a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0 0x150000 0x10000" "$TEST_IMG.base" | _filter_qemu_io 148a1144c0dSKevin Wolf 149a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0 0x140000 0x20000" "$TEST_IMG" | _filter_qemu_io 150a1144c0dSKevin Wolf 151a1144c0dSKevin Wolfecho 152a1144c0dSKevin Wolfecho "== zero -> compressed ==" 153a1144c0dSKevin Wolf 154a1144c0dSKevin Wolf$QEMU_IO -c "write -c -P 0 0x170000 0x10000" "$TEST_IMG" | _filter_qemu_io 155a1144c0dSKevin Wolf$QEMU_IO -c "write -z 0x160000 0x10000" "$TEST_IMG" | _filter_qemu_io 156a1144c0dSKevin Wolf 157a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0 0x160000 0x20000" "$TEST_IMG" | _filter_qemu_io 158a1144c0dSKevin Wolf 159a1144c0dSKevin Wolf 160a1144c0dSKevin Wolf_check_test_img 161a1144c0dSKevin Wolf 162a1144c0dSKevin Wolf# success, all done 163a1144c0dSKevin Wolfecho "*** done" 164a1144c0dSKevin Wolfrm -f $seq.full 165a1144c0dSKevin Wolfstatus=0 166