111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 29dd003a9SVladimir Sementsov-Ogievskiy# group: rw auto quick 3a1cb48a3SMax Reitz# 4a1cb48a3SMax Reitz# Test case for qcow2 metadata cache size specification 5a1cb48a3SMax Reitz# 6a1cb48a3SMax Reitz# Copyright (C) 2014 Red Hat, Inc. 7a1cb48a3SMax Reitz# 8a1cb48a3SMax Reitz# This program is free software; you can redistribute it and/or modify 9a1cb48a3SMax Reitz# it under the terms of the GNU General Public License as published by 10a1cb48a3SMax Reitz# the Free Software Foundation; either version 2 of the License, or 11a1cb48a3SMax Reitz# (at your option) any later version. 12a1cb48a3SMax Reitz# 13a1cb48a3SMax Reitz# This program is distributed in the hope that it will be useful, 14a1cb48a3SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of 15a1cb48a3SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16a1cb48a3SMax Reitz# GNU General Public License for more details. 17a1cb48a3SMax Reitz# 18a1cb48a3SMax Reitz# You should have received a copy of the GNU General Public License 19a1cb48a3SMax Reitz# along with this program. If not, see <http://www.gnu.org/licenses/>. 20a1cb48a3SMax Reitz# 21a1cb48a3SMax Reitz 22a1cb48a3SMax Reitz# creator 23*42a5009dSJohn Snowowner=hreitz@redhat.com 24a1cb48a3SMax Reitz 25a1cb48a3SMax Reitzseq=$(basename $0) 26a1cb48a3SMax Reitzecho "QA output created by $seq" 27a1cb48a3SMax Reitz 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 4157284d2aSMax Reitz_supported_proto file nfs fuse 423be2024aSMax Reitz# Internal snapshots are (currently) impossible with refcount_bits=1, 433be2024aSMax Reitz# and generally impossible with external data files 443be2024aSMax Reitz_unsupported_imgopts 'refcount_bits=1[^0-9]' data_file 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 694450c396SAlberto Garcia# Invalid cache entry sizes 704450c396SAlberto Garcia$QEMU_IO -c "open -o l2-cache-entry-size=256 $TEST_IMG" \ 714450c396SAlberto Garcia 2>&1 | _filter_testdir | _filter_imgfmt 724450c396SAlberto Garcia$QEMU_IO -c "open -o l2-cache-entry-size=4242 $TEST_IMG" \ 734450c396SAlberto Garcia 2>&1 | _filter_testdir | _filter_imgfmt 744450c396SAlberto Garcia$QEMU_IO -c "open -o l2-cache-entry-size=128k $TEST_IMG" \ 754450c396SAlberto Garcia 2>&1 | _filter_testdir | _filter_imgfmt 764450c396SAlberto Garcia 77a1cb48a3SMax Reitzecho 78a1cb48a3SMax Reitzecho '=== Testing valid option combinations ===' 79a1cb48a3SMax Reitzecho 80a1cb48a3SMax Reitz 81a1cb48a3SMax Reitz# There should be a reasonable and working minimum 82a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=0 $TEST_IMG" -c 'read -P 42 0 64k' \ 83a1cb48a3SMax Reitz | _filter_qemu_io 84a1cb48a3SMax Reitz$QEMU_IO -c "open -o l2-cache-size=0 $TEST_IMG" -c 'read -P 42 0 64k' \ 85a1cb48a3SMax Reitz | _filter_qemu_io 86a1cb48a3SMax Reitz$QEMU_IO -c "open -o refcount-cache-size=0 $TEST_IMG" -c 'read -P 42 0 64k' \ 87a1cb48a3SMax Reitz | _filter_qemu_io 88a1cb48a3SMax Reitz 89a1cb48a3SMax Reitz# Derive cache sizes from combined size (with a reasonable ratio, but we cannot 90a1cb48a3SMax Reitz# test that) 91a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=2M $TEST_IMG" -c 'read -P 42 0 64k' \ 92a1cb48a3SMax Reitz | _filter_qemu_io 93a1cb48a3SMax Reitz# Fix one cache, derive the other 94a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=2M,l2-cache-size=1M $TEST_IMG" \ 95a1cb48a3SMax Reitz -c 'read -P 42 0 64k' \ 96a1cb48a3SMax Reitz | _filter_qemu_io 97a1cb48a3SMax Reitz$QEMU_IO -c "open -o cache-size=2M,refcount-cache-size=1M $TEST_IMG" \ 98a1cb48a3SMax Reitz -c 'read -P 42 0 64k' \ 99a1cb48a3SMax Reitz | _filter_qemu_io 100a1cb48a3SMax Reitz# Directly set both caches 101a1cb48a3SMax Reitz$QEMU_IO -c "open -o l2-cache-size=1M,refcount-cache-size=0.25M $TEST_IMG" \ 102a1cb48a3SMax Reitz -c 'read -P 42 0 64k' \ 103a1cb48a3SMax Reitz | _filter_qemu_io 104a1cb48a3SMax Reitz 1054450c396SAlberto Garcia# Valid cache entry sizes 1064450c396SAlberto Garcia$QEMU_IO -c "open -o l2-cache-entry-size=512 $TEST_IMG" \ 1074450c396SAlberto Garcia 2>&1 | _filter_testdir | _filter_imgfmt 1084450c396SAlberto Garcia$QEMU_IO -c "open -o l2-cache-entry-size=16k $TEST_IMG" \ 1094450c396SAlberto Garcia 2>&1 | _filter_testdir | _filter_imgfmt 1104450c396SAlberto Garcia$QEMU_IO -c "open -o l2-cache-entry-size=64k $TEST_IMG" \ 1114450c396SAlberto Garcia 2>&1 | _filter_testdir | _filter_imgfmt 1124450c396SAlberto Garcia 1134450c396SAlberto Garcia 114a4291eafSMax Reitzecho 115a4291eafSMax Reitzecho '=== Testing minimal L2 cache and COW ===' 116a4291eafSMax Reitzecho 117a4291eafSMax Reitz 118a4291eafSMax Reitz$QEMU_IMG snapshot -c foo "$TEST_IMG" 119a4291eafSMax Reitz# This requires a COW operation, which accesses two L2 tables simultaneously 120a4291eafSMax Reitz# (COW source and destination), so there must be enough space in the cache to 121a4291eafSMax Reitz# place both tables there (and qemu should not crash) 122a4291eafSMax Reitz$QEMU_IO -c "open -o cache-size=0 $TEST_IMG" -c 'write 0 64k' | _filter_qemu_io 123a4291eafSMax Reitz 124a1cb48a3SMax Reitz# success, all done 125a1cb48a3SMax Reitzecho '*** done' 126a1cb48a3SMax Reitzrm -f $seq.full 127a1cb48a3SMax Reitzstatus=0 128