summaryrefslogtreecommitdiffstats
path: root/qemu/tests/qemu-iotests/common.pattern
diff options
context:
space:
mode:
authorYang Zhang <yang.z.zhang@intel.com>2015-08-28 09:58:54 +0800
committerYang Zhang <yang.z.zhang@intel.com>2015-09-01 12:44:00 +0800
commite44e3482bdb4d0ebde2d8b41830ac2cdb07948fb (patch)
tree66b09f592c55df2878107a468a91d21506104d3f /qemu/tests/qemu-iotests/common.pattern
parent9ca8dbcc65cfc63d6f5ef3312a33184e1d726e00 (diff)
Add qemu 2.4.0
Change-Id: Ic99cbad4b61f8b127b7dc74d04576c0bcbaaf4f5 Signed-off-by: Yang Zhang <yang.z.zhang@intel.com>
Diffstat (limited to 'qemu/tests/qemu-iotests/common.pattern')
-rw-r--r--qemu/tests/qemu-iotests/common.pattern140
1 files changed, 140 insertions, 0 deletions
diff --git a/qemu/tests/qemu-iotests/common.pattern b/qemu/tests/qemu-iotests/common.pattern
new file mode 100644
index 000000000..ddfbca1b7
--- /dev/null
+++ b/qemu/tests/qemu-iotests/common.pattern
@@ -0,0 +1,140 @@
+#!/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
+}