xref: /qemu/tests/qemu-iotests/103 (revision c5f7c0af473cadb8b0b5fc6d399e4ede1fc9408d)
1a1cb48a3SMax Reitz#!/bin/bash
2a1cb48a3SMax Reitz#
3a1cb48a3SMax Reitz# Test case for qcow2 metadata cache size specification
4a1cb48a3SMax Reitz#
5a1cb48a3SMax Reitz# Copyright (C) 2014 Red Hat, Inc.
6a1cb48a3SMax Reitz#
7a1cb48a3SMax Reitz# This program is free software; you can redistribute it and/or modify
8a1cb48a3SMax Reitz# it under the terms of the GNU General Public License as published by
9a1cb48a3SMax Reitz# the Free Software Foundation; either version 2 of the License, or
10a1cb48a3SMax Reitz# (at your option) any later version.
11a1cb48a3SMax Reitz#
12a1cb48a3SMax Reitz# This program is distributed in the hope that it will be useful,
13a1cb48a3SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
14a1cb48a3SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15a1cb48a3SMax Reitz# GNU General Public License for more details.
16a1cb48a3SMax Reitz#
17a1cb48a3SMax Reitz# You should have received a copy of the GNU General Public License
18a1cb48a3SMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19a1cb48a3SMax Reitz#
20a1cb48a3SMax Reitz
21a1cb48a3SMax Reitz# creator
22a1cb48a3SMax Reitzowner=mreitz@redhat.com
23a1cb48a3SMax Reitz
24a1cb48a3SMax Reitzseq=$(basename $0)
25a1cb48a3SMax Reitzecho "QA output created by $seq"
26a1cb48a3SMax Reitz
27a1cb48a3SMax Reitzhere=$PWD
28a1cb48a3SMax Reitztmp=/tmp/$$
29a1cb48a3SMax Reitzstatus=1	# failure is the default!
30a1cb48a3SMax Reitz
31a1cb48a3SMax Reitz_cleanup()
32a1cb48a3SMax Reitz{
33a1cb48a3SMax Reitz	_cleanup_test_img
34a1cb48a3SMax Reitz}
35a1cb48a3SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
36a1cb48a3SMax Reitz
37a1cb48a3SMax Reitz# get standard environment, filters and checks
38a1cb48a3SMax Reitz. ./common.rc
39a1cb48a3SMax Reitz. ./common.filter
40a1cb48a3SMax Reitz
41a1cb48a3SMax Reitz_supported_fmt qcow2
42*c5f7c0afSPeter Lieven_supported_proto file nfs
43a1cb48a3SMax Reitz_supported_os Linux
44a1cb48a3SMax Reitz
45a1cb48a3SMax ReitzIMG_SIZE=64K
46a1cb48a3SMax Reitz
47a1cb48a3SMax Reitz_make_test_img $IMG_SIZE
48a1cb48a3SMax Reitz$QEMU_IO -c 'write -P 42 0 64k' "$TEST_IMG" | _filter_qemu_io
49a1cb48a3SMax Reitz
50a1cb48a3SMax Reitzecho
51a1cb48a3SMax Reitzecho '=== Testing invalid option combinations ==='
52a1cb48a3SMax Reitzecho
53a1cb48a3SMax Reitz
54a1cb48a3SMax Reitz# all sizes set at the same time
55a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=1.25M,l2-cache-size=1M,refcount-cache-size=0.25M $TEST_IMG" \
56a1cb48a3SMax Reitz    2>&1 | _filter_testdir | _filter_imgfmt
57a1cb48a3SMax Reitz# l2-cache-size may not exceed cache-size
58a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=1M,l2-cache-size=2M $TEST_IMG" 2>&1 \
59a1cb48a3SMax Reitz    | _filter_testdir | _filter_imgfmt
60a1cb48a3SMax Reitz# refcount-cache-size may not exceed cache-size
61a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=1M,refcount-cache-size=2M $TEST_IMG" 2>&1 \
62a1cb48a3SMax Reitz    | _filter_testdir | _filter_imgfmt
63a1cb48a3SMax Reitz# 0 should be a valid size (e.g. for enforcing the minimum), so this should not
64a1cb48a3SMax Reitz# work
65a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=0,l2-cache-size=0,refcount-cache-size=0 $TEST_IMG" \
66a1cb48a3SMax Reitz    2>&1 | _filter_testdir | _filter_imgfmt
67a1cb48a3SMax Reitz
68a1cb48a3SMax Reitzecho
69a1cb48a3SMax Reitzecho '=== Testing valid option combinations ==='
70a1cb48a3SMax Reitzecho
71a1cb48a3SMax Reitz
72a1cb48a3SMax Reitz# There should be a reasonable and working minimum
73a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=0 $TEST_IMG" -c 'read -P 42 0 64k' \
74a1cb48a3SMax Reitz    | _filter_qemu_io
75a1cb48a3SMax Reitz$QEMU_IO -c "open -o l2-cache-size=0 $TEST_IMG" -c 'read -P 42 0 64k' \
76a1cb48a3SMax Reitz    | _filter_qemu_io
77a1cb48a3SMax Reitz$QEMU_IO -c "open -o refcount-cache-size=0 $TEST_IMG" -c 'read -P 42 0 64k' \
78a1cb48a3SMax Reitz    | _filter_qemu_io
79a1cb48a3SMax Reitz
80a1cb48a3SMax Reitz# Derive cache sizes from combined size (with a reasonable ratio, but we cannot
81a1cb48a3SMax Reitz# test that)
82a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=2M $TEST_IMG" -c 'read -P 42 0 64k' \
83a1cb48a3SMax Reitz    | _filter_qemu_io
84a1cb48a3SMax Reitz# Fix one cache, derive the other
85a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=2M,l2-cache-size=1M $TEST_IMG" \
86a1cb48a3SMax Reitz         -c 'read -P 42 0 64k' \
87a1cb48a3SMax Reitz    | _filter_qemu_io
88a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=2M,refcount-cache-size=1M $TEST_IMG" \
89a1cb48a3SMax Reitz         -c 'read -P 42 0 64k' \
90a1cb48a3SMax Reitz    | _filter_qemu_io
91a1cb48a3SMax Reitz# Directly set both caches
92a1cb48a3SMax Reitz$QEMU_IO -c "open -o l2-cache-size=1M,refcount-cache-size=0.25M $TEST_IMG" \
93a1cb48a3SMax Reitz         -c 'read -P 42 0 64k' \
94a1cb48a3SMax Reitz    | _filter_qemu_io
95a1cb48a3SMax Reitz
96a1cb48a3SMax Reitz# success, all done
97a1cb48a3SMax Reitzecho '*** done'
98a1cb48a3SMax Reitzrm -f $seq.full
99a1cb48a3SMax Reitzstatus=0
100