xref: /openbmc/qemu/tests/qemu-iotests/103 (revision a03a57a0f9ff4cc405ca7644d965154afe1ac51e)
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 Reitzstatus=1	# failure is the default!
29a1cb48a3SMax Reitz
30a1cb48a3SMax Reitz_cleanup()
31a1cb48a3SMax Reitz{
32a1cb48a3SMax Reitz	_cleanup_test_img
33a1cb48a3SMax Reitz}
34a1cb48a3SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
35a1cb48a3SMax Reitz
36a1cb48a3SMax Reitz# get standard environment, filters and checks
37a1cb48a3SMax Reitz. ./common.rc
38a1cb48a3SMax Reitz. ./common.filter
39a1cb48a3SMax Reitz
40a1cb48a3SMax Reitz_supported_fmt qcow2
41c5f7c0afSPeter Lieven_supported_proto file nfs
42a1cb48a3SMax Reitz_supported_os Linux
43*a03a57a0SMax Reitz# Internal snapshots are (currently) impossible with refcount_bits=1
44*a03a57a0SMax Reitz_unsupported_imgopts 'refcount_bits=1[^0-9]'
45a1cb48a3SMax Reitz
46a1cb48a3SMax ReitzIMG_SIZE=64K
47a1cb48a3SMax Reitz
48a1cb48a3SMax Reitz_make_test_img $IMG_SIZE
49a1cb48a3SMax Reitz$QEMU_IO -c 'write -P 42 0 64k' "$TEST_IMG" | _filter_qemu_io
50a1cb48a3SMax Reitz
51a1cb48a3SMax Reitzecho
52a1cb48a3SMax Reitzecho '=== Testing invalid option combinations ==='
53a1cb48a3SMax Reitzecho
54a1cb48a3SMax Reitz
55a1cb48a3SMax Reitz# all sizes set at the same time
56a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=1.25M,l2-cache-size=1M,refcount-cache-size=0.25M $TEST_IMG" \
57a1cb48a3SMax Reitz    2>&1 | _filter_testdir | _filter_imgfmt
58a1cb48a3SMax Reitz# l2-cache-size may not exceed cache-size
59a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=1M,l2-cache-size=2M $TEST_IMG" 2>&1 \
60a1cb48a3SMax Reitz    | _filter_testdir | _filter_imgfmt
61a1cb48a3SMax Reitz# refcount-cache-size may not exceed cache-size
62a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=1M,refcount-cache-size=2M $TEST_IMG" 2>&1 \
63a1cb48a3SMax Reitz    | _filter_testdir | _filter_imgfmt
64a1cb48a3SMax Reitz# 0 should be a valid size (e.g. for enforcing the minimum), so this should not
65a1cb48a3SMax Reitz# work
66a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=0,l2-cache-size=0,refcount-cache-size=0 $TEST_IMG" \
67a1cb48a3SMax Reitz    2>&1 | _filter_testdir | _filter_imgfmt
68a1cb48a3SMax Reitz
69a1cb48a3SMax Reitzecho
70a1cb48a3SMax Reitzecho '=== Testing valid option combinations ==='
71a1cb48a3SMax Reitzecho
72a1cb48a3SMax Reitz
73a1cb48a3SMax Reitz# There should be a reasonable and working minimum
74a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=0 $TEST_IMG" -c 'read -P 42 0 64k' \
75a1cb48a3SMax Reitz    | _filter_qemu_io
76a1cb48a3SMax Reitz$QEMU_IO -c "open -o l2-cache-size=0 $TEST_IMG" -c 'read -P 42 0 64k' \
77a1cb48a3SMax Reitz    | _filter_qemu_io
78a1cb48a3SMax Reitz$QEMU_IO -c "open -o refcount-cache-size=0 $TEST_IMG" -c 'read -P 42 0 64k' \
79a1cb48a3SMax Reitz    | _filter_qemu_io
80a1cb48a3SMax Reitz
81a1cb48a3SMax Reitz# Derive cache sizes from combined size (with a reasonable ratio, but we cannot
82a1cb48a3SMax Reitz# test that)
83a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=2M $TEST_IMG" -c 'read -P 42 0 64k' \
84a1cb48a3SMax Reitz    | _filter_qemu_io
85a1cb48a3SMax Reitz# Fix one cache, derive the other
86a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=2M,l2-cache-size=1M $TEST_IMG" \
87a1cb48a3SMax Reitz         -c 'read -P 42 0 64k' \
88a1cb48a3SMax Reitz    | _filter_qemu_io
89a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=2M,refcount-cache-size=1M $TEST_IMG" \
90a1cb48a3SMax Reitz         -c 'read -P 42 0 64k' \
91a1cb48a3SMax Reitz    | _filter_qemu_io
92a1cb48a3SMax Reitz# Directly set both caches
93a1cb48a3SMax Reitz$QEMU_IO -c "open -o l2-cache-size=1M,refcount-cache-size=0.25M $TEST_IMG" \
94a1cb48a3SMax Reitz         -c 'read -P 42 0 64k' \
95a1cb48a3SMax Reitz    | _filter_qemu_io
96a1cb48a3SMax Reitz
97a4291eafSMax Reitzecho
98a4291eafSMax Reitzecho '=== Testing minimal L2 cache and COW ==='
99a4291eafSMax Reitzecho
100a4291eafSMax Reitz
101a4291eafSMax Reitz$QEMU_IMG snapshot -c foo "$TEST_IMG"
102a4291eafSMax Reitz# This requires a COW operation, which accesses two L2 tables simultaneously
103a4291eafSMax Reitz# (COW source and destination), so there must be enough space in the cache to
104a4291eafSMax Reitz# place both tables there (and qemu should not crash)
105a4291eafSMax Reitz$QEMU_IO -c "open -o cache-size=0 $TEST_IMG" -c 'write 0 64k' | _filter_qemu_io
106a4291eafSMax Reitz
107a1cb48a3SMax Reitz# success, all done
108a1cb48a3SMax Reitzecho '*** done'
109a1cb48a3SMax Reitzrm -f $seq.full
110a1cb48a3SMax Reitzstatus=0
111