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