Received: from eggs.gnu.org ([2001:4830:134:3::10]:34750) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1GMD-0007oM-EK for qemu-devel@nongnu.org; Mon, 31 Oct 2016 13:26:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c1GMA-0000Dx-Qm for qemu-devel@nongnu.org; Mon, 31 Oct 2016 13:26:49 -0400 From: Kevin Wolf Date: Mon, 31 Oct 2016 18:25:55 +0100 Message-Id: <1477934758-29332-27-git-send-email-kwolf@redhat.com> In-Reply-To: <1477934758-29332-1-git-send-email-kwolf@redhat.com> References: <1477934758-29332-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 26/29] qemu-iotests: test 'offset' and 'size' options in raw driver List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD Signed-off-by: Kevin Wolf --- tests/qemu-iotests/171 | 212 ++++++++++++++++++++++++++++++ tests/qemu-iotests/171.out | 313 +++++++++++++++++++++++++++++++++++++++= ++++++ tests/qemu-iotests/group | 1 + 3 files changed, 526 insertions(+) create mode 100755 tests/qemu-iotests/171 create mode 100644 tests/qemu-iotests/171.out diff --git a/tests/qemu-iotests/171 b/tests/qemu-iotests/171 new file mode 100755 index 0000000..257be10 --- /dev/null +++ b/tests/qemu-iotests/171 @@ -0,0 +1,212 @@ +#!/bin/bash +# +# Test 'offset' and 'size' options of the raw driver. Make sure we can't +# (or can) read and write outside of the image size. +# +# Copyright (C) 2016 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# creator +owner=3Dtgolembi@redhat.com + +seq=3D`basename $0` +echo "QA output created by $seq" + +here=3D`pwd` +status=3D1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt raw +_supported_proto file +_supported_os Linux + + +# Create JSON with options +img_json() { + echo -n 'json:{"driver":"raw", ' + echo -n "\"offset\":\"$img_offset\", " + if [ "$img_size" -ne -1 ] ; then + echo -n "\"size\":\"$img_size\", " + fi + echo -n '"file": {' + echo -n '"driver":"file", ' + echo -n "\"filename\":\"$TEST_IMG\" " + echo -n "} }" +} + +do_general_test() { + if [ "$img_size" -ge 0 ] ; then + test_size=3D$img_size + else + test_size=3D$((size-img_offset)) + fi + + echo + echo "write to image" + $QEMU_IO -c "write -P 0x0a 0 $test_size" "$(img_json)" | _filter_qem= u_io + + echo + echo "read the image" + $QEMU_IO -c "read -P 0x0a 0 $test_size" "$(img_json)" | _filter_qemu= _io + + echo + echo "check that offset is respected" + $QEMU_IO -c "read -v $((img_offset-2)) 4" $TEST_IMG | _filter_qemu_i= o + + echo + echo "write before image boundary" + $QEMU_IO -c "write $((test_size-1)) 1" "$(img_json)" | _filter_qemu_= io + + echo + echo "write across image boundary" + $QEMU_IO -c "write $((test_size-1)) 2" "$(img_json)" | _filter_qemu_= io + + echo + echo "write at image boundary" + $QEMU_IO -c "write $test_size 1" "$(img_json)" | _filter_qemu_io + + echo + echo "write after image boundary" + $QEMU_IO -c "write $((test_size+512)) 1" "$(img_json)" | _filter_qem= u_io + + echo + echo "writev before/after image boundary" + $QEMU_IO -c "writev $((test_size-512)) 512 512" "$(img_json)" | _fil= ter_qemu_io + + echo + echo "read before image boundary" + $QEMU_IO -c "read $((test_size-1)) 1" "$(img_json)" | _filter_qemu_i= o + + echo + echo "read across image boundary" + $QEMU_IO -c "read $((test_size-1)) 2" "$(img_json)" | _filter_qemu_i= o + + echo + echo "read at image boundary" + $QEMU_IO -c "read $test_size 1" "$(img_json)" | _filter_qemu_io + + echo + echo "read after image boundary" + $QEMU_IO -c "read $((test_size+512)) 1" "$(img_json)" | _filter_qemu= _io + + echo + echo "readv before/after image boundary" + $QEMU_IO -c "readv $((test_size-512)) 512 512" "$(img_json)" | _filt= er_qemu_io + + echo + echo "fill image with pattern" + $QEMU_IO -c "write -P 0x0a 0 $size" $TEST_IMG | _filter_qemu_io + + echo + echo "write zeroes and check" + $QEMU_IO -c "write -z 0 512" "$(img_json)" | _filter_qemu_io + $QEMU_IO -c "read -v $((img_offset-2)) 4" $TEST_IMG | _filter_qemu_i= o + + echo + echo "write zeroes across image boundary" + $QEMU_IO -c "write -z $((test_size-1)) 2" "$(img_json)" | _filter_qe= mu_io + + echo + echo "write zeroes at image boundary and check" + $QEMU_IO -c "write -z $((test_size-2)) 2" "$(img_json)" | _filter_qe= mu_io + $QEMU_IO -c "read -v $((img_offset+test_size-2)) 2" $TEST_IMG | _fil= ter_qemu_io + $QEMU_IO -c "read -v $((img_offset+test_size)) 2" $TEST_IMG | _filte= r_qemu_io + + echo + echo "fill image with pattern" + $QEMU_IO -c "write -P 0x0a 0 $size" $TEST_IMG | _filter_qemu_io + + echo + echo "discard and check" + $QEMU_IO -c "discard 0 512" "$(img_json)" | _filter_qemu_io + $QEMU_IO -c "read -v $((img_offset-2)) 4" $TEST_IMG | _filter_qemu_i= o + + echo + echo "discard across image boundary" + $QEMU_IO -c "discard $((test_size-1)) 2" "$(img_json)" | _filter_qem= u_io + + echo + echo "discard at image boundary and check" + $QEMU_IO -c "discard $((test_size-2)) 2" "$(img_json)" | _filter_qem= u_io + $QEMU_IO -c "read -v $((img_offset+test_size-2)) 2" $TEST_IMG | _fil= ter_qemu_io + $QEMU_IO -c "read -v $((img_offset+test_size)) 2" $TEST_IMG | _filte= r_qemu_io +} + +echo +echo "=3D=3D test 'offset' option =3D=3D" +size=3D4096 +img_offset=3D512 +img_size=3D-1 +_make_test_img $size +do_general_test +_cleanup_test_img + +echo +echo "=3D=3D test 'offset' and 'size' options =3D=3D" +size=3D4096 +img_offset=3D512 +img_size=3D2048 +_make_test_img $size +do_general_test +_cleanup_test_img + +echo +echo "=3D=3D test misaligned 'offset' =3D=3D" +size=3D4096 +img_offset=3D10 +img_size=3D2048 +_make_test_img $size +do_general_test +_cleanup_test_img + +echo +echo "=3D=3D test reopen =3D=3D" +size=3D4096 +img_offset=3D512 +img_size=3D512 +_make_test_img $size +( +$QEMU_IO "$(img_json)" <