xref: /openbmc/qemu/tests/qemu-iotests/037 (revision 9b652fbe)
1bce283ccSKevin Wolf#!/bin/bash
2bce283ccSKevin Wolf#
3bce283ccSKevin Wolf# Test COW from backing files
4bce283ccSKevin Wolf#
5bce283ccSKevin Wolf# Copyright (C) 2012 Red Hat, Inc.
6bce283ccSKevin Wolf#
7bce283ccSKevin Wolf# This program is free software; you can redistribute it and/or modify
8bce283ccSKevin Wolf# it under the terms of the GNU General Public License as published by
9bce283ccSKevin Wolf# the Free Software Foundation; either version 2 of the License, or
10bce283ccSKevin Wolf# (at your option) any later version.
11bce283ccSKevin Wolf#
12bce283ccSKevin Wolf# This program is distributed in the hope that it will be useful,
13bce283ccSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
14bce283ccSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15bce283ccSKevin Wolf# GNU General Public License for more details.
16bce283ccSKevin Wolf#
17bce283ccSKevin Wolf# You should have received a copy of the GNU General Public License
18bce283ccSKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19bce283ccSKevin Wolf#
20bce283ccSKevin Wolf
21bce283ccSKevin Wolf# creator
22bce283ccSKevin Wolfowner=kwolf@redhat.com
23bce283ccSKevin Wolf
24bce283ccSKevin Wolfseq=`basename $0`
25bce283ccSKevin Wolfecho "QA output created by $seq"
26bce283ccSKevin Wolf
27bce283ccSKevin Wolfhere=`pwd`
28bce283ccSKevin Wolftmp=/tmp/$$
29bce283ccSKevin Wolfstatus=1	# failure is the default!
30bce283ccSKevin Wolf
31bce283ccSKevin Wolf_cleanup()
32bce283ccSKevin Wolf{
33bce283ccSKevin Wolf	_cleanup_test_img
34bce283ccSKevin Wolf}
35bce283ccSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
36bce283ccSKevin Wolf
37bce283ccSKevin Wolf# get standard environment, filters and checks
38bce283ccSKevin Wolf. ./common.rc
39bce283ccSKevin Wolf. ./common.filter
40bce283ccSKevin Wolf
41bce283ccSKevin Wolf_supported_fmt qcow qcow2 vmdk qed
421f7bf7d0SPeter Lieven_supported_proto file
43bce283ccSKevin Wolf_supported_os Linux
44d2329f27SFam Zheng_unsupported_imgopts "subformat=monolithicFlat" \
45d2329f27SFam Zheng                     "subformat=twoGbMaxExtentFlat" \
46d2329f27SFam Zheng                     "subformat=twoGbMaxExtentSparse"
47bce283ccSKevin Wolf
48bce283ccSKevin WolfCLUSTER_SIZE=4k
49bce283ccSKevin Wolfsize=128M
50bce283ccSKevin Wolf
51bce283ccSKevin Wolfecho
52bce283ccSKevin Wolfecho "== creating backing file for COW tests =="
53bce283ccSKevin Wolf
54*9b652fbeSFam ZhengTEST_IMG_SAVE="$TEST_IMG"
55*9b652fbeSFam ZhengTEST_IMG="$TEST_IMG.base"
56*9b652fbeSFam Zheng
57bce283ccSKevin Wolf_make_test_img $size
58bce283ccSKevin Wolf
59bce283ccSKevin Wolffunction backing_io()
60bce283ccSKevin Wolf{
61bce283ccSKevin Wolf    local offset=$1
62bce283ccSKevin Wolf    local sectors=$2
63bce283ccSKevin Wolf    local op=$3
64bce283ccSKevin Wolf    local pattern=0
65bce283ccSKevin Wolf    local cur_sec=0
66bce283ccSKevin Wolf
67bce283ccSKevin Wolf    for i in $(seq 0 $((sectors - 1))); do
68bce283ccSKevin Wolf        cur_sec=$((offset / 512 + i))
69bce283ccSKevin Wolf        pattern=$(( ( (cur_sec % 256) + (cur_sec / 256)) % 256 ))
70bce283ccSKevin Wolf
71bce283ccSKevin Wolf        echo "$op -P $pattern $((cur_sec * 512)) 512"
72bce283ccSKevin Wolf    done
73bce283ccSKevin Wolf}
74bce283ccSKevin Wolf
75fef9c191SJeff Codybacking_io 0 256 write | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
76bce283ccSKevin Wolf
77*9b652fbeSFam ZhengTEST_IMG="$TEST_IMG_SAVE"
78bce283ccSKevin Wolf
79fef9c191SJeff Cody_make_test_img -b "$TEST_IMG.base" 6G
80bce283ccSKevin Wolf
81bce283ccSKevin Wolfecho
82bce283ccSKevin Wolfecho "== COW in a single cluster =="
83fef9c191SJeff Cody$QEMU_IO -c "write -P 0x77 0 2k" "$TEST_IMG" | _filter_qemu_io
84fef9c191SJeff Cody$QEMU_IO -c "write -P 0x88 6k 2k" "$TEST_IMG" | _filter_qemu_io
85fef9c191SJeff Cody$QEMU_IO -c "write -P 0x99 9k 2k" "$TEST_IMG" | _filter_qemu_io
86bce283ccSKevin Wolf
87fef9c191SJeff Cody$QEMU_IO -c "read -P 0x77 0 2k" "$TEST_IMG" | _filter_qemu_io
88fef9c191SJeff Codybacking_io $((2 * 1024)) 8 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
89fef9c191SJeff Cody$QEMU_IO -c "read -P 0x88 6k 2k" "$TEST_IMG" | _filter_qemu_io
90fef9c191SJeff Codybacking_io $((8 * 1024)) 2 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
91fef9c191SJeff Cody$QEMU_IO -c "read -P 0x99 9k 2k" "$TEST_IMG" | _filter_qemu_io
92fef9c191SJeff Codybacking_io $((11 * 1024)) 2 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
93bce283ccSKevin Wolf
94bce283ccSKevin Wolfecho
95bce283ccSKevin Wolfecho "== COW in two-cluster allocations =="
96fef9c191SJeff Cody$QEMU_IO -c "write -P 0x77 16k 6k" "$TEST_IMG" | _filter_qemu_io
97fef9c191SJeff Cody$QEMU_IO -c "write -P 0x88 26k 6k" "$TEST_IMG" | _filter_qemu_io
98fef9c191SJeff Cody$QEMU_IO -c "write -P 0x99 33k 5k" "$TEST_IMG" | _filter_qemu_io
99bce283ccSKevin Wolf
100fef9c191SJeff Cody$QEMU_IO -c "read -P 0x77 16k 6k" "$TEST_IMG" | _filter_qemu_io
101fef9c191SJeff Codybacking_io $((22 * 1024)) 8 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
102fef9c191SJeff Cody$QEMU_IO -c "read -P 0x88 26k 6k" "$TEST_IMG" | _filter_qemu_io
103fef9c191SJeff Codybacking_io $((32 * 1024)) 2 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
104fef9c191SJeff Cody$QEMU_IO -c "read -P 0x99 33k 5k" "$TEST_IMG" | _filter_qemu_io
105fef9c191SJeff Codybacking_io $((38 * 1024)) 4 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
106bce283ccSKevin Wolf
107bce283ccSKevin Wolfecho
108bce283ccSKevin Wolfecho "== COW in multi-cluster allocations =="
109fef9c191SJeff Cody$QEMU_IO -c "write -P 0x77 48k 15k" "$TEST_IMG" | _filter_qemu_io
110fef9c191SJeff Cody$QEMU_IO -c "write -P 0x88 66k 14k" "$TEST_IMG" | _filter_qemu_io
111fef9c191SJeff Cody$QEMU_IO -c "write -P 0x99 83k 15k" "$TEST_IMG" | _filter_qemu_io
112bce283ccSKevin Wolf
113fef9c191SJeff Cody$QEMU_IO -c "read -P 0x77 48k 15k" "$TEST_IMG" | _filter_qemu_io
114fef9c191SJeff Codybacking_io $((63 * 1024)) 6 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
115fef9c191SJeff Cody$QEMU_IO -c "read -P 0x88 66k 14k" "$TEST_IMG" | _filter_qemu_io
116fef9c191SJeff Codybacking_io $((80 * 1024)) 6 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
117fef9c191SJeff Cody$QEMU_IO -c "read -P 0x99 83k 15k" "$TEST_IMG" | _filter_qemu_io
118fef9c191SJeff Codybacking_io $((98 * 1024)) 4 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
119bce283ccSKevin Wolf
120bce283ccSKevin Wolf_check_test_img
121bce283ccSKevin Wolf
122bce283ccSKevin Wolf# success, all done
123bce283ccSKevin Wolfecho "*** done"
124bce283ccSKevin Wolfrm -f $seq.full
125bce283ccSKevin Wolfstatus=0
126