xref: /openbmc/qemu/tests/qemu-iotests/common.pattern (revision 9c9afe576f88415a4b15ec434e0d8491f4fc36dc)
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
16e8c212d6SChristoph Hellwig# along with this program.  If not, see <http://www.gnu.org/licenses/>.
176bf19c94SChristoph Hellwig#
186bf19c94SChristoph Hellwig
199128ae5eSKevin Wolffunction do_is_allocated() {
209128ae5eSKevin Wolf    local start=$1
219128ae5eSKevin Wolf    local size=$(( $2 / 512))
229128ae5eSKevin Wolf    local step=$3
239128ae5eSKevin Wolf    local count=$4
249128ae5eSKevin Wolf
259128ae5eSKevin Wolf    for i in `seq 1 $count`; do
269128ae5eSKevin Wolf        echo alloc $(( start + i * step )) $size
279128ae5eSKevin Wolf    done
289128ae5eSKevin Wolf}
299128ae5eSKevin Wolf
309128ae5eSKevin Wolffunction is_allocated() {
319128ae5eSKevin Wolf    do_is_allocated "$@" | $QEMU_IO $TEST_IMG | _filter_qemu_io
329128ae5eSKevin Wolf}
339128ae5eSKevin Wolf
346bf19c94SChristoph Hellwigfunction do_io() {
356bf19c94SChristoph Hellwig    local op=$1
366bf19c94SChristoph Hellwig    local start=$2
376bf19c94SChristoph Hellwig    local size=$3
386bf19c94SChristoph Hellwig    local step=$4
396bf19c94SChristoph Hellwig    local count=$5
406bf19c94SChristoph Hellwig    local pattern=$6
416bf19c94SChristoph Hellwig
426bf19c94SChristoph Hellwig    echo === IO: pattern $pattern >&2
436bf19c94SChristoph Hellwig    for i in `seq 1 $count`; do
446bf19c94SChristoph Hellwig        echo $op -P $pattern $(( start + i * step )) $size
456bf19c94SChristoph Hellwig    done
466bf19c94SChristoph Hellwig}
476bf19c94SChristoph Hellwig
486bf19c94SChristoph Hellwigfunction io_pattern() {
49*9c9afe57SKevin Wolf    do_io "$@" | $QEMU_IO $TEST_IMG | _filter_qemu_io
506bf19c94SChristoph Hellwig}
516bf19c94SChristoph Hellwig
526bf19c94SChristoph Hellwigfunction io() {
536bf19c94SChristoph Hellwig    local start=$2
546bf19c94SChristoph Hellwig    local pattern=$(( (start >> 9) % 256 ))
556bf19c94SChristoph Hellwig
56*9c9afe57SKevin Wolf    do_io "$@" $pattern | $QEMU_IO $TEST_IMG | _filter_qemu_io
576bf19c94SChristoph Hellwig}
586bf19c94SChristoph Hellwig
596bf19c94SChristoph Hellwigfunction io_zero() {
60*9c9afe57SKevin Wolf    do_io "$@" 0 | $QEMU_IO $TEST_IMG | _filter_qemu_io
616bf19c94SChristoph Hellwig}
626bf19c94SChristoph Hellwig
636bf19c94SChristoph Hellwigfunction io_test() {
646bf19c94SChristoph Hellwig    local op=$1
656bf19c94SChristoph Hellwig    local offset=$2
666bf19c94SChristoph Hellwig
676bf19c94SChristoph Hellwig    # Complete clusters (size = 4k)
68*9c9afe57SKevin Wolf    io "$op" $offset 4096 4096 256
696bf19c94SChristoph Hellwig    offset=$((offset + 256 * 4096))
706bf19c94SChristoph Hellwig
716bf19c94SChristoph Hellwig    # From somewhere in the middle to the end of a cluster
72*9c9afe57SKevin Wolf    io "$op" $((offset + 2048)) 2048 4096 256
736bf19c94SChristoph Hellwig    offset=$((offset + 256 * 4096))
746bf19c94SChristoph Hellwig
756bf19c94SChristoph Hellwig    # From the start to somewhere in the middle of a cluster
76*9c9afe57SKevin Wolf    io "$op" $offset 2048 4096 256
776bf19c94SChristoph Hellwig    offset=$((offset + 256 * 4096))
786bf19c94SChristoph Hellwig
796bf19c94SChristoph Hellwig    # Completely misaligned (and small)
80*9c9afe57SKevin Wolf    io "$op" $((offset + 1024)) 2048 4096 256
816bf19c94SChristoph Hellwig    offset=$((offset + 256 * 4096))
826bf19c94SChristoph Hellwig
836bf19c94SChristoph Hellwig    # Spanning multiple clusters
84*9c9afe57SKevin Wolf    io "$op" $((offset + 2048)) 8192 12288 64
856bf19c94SChristoph Hellwig    offset=$((offset + 64 * 12288))
866bf19c94SChristoph Hellwig
876bf19c94SChristoph Hellwig    # Spanning multiple L2 tables
886bf19c94SChristoph Hellwig    # L2 table size: 512 clusters of 4k = 2M
89*9c9afe57SKevin Wolf    io "$op" $((offset + 2048)) 4194304 4999680 8
906bf19c94SChristoph Hellwig    offset=$((offset + 8 * 4999680))
916bf19c94SChristoph Hellwig
926bf19c94SChristoph Hellwig    if false; then
936bf19c94SChristoph Hellwig        true
946bf19c94SChristoph Hellwig    fi
956bf19c94SChristoph Hellwig}
966bf19c94SChristoph Hellwig
976bf19c94SChristoph Hellwigfunction io_test2() {
986bf19c94SChristoph Hellwig    local orig_offset=$1
996bf19c94SChristoph Hellwig
1006bf19c94SChristoph Hellwig    # Pattern (repeat after 9 clusters):
1016bf19c94SChristoph Hellwig    # used - used - free - used - compressed - compressed - free - free - compressed
1026bf19c94SChristoph Hellwig
1036bf19c94SChristoph Hellwig    # Write the clusters to be compressed
1046bf19c94SChristoph Hellwig    echo === Clusters to be compressed [1]
1056bf19c94SChristoph Hellwig    io_pattern writev $((offset + 4 * 4096)) 4096 $((9 * 4096)) 256 165
1066bf19c94SChristoph Hellwig    echo === Clusters to be compressed [2]
1076bf19c94SChristoph Hellwig    io_pattern writev $((offset + 5 * 4096)) 4096 $((9 * 4096)) 256 165
1086bf19c94SChristoph Hellwig    echo === Clusters to be compressed [3]
1096bf19c94SChristoph Hellwig    io_pattern writev $((offset + 8 * 4096)) 4096 $((9 * 4096)) 256 165
1106bf19c94SChristoph Hellwig
1116bf19c94SChristoph Hellwig    mv $TEST_IMG $TEST_IMG.orig
112e76a8e89SChristoph Hellwig    $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -c $TEST_IMG.orig $TEST_IMG
1136bf19c94SChristoph Hellwig
1146bf19c94SChristoph Hellwig    # Write the used clusters
1156bf19c94SChristoph Hellwig    echo === Used clusters [1]
1166bf19c94SChristoph Hellwig    io_pattern writev $((offset + 0 * 4096)) 4096 $((9 * 4096)) 256 165
1176bf19c94SChristoph Hellwig    echo === Used clusters [2]
1186bf19c94SChristoph Hellwig    io_pattern writev $((offset + 1 * 4096)) 4096 $((9 * 4096)) 256 165
1196bf19c94SChristoph Hellwig    echo === Used clusters [3]
1206bf19c94SChristoph Hellwig    io_pattern writev $((offset + 3 * 4096)) 4096 $((9 * 4096)) 256 165
1216bf19c94SChristoph Hellwig
1226bf19c94SChristoph Hellwig    # Read them
1236bf19c94SChristoph Hellwig    echo === Read used/compressed clusters
1246bf19c94SChristoph Hellwig    io_pattern readv $((offset + 0 * 4096)) $((2 * 4096)) $((9 * 4096)) 256 165
1256bf19c94SChristoph Hellwig    io_pattern readv $((offset + 3 * 4096)) $((3 * 4096)) $((9 * 4096)) 256 165
1266bf19c94SChristoph Hellwig    io_pattern readv $((offset + 8 * 4096)) $((1 * 4096)) $((9 * 4096)) 256 165
1276bf19c94SChristoph Hellwig
1286bf19c94SChristoph Hellwig    echo === Read zeros
1296bf19c94SChristoph Hellwig    io_zero readv $((offset + 2 * 4096)) $((1 * 4096)) $((9 * 4096)) 256
1306bf19c94SChristoph Hellwig    io_zero readv $((offset + 6 * 4096)) $((2 * 4096)) $((9 * 4096)) 256
1316bf19c94SChristoph Hellwig}
132