Statistics
| Branch: | Revision:

root / tests / qemu-iotests / common.pattern @ 08e4ed6c

History | View | Annotate | Download (4.8 kB)

1 908eaf68 Stefan Hajnoczi
#!/bin/bash
2 6bf19c94 Christoph Hellwig
#
3 6bf19c94 Christoph Hellwig
# Copyright (C) 2009 Red Hat, Inc.
4 6bf19c94 Christoph Hellwig
#
5 6bf19c94 Christoph Hellwig
# This program is free software; you can redistribute it and/or modify
6 6bf19c94 Christoph Hellwig
# it under the terms of the GNU General Public License as published by
7 6bf19c94 Christoph Hellwig
# the Free Software Foundation; either version 2 of the License, or
8 6bf19c94 Christoph Hellwig
# (at your option) any later version.
9 6bf19c94 Christoph Hellwig
#
10 6bf19c94 Christoph Hellwig
# This program is distributed in the hope that it will be useful,
11 6bf19c94 Christoph Hellwig
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12 6bf19c94 Christoph Hellwig
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 6bf19c94 Christoph Hellwig
# GNU General Public License for more details.
14 6bf19c94 Christoph Hellwig
#
15 6bf19c94 Christoph Hellwig
# You should have received a copy of the GNU General Public License
16 e8c212d6 Christoph Hellwig
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 6bf19c94 Christoph Hellwig
#
18 6bf19c94 Christoph Hellwig
19 9128ae5e Kevin Wolf
function do_is_allocated() {
20 9128ae5e Kevin Wolf
    local start=$1
21 9128ae5e Kevin Wolf
    local size=$(( $2 / 512))
22 9128ae5e Kevin Wolf
    local step=$3
23 9128ae5e Kevin Wolf
    local count=$4
24 9128ae5e Kevin Wolf
25 9128ae5e Kevin Wolf
    for i in `seq 1 $count`; do
26 dd0c35d6 Stefan Hajnoczi
        echo alloc $(( start + (i - 1) * step )) $size
27 9128ae5e Kevin Wolf
    done
28 9128ae5e Kevin Wolf
}
29 9128ae5e Kevin Wolf
30 9128ae5e Kevin Wolf
function is_allocated() {
31 9128ae5e Kevin Wolf
    do_is_allocated "$@" | $QEMU_IO $TEST_IMG | _filter_qemu_io
32 9128ae5e Kevin Wolf
}
33 9128ae5e Kevin Wolf
34 6bf19c94 Christoph Hellwig
function do_io() {
35 6bf19c94 Christoph Hellwig
    local op=$1
36 6bf19c94 Christoph Hellwig
    local start=$2
37 6bf19c94 Christoph Hellwig
    local size=$3
38 6bf19c94 Christoph Hellwig
    local step=$4
39 6bf19c94 Christoph Hellwig
    local count=$5
40 6bf19c94 Christoph Hellwig
    local pattern=$6
41 6bf19c94 Christoph Hellwig
42 6bf19c94 Christoph Hellwig
    echo === IO: pattern $pattern >&2
43 6bf19c94 Christoph Hellwig
    for i in `seq 1 $count`; do
44 dd0c35d6 Stefan Hajnoczi
        echo $op -P $pattern $(( start + (i - 1) * step )) $size
45 6bf19c94 Christoph Hellwig
    done
46 6bf19c94 Christoph Hellwig
}
47 6bf19c94 Christoph Hellwig
48 6bf19c94 Christoph Hellwig
function io_pattern() {
49 9c9afe57 Kevin Wolf
    do_io "$@" | $QEMU_IO $TEST_IMG | _filter_qemu_io
50 6bf19c94 Christoph Hellwig
}
51 6bf19c94 Christoph Hellwig
52 6bf19c94 Christoph Hellwig
function io() {
53 6bf19c94 Christoph Hellwig
    local start=$2
54 6bf19c94 Christoph Hellwig
    local pattern=$(( (start >> 9) % 256 ))
55 6bf19c94 Christoph Hellwig
56 9c9afe57 Kevin Wolf
    do_io "$@" $pattern | $QEMU_IO $TEST_IMG | _filter_qemu_io
57 6bf19c94 Christoph Hellwig
}
58 6bf19c94 Christoph Hellwig
59 6bf19c94 Christoph Hellwig
function io_zero() {
60 9c9afe57 Kevin Wolf
    do_io "$@" 0 | $QEMU_IO $TEST_IMG | _filter_qemu_io
61 6bf19c94 Christoph Hellwig
}
62 6bf19c94 Christoph Hellwig
63 6bf19c94 Christoph Hellwig
function io_test() {
64 6bf19c94 Christoph Hellwig
    local op=$1
65 6bf19c94 Christoph Hellwig
    local offset=$2
66 8fc1024c Kevin Wolf
    local cluster_size=$3
67 6bf19c94 Christoph Hellwig
68 8fc1024c Kevin Wolf
    local num_large=$4
69 8fc1024c Kevin Wolf
    local num_medium=$((num_large * num_large))
70 8fc1024c Kevin Wolf
    local num_small=$((4 * num_medium))
71 8fc1024c Kevin Wolf
72 8fc1024c Kevin Wolf
    local half_cluster=$((cluster_size / 2))
73 8fc1024c Kevin Wolf
    local quarter_cluster=$((cluster_size / 4))
74 8fc1024c Kevin Wolf
    local l2_size=$((cluster_size * cluster_size / 8))
75 8fc1024c Kevin Wolf
76 8fc1024c Kevin Wolf
    # Complete clusters
77 8fc1024c Kevin Wolf
    io "$op" $offset $cluster_size $cluster_size $num_small
78 8fc1024c Kevin Wolf
    offset=$((offset + num_small * $cluster_size))
79 6bf19c94 Christoph Hellwig
80 6bf19c94 Christoph Hellwig
    # From somewhere in the middle to the end of a cluster
81 8fc1024c Kevin Wolf
    io "$op" $((offset + $half_cluster)) $half_cluster $cluster_size $num_small
82 8fc1024c Kevin Wolf
    offset=$((offset + num_small * $cluster_size))
83 6bf19c94 Christoph Hellwig
84 6bf19c94 Christoph Hellwig
    # From the start to somewhere in the middle of a cluster
85 8fc1024c Kevin Wolf
    io "$op" $offset $half_cluster $cluster_size $num_small
86 8fc1024c Kevin Wolf
    offset=$((offset + num_small * $cluster_size))
87 6bf19c94 Christoph Hellwig
88 6bf19c94 Christoph Hellwig
    # Completely misaligned (and small)
89 8fc1024c Kevin Wolf
    io "$op" $((offset + $quarter_cluster)) $half_cluster $cluster_size $num_small
90 8fc1024c Kevin Wolf
    offset=$((offset + num_small * $cluster_size))
91 6bf19c94 Christoph Hellwig
92 6bf19c94 Christoph Hellwig
    # Spanning multiple clusters
93 8fc1024c Kevin Wolf
    io "$op" $((offset + $half_cluster)) $((cluster_size * 2)) $((cluster_size * 3)) $num_medium
94 8fc1024c Kevin Wolf
    offset=$((offset + num_medium * 3 * $cluster_size))
95 6bf19c94 Christoph Hellwig
96 6bf19c94 Christoph Hellwig
    # Spanning multiple L2 tables
97 6bf19c94 Christoph Hellwig
    # L2 table size: 512 clusters of 4k = 2M
98 ac5e2b20 Kevin Wolf
    offset=$(( ((offset + l2_size - 1) & ~(l2_size - 1)) - (3 * half_cluster) ))
99 ac5e2b20 Kevin Wolf
    io "$op" $offset $((6 * half_cluster)) $(( l2_size + half_cluster )) $num_large
100 ac5e2b20 Kevin Wolf
    offset=$((offset + num_large * ( l2_size + half_cluster )))
101 6bf19c94 Christoph Hellwig
}
102 6bf19c94 Christoph Hellwig
103 6bf19c94 Christoph Hellwig
function io_test2() {
104 6bf19c94 Christoph Hellwig
    local orig_offset=$1
105 8fc1024c Kevin Wolf
    local cluster_size=$2
106 8fc1024c Kevin Wolf
    local num=$3
107 6bf19c94 Christoph Hellwig
108 6bf19c94 Christoph Hellwig
    # Pattern (repeat after 9 clusters):
109 8fc1024c Kevin Wolf
    #	used - used - free - used - compressed - compressed -
110 8fc1024c Kevin Wolf
    #	free - free - compressed
111 6bf19c94 Christoph Hellwig
112 6bf19c94 Christoph Hellwig
    # Write the clusters to be compressed
113 6bf19c94 Christoph Hellwig
    echo === Clusters to be compressed [1]
114 8fc1024c Kevin Wolf
    io_pattern writev $((offset + 4 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
115 6bf19c94 Christoph Hellwig
    echo === Clusters to be compressed [2]
116 8fc1024c Kevin Wolf
    io_pattern writev $((offset + 5 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
117 6bf19c94 Christoph Hellwig
    echo === Clusters to be compressed [3]
118 8fc1024c Kevin Wolf
    io_pattern writev $((offset + 8 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
119 6bf19c94 Christoph Hellwig
120 6bf19c94 Christoph Hellwig
    mv $TEST_IMG $TEST_IMG.orig
121 e76a8e89 Christoph Hellwig
    $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -c $TEST_IMG.orig $TEST_IMG
122 6bf19c94 Christoph Hellwig
123 6bf19c94 Christoph Hellwig
    # Write the used clusters
124 6bf19c94 Christoph Hellwig
    echo === Used clusters [1]
125 8fc1024c Kevin Wolf
    io_pattern writev $((offset + 0 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
126 6bf19c94 Christoph Hellwig
    echo === Used clusters [2]
127 8fc1024c Kevin Wolf
    io_pattern writev $((offset + 1 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
128 6bf19c94 Christoph Hellwig
    echo === Used clusters [3]
129 8fc1024c Kevin Wolf
    io_pattern writev $((offset + 3 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
130 6bf19c94 Christoph Hellwig
131 6bf19c94 Christoph Hellwig
    # Read them
132 6bf19c94 Christoph Hellwig
    echo === Read used/compressed clusters
133 8fc1024c Kevin Wolf
    io_pattern readv $((offset + 0 * $cluster_size)) $((2 * $cluster_size)) $((9 * $cluster_size)) $num 165
134 8fc1024c Kevin Wolf
    io_pattern readv $((offset + 3 * $cluster_size)) $((3 * $cluster_size)) $((9 * $cluster_size)) $num 165
135 8fc1024c Kevin Wolf
    io_pattern readv $((offset + 8 * $cluster_size)) $((1 * $cluster_size)) $((9 * $cluster_size)) $num 165
136 6bf19c94 Christoph Hellwig
137 6bf19c94 Christoph Hellwig
    echo === Read zeros
138 8fc1024c Kevin Wolf
    io_zero readv $((offset + 2 * $cluster_size)) $((1 * $cluster_size)) $((9 * $cluster_size)) $num
139 8fc1024c Kevin Wolf
    io_zero readv $((offset + 6 * $cluster_size)) $((2 * $cluster_size)) $((9 * $cluster_size)) $num
140 6bf19c94 Christoph Hellwig
}