xref: /openbmc/qemu/tests/qemu-iotests/092 (revision f91ecbd7)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env 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 Wolfstatus=1	# failure is the default!
287159a45bSKevin Wolf
297159a45bSKevin Wolf_cleanup()
307159a45bSKevin Wolf{
31*f91ecbd7SMax Reitz    _rm_test_img "$TEST_IMG.snap"
327159a45bSKevin Wolf    _cleanup_test_img
337159a45bSKevin Wolf}
347159a45bSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
357159a45bSKevin Wolf
367159a45bSKevin Wolf# get standard environment, filters and checks
377159a45bSKevin Wolf. ./common.rc
387159a45bSKevin Wolf. ./common.filter
397159a45bSKevin Wolf
407159a45bSKevin Wolf_supported_fmt qcow
41c5f7c0afSPeter Lieven_supported_proto file
427159a45bSKevin Wolf_supported_os Linux
437159a45bSKevin Wolf
44d66e5ceeSKevin Wolfoffset_backing_file_offset=8
45d66e5ceeSKevin Wolfoffset_backing_file_size=16
4646485de0SKevin 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
7646485de0SKevin Wolfecho
7746485de0SKevin Wolfecho "== Invalid size =="
7846485de0SKevin Wolf_make_test_img 64M
7946485de0SKevin Wolfpoke_file "$TEST_IMG" "$offset_size" "\xee\xee\xee\xee\xee\xee\xee\xee"
8046485de0SKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
8146485de0SKevin Wolfpoke_file "$TEST_IMG" "$offset_size" "\x7f\xff\xff\xff\xff\xff\xff\xff"
8246485de0SKevin Wolf{ $QEMU_IO -c "write 0 64M" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
8346485de0SKevin Wolf
84d66e5ceeSKevin Wolfecho
85d66e5ceeSKevin Wolfecho "== Invalid backing file length =="
86d66e5ceeSKevin Wolf_make_test_img 64M
87d66e5ceeSKevin Wolfpoke_file "$TEST_IMG" "$offset_backing_file_offset" "\x00\x00\x00\xff"
88d66e5ceeSKevin Wolfpoke_file "$TEST_IMG" "$offset_backing_file_size" "\xff\xff\xff\xff"
89d66e5ceeSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
90d66e5ceeSKevin Wolfpoke_file "$TEST_IMG" "$offset_backing_file_size" "\x7f\xff\xff\xff"
91d66e5ceeSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir
92d66e5ceeSKevin Wolf
937159a45bSKevin Wolf# success, all done
947159a45bSKevin Wolfecho "*** done"
957159a45bSKevin Wolfrm -f $seq.full
967159a45bSKevin Wolfstatus=0
97