xref: /openbmc/qemu/tests/qemu-iotests/174 (revision 0e324626)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
2*9dd003a9SVladimir Sementsov-Ogievskiy# group: auto
3bf68bcb1SNir Soffer#
4bf68bcb1SNir Soffer# Test that qemu-io fail with non-zero exit code
5bf68bcb1SNir Soffer#
6bf68bcb1SNir Soffer# Copyright (C) 2017 Nir Soffer <nirsof@gmail.com>
7bf68bcb1SNir Soffer#
8bf68bcb1SNir Soffer# This program is free software; you can redistribute it and/or modify
9bf68bcb1SNir Soffer# it under the terms of the GNU General Public License as published by
10bf68bcb1SNir Soffer# the Free Software Foundation; either version 2 of the License, or
11bf68bcb1SNir Soffer# (at your option) any later version.
12bf68bcb1SNir Soffer#
13bf68bcb1SNir Soffer# This program is distributed in the hope that it will be useful,
14bf68bcb1SNir Soffer# but WITHOUT ANY WARRANTY; without even the implied warranty of
15bf68bcb1SNir Soffer# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16bf68bcb1SNir Soffer# GNU General Public License for more details.
17bf68bcb1SNir Soffer#
18bf68bcb1SNir Soffer# You should have received a copy of the GNU General Public License
19bf68bcb1SNir Soffer# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20bf68bcb1SNir Soffer#
21bf68bcb1SNir Soffer
22bf68bcb1SNir Soffer# creator
23bf68bcb1SNir Sofferowner=nirsof@gmail.com
24bf68bcb1SNir Soffer
25bf68bcb1SNir Sofferseq=`basename $0`
26bf68bcb1SNir Sofferecho "QA output created by $seq"
27bf68bcb1SNir Soffer
28bf68bcb1SNir Sofferstatus=1	# failure is the default!
29bf68bcb1SNir Soffer
30bf68bcb1SNir Soffer_cleanup()
31bf68bcb1SNir Soffer{
32bf68bcb1SNir Soffer	_cleanup_test_img
33bf68bcb1SNir Soffer}
34bf68bcb1SNir Soffertrap "_cleanup; exit \$status" 0 1 2 3 15
35bf68bcb1SNir Soffer
36bf68bcb1SNir Soffer# get standard environment, filters and checks
37bf68bcb1SNir Soffer. ./common.rc
38bf68bcb1SNir Soffer. ./common.filter
39bf68bcb1SNir Soffer
40bf68bcb1SNir Soffer_unsupported_fmt raw
41bf68bcb1SNir Soffer
42bf68bcb1SNir Soffer
43bf68bcb1SNir Soffersize=256K
44d81fe252SMax Reitz
45d81fe252SMax Reitz# _make_test_img may set variables that we need to retain.  Everything
46d81fe252SMax Reitz# in a pipe is executed in a subshell, so doing so would throw away
47d81fe252SMax Reitz# all changes.  Therefore, we have to store the output in some temp
48d81fe252SMax Reitz# file and filter that.
49d81fe252SMax Reitzscratch_out="$TEST_DIR/img-create.out"
50d81fe252SMax ReitzIMGFMT=raw IMGKEYSECRET= _make_test_img --no-opts $size >"$scratch_out"
51d81fe252SMax Reitz_filter_imgfmt <"$scratch_out"
52d81fe252SMax Reitzrm -f "$scratch_out"
53bf68bcb1SNir Soffer
54bf68bcb1SNir Sofferecho
55bf68bcb1SNir Sofferecho "== reading wrong format should fail =="
56bf68bcb1SNir Soffer$QEMU_IO -f $IMGFMT -c "read 0 $size" "$TEST_IMG" 2>/dev/null
57bf68bcb1SNir Soffertest $? -eq 1 || _fail "did not fail"
58bf68bcb1SNir Soffer
59bf68bcb1SNir Sofferecho
60bf68bcb1SNir Sofferecho "== reading missing file should fail =="
61bf68bcb1SNir Soffer$QEMU_IO -c "read 0 $size" "$TEST_DIR/missing" 2>/dev/null
62bf68bcb1SNir Soffertest $? -eq 1 || _fail "did not fail"
63bf68bcb1SNir Soffer
64bf68bcb1SNir Soffer# success, all done
65bf68bcb1SNir Sofferecho "*** done"
66bf68bcb1SNir Sofferrm -f $seq.full
67bf68bcb1SNir Sofferstatus=0
68