111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 2*9dd003a9SVladimir Sementsov-Ogievskiy# group: rw auto quick 3a1144c0dSKevin Wolf# 4a1144c0dSKevin Wolf# Test count_contiguous_clusters in qcow2 5a1144c0dSKevin Wolf# 6a1144c0dSKevin Wolf# Copyright (C) 2013 Red Hat, Inc. 7a1144c0dSKevin Wolf# 8a1144c0dSKevin Wolf# This program is free software; you can redistribute it and/or modify 9a1144c0dSKevin Wolf# it under the terms of the GNU General Public License as published by 10a1144c0dSKevin Wolf# the Free Software Foundation; either version 2 of the License, or 11a1144c0dSKevin Wolf# (at your option) any later version. 12a1144c0dSKevin Wolf# 13a1144c0dSKevin Wolf# This program is distributed in the hope that it will be useful, 14a1144c0dSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 15a1144c0dSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16a1144c0dSKevin Wolf# GNU General Public License for more details. 17a1144c0dSKevin Wolf# 18a1144c0dSKevin Wolf# You should have received a copy of the GNU General Public License 19a1144c0dSKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 20a1144c0dSKevin Wolf# 21a1144c0dSKevin Wolf 22a1144c0dSKevin Wolf# creator 23a1144c0dSKevin Wolfowner=kwolf@redhat.com 24a1144c0dSKevin Wolf 25a1144c0dSKevin Wolfseq=`basename $0` 26a1144c0dSKevin Wolfecho "QA output created by $seq" 27a1144c0dSKevin Wolf 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 423be2024aSMax Reitz# External data files do not support compressed clusters 433be2024aSMax Reitz# (TODO: Consider writing a version for external data files that does 443be2024aSMax Reitz# not test compressed clusters) 453be2024aSMax 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 55b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG.base" -F $IMGFMT 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