]> git.proxmox.com Git - mirror_qemu.git/blame - tests/qemu-iotests/common.pattern
qemu-iotests: Initial import into the public repository.
[mirror_qemu.git] / tests / qemu-iotests / common.pattern
CommitLineData
6bf19c94
CH
1#!/bin/sh
2#
3# Copyright (C) 2009 Red Hat, Inc.
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18# USA
19#
20
21function do_io() {
22 local op=$1
23 local start=$2
24 local size=$3
25 local step=$4
26 local count=$5
27 local pattern=$6
28
29 echo === IO: pattern $pattern >&2
30 for i in `seq 1 $count`; do
31 echo $op -P $pattern $(( start + i * step )) $size
32 done
33}
34
35function io_pattern() {
36 do_io $@ | $QEMU_IO $TEST_IMG | _filter_qemu_io
37}
38
39function io() {
40 local start=$2
41 local pattern=$(( (start >> 9) % 256 ))
42
43 do_io $@ $pattern | $QEMU_IO $TEST_IMG | _filter_qemu_io
44}
45
46function io_zero() {
47 do_io $@ 0 | $QEMU_IO $TEST_IMG | _filter_qemu_io
48}
49
50function io_test() {
51 local op=$1
52 local offset=$2
53
54 # Complete clusters (size = 4k)
55 io $op $offset 4096 4096 256
56 offset=$((offset + 256 * 4096))
57
58 # From somewhere in the middle to the end of a cluster
59 io $op $((offset + 2048)) 2048 4096 256
60 offset=$((offset + 256 * 4096))
61
62 # From the start to somewhere in the middle of a cluster
63 io $op $offset 2048 4096 256
64 offset=$((offset + 256 * 4096))
65
66 # Completely misaligned (and small)
67 io $op $((offset + 1024)) 2048 4096 256
68 offset=$((offset + 256 * 4096))
69
70 # Spanning multiple clusters
71 io $op $((offset + 2048)) 8192 12288 64
72 offset=$((offset + 64 * 12288))
73
74 # Spanning multiple L2 tables
75 # L2 table size: 512 clusters of 4k = 2M
76 io $op $((offset + 2048)) 4194304 4999680 8
77 offset=$((offset + 8 * 4999680))
78
79 if false; then
80 true
81 fi
82}
83
84function io_test2() {
85 local orig_offset=$1
86
87 # Pattern (repeat after 9 clusters):
88 # used - used - free - used - compressed - compressed - free - free - compressed
89
90 # Write the clusters to be compressed
91 echo === Clusters to be compressed [1]
92 io_pattern writev $((offset + 4 * 4096)) 4096 $((9 * 4096)) 256 165
93 echo === Clusters to be compressed [2]
94 io_pattern writev $((offset + 5 * 4096)) 4096 $((9 * 4096)) 256 165
95 echo === Clusters to be compressed [3]
96 io_pattern writev $((offset + 8 * 4096)) 4096 $((9 * 4096)) 256 165
97
98 mv $TEST_IMG $TEST_IMG.orig
99 $QEMU_IMG convert -f qcow2 -O qcow2 -c $TEST_IMG.orig $TEST_IMG
100
101 # Write the used clusters
102 echo === Used clusters [1]
103 io_pattern writev $((offset + 0 * 4096)) 4096 $((9 * 4096)) 256 165
104 echo === Used clusters [2]
105 io_pattern writev $((offset + 1 * 4096)) 4096 $((9 * 4096)) 256 165
106 echo === Used clusters [3]
107 io_pattern writev $((offset + 3 * 4096)) 4096 $((9 * 4096)) 256 165
108
109 # Read them
110 echo === Read used/compressed clusters
111 io_pattern readv $((offset + 0 * 4096)) $((2 * 4096)) $((9 * 4096)) 256 165
112 io_pattern readv $((offset + 3 * 4096)) $((3 * 4096)) $((9 * 4096)) 256 165
113 io_pattern readv $((offset + 8 * 4096)) $((1 * 4096)) $((9 * 4096)) 256 165
114
115 echo === Read zeros
116 io_zero readv $((offset + 2 * 4096)) $((1 * 4096)) $((9 * 4096)) 256
117 io_zero readv $((offset + 6 * 4096)) $((2 * 4096)) $((9 * 4096)) 256
118}