17159a45bSKevin Wolf#!/bin/bash 27159a45bSKevin Wolf# 37159a45bSKevin Wolf# qcow1 format input validation tests 47159a45bSKevin Wolf# 57159a45bSKevin Wolf# Copyright (C) 2014 Red Hat, Inc. 67159a45bSKevin Wolf# 77159a45bSKevin Wolf# This program is free software; you can redistribute it and/or modify 87159a45bSKevin Wolf# it under the terms of the GNU General Public License as published by 97159a45bSKevin Wolf# the Free Software Foundation; either version 2 of the License, or 107159a45bSKevin Wolf# (at your option) any later version. 117159a45bSKevin Wolf# 127159a45bSKevin Wolf# This program is distributed in the hope that it will be useful, 137159a45bSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 147159a45bSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 157159a45bSKevin Wolf# GNU General Public License for more details. 167159a45bSKevin Wolf# 177159a45bSKevin Wolf# You should have received a copy of the GNU General Public License 187159a45bSKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 197159a45bSKevin Wolf# 207159a45bSKevin Wolf 217159a45bSKevin Wolf# creator 227159a45bSKevin Wolfowner=kwolf@redhat.com 237159a45bSKevin Wolf 247159a45bSKevin Wolfseq=`basename $0` 257159a45bSKevin Wolfecho "QA output created by $seq" 267159a45bSKevin Wolf 277159a45bSKevin Wolfhere=`pwd` 287159a45bSKevin Wolftmp=/tmp/$$ 297159a45bSKevin Wolfstatus=1 # failure is the default! 307159a45bSKevin Wolf 317159a45bSKevin Wolf_cleanup() 327159a45bSKevin Wolf{ 337159a45bSKevin Wolf rm -f $TEST_IMG.snap 347159a45bSKevin Wolf _cleanup_test_img 357159a45bSKevin Wolf} 367159a45bSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 377159a45bSKevin Wolf 387159a45bSKevin Wolf# get standard environment, filters and checks 397159a45bSKevin Wolf. ./common.rc 407159a45bSKevin Wolf. ./common.filter 417159a45bSKevin Wolf 427159a45bSKevin Wolf_supported_fmt qcow 437159a45bSKevin Wolf_supported_proto generic 447159a45bSKevin Wolf_supported_os Linux 457159a45bSKevin Wolf 46*46485de0SKevin Wolfoffset_size=24 477159a45bSKevin Wolfoffset_cluster_bits=32 4842eb5817SKevin Wolfoffset_l2_bits=33 497159a45bSKevin Wolf 507159a45bSKevin Wolfecho 517159a45bSKevin Wolfecho "== Invalid cluster size ==" 527159a45bSKevin Wolf_make_test_img 64M 537159a45bSKevin Wolfpoke_file "$TEST_IMG" "$offset_cluster_bits" "\xff" 547159a45bSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 557159a45bSKevin Wolfpoke_file "$TEST_IMG" "$offset_cluster_bits" "\x1f" 567159a45bSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 577159a45bSKevin Wolfpoke_file "$TEST_IMG" "$offset_cluster_bits" "\x08" 587159a45bSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 597159a45bSKevin Wolfpoke_file "$TEST_IMG" "$offset_cluster_bits" "\x11" 607159a45bSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 617159a45bSKevin Wolf 6242eb5817SKevin Wolfecho 6342eb5817SKevin Wolfecho "== Invalid L2 table size ==" 6442eb5817SKevin Wolf_make_test_img 64M 6542eb5817SKevin Wolfpoke_file "$TEST_IMG" "$offset_l2_bits" "\xff" 6642eb5817SKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 6742eb5817SKevin Wolfpoke_file "$TEST_IMG" "$offset_l2_bits" "\x05" 6842eb5817SKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 6942eb5817SKevin Wolfpoke_file "$TEST_IMG" "$offset_l2_bits" "\x0e" 7042eb5817SKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 7142eb5817SKevin Wolf 7242eb5817SKevin Wolf# 1 << 0x1b = 2^31 / L2_CACHE_SIZE 7342eb5817SKevin Wolfpoke_file "$TEST_IMG" "$offset_l2_bits" "\x1b" 7442eb5817SKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 7542eb5817SKevin Wolf 76*46485de0SKevin Wolfecho 77*46485de0SKevin Wolfecho "== Invalid size ==" 78*46485de0SKevin Wolf_make_test_img 64M 79*46485de0SKevin Wolfpoke_file "$TEST_IMG" "$offset_size" "\xee\xee\xee\xee\xee\xee\xee\xee" 80*46485de0SKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 81*46485de0SKevin Wolfpoke_file "$TEST_IMG" "$offset_size" "\x7f\xff\xff\xff\xff\xff\xff\xff" 82*46485de0SKevin Wolf{ $QEMU_IO -c "write 0 64M" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 83*46485de0SKevin Wolf 847159a45bSKevin Wolf# success, all done 857159a45bSKevin Wolfecho "*** done" 867159a45bSKevin Wolfrm -f $seq.full 877159a45bSKevin Wolfstatus=0 88