#!/bin/bash
#
# 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
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

function do_is_allocated() {
    local start=$1
    local size=$(( $2 / 512))
    local step=$3
    local count=$4

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

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

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
        echo $op -P $pattern $(( start + (i - 1) * step )) $size
    done
}

function io_pattern() {
    do_io "$@" | $QEMU_IO $TEST_IMG | _filter_qemu_io
}

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

    do_io "$@" $pattern | $QEMU_IO $TEST_IMG | _filter_qemu_io
}

function io_zero() {
    do_io "$@" 0 | $QEMU_IO $TEST_IMG | _filter_qemu_io
}

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

    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))

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

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

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

    # Spanning multiple clusters
    io "$op" $((offset + $half_cluster)) $((cluster_size * 2)) $((cluster_size * 3)) $num_medium
    offset=$((offset + num_medium * 3 * $cluster_size))

    # Spanning multiple L2 tables
    # L2 table size: 512 clusters of 4k = 2M
    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 )))
}

function io_test2() {
    local orig_offset=$1
    local cluster_size=$2
    local num=$3

    # Pattern (repeat after 9 clusters):
    #        used - used - free - used - compressed - compressed -
    #        free - free - compressed

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

    mv $TEST_IMG $TEST_IMG.orig
    $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -c $TEST_IMG.orig $TEST_IMG

    # Write the used clusters
    echo === Used clusters [1]
    io_pattern writev $((offset + 0 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
    echo === Used clusters [2]
    io_pattern writev $((offset + 1 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
    echo === Used clusters [3]
    io_pattern writev $((offset + 3 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165

    # Read them
    echo === Read used/compressed clusters
    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

    echo === Read zeros
    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
}
