xref: /openbmc/qemu/tests/qemu-iotests/177 (revision 40812d937392fddc11f72a668aef251039cc15ce)
1*40812d93SEric Blake#!/bin/bash
2*40812d93SEric Blake#
3*40812d93SEric Blake# Test corner cases with unusual block geometries
4*40812d93SEric Blake#
5*40812d93SEric Blake# Copyright (C) 2016-2017 Red Hat, Inc.
6*40812d93SEric Blake#
7*40812d93SEric Blake# This program is free software; you can redistribute it and/or modify
8*40812d93SEric Blake# it under the terms of the GNU General Public License as published by
9*40812d93SEric Blake# the Free Software Foundation; either version 2 of the License, or
10*40812d93SEric Blake# (at your option) any later version.
11*40812d93SEric Blake#
12*40812d93SEric Blake# This program is distributed in the hope that it will be useful,
13*40812d93SEric Blake# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*40812d93SEric Blake# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*40812d93SEric Blake# GNU General Public License for more details.
16*40812d93SEric Blake#
17*40812d93SEric Blake# You should have received a copy of the GNU General Public License
18*40812d93SEric Blake# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19*40812d93SEric Blake#
20*40812d93SEric Blake
21*40812d93SEric Blake# creator
22*40812d93SEric Blakeowner=eblake@redhat.com
23*40812d93SEric Blake
24*40812d93SEric Blakeseq=`basename $0`
25*40812d93SEric Blakeecho "QA output created by $seq"
26*40812d93SEric Blake
27*40812d93SEric Blakehere=`pwd`
28*40812d93SEric Blakestatus=1	# failure is the default!
29*40812d93SEric Blake
30*40812d93SEric Blake_cleanup()
31*40812d93SEric Blake{
32*40812d93SEric Blake	_cleanup_test_img
33*40812d93SEric Blake}
34*40812d93SEric Blaketrap "_cleanup; exit \$status" 0 1 2 3 15
35*40812d93SEric Blake
36*40812d93SEric Blake# get standard environment, filters and checks
37*40812d93SEric Blake. ./common.rc
38*40812d93SEric Blake. ./common.filter
39*40812d93SEric Blake
40*40812d93SEric Blake_supported_fmt qcow2
41*40812d93SEric Blake_supported_proto file
42*40812d93SEric Blake
43*40812d93SEric BlakeCLUSTER_SIZE=1M
44*40812d93SEric Blakesize=128M
45*40812d93SEric Blakeoptions=driver=blkdebug,image.driver=qcow2
46*40812d93SEric Blake
47*40812d93SEric Blakeecho
48*40812d93SEric Blakeecho "== setting up files =="
49*40812d93SEric Blake
50*40812d93SEric BlakeTEST_IMG="$TEST_IMG.base" _make_test_img $size
51*40812d93SEric Blake$QEMU_IO -c "write -P 11 0 $size" "$TEST_IMG.base" | _filter_qemu_io
52*40812d93SEric Blake_make_test_img -b "$TEST_IMG.base"
53*40812d93SEric Blake$QEMU_IO -c "write -P 22 0 $size" "$TEST_IMG" | _filter_qemu_io
54*40812d93SEric Blake
55*40812d93SEric Blake# Limited to 64k max-transfer
56*40812d93SEric Blakeecho
57*40812d93SEric Blakeecho "== constrained alignment and max-transfer =="
58*40812d93SEric Blakelimits=align=4k,max-transfer=64k
59*40812d93SEric Blake$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
60*40812d93SEric Blake         -c "write -P 33 1000 128k" -c "read -P 33 1000 128k" | _filter_qemu_io
61*40812d93SEric Blake
62*40812d93SEric Blakeecho
63*40812d93SEric Blakeecho "== write zero with constrained max-transfer =="
64*40812d93SEric Blakelimits=align=512,max-transfer=64k,opt-write-zero=$CLUSTER_SIZE
65*40812d93SEric Blake$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
66*40812d93SEric Blake         -c "write -z 8003584 2093056" | _filter_qemu_io
67*40812d93SEric Blake
68*40812d93SEric Blake# non-power-of-2 write-zero/discard alignments
69*40812d93SEric Blakeecho
70*40812d93SEric Blakeecho "== non-power-of-2 write zeroes limits =="
71*40812d93SEric Blake
72*40812d93SEric Blakelimits=align=512,opt-write-zero=15M,max-write-zero=15M,opt-discard=15M,max-discard=15M
73*40812d93SEric Blake$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
74*40812d93SEric Blake         -c "write -z 32M 32M" | _filter_qemu_io
75*40812d93SEric Blake
76*40812d93SEric Blakeecho
77*40812d93SEric Blakeecho "== non-power-of-2 discard limits =="
78*40812d93SEric Blake
79*40812d93SEric Blakelimits=align=512,opt-write-zero=15M,max-write-zero=15M,opt-discard=15M,max-discard=15M
80*40812d93SEric Blake$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
81*40812d93SEric Blake         -c "discard 80000001 30M" | _filter_qemu_io
82*40812d93SEric Blake
83*40812d93SEric Blakeecho
84*40812d93SEric Blakeecho "== verify image content =="
85*40812d93SEric Blake
86*40812d93SEric Blakefunction verify_io()
87*40812d93SEric Blake{
88*40812d93SEric Blake    if ($QEMU_IMG info -f "$IMGFMT" "$TEST_IMG" |
89*40812d93SEric Blake	    grep "compat: 0.10" > /dev/null); then
90*40812d93SEric Blake        # For v2 images, discarded clusters are read from the backing file
91*40812d93SEric Blake        discarded=11
92*40812d93SEric Blake    else
93*40812d93SEric Blake        # Discarded clusters are zeroed for v3 or later
94*40812d93SEric Blake        discarded=0
95*40812d93SEric Blake    fi
96*40812d93SEric Blake
97*40812d93SEric Blake    echo read -P 22 0 1000
98*40812d93SEric Blake    echo read -P 33 1000 128k
99*40812d93SEric Blake    echo read -P 22 132072 7871512
100*40812d93SEric Blake    echo read -P 0 8003584 2093056
101*40812d93SEric Blake    echo read -P 22 10096640 23457792
102*40812d93SEric Blake    echo read -P 0 32M 32M
103*40812d93SEric Blake    echo read -P 22 64M 13M
104*40812d93SEric Blake    echo read -P $discarded 77M 29M
105*40812d93SEric Blake    echo read -P 22 106M 22M
106*40812d93SEric Blake}
107*40812d93SEric Blake
108*40812d93SEric Blakeverify_io | $QEMU_IO -r "$TEST_IMG" | _filter_qemu_io
109*40812d93SEric Blake
110*40812d93SEric Blake_check_test_img
111*40812d93SEric Blake
112*40812d93SEric Blake# success, all done
113*40812d93SEric Blakeecho "*** done"
114*40812d93SEric Blakestatus=0
115