xref: /openbmc/qemu/tests/qemu-iotests/023 (revision 11a82d14293cd66f428f535741717ff338c0722b)
1*11a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
2ac5e2b20SKevin Wolf#
3ac5e2b20SKevin Wolf# qcow2 pattern test with various cluster sizes
4ac5e2b20SKevin Wolf#
5ac5e2b20SKevin Wolf# Copyright (C) 2009 Red Hat, Inc.
6ac5e2b20SKevin Wolf#
7ac5e2b20SKevin Wolf# This program is free software; you can redistribute it and/or modify
8ac5e2b20SKevin Wolf# it under the terms of the GNU General Public License as published by
9ac5e2b20SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
10ac5e2b20SKevin Wolf# (at your option) any later version.
11ac5e2b20SKevin Wolf#
12ac5e2b20SKevin Wolf# This program is distributed in the hope that it will be useful,
13ac5e2b20SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
14ac5e2b20SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15ac5e2b20SKevin Wolf# GNU General Public License for more details.
16ac5e2b20SKevin Wolf#
17ac5e2b20SKevin Wolf# You should have received a copy of the GNU General Public License
18ac5e2b20SKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19ac5e2b20SKevin Wolf#
20ac5e2b20SKevin Wolf
21ac5e2b20SKevin Wolf# creator
22ac5e2b20SKevin Wolfowner=kwolf@redhat.com
23ac5e2b20SKevin Wolf
24ac5e2b20SKevin Wolfseq=`basename $0`
25ac5e2b20SKevin Wolfecho "QA output created by $seq"
26ac5e2b20SKevin Wolf
27ac5e2b20SKevin Wolfstatus=1	# failure is the default!
28ac5e2b20SKevin Wolf
29ac5e2b20SKevin Wolf_cleanup()
30ac5e2b20SKevin Wolf{
31ac5e2b20SKevin Wolf	_cleanup_test_img
32ac5e2b20SKevin Wolf}
33ac5e2b20SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
34ac5e2b20SKevin Wolf
35ac5e2b20SKevin Wolf# get standard environment, filters and checks
36ac5e2b20SKevin Wolf. ./common.rc
37ac5e2b20SKevin Wolf. ./common.filter
38ac5e2b20SKevin Wolf. ./common.pattern
39ac5e2b20SKevin Wolf
40ac5e2b20SKevin Wolf# much of this could be generic for any format supporting compression.
41ac5e2b20SKevin Wolf_supported_fmt qcow qcow2
421f7bf7d0SPeter Lieven_supported_proto file
43ac5e2b20SKevin Wolf_supported_os Linux
44ac5e2b20SKevin Wolf
45ac5e2b20SKevin WolfTEST_OFFSETS="0 4294967296"
46ac5e2b20SKevin WolfTEST_OPS="writev read write readv"
47ac5e2b20SKevin Wolf
48ac5e2b20SKevin Wolf# Can't use 512 byte clusters, the tests use cluster halves
49ac5e2b20SKevin WolfCLUSTER_SIZES="1024 4096 16384 65536"
50ac5e2b20SKevin Wolf
51ac5e2b20SKevin Wolffor CLUSTER_SIZE in $CLUSTER_SIZES; do
52ac5e2b20SKevin Wolf
53ac5e2b20SKevin Wolf    echo "Creating new image; cluster size: $CLUSTER_SIZE"
54ac5e2b20SKevin Wolf    echo
55ac5e2b20SKevin Wolf
56ac5e2b20SKevin Wolf    _make_test_img 8G
57ac5e2b20SKevin Wolf
58ac5e2b20SKevin Wolf    echo "Testing empty image"
59ac5e2b20SKevin Wolf    echo
60ac5e2b20SKevin Wolf
61ac5e2b20SKevin Wolf    for offset in $TEST_OFFSETS; do
62ac5e2b20SKevin Wolf        echo "At offset $offset:"
63ac5e2b20SKevin Wolf        for op in $TEST_OPS; do
64ac5e2b20SKevin Wolf            io_test $op $offset $CLUSTER_SIZE 3
65ac5e2b20SKevin Wolf        done
66ac5e2b20SKevin Wolf        _check_test_img
67ac5e2b20SKevin Wolf    done
68ac5e2b20SKevin Wolf
69ac5e2b20SKevin Wolf    echo "Compressing image"
70ac5e2b20SKevin Wolf    echo
71ac5e2b20SKevin Wolf
72fef9c191SJeff Cody    mv "$TEST_IMG" "$TEST_IMG.orig"
73fef9c191SJeff Cody    $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -c "$TEST_IMG.orig" "$TEST_IMG"
74ac5e2b20SKevin Wolf
75ac5e2b20SKevin Wolf    echo "Testing compressed image"
76ac5e2b20SKevin Wolf    echo
77ac5e2b20SKevin Wolf
78ac5e2b20SKevin Wolf    for offset in $TEST_OFFSETS; do
79ac5e2b20SKevin Wolf        echo "With offset $offset:"
80ac5e2b20SKevin Wolf        for op in read readv; do
81ac5e2b20SKevin Wolf            io_test $op $offset $CLUSTER_SIZE 3
82ac5e2b20SKevin Wolf        done
83ac5e2b20SKevin Wolf        _check_test_img
84ac5e2b20SKevin Wolf    done
85ac5e2b20SKevin Wolf
86ac5e2b20SKevin Wolf    echo "Testing compressed image with odd offsets"
87ac5e2b20SKevin Wolf    echo
88ac5e2b20SKevin Wolf    for offset in $TEST_OFFSETS; do
89ac5e2b20SKevin Wolf        # Some odd offset (1 sector), so tests will write to areas occupied partly
90ac5e2b20SKevin Wolf        # by old (compressed) data and empty clusters
91ac5e2b20SKevin Wolf        offset=$((offset + 512))
92ac5e2b20SKevin Wolf        echo "With offset $offset:"
93ac5e2b20SKevin Wolf        for op in $TEST_OPS; do
94ac5e2b20SKevin Wolf            io_test $op $offset $CLUSTER_SIZE 3
95ac5e2b20SKevin Wolf        done
96ac5e2b20SKevin Wolf        _check_test_img
97ac5e2b20SKevin Wolf    done
98ac5e2b20SKevin Wolf
99ac5e2b20SKevin Wolf    echo "Creating another new image"
100ac5e2b20SKevin Wolf    echo
101ac5e2b20SKevin Wolf
102ac5e2b20SKevin Wolf    _make_test_img 8G
103ac5e2b20SKevin Wolf
104ac5e2b20SKevin Wolf    echo "More complex patterns"
105ac5e2b20SKevin Wolf    echo
106ac5e2b20SKevin Wolf
107ac5e2b20SKevin Wolf    for offset in $TEST_OFFSETS; do
108ac5e2b20SKevin Wolf        echo test2: With offset $offset
109ac5e2b20SKevin Wolf        io_test2 $offset $CLUSTER_SIZE 4
110ac5e2b20SKevin Wolf        _check_test_img
111ac5e2b20SKevin Wolf    done
112ac5e2b20SKevin Wolf
113ac5e2b20SKevin Wolfdone
114ac5e2b20SKevin Wolf
115ac5e2b20SKevin Wolf# success, all done
116ac5e2b20SKevin Wolfecho "*** done"
117ac5e2b20SKevin Wolfrm -f $seq.full
118ac5e2b20SKevin Wolfstatus=0
119