xref: /openbmc/qemu/tests/qemu-iotests/116 (revision 319fc53e344d5cead970c74f088ae5c607d426b3)
1*319fc53eSStefan Hajnoczi#!/bin/bash
2*319fc53eSStefan Hajnoczi#
3*319fc53eSStefan Hajnoczi# Test error code paths for invalid QED images
4*319fc53eSStefan Hajnoczi#
5*319fc53eSStefan Hajnoczi# The aim of this test is to exercise the error paths in qed_open() to ensure
6*319fc53eSStefan Hajnoczi# there are no crashes with invalid input files.
7*319fc53eSStefan Hajnoczi#
8*319fc53eSStefan Hajnoczi# Copyright (C) 2015 Red Hat, Inc.
9*319fc53eSStefan Hajnoczi#
10*319fc53eSStefan Hajnoczi# This program is free software; you can redistribute it and/or modify
11*319fc53eSStefan Hajnoczi# it under the terms of the GNU General Public License as published by
12*319fc53eSStefan Hajnoczi# the Free Software Foundation; either version 2 of the License, or
13*319fc53eSStefan Hajnoczi# (at your option) any later version.
14*319fc53eSStefan Hajnoczi#
15*319fc53eSStefan Hajnoczi# This program is distributed in the hope that it will be useful,
16*319fc53eSStefan Hajnoczi# but WITHOUT ANY WARRANTY; without even the implied warranty of
17*319fc53eSStefan Hajnoczi# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*319fc53eSStefan Hajnoczi# GNU General Public License for more details.
19*319fc53eSStefan Hajnoczi#
20*319fc53eSStefan Hajnoczi# You should have received a copy of the GNU General Public License
21*319fc53eSStefan Hajnoczi# along with this program.  If not, see <http://www.gnu.org/licenses/>.
22*319fc53eSStefan Hajnoczi#
23*319fc53eSStefan Hajnoczi
24*319fc53eSStefan Hajnoczi# creator
25*319fc53eSStefan Hajnocziowner=stefanha@redhat.com
26*319fc53eSStefan Hajnoczi
27*319fc53eSStefan Hajnocziseq=`basename $0`
28*319fc53eSStefan Hajnocziecho "QA output created by $seq"
29*319fc53eSStefan Hajnoczi
30*319fc53eSStefan Hajnoczihere=`pwd`
31*319fc53eSStefan Hajnoczitmp=/tmp/$$
32*319fc53eSStefan Hajnoczistatus=1	# failure is the default!
33*319fc53eSStefan Hajnoczi
34*319fc53eSStefan Hajnoczi_cleanup()
35*319fc53eSStefan Hajnoczi{
36*319fc53eSStefan Hajnoczi	_cleanup_test_img
37*319fc53eSStefan Hajnoczi}
38*319fc53eSStefan Hajnoczitrap "_cleanup; exit \$status" 0 1 2 3 15
39*319fc53eSStefan Hajnoczi
40*319fc53eSStefan Hajnoczi# get standard environment, filters and checks
41*319fc53eSStefan Hajnoczi. ./common.rc
42*319fc53eSStefan Hajnoczi. ./common.filter
43*319fc53eSStefan Hajnoczi
44*319fc53eSStefan Hajnoczi_supported_fmt qed
45*319fc53eSStefan Hajnoczi_supported_proto generic
46*319fc53eSStefan Hajnoczi_supported_os Linux
47*319fc53eSStefan Hajnoczi
48*319fc53eSStefan Hajnoczi
49*319fc53eSStefan Hajnoczisize=128M
50*319fc53eSStefan Hajnoczi
51*319fc53eSStefan Hajnocziecho
52*319fc53eSStefan Hajnocziecho "== truncated header cluster =="
53*319fc53eSStefan Hajnoczi_make_test_img $size
54*319fc53eSStefan Hajnoczitruncate -s 512 "$TEST_IMG"
55*319fc53eSStefan Hajnoczi$QEMU_IO -f "$IMGFMT" -c "read 0 $size" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
56*319fc53eSStefan Hajnoczi
57*319fc53eSStefan Hajnocziecho
58*319fc53eSStefan Hajnocziecho "== invalid header magic =="
59*319fc53eSStefan Hajnoczi_make_test_img $size
60*319fc53eSStefan Hajnoczipoke_file "$TEST_IMG" "0" "QEDX"
61*319fc53eSStefan Hajnoczi$QEMU_IO -f "$IMGFMT" -c "read 0 $size" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
62*319fc53eSStefan Hajnoczi
63*319fc53eSStefan Hajnocziecho
64*319fc53eSStefan Hajnocziecho "== invalid cluster size =="
65*319fc53eSStefan Hajnoczi_make_test_img $size
66*319fc53eSStefan Hajnoczipoke_file "$TEST_IMG" "4" "\xff\xff\xff\xff"
67*319fc53eSStefan Hajnoczi$QEMU_IO -f "$IMGFMT" -c "read 0 $size" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
68*319fc53eSStefan Hajnoczi
69*319fc53eSStefan Hajnocziecho
70*319fc53eSStefan Hajnocziecho "== invalid table size =="
71*319fc53eSStefan Hajnoczi_make_test_img $size
72*319fc53eSStefan Hajnoczipoke_file "$TEST_IMG" "8" "\xff\xff\xff\xff"
73*319fc53eSStefan Hajnoczi$QEMU_IO -f "$IMGFMT" -c "read 0 $size" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
74*319fc53eSStefan Hajnoczi
75*319fc53eSStefan Hajnocziecho
76*319fc53eSStefan Hajnocziecho "== invalid header size =="
77*319fc53eSStefan Hajnoczi_make_test_img $size
78*319fc53eSStefan Hajnoczipoke_file "$TEST_IMG" "12" "\xff\xff\xff\xff"
79*319fc53eSStefan Hajnoczi$QEMU_IO -f "$IMGFMT" -c "read 0 $size" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
80*319fc53eSStefan Hajnoczi
81*319fc53eSStefan Hajnocziecho
82*319fc53eSStefan Hajnocziecho "== invalid L1 table offset =="
83*319fc53eSStefan Hajnoczi_make_test_img $size
84*319fc53eSStefan Hajnoczipoke_file "$TEST_IMG" "40" "\xff\xff\xff\xff\xff\xff\xff\xff"
85*319fc53eSStefan Hajnoczi$QEMU_IO -f "$IMGFMT" -c "read 0 $size" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
86*319fc53eSStefan Hajnoczi
87*319fc53eSStefan Hajnocziecho
88*319fc53eSStefan Hajnocziecho "== invalid image size =="
89*319fc53eSStefan Hajnoczi_make_test_img $size
90*319fc53eSStefan Hajnoczipoke_file "$TEST_IMG" "48" "\xff\xff\xff\xff\xff\xff\xff\xff"
91*319fc53eSStefan Hajnoczi$QEMU_IO -f "$IMGFMT" -c "read 0 $size" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
92*319fc53eSStefan Hajnoczi
93*319fc53eSStefan Hajnoczi# success, all done
94*319fc53eSStefan Hajnocziecho "*** done"
95*319fc53eSStefan Hajnoczirm -f $seq.full
96*319fc53eSStefan Hajnoczistatus=0
97