105560fceSStefan Hajnoczi#!/bin/bash 205560fceSStefan Hajnoczi# 305560fceSStefan Hajnoczi# cloop format input validation tests 405560fceSStefan Hajnoczi# 505560fceSStefan Hajnoczi# Copyright (C) 2013 Red Hat, Inc. 605560fceSStefan Hajnoczi# 705560fceSStefan Hajnoczi# This program is free software; you can redistribute it and/or modify 805560fceSStefan Hajnoczi# it under the terms of the GNU General Public License as published by 905560fceSStefan Hajnoczi# the Free Software Foundation; either version 2 of the License, or 1005560fceSStefan Hajnoczi# (at your option) any later version. 1105560fceSStefan Hajnoczi# 1205560fceSStefan Hajnoczi# This program is distributed in the hope that it will be useful, 1305560fceSStefan Hajnoczi# but WITHOUT ANY WARRANTY; without even the implied warranty of 1405560fceSStefan Hajnoczi# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1505560fceSStefan Hajnoczi# GNU General Public License for more details. 1605560fceSStefan Hajnoczi# 1705560fceSStefan Hajnoczi# You should have received a copy of the GNU General Public License 1805560fceSStefan Hajnoczi# along with this program. If not, see <http://www.gnu.org/licenses/>. 1905560fceSStefan Hajnoczi# 2005560fceSStefan Hajnoczi 2105560fceSStefan Hajnoczi# creator 2205560fceSStefan Hajnocziowner=stefanha@redhat.com 2305560fceSStefan Hajnoczi 2405560fceSStefan Hajnocziseq=`basename $0` 2505560fceSStefan Hajnocziecho "QA output created by $seq" 2605560fceSStefan Hajnoczi 2705560fceSStefan Hajnoczihere=`pwd` 2805560fceSStefan Hajnoczitmp=/tmp/$$ 2905560fceSStefan Hajnoczistatus=1 # failure is the default! 3005560fceSStefan Hajnoczi 3105560fceSStefan Hajnoczi_cleanup() 3205560fceSStefan Hajnoczi{ 3305560fceSStefan Hajnoczi _cleanup_test_img 3405560fceSStefan Hajnoczi} 3505560fceSStefan Hajnoczitrap "_cleanup; exit \$status" 0 1 2 3 15 3605560fceSStefan Hajnoczi 3705560fceSStefan Hajnoczi# get standard environment, filters and checks 3805560fceSStefan Hajnoczi. ./common.rc 3905560fceSStefan Hajnoczi. ./common.filter 4005560fceSStefan Hajnoczi 4105560fceSStefan Hajnoczi_supported_fmt cloop 42*c5f7c0afSPeter Lieven_supported_proto file 4305560fceSStefan Hajnoczi_supported_os Linux 4405560fceSStefan Hajnoczi 45d65f97a8SStefan Hajnocziblock_size_offset=128 46509a41baSStefan Hajnoczin_blocks_offset=132 47f56b9bc3SStefan Hajnoczioffsets_offset=136 48d65f97a8SStefan Hajnoczi 4905560fceSStefan Hajnocziecho 5005560fceSStefan Hajnocziecho "== check that the first sector can be read ==" 5105560fceSStefan Hajnoczi_use_sample_img simple-pattern.cloop.bz2 5205560fceSStefan Hajnoczi$QEMU_IO -c "read 0 512" $TEST_IMG 2>&1 | _filter_qemu_io | _filter_testdir 5305560fceSStefan Hajnoczi 54d65f97a8SStefan Hajnocziecho 5542d43d35SStefan Hajnocziecho "== check that the last sector can be read ==" 5642d43d35SStefan Hajnoczi_use_sample_img simple-pattern.cloop.bz2 5742d43d35SStefan Hajnoczi$QEMU_IO -c "read $((1024 * 1024 - 512)) 512" $TEST_IMG 2>&1 | _filter_qemu_io | _filter_testdir 5842d43d35SStefan Hajnoczi 5942d43d35SStefan Hajnocziecho 60d65f97a8SStefan Hajnocziecho "== block_size must be a multiple of 512 ==" 61d65f97a8SStefan Hajnoczi_use_sample_img simple-pattern.cloop.bz2 62d65f97a8SStefan Hajnoczipoke_file "$TEST_IMG" "$block_size_offset" "\x00\x00\x02\x01" 63d65f97a8SStefan Hajnoczi$QEMU_IO -c "read 0 512" $TEST_IMG 2>&1 | _filter_qemu_io | _filter_testdir 64d65f97a8SStefan Hajnoczi 65d65f97a8SStefan Hajnocziecho 66d65f97a8SStefan Hajnocziecho "== block_size cannot be zero ==" 67d65f97a8SStefan Hajnoczi_use_sample_img simple-pattern.cloop.bz2 68d65f97a8SStefan Hajnoczipoke_file "$TEST_IMG" "$block_size_offset" "\x00\x00\x00\x00" 69d65f97a8SStefan Hajnoczi$QEMU_IO -c "read 0 512" $TEST_IMG 2>&1 | _filter_qemu_io | _filter_testdir 70d65f97a8SStefan Hajnoczi 71d65f97a8SStefan Hajnocziecho 72d65f97a8SStefan Hajnocziecho "== huge block_size ===" 73d65f97a8SStefan Hajnoczi_use_sample_img simple-pattern.cloop.bz2 74d65f97a8SStefan Hajnoczipoke_file "$TEST_IMG" "$block_size_offset" "\xff\xff\xfe\x00" 75d65f97a8SStefan Hajnoczi$QEMU_IO -c "read 0 512" $TEST_IMG 2>&1 | _filter_qemu_io | _filter_testdir 76d65f97a8SStefan Hajnoczi 77509a41baSStefan Hajnocziecho 78509a41baSStefan Hajnocziecho "== offsets_size overflow ===" 79509a41baSStefan Hajnoczi_use_sample_img simple-pattern.cloop.bz2 80509a41baSStefan Hajnoczipoke_file "$TEST_IMG" "$n_blocks_offset" "\xff\xff\xff\xff" 81509a41baSStefan Hajnoczi$QEMU_IO -c "read 0 512" $TEST_IMG 2>&1 | _filter_qemu_io | _filter_testdir 82509a41baSStefan Hajnoczi 837b103b36SStefan Hajnocziecho 847b103b36SStefan Hajnocziecho "== refuse images that require too many offsets ===" 857b103b36SStefan Hajnoczi_use_sample_img simple-pattern.cloop.bz2 867b103b36SStefan Hajnoczipoke_file "$TEST_IMG" "$n_blocks_offset" "\x04\x00\x00\x01" 877b103b36SStefan Hajnoczi$QEMU_IO -c "read 0 512" $TEST_IMG 2>&1 | _filter_qemu_io | _filter_testdir 887b103b36SStefan Hajnoczi 89f56b9bc3SStefan Hajnocziecho 90f56b9bc3SStefan Hajnocziecho "== refuse images with non-monotonically increasing offsets ==" 91f56b9bc3SStefan Hajnoczi_use_sample_img simple-pattern.cloop.bz2 92f56b9bc3SStefan Hajnoczipoke_file "$TEST_IMG" "$offsets_offset" "\x00\x00\x00\x00\xff\xff\xff\xff" 93f56b9bc3SStefan Hajnoczipoke_file "$TEST_IMG" $((offsets_offset + 8)) "\x00\x00\x00\x00\xff\xfe\x00\x00" 94f56b9bc3SStefan Hajnoczi$QEMU_IO -c "read 0 512" $TEST_IMG 2>&1 | _filter_qemu_io | _filter_testdir 95f56b9bc3SStefan Hajnoczi 96f56b9bc3SStefan Hajnocziecho 97f56b9bc3SStefan Hajnocziecho "== refuse images with invalid compressed block size ==" 98f56b9bc3SStefan Hajnoczi_use_sample_img simple-pattern.cloop.bz2 99f56b9bc3SStefan Hajnoczipoke_file "$TEST_IMG" "$offsets_offset" "\x00\x00\x00\x00\x00\x00\x00\x00" 100f56b9bc3SStefan Hajnoczipoke_file "$TEST_IMG" $((offsets_offset + 8)) "\xff\xff\xff\xff\xff\xff\xff\xff" 101f56b9bc3SStefan Hajnoczi$QEMU_IO -c "read 0 512" $TEST_IMG 2>&1 | _filter_qemu_io | _filter_testdir 102f56b9bc3SStefan Hajnoczi 10305560fceSStefan Hajnoczi# success, all done 10405560fceSStefan Hajnocziecho "*** done" 10505560fceSStefan Hajnoczirm -f $seq.full 10605560fceSStefan Hajnoczistatus=0 107