xref: /qemu/tests/qemu-iotests/common.pattern (revision 9128ae5e617b67c95a27822a938bed1607119ba2)
16bf19c94SChristoph Hellwig#!/bin/sh
26bf19c94SChristoph Hellwig#
36bf19c94SChristoph Hellwig# Copyright (C) 2009 Red Hat, Inc.
46bf19c94SChristoph Hellwig#
56bf19c94SChristoph Hellwig# This program is free software; you can redistribute it and/or modify
66bf19c94SChristoph Hellwig# it under the terms of the GNU General Public License as published by
76bf19c94SChristoph Hellwig# the Free Software Foundation; either version 2 of the License, or
86bf19c94SChristoph Hellwig# (at your option) any later version.
96bf19c94SChristoph Hellwig#
106bf19c94SChristoph Hellwig# This program is distributed in the hope that it will be useful,
116bf19c94SChristoph Hellwig# but WITHOUT ANY WARRANTY; without even the implied warranty of
126bf19c94SChristoph Hellwig# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
136bf19c94SChristoph Hellwig# GNU General Public License for more details.
146bf19c94SChristoph Hellwig#
156bf19c94SChristoph Hellwig# You should have received a copy of the GNU General Public License
166bf19c94SChristoph Hellwig# along with this program; if not, write to the Free Software
176bf19c94SChristoph Hellwig# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
186bf19c94SChristoph Hellwig# USA
196bf19c94SChristoph Hellwig#
206bf19c94SChristoph Hellwig
21*9128ae5eSKevin Wolffunction do_is_allocated() {
22*9128ae5eSKevin Wolf    local start=$1
23*9128ae5eSKevin Wolf    local size=$(( $2 / 512))
24*9128ae5eSKevin Wolf    local step=$3
25*9128ae5eSKevin Wolf    local count=$4
26*9128ae5eSKevin Wolf
27*9128ae5eSKevin Wolf    for i in `seq 1 $count`; do
28*9128ae5eSKevin Wolf        echo alloc $(( start + i * step )) $size
29*9128ae5eSKevin Wolf    done
30*9128ae5eSKevin Wolf}
31*9128ae5eSKevin Wolf
32*9128ae5eSKevin Wolffunction is_allocated() {
33*9128ae5eSKevin Wolf    do_is_allocated "$@" | $QEMU_IO $TEST_IMG | _filter_qemu_io
34*9128ae5eSKevin Wolf}
35*9128ae5eSKevin Wolf
366bf19c94SChristoph Hellwigfunction do_io() {
376bf19c94SChristoph Hellwig    local op=$1
386bf19c94SChristoph Hellwig    local start=$2
396bf19c94SChristoph Hellwig    local size=$3
406bf19c94SChristoph Hellwig    local step=$4
416bf19c94SChristoph Hellwig    local count=$5
426bf19c94SChristoph Hellwig    local pattern=$6
436bf19c94SChristoph Hellwig
446bf19c94SChristoph Hellwig    echo === IO: pattern $pattern >&2
456bf19c94SChristoph Hellwig    for i in `seq 1 $count`; do
466bf19c94SChristoph Hellwig        echo $op -P $pattern $(( start + i * step )) $size
476bf19c94SChristoph Hellwig    done
486bf19c94SChristoph Hellwig}
496bf19c94SChristoph Hellwig
506bf19c94SChristoph Hellwigfunction io_pattern() {
516bf19c94SChristoph Hellwig    do_io $@ | $QEMU_IO $TEST_IMG | _filter_qemu_io
526bf19c94SChristoph Hellwig}
536bf19c94SChristoph Hellwig
546bf19c94SChristoph Hellwigfunction io() {
556bf19c94SChristoph Hellwig    local start=$2
566bf19c94SChristoph Hellwig    local pattern=$(( (start >> 9) % 256 ))
576bf19c94SChristoph Hellwig
586bf19c94SChristoph Hellwig    do_io $@ $pattern | $QEMU_IO $TEST_IMG | _filter_qemu_io
596bf19c94SChristoph Hellwig}
606bf19c94SChristoph Hellwig
616bf19c94SChristoph Hellwigfunction io_zero() {
626bf19c94SChristoph Hellwig    do_io $@ 0 | $QEMU_IO $TEST_IMG | _filter_qemu_io
636bf19c94SChristoph Hellwig}
646bf19c94SChristoph Hellwig
656bf19c94SChristoph Hellwigfunction io_test() {
666bf19c94SChristoph Hellwig    local op=$1
676bf19c94SChristoph Hellwig    local offset=$2
686bf19c94SChristoph Hellwig
696bf19c94SChristoph Hellwig    # Complete clusters (size = 4k)
706bf19c94SChristoph Hellwig    io $op $offset 4096 4096 256
716bf19c94SChristoph Hellwig    offset=$((offset + 256 * 4096))
726bf19c94SChristoph Hellwig
736bf19c94SChristoph Hellwig    # From somewhere in the middle to the end of a cluster
746bf19c94SChristoph Hellwig    io $op $((offset + 2048)) 2048 4096 256
756bf19c94SChristoph Hellwig    offset=$((offset + 256 * 4096))
766bf19c94SChristoph Hellwig
776bf19c94SChristoph Hellwig    # From the start to somewhere in the middle of a cluster
786bf19c94SChristoph Hellwig    io $op $offset 2048 4096 256
796bf19c94SChristoph Hellwig    offset=$((offset + 256 * 4096))
806bf19c94SChristoph Hellwig
816bf19c94SChristoph Hellwig    # Completely misaligned (and small)
826bf19c94SChristoph Hellwig    io $op $((offset + 1024)) 2048 4096 256
836bf19c94SChristoph Hellwig    offset=$((offset + 256 * 4096))
846bf19c94SChristoph Hellwig
856bf19c94SChristoph Hellwig    # Spanning multiple clusters
866bf19c94SChristoph Hellwig    io $op $((offset + 2048)) 8192 12288 64
876bf19c94SChristoph Hellwig    offset=$((offset + 64 * 12288))
886bf19c94SChristoph Hellwig
896bf19c94SChristoph Hellwig    # Spanning multiple L2 tables
906bf19c94SChristoph Hellwig    # L2 table size: 512 clusters of 4k = 2M
916bf19c94SChristoph Hellwig    io $op $((offset + 2048)) 4194304 4999680 8
926bf19c94SChristoph Hellwig    offset=$((offset + 8 * 4999680))
936bf19c94SChristoph Hellwig
946bf19c94SChristoph Hellwig    if false; then
956bf19c94SChristoph Hellwig        true
966bf19c94SChristoph Hellwig    fi
976bf19c94SChristoph Hellwig}
986bf19c94SChristoph Hellwig
996bf19c94SChristoph Hellwigfunction io_test2() {
1006bf19c94SChristoph Hellwig    local orig_offset=$1
1016bf19c94SChristoph Hellwig
1026bf19c94SChristoph Hellwig    # Pattern (repeat after 9 clusters):
1036bf19c94SChristoph Hellwig    # used - used - free - used - compressed - compressed - free - free - compressed
1046bf19c94SChristoph Hellwig
1056bf19c94SChristoph Hellwig    # Write the clusters to be compressed
1066bf19c94SChristoph Hellwig    echo === Clusters to be compressed [1]
1076bf19c94SChristoph Hellwig    io_pattern writev $((offset + 4 * 4096)) 4096 $((9 * 4096)) 256 165
1086bf19c94SChristoph Hellwig    echo === Clusters to be compressed [2]
1096bf19c94SChristoph Hellwig    io_pattern writev $((offset + 5 * 4096)) 4096 $((9 * 4096)) 256 165
1106bf19c94SChristoph Hellwig    echo === Clusters to be compressed [3]
1116bf19c94SChristoph Hellwig    io_pattern writev $((offset + 8 * 4096)) 4096 $((9 * 4096)) 256 165
1126bf19c94SChristoph Hellwig
1136bf19c94SChristoph Hellwig    mv $TEST_IMG $TEST_IMG.orig
114e76a8e89SChristoph Hellwig    $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -c $TEST_IMG.orig $TEST_IMG
1156bf19c94SChristoph Hellwig
1166bf19c94SChristoph Hellwig    # Write the used clusters
1176bf19c94SChristoph Hellwig    echo === Used clusters [1]
1186bf19c94SChristoph Hellwig    io_pattern writev $((offset + 0 * 4096)) 4096 $((9 * 4096)) 256 165
1196bf19c94SChristoph Hellwig    echo === Used clusters [2]
1206bf19c94SChristoph Hellwig    io_pattern writev $((offset + 1 * 4096)) 4096 $((9 * 4096)) 256 165
1216bf19c94SChristoph Hellwig    echo === Used clusters [3]
1226bf19c94SChristoph Hellwig    io_pattern writev $((offset + 3 * 4096)) 4096 $((9 * 4096)) 256 165
1236bf19c94SChristoph Hellwig
1246bf19c94SChristoph Hellwig    # Read them
1256bf19c94SChristoph Hellwig    echo === Read used/compressed clusters
1266bf19c94SChristoph Hellwig    io_pattern readv $((offset + 0 * 4096)) $((2 * 4096)) $((9 * 4096)) 256 165
1276bf19c94SChristoph Hellwig    io_pattern readv $((offset + 3 * 4096)) $((3 * 4096)) $((9 * 4096)) 256 165
1286bf19c94SChristoph Hellwig    io_pattern readv $((offset + 8 * 4096)) $((1 * 4096)) $((9 * 4096)) 256 165
1296bf19c94SChristoph Hellwig
1306bf19c94SChristoph Hellwig    echo === Read zeros
1316bf19c94SChristoph Hellwig    io_zero readv $((offset + 2 * 4096)) $((1 * 4096)) $((9 * 4096)) 256
1326bf19c94SChristoph Hellwig    io_zero readv $((offset + 6 * 4096)) $((2 * 4096)) $((9 * 4096)) 256
1336bf19c94SChristoph Hellwig}
134