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