replace FSF postal addresses with www.gnu.org links
[qemu-iotests/stefanha.git] / common.pattern
blob63df923412275e98d327d2e1f58188e53142dab0
1 #!/bin/sh
3 # Copyright (C) 2009 Red Hat, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 function do_is_allocated() {
20 local start=$1
21 local size=$(( $2 / 512))
22 local step=$3
23 local count=$4
25 for i in `seq 1 $count`; do
26 echo alloc $(( start + i * step )) $size
27 done
30 function is_allocated() {
31 do_is_allocated "$@" | $QEMU_IO $TEST_IMG | _filter_qemu_io
34 function do_io() {
35 local op=$1
36 local start=$2
37 local size=$3
38 local step=$4
39 local count=$5
40 local pattern=$6
42 echo === IO: pattern $pattern >&2
43 for i in `seq 1 $count`; do
44 echo $op -P $pattern $(( start + i * step )) $size
45 done
48 function io_pattern() {
49 do_io $@ | $QEMU_IO $TEST_IMG | _filter_qemu_io
52 function io() {
53 local start=$2
54 local pattern=$(( (start >> 9) % 256 ))
56 do_io $@ $pattern | $QEMU_IO $TEST_IMG | _filter_qemu_io
59 function io_zero() {
60 do_io $@ 0 | $QEMU_IO $TEST_IMG | _filter_qemu_io
63 function io_test() {
64 local op=$1
65 local offset=$2
67 # Complete clusters (size = 4k)
68 io $op $offset 4096 4096 256
69 offset=$((offset + 256 * 4096))
71 # From somewhere in the middle to the end of a cluster
72 io $op $((offset + 2048)) 2048 4096 256
73 offset=$((offset + 256 * 4096))
75 # From the start to somewhere in the middle of a cluster
76 io $op $offset 2048 4096 256
77 offset=$((offset + 256 * 4096))
79 # Completely misaligned (and small)
80 io $op $((offset + 1024)) 2048 4096 256
81 offset=$((offset + 256 * 4096))
83 # Spanning multiple clusters
84 io $op $((offset + 2048)) 8192 12288 64
85 offset=$((offset + 64 * 12288))
87 # Spanning multiple L2 tables
88 # L2 table size: 512 clusters of 4k = 2M
89 io $op $((offset + 2048)) 4194304 4999680 8
90 offset=$((offset + 8 * 4999680))
92 if false; then
93 true
97 function io_test2() {
98 local orig_offset=$1
100 # Pattern (repeat after 9 clusters):
101 # used - used - free - used - compressed - compressed - free - free - compressed
103 # Write the clusters to be compressed
104 echo === Clusters to be compressed [1]
105 io_pattern writev $((offset + 4 * 4096)) 4096 $((9 * 4096)) 256 165
106 echo === Clusters to be compressed [2]
107 io_pattern writev $((offset + 5 * 4096)) 4096 $((9 * 4096)) 256 165
108 echo === Clusters to be compressed [3]
109 io_pattern writev $((offset + 8 * 4096)) 4096 $((9 * 4096)) 256 165
111 mv $TEST_IMG $TEST_IMG.orig
112 $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -c $TEST_IMG.orig $TEST_IMG
114 # Write the used clusters
115 echo === Used clusters [1]
116 io_pattern writev $((offset + 0 * 4096)) 4096 $((9 * 4096)) 256 165
117 echo === Used clusters [2]
118 io_pattern writev $((offset + 1 * 4096)) 4096 $((9 * 4096)) 256 165
119 echo === Used clusters [3]
120 io_pattern writev $((offset + 3 * 4096)) 4096 $((9 * 4096)) 256 165
122 # Read them
123 echo === Read used/compressed clusters
124 io_pattern readv $((offset + 0 * 4096)) $((2 * 4096)) $((9 * 4096)) 256 165
125 io_pattern readv $((offset + 3 * 4096)) $((3 * 4096)) $((9 * 4096)) 256 165
126 io_pattern readv $((offset + 8 * 4096)) $((1 * 4096)) $((9 * 4096)) 256 165
128 echo === Read zeros
129 io_zero readv $((offset + 2 * 4096)) $((1 * 4096)) $((9 * 4096)) 256
130 io_zero readv $((offset + 6 * 4096)) $((2 * 4096)) $((9 * 4096)) 256