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