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*d66e5ceeSKevin Wolfoffset_backing_file_offset=8 47*d66e5ceeSKevin Wolfoffset_backing_file_size=16 4846485de0SKevin Wolfoffset_size=24 497159a45bSKevin Wolfoffset_cluster_bits=32 5042eb5817SKevin Wolfoffset_l2_bits=33 517159a45bSKevin Wolf 527159a45bSKevin Wolfecho 537159a45bSKevin Wolfecho "== Invalid cluster size ==" 547159a45bSKevin Wolf_make_test_img 64M 557159a45bSKevin Wolfpoke_file "$TEST_IMG" "$offset_cluster_bits" "\xff" 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" "\x1f" 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" "\x08" 607159a45bSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 617159a45bSKevin Wolfpoke_file "$TEST_IMG" "$offset_cluster_bits" "\x11" 627159a45bSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 637159a45bSKevin Wolf 6442eb5817SKevin Wolfecho 6542eb5817SKevin Wolfecho "== Invalid L2 table size ==" 6642eb5817SKevin Wolf_make_test_img 64M 6742eb5817SKevin Wolfpoke_file "$TEST_IMG" "$offset_l2_bits" "\xff" 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" "\x05" 7042eb5817SKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 7142eb5817SKevin Wolfpoke_file "$TEST_IMG" "$offset_l2_bits" "\x0e" 7242eb5817SKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 7342eb5817SKevin Wolf 7442eb5817SKevin Wolf# 1 << 0x1b = 2^31 / L2_CACHE_SIZE 7542eb5817SKevin Wolfpoke_file "$TEST_IMG" "$offset_l2_bits" "\x1b" 7642eb5817SKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 7742eb5817SKevin Wolf 7846485de0SKevin Wolfecho 7946485de0SKevin Wolfecho "== Invalid size ==" 8046485de0SKevin Wolf_make_test_img 64M 8146485de0SKevin Wolfpoke_file "$TEST_IMG" "$offset_size" "\xee\xee\xee\xee\xee\xee\xee\xee" 8246485de0SKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 8346485de0SKevin Wolfpoke_file "$TEST_IMG" "$offset_size" "\x7f\xff\xff\xff\xff\xff\xff\xff" 8446485de0SKevin Wolf{ $QEMU_IO -c "write 0 64M" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 8546485de0SKevin Wolf 86*d66e5ceeSKevin Wolfecho 87*d66e5ceeSKevin Wolfecho "== Invalid backing file length ==" 88*d66e5ceeSKevin Wolf_make_test_img 64M 89*d66e5ceeSKevin Wolfpoke_file "$TEST_IMG" "$offset_backing_file_offset" "\x00\x00\x00\xff" 90*d66e5ceeSKevin Wolfpoke_file "$TEST_IMG" "$offset_backing_file_size" "\xff\xff\xff\xff" 91*d66e5ceeSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 92*d66e5ceeSKevin Wolfpoke_file "$TEST_IMG" "$offset_backing_file_size" "\x7f\xff\xff\xff" 93*d66e5ceeSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 94*d66e5ceeSKevin Wolf 957159a45bSKevin Wolf# success, all done 967159a45bSKevin Wolfecho "*** done" 977159a45bSKevin Wolfrm -f $seq.full 987159a45bSKevin Wolfstatus=0 99