111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 2*9dd003a9SVladimir Sementsov-Ogievskiy# group: rw quick 37159a45bSKevin Wolf# 47159a45bSKevin Wolf# qcow1 format input validation tests 57159a45bSKevin Wolf# 67159a45bSKevin Wolf# Copyright (C) 2014 Red Hat, Inc. 77159a45bSKevin Wolf# 87159a45bSKevin Wolf# This program is free software; you can redistribute it and/or modify 97159a45bSKevin Wolf# it under the terms of the GNU General Public License as published by 107159a45bSKevin Wolf# the Free Software Foundation; either version 2 of the License, or 117159a45bSKevin Wolf# (at your option) any later version. 127159a45bSKevin Wolf# 137159a45bSKevin Wolf# This program is distributed in the hope that it will be useful, 147159a45bSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 157159a45bSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 167159a45bSKevin Wolf# GNU General Public License for more details. 177159a45bSKevin Wolf# 187159a45bSKevin Wolf# You should have received a copy of the GNU General Public License 197159a45bSKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 207159a45bSKevin Wolf# 217159a45bSKevin Wolf 227159a45bSKevin Wolf# creator 237159a45bSKevin Wolfowner=kwolf@redhat.com 247159a45bSKevin Wolf 257159a45bSKevin Wolfseq=`basename $0` 267159a45bSKevin Wolfecho "QA output created by $seq" 277159a45bSKevin Wolf 287159a45bSKevin Wolfstatus=1 # failure is the default! 297159a45bSKevin Wolf 307159a45bSKevin Wolf_cleanup() 317159a45bSKevin Wolf{ 32f91ecbd7SMax Reitz _rm_test_img "$TEST_IMG.snap" 337159a45bSKevin Wolf _cleanup_test_img 347159a45bSKevin Wolf} 357159a45bSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 367159a45bSKevin Wolf 377159a45bSKevin Wolf# get standard environment, filters and checks 387159a45bSKevin Wolf. ./common.rc 397159a45bSKevin Wolf. ./common.filter 407159a45bSKevin Wolf 417159a45bSKevin Wolf_supported_fmt qcow 42c5f7c0afSPeter Lieven_supported_proto file 437159a45bSKevin Wolf_supported_os Linux 447159a45bSKevin Wolf 45d66e5ceeSKevin Wolfoffset_backing_file_offset=8 46d66e5ceeSKevin Wolfoffset_backing_file_size=16 4746485de0SKevin Wolfoffset_size=24 487159a45bSKevin Wolfoffset_cluster_bits=32 4942eb5817SKevin Wolfoffset_l2_bits=33 507159a45bSKevin Wolf 517159a45bSKevin Wolfecho 527159a45bSKevin Wolfecho "== Invalid cluster size ==" 537159a45bSKevin Wolf_make_test_img 64M 547159a45bSKevin Wolfpoke_file "$TEST_IMG" "$offset_cluster_bits" "\xff" 557159a45bSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 567159a45bSKevin Wolfpoke_file "$TEST_IMG" "$offset_cluster_bits" "\x1f" 577159a45bSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 587159a45bSKevin Wolfpoke_file "$TEST_IMG" "$offset_cluster_bits" "\x08" 597159a45bSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 607159a45bSKevin Wolfpoke_file "$TEST_IMG" "$offset_cluster_bits" "\x11" 617159a45bSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 627159a45bSKevin Wolf 6342eb5817SKevin Wolfecho 6442eb5817SKevin Wolfecho "== Invalid L2 table size ==" 6542eb5817SKevin Wolf_make_test_img 64M 6642eb5817SKevin Wolfpoke_file "$TEST_IMG" "$offset_l2_bits" "\xff" 6742eb5817SKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 6842eb5817SKevin Wolfpoke_file "$TEST_IMG" "$offset_l2_bits" "\x05" 6942eb5817SKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 7042eb5817SKevin Wolfpoke_file "$TEST_IMG" "$offset_l2_bits" "\x0e" 7142eb5817SKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 7242eb5817SKevin Wolf 7342eb5817SKevin Wolf# 1 << 0x1b = 2^31 / L2_CACHE_SIZE 7442eb5817SKevin Wolfpoke_file "$TEST_IMG" "$offset_l2_bits" "\x1b" 7542eb5817SKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 7642eb5817SKevin Wolf 7746485de0SKevin Wolfecho 7846485de0SKevin Wolfecho "== Invalid size ==" 7946485de0SKevin Wolf_make_test_img 64M 8046485de0SKevin Wolfpoke_file "$TEST_IMG" "$offset_size" "\xee\xee\xee\xee\xee\xee\xee\xee" 8146485de0SKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 8246485de0SKevin Wolfpoke_file "$TEST_IMG" "$offset_size" "\x7f\xff\xff\xff\xff\xff\xff\xff" 8346485de0SKevin Wolf{ $QEMU_IO -c "write 0 64M" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 8446485de0SKevin Wolf 85d66e5ceeSKevin Wolfecho 86d66e5ceeSKevin Wolfecho "== Invalid backing file length ==" 87d66e5ceeSKevin Wolf_make_test_img 64M 88d66e5ceeSKevin Wolfpoke_file "$TEST_IMG" "$offset_backing_file_offset" "\x00\x00\x00\xff" 89d66e5ceeSKevin Wolfpoke_file "$TEST_IMG" "$offset_backing_file_size" "\xff\xff\xff\xff" 90d66e5ceeSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 91d66e5ceeSKevin Wolfpoke_file "$TEST_IMG" "$offset_backing_file_size" "\x7f\xff\xff\xff" 92d66e5ceeSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 93d66e5ceeSKevin Wolf 947159a45bSKevin Wolf# success, all done 957159a45bSKevin Wolfecho "*** done" 967159a45bSKevin Wolfrm -f $seq.full 977159a45bSKevin Wolfstatus=0 98