111a82d14SPhilippe 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 42*3be2024aSMax Reitz# External data files do not support compressed clusters 43*3be2024aSMax Reitz# (TODO: Consider writing a version for external data files that does 44*3be2024aSMax Reitz# not test compressed clusters) 45*3be2024aSMax Reitz_unsupported_imgopts data_file 46a1144c0dSKevin Wolf 47a1144c0dSKevin WolfCLUSTER_SIZE=64k 48a1144c0dSKevin Wolfsize=128M 49a1144c0dSKevin Wolf 50a1144c0dSKevin Wolfecho 51a1144c0dSKevin Wolfecho "== creating backing file ==" 52a1144c0dSKevin Wolf 53a1144c0dSKevin WolfTEST_IMG="$TEST_IMG.base" _make_test_img $size 54a1144c0dSKevin Wolf 55a1144c0dSKevin Wolf_make_test_img -b "$TEST_IMG.base" 56a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0xa5 0 $size" "$TEST_IMG.base" | _filter_qemu_io 57a1144c0dSKevin Wolf 58a1144c0dSKevin Wolfecho 59a1144c0dSKevin Wolfecho "== normal -> unallocated ==" 60a1144c0dSKevin Wolf 61a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x11 0 0x10000" "$TEST_IMG" | _filter_qemu_io 62a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x11 0x10000 0x10000" "$TEST_IMG.base" | _filter_qemu_io 63a1144c0dSKevin Wolf 64a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0x11 0 0x20000" "$TEST_IMG" | _filter_qemu_io 65a1144c0dSKevin Wolf 66a1144c0dSKevin Wolfecho 67a1144c0dSKevin Wolfecho "== normal -> compressed ==" 68a1144c0dSKevin Wolf 69a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x22 0x20000 0x10000" "$TEST_IMG" | _filter_qemu_io 70a1144c0dSKevin Wolf$QEMU_IO -c "write -c -P 0x22 0x30000 0x10000" "$TEST_IMG" | _filter_qemu_io 71a1144c0dSKevin Wolf 72a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0x22 0x20000 0x20000" "$TEST_IMG" | _filter_qemu_io 73a1144c0dSKevin Wolf 74a1144c0dSKevin Wolfecho 75a1144c0dSKevin Wolfecho "== normal -> zero ==" 76a1144c0dSKevin Wolf 77a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x33 0x40000 0x20000" "$TEST_IMG" | _filter_qemu_io 78a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x33 0x40000 0x20000" "$TEST_IMG.base" | _filter_qemu_io 79a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0 0x40000 0x10000" "$TEST_IMG" | _filter_qemu_io 80a1144c0dSKevin Wolf$QEMU_IO -c "write -z 0x50000 0x10000" "$TEST_IMG" | _filter_qemu_io 81a1144c0dSKevin Wolf 82a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0 0x40000 0x20000" "$TEST_IMG" | _filter_qemu_io 83a1144c0dSKevin Wolf 84a1144c0dSKevin Wolfecho 85a1144c0dSKevin Wolfecho 86a1144c0dSKevin Wolfecho "== unallocated -> normal ==" 87a1144c0dSKevin Wolf 88a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x44 0x60000 0x10000" "$TEST_IMG.base" | _filter_qemu_io 89a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x44 0x70000 0x10000" "$TEST_IMG" | _filter_qemu_io 90a1144c0dSKevin Wolf 91a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0x44 0x60000 0x20000" "$TEST_IMG" | _filter_qemu_io 92a1144c0dSKevin Wolf 93a1144c0dSKevin Wolfecho 94a1144c0dSKevin Wolfecho "== unallocated -> compressed ==" 95a1144c0dSKevin Wolf 96a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x55 0x80000 0x10000" "$TEST_IMG.base" | _filter_qemu_io 97a1144c0dSKevin Wolf$QEMU_IO -c "write -c -P 0x55 0x90000 0x10000" "$TEST_IMG" | _filter_qemu_io 98a1144c0dSKevin Wolf 99a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0x55 0x80000 0x20000" "$TEST_IMG" | _filter_qemu_io 100a1144c0dSKevin Wolf 101a1144c0dSKevin Wolfecho 102a1144c0dSKevin Wolfecho "== unallocated -> zero ==" 103a1144c0dSKevin Wolf 104a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x66 0xa0000 0x20000" "$TEST_IMG.base" | _filter_qemu_io 105a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0 0xa0000 0x10000" "$TEST_IMG.base" | _filter_qemu_io 106a1144c0dSKevin Wolf$QEMU_IO -c "write -z 0xb0000 0x10000" "$TEST_IMG" | _filter_qemu_io 107a1144c0dSKevin Wolf 108a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0 0xa0000 0x20000" "$TEST_IMG" | _filter_qemu_io 109a1144c0dSKevin Wolf 110a1144c0dSKevin Wolfecho 111a1144c0dSKevin Wolfecho 112a1144c0dSKevin Wolfecho "== compressed -> normal ==" 113a1144c0dSKevin Wolf 114a1144c0dSKevin Wolf$QEMU_IO -c "write -c -P 0x77 0xc0000 0x10000" "$TEST_IMG" | _filter_qemu_io 115a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x77 0xd0000 0x10000" "$TEST_IMG" | _filter_qemu_io 116a1144c0dSKevin Wolf 117a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0x77 0xc0000 0x20000" "$TEST_IMG" | _filter_qemu_io 118a1144c0dSKevin Wolf 119a1144c0dSKevin Wolfecho 120a1144c0dSKevin Wolfecho "== compressed -> unallocated ==" 121a1144c0dSKevin Wolf 122a1144c0dSKevin Wolf$QEMU_IO -c "write -c -P 0x88 0xe0000 0x10000" "$TEST_IMG" | _filter_qemu_io 123a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0x88 0xf0000 0x10000" "$TEST_IMG.base" | _filter_qemu_io 124a1144c0dSKevin Wolf 125a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0x88 0xe0000 0x20000" "$TEST_IMG" | _filter_qemu_io 126a1144c0dSKevin Wolf 127a1144c0dSKevin Wolfecho 128a1144c0dSKevin Wolfecho "== compressed -> zero ==" 129a1144c0dSKevin Wolf 130a1144c0dSKevin Wolf$QEMU_IO -c "write -c -P 0 0x100000 0x10000" "$TEST_IMG" | _filter_qemu_io 131a1144c0dSKevin Wolf$QEMU_IO -c "write -c -P 0x99 0x110000 0x10000" "$TEST_IMG" | _filter_qemu_io 132a1144c0dSKevin Wolf$QEMU_IO -c "write -z 0x110000 0x10000" "$TEST_IMG" | _filter_qemu_io 133a1144c0dSKevin Wolf 134a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0 0x100000 0x20000" "$TEST_IMG" | _filter_qemu_io 135a1144c0dSKevin Wolf 136a1144c0dSKevin Wolfecho 137a1144c0dSKevin Wolfecho 138a1144c0dSKevin Wolfecho "== zero -> normal ==" 139a1144c0dSKevin Wolf 140a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0xaa 0x120000 0x10000" "$TEST_IMG" | _filter_qemu_io 141a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0 0x130000 0x10000" "$TEST_IMG" | _filter_qemu_io 142a1144c0dSKevin Wolf$QEMU_IO -c "write -z 0x120000 0x10000" "$TEST_IMG" | _filter_qemu_io 143a1144c0dSKevin Wolf 144a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0 0x120000 0x20000" "$TEST_IMG" | _filter_qemu_io 145a1144c0dSKevin Wolf 146a1144c0dSKevin Wolfecho 147a1144c0dSKevin Wolfecho "== zero -> unallocated ==" 148a1144c0dSKevin Wolf 149a1144c0dSKevin Wolf$QEMU_IO -c "write -z 0x140000 0x10000" "$TEST_IMG" | _filter_qemu_io 150a1144c0dSKevin Wolf$QEMU_IO -c "write -P 0 0x150000 0x10000" "$TEST_IMG.base" | _filter_qemu_io 151a1144c0dSKevin Wolf 152a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0 0x140000 0x20000" "$TEST_IMG" | _filter_qemu_io 153a1144c0dSKevin Wolf 154a1144c0dSKevin Wolfecho 155a1144c0dSKevin Wolfecho "== zero -> compressed ==" 156a1144c0dSKevin Wolf 157a1144c0dSKevin Wolf$QEMU_IO -c "write -c -P 0 0x170000 0x10000" "$TEST_IMG" | _filter_qemu_io 158a1144c0dSKevin Wolf$QEMU_IO -c "write -z 0x160000 0x10000" "$TEST_IMG" | _filter_qemu_io 159a1144c0dSKevin Wolf 160a1144c0dSKevin Wolf$QEMU_IO -c "read -P 0 0x160000 0x20000" "$TEST_IMG" | _filter_qemu_io 161a1144c0dSKevin Wolf 162a1144c0dSKevin Wolf 163a1144c0dSKevin Wolf_check_test_img 164a1144c0dSKevin Wolf 165a1144c0dSKevin Wolf# success, all done 166a1144c0dSKevin Wolfecho "*** done" 167a1144c0dSKevin Wolfrm -f $seq.full 168a1144c0dSKevin Wolfstatus=0 169