1*11a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 2319fc53eSStefan Hajnoczi# 3319fc53eSStefan Hajnoczi# Test error code paths for invalid QED images 4319fc53eSStefan Hajnoczi# 5319fc53eSStefan Hajnoczi# The aim of this test is to exercise the error paths in qed_open() to ensure 6319fc53eSStefan Hajnoczi# there are no crashes with invalid input files. 7319fc53eSStefan Hajnoczi# 8319fc53eSStefan Hajnoczi# Copyright (C) 2015 Red Hat, Inc. 9319fc53eSStefan Hajnoczi# 10319fc53eSStefan Hajnoczi# This program is free software; you can redistribute it and/or modify 11319fc53eSStefan Hajnoczi# it under the terms of the GNU General Public License as published by 12319fc53eSStefan Hajnoczi# the Free Software Foundation; either version 2 of the License, or 13319fc53eSStefan Hajnoczi# (at your option) any later version. 14319fc53eSStefan Hajnoczi# 15319fc53eSStefan Hajnoczi# This program is distributed in the hope that it will be useful, 16319fc53eSStefan Hajnoczi# but WITHOUT ANY WARRANTY; without even the implied warranty of 17319fc53eSStefan Hajnoczi# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18319fc53eSStefan Hajnoczi# GNU General Public License for more details. 19319fc53eSStefan Hajnoczi# 20319fc53eSStefan Hajnoczi# You should have received a copy of the GNU General Public License 21319fc53eSStefan Hajnoczi# along with this program. If not, see <http://www.gnu.org/licenses/>. 22319fc53eSStefan Hajnoczi# 23319fc53eSStefan Hajnoczi 24319fc53eSStefan Hajnoczi# creator 25319fc53eSStefan Hajnocziowner=stefanha@redhat.com 26319fc53eSStefan Hajnoczi 27319fc53eSStefan Hajnocziseq=`basename $0` 28319fc53eSStefan Hajnocziecho "QA output created by $seq" 29319fc53eSStefan Hajnoczi 30319fc53eSStefan Hajnoczistatus=1 # failure is the default! 31319fc53eSStefan Hajnoczi 32319fc53eSStefan Hajnoczi_cleanup() 33319fc53eSStefan Hajnoczi{ 34319fc53eSStefan Hajnoczi _cleanup_test_img 35319fc53eSStefan Hajnoczi} 36319fc53eSStefan Hajnoczitrap "_cleanup; exit \$status" 0 1 2 3 15 37319fc53eSStefan Hajnoczi 38319fc53eSStefan Hajnoczi# get standard environment, filters and checks 39319fc53eSStefan Hajnoczi. ./common.rc 40319fc53eSStefan Hajnoczi. ./common.filter 41319fc53eSStefan Hajnoczi 42319fc53eSStefan Hajnoczi_supported_fmt qed 43319fc53eSStefan Hajnoczi_supported_proto generic 44319fc53eSStefan Hajnoczi_supported_os Linux 45319fc53eSStefan Hajnoczi 46319fc53eSStefan Hajnoczi 47319fc53eSStefan Hajnoczisize=128M 48319fc53eSStefan Hajnoczi 49319fc53eSStefan Hajnocziecho 50319fc53eSStefan Hajnocziecho "== truncated header cluster ==" 51319fc53eSStefan Hajnoczi_make_test_img $size 52319fc53eSStefan Hajnoczitruncate -s 512 "$TEST_IMG" 53319fc53eSStefan Hajnoczi$QEMU_IO -f "$IMGFMT" -c "read 0 $size" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 54319fc53eSStefan Hajnoczi 55319fc53eSStefan Hajnocziecho 56319fc53eSStefan Hajnocziecho "== invalid header magic ==" 57319fc53eSStefan Hajnoczi_make_test_img $size 58319fc53eSStefan Hajnoczipoke_file "$TEST_IMG" "0" "QEDX" 59319fc53eSStefan Hajnoczi$QEMU_IO -f "$IMGFMT" -c "read 0 $size" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 60319fc53eSStefan Hajnoczi 61319fc53eSStefan Hajnocziecho 62319fc53eSStefan Hajnocziecho "== invalid cluster size ==" 63319fc53eSStefan Hajnoczi_make_test_img $size 64319fc53eSStefan Hajnoczipoke_file "$TEST_IMG" "4" "\xff\xff\xff\xff" 65319fc53eSStefan Hajnoczi$QEMU_IO -f "$IMGFMT" -c "read 0 $size" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 66319fc53eSStefan Hajnoczi 67319fc53eSStefan Hajnocziecho 68319fc53eSStefan Hajnocziecho "== invalid table size ==" 69319fc53eSStefan Hajnoczi_make_test_img $size 70319fc53eSStefan Hajnoczipoke_file "$TEST_IMG" "8" "\xff\xff\xff\xff" 71319fc53eSStefan Hajnoczi$QEMU_IO -f "$IMGFMT" -c "read 0 $size" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 72319fc53eSStefan Hajnoczi 73319fc53eSStefan Hajnocziecho 74319fc53eSStefan Hajnocziecho "== invalid header size ==" 75319fc53eSStefan Hajnoczi_make_test_img $size 76319fc53eSStefan Hajnoczipoke_file "$TEST_IMG" "12" "\xff\xff\xff\xff" 77319fc53eSStefan Hajnoczi$QEMU_IO -f "$IMGFMT" -c "read 0 $size" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 78319fc53eSStefan Hajnoczi 79319fc53eSStefan Hajnocziecho 80319fc53eSStefan Hajnocziecho "== invalid L1 table offset ==" 81319fc53eSStefan Hajnoczi_make_test_img $size 82319fc53eSStefan Hajnoczipoke_file "$TEST_IMG" "40" "\xff\xff\xff\xff\xff\xff\xff\xff" 83319fc53eSStefan Hajnoczi$QEMU_IO -f "$IMGFMT" -c "read 0 $size" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 84319fc53eSStefan Hajnoczi 85319fc53eSStefan Hajnocziecho 86319fc53eSStefan Hajnocziecho "== invalid image size ==" 87319fc53eSStefan Hajnoczi_make_test_img $size 88319fc53eSStefan Hajnoczipoke_file "$TEST_IMG" "48" "\xff\xff\xff\xff\xff\xff\xff\xff" 89319fc53eSStefan Hajnoczi$QEMU_IO -f "$IMGFMT" -c "read 0 $size" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 90319fc53eSStefan Hajnoczi 91319fc53eSStefan Hajnoczi# success, all done 92319fc53eSStefan Hajnocziecho "*** done" 93319fc53eSStefan Hajnoczirm -f $seq.full 94319fc53eSStefan Hajnoczistatus=0 95