xref: /openbmc/qemu/tests/qemu-iotests/common.pattern (revision 339205e7ef370663b329e34fd9e905ca00321aa4)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
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
198cedcffdSEric Blakedo_is_allocated() {
209128ae5eSKevin Wolf    local start=$1
214401fdc7SEric Blake    local size=$2
229128ae5eSKevin Wolf    local step=$3
239128ae5eSKevin Wolf    local count=$4
249128ae5eSKevin Wolf
2530edd9faSThomas Huth    for ((i=1;i<=$count;i++)); do
26*25fb2e9cSMax Reitz        echo "alloc $(( start + (i - 1) * step )) $size"
279128ae5eSKevin Wolf    done
289128ae5eSKevin Wolf}
299128ae5eSKevin Wolf
308cedcffdSEric Blakeis_allocated() {
3100840438SJeff Cody    do_is_allocated "$@" | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
329128ae5eSKevin Wolf}
339128ae5eSKevin Wolf
348cedcffdSEric Blakedo_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
42*25fb2e9cSMax Reitz    echo "=== IO: pattern $pattern" >&2
4330edd9faSThomas Huth    for ((i=1;i<=$count;i++)); do
44*25fb2e9cSMax Reitz        echo "$op -P $pattern $(( start + (i - 1) * step )) $size"
456bf19c94SChristoph Hellwig    done
466bf19c94SChristoph Hellwig}
476bf19c94SChristoph Hellwig
488cedcffdSEric Blakeio_pattern() {
4900840438SJeff Cody    do_io "$@" | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
506bf19c94SChristoph Hellwig}
516bf19c94SChristoph Hellwig
528cedcffdSEric Blakeio() {
536bf19c94SChristoph Hellwig    local start=$2
546bf19c94SChristoph Hellwig    local pattern=$(( (start >> 9) % 256 ))
556bf19c94SChristoph Hellwig
5600840438SJeff Cody    do_io "$@" $pattern | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
576bf19c94SChristoph Hellwig}
586bf19c94SChristoph Hellwig
598cedcffdSEric Blakeio_zero() {
6000840438SJeff Cody    do_io "$@" 0 | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
616bf19c94SChristoph Hellwig}
626bf19c94SChristoph Hellwig
638cedcffdSEric Blakeio_test() {
646bf19c94SChristoph Hellwig    local op=$1
656bf19c94SChristoph Hellwig    local offset=$2
668fc1024cSKevin Wolf    local cluster_size=$3
676bf19c94SChristoph Hellwig
688fc1024cSKevin Wolf    local num_large=$4
698fc1024cSKevin Wolf    local num_medium=$((num_large * num_large))
708fc1024cSKevin Wolf    local num_small=$((4 * num_medium))
718fc1024cSKevin Wolf
728fc1024cSKevin Wolf    local half_cluster=$((cluster_size / 2))
738fc1024cSKevin Wolf    local quarter_cluster=$((cluster_size / 4))
748fc1024cSKevin Wolf    local l2_size=$((cluster_size * cluster_size / 8))
758fc1024cSKevin Wolf
768fc1024cSKevin Wolf    # Complete clusters
778fc1024cSKevin Wolf    io "$op" $offset $cluster_size $cluster_size $num_small
788fc1024cSKevin Wolf    offset=$((offset + num_small * $cluster_size))
796bf19c94SChristoph Hellwig
806bf19c94SChristoph Hellwig    # From somewhere in the middle to the end of a cluster
818fc1024cSKevin Wolf    io "$op" $((offset + $half_cluster)) $half_cluster $cluster_size $num_small
828fc1024cSKevin Wolf    offset=$((offset + num_small * $cluster_size))
836bf19c94SChristoph Hellwig
846bf19c94SChristoph Hellwig    # From the start to somewhere in the middle of a cluster
858fc1024cSKevin Wolf    io "$op" $offset $half_cluster $cluster_size $num_small
868fc1024cSKevin Wolf    offset=$((offset + num_small * $cluster_size))
876bf19c94SChristoph Hellwig
886bf19c94SChristoph Hellwig    # Completely misaligned (and small)
898fc1024cSKevin Wolf    io "$op" $((offset + $quarter_cluster)) $half_cluster $cluster_size $num_small
908fc1024cSKevin Wolf    offset=$((offset + num_small * $cluster_size))
916bf19c94SChristoph Hellwig
926bf19c94SChristoph Hellwig    # Spanning multiple clusters
938fc1024cSKevin Wolf    io "$op" $((offset + $half_cluster)) $((cluster_size * 2)) $((cluster_size * 3)) $num_medium
948fc1024cSKevin Wolf    offset=$((offset + num_medium * 3 * $cluster_size))
956bf19c94SChristoph Hellwig
966bf19c94SChristoph Hellwig    # Spanning multiple L2 tables
976bf19c94SChristoph Hellwig    # L2 table size: 512 clusters of 4k = 2M
98ac5e2b20SKevin Wolf    offset=$(( ((offset + l2_size - 1) & ~(l2_size - 1)) - (3 * half_cluster) ))
99ac5e2b20SKevin Wolf    io "$op" $offset $((6 * half_cluster)) $(( l2_size + half_cluster )) $num_large
100ac5e2b20SKevin Wolf    offset=$((offset + num_large * ( l2_size + half_cluster )))
1016bf19c94SChristoph Hellwig}
1026bf19c94SChristoph Hellwig
1038cedcffdSEric Blakeio_test2() {
1046bf19c94SChristoph Hellwig    local orig_offset=$1
1058fc1024cSKevin Wolf    local cluster_size=$2
1068fc1024cSKevin Wolf    local num=$3
1076bf19c94SChristoph Hellwig
1086bf19c94SChristoph Hellwig    # Pattern (repeat after 9 clusters):
1098fc1024cSKevin Wolf    #        used - used - free - used - compressed - compressed -
1108fc1024cSKevin Wolf    #        free - free - compressed
1116bf19c94SChristoph Hellwig
1126bf19c94SChristoph Hellwig    # Write the clusters to be compressed
113*25fb2e9cSMax Reitz    echo '=== Clusters to be compressed [1]'
1148fc1024cSKevin Wolf    io_pattern writev $((offset + 4 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
115*25fb2e9cSMax Reitz    echo '=== Clusters to be compressed [2]'
1168fc1024cSKevin Wolf    io_pattern writev $((offset + 5 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
117*25fb2e9cSMax Reitz    echo '=== Clusters to be compressed [3]'
1188fc1024cSKevin Wolf    io_pattern writev $((offset + 8 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
1196bf19c94SChristoph Hellwig
12000840438SJeff Cody    mv "$TEST_IMG" "$TEST_IMG.orig"
12100840438SJeff Cody    $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -c "$TEST_IMG.orig" "$TEST_IMG"
1226bf19c94SChristoph Hellwig
1236bf19c94SChristoph Hellwig    # Write the used clusters
124*25fb2e9cSMax Reitz    echo '=== Used clusters [1]'
1258fc1024cSKevin Wolf    io_pattern writev $((offset + 0 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
126*25fb2e9cSMax Reitz    echo '=== Used clusters [2]'
1278fc1024cSKevin Wolf    io_pattern writev $((offset + 1 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
128*25fb2e9cSMax Reitz    echo '=== Used clusters [3]'
1298fc1024cSKevin Wolf    io_pattern writev $((offset + 3 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165
1306bf19c94SChristoph Hellwig
1316bf19c94SChristoph Hellwig    # Read them
132*25fb2e9cSMax Reitz    echo '=== Read used/compressed clusters'
1338fc1024cSKevin Wolf    io_pattern readv $((offset + 0 * $cluster_size)) $((2 * $cluster_size)) $((9 * $cluster_size)) $num 165
1348fc1024cSKevin Wolf    io_pattern readv $((offset + 3 * $cluster_size)) $((3 * $cluster_size)) $((9 * $cluster_size)) $num 165
1358fc1024cSKevin Wolf    io_pattern readv $((offset + 8 * $cluster_size)) $((1 * $cluster_size)) $((9 * $cluster_size)) $num 165
1366bf19c94SChristoph Hellwig
137*25fb2e9cSMax Reitz    echo '=== Read zeros'
1388fc1024cSKevin Wolf    io_zero readv $((offset + 2 * $cluster_size)) $((1 * $cluster_size)) $((9 * $cluster_size)) $num
1398fc1024cSKevin Wolf    io_zero readv $((offset + 6 * $cluster_size)) $((2 * $cluster_size)) $((9 * $cluster_size)) $num
1406bf19c94SChristoph Hellwig}
141