common.pattern 4.8 KB
Newer Older
1
#!/bin/bash
2 3 4 5 6 7 8 9 10 11 12 13 14 15
#
# Copyright (C) 2009 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
16
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 18
#

19 20 21 22 23 24 25
function do_is_allocated() {
    local start=$1
    local size=$(( $2 / 512))
    local step=$3
    local count=$4

    for i in `seq 1 $count`; do
26
        echo alloc $(( start + (i - 1) * step )) $size
27 28 29 30
    done
}

function is_allocated() {
31
    do_is_allocated "$@" | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
32 33
}

34 35 36 37 38 39 40 41 42 43
function do_io() {
    local op=$1
    local start=$2
    local size=$3
    local step=$4
    local count=$5
    local pattern=$6

    echo === IO: pattern $pattern >&2
    for i in `seq 1 $count`; do
44
        echo $op -P $pattern $(( start + (i - 1) * step )) $size
45 46 47 48
    done
}

function io_pattern() {
49
    do_io "$@" | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
50 51 52 53 54 55
}

function io() {
    local start=$2
    local pattern=$(( (start >> 9) % 256 ))

56
    do_io "$@" $pattern | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
57 58 59
}

function io_zero() {
60
    do_io "$@" 0 | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
61 62 63 64 65
}

function io_test() {
    local op=$1
    local offset=$2
66
    local cluster_size=$3
67

68 69 70 71 72 73 74 75 76 77 78
    local num_large=$4
    local num_medium=$((num_large * num_large))
    local num_small=$((4 * num_medium))

    local half_cluster=$((cluster_size / 2))
    local quarter_cluster=$((cluster_size / 4))
    local l2_size=$((cluster_size * cluster_size / 8))

    # Complete clusters
    io "$op" $offset $cluster_size $cluster_size $num_small
    offset=$((offset + num_small * $cluster_size))
79 80

    # From somewhere in the middle to the end of a cluster
81 82
    io "$op" $((offset + $half_cluster)) $half_cluster $cluster_size $num_small
    offset=$((offset + num_small * $cluster_size))
83 84

    # From the start to somewhere in the middle of a cluster
85 86
    io "$op" $offset $half_cluster $cluster_size $num_small
    offset=$((offset + num_small * $cluster_size))
87 88

    # Completely misaligned (and small)
89 90
    io "$op" $((offset + $quarter_cluster)) $half_cluster $cluster_size $num_small
    offset=$((offset + num_small * $cluster_size))
91 92

    # Spanning multiple clusters
93 94
    io "$op" $((offset + $half_cluster)) $((cluster_size * 2)) $((cluster_size * 3)) $num_medium
    offset=$((offset + num_medium * 3 * $cluster_size))
95 96 97

    # Spanning multiple L2 tables
    # L2 table size: 512 clusters of 4k = 2M
98 99 100
    offset=$(( ((offset + l2_size - 1) & ~(l2_size - 1)) - (3 * half_cluster) ))
    io "$op" $offset $((6 * half_cluster)) $(( l2_size + half_cluster )) $num_large
    offset=$((offset + num_large * ( l2_size + half_cluster )))
101 102 103 104
}

function io_test2() {
    local orig_offset=$1
105 106
    local cluster_size=$2
    local num=$3
107 108

    # Pattern (repeat after 9 clusters):
K
Kevin Wolf 已提交
109 110
    #        used - used - free - used - compressed - compressed -
    #        free - free - compressed
111 112 113

    # Write the clusters to be compressed
    echo === Clusters to be compressed [1]
114
    io_pattern writev $((offset + 4 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
115
    echo === Clusters to be compressed [2]
116
    io_pattern writev $((offset + 5 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
117
    echo === Clusters to be compressed [3]
118
    io_pattern writev $((offset + 8 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
119

120 121
    mv "$TEST_IMG" "$TEST_IMG.orig"
    $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -c "$TEST_IMG.orig" "$TEST_IMG"
122 123 124

    # Write the used clusters
    echo === Used clusters [1]
125
    io_pattern writev $((offset + 0 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
126
    echo === Used clusters [2]
127
    io_pattern writev $((offset + 1 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
128
    echo === Used clusters [3]
129
    io_pattern writev $((offset + 3 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
130 131 132

    # Read them
    echo === Read used/compressed clusters
133 134 135
    io_pattern readv $((offset + 0 * $cluster_size)) $((2 * $cluster_size)) $((9 * $cluster_size)) $num 165
    io_pattern readv $((offset + 3 * $cluster_size)) $((3 * $cluster_size)) $((9 * $cluster_size)) $num 165
    io_pattern readv $((offset + 8 * $cluster_size)) $((1 * $cluster_size)) $((9 * $cluster_size)) $num 165
136 137

    echo === Read zeros
138 139
    io_zero readv $((offset + 2 * $cluster_size)) $((1 * $cluster_size)) $((9 * $cluster_size)) $num
    io_zero readv $((offset + 6 * $cluster_size)) $((2 * $cluster_size)) $((9 * $cluster_size)) $num
140
}