This patch is part of the Fast Virtual Disk (FVD) proposal. See http://wiki.qemu.org/Features/FVD.
test-qcow2.sh drives 'qemu-io --auto' to perform fully automated testing for QCOW2. Signed-off-by: Chunqiang Tang <ct...@us.ibm.com> --- test-qcow2.sh | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 89 insertions(+), 0 deletions(-) create mode 100755 test-qcow2.sh diff --git a/test-qcow2.sh b/test-qcow2.sh new file mode 100755 index 0000000..d1e4dc0 --- /dev/null +++ b/test-qcow2.sh @@ -0,0 +1,89 @@ +#!/bin/bash + +# Drive 'qemu-io --auto' to test the QCOW2 image format. +# +# Copyright IBM, Corp. 2010 +# +# Authors: +# Chunqiang Tang <ct...@us.ibm.com> +# +# This work is licensed under the terms of the GNU GPL, version 2 or later. +# See the COPYING.LIB file in the top-level directory. + +if [ $USER != "root" ]; then + echo "This command must be run by root in order to mount tmpfs." + exit 1 +fi + +QEMU_DIR=. +QEMU_IMG=$QEMU_DIR/qemu-img +QEMU_IO=$QEMU_DIR/qemu-io + +if [ ! -e $QEMU_IMG ]; then + echo "$QEMU_IMG does not exist." + exit 1; +fi + +if [ ! -e $QEMU_IO ]; then + echo "$QEMU_IO does not exist." + exit 1; +fi + +DATA_DIR=/var/ramdisk +TRUTH_IMG=$DATA_DIR/truth.raw +TEST_IMG=$DATA_DIR/test.qcow2 +TEST_BASE=$DATA_DIR/zero-500M.raw +CMD_LOG=./test-qcow2.log + +parallel=100 +round=10000 +fail_prob=0.1 +cancel_prob=0 +instant_qemubh=true +seed=$RANDOM$RANDOM +count=0 + +function invoke() { + echo "$*" >> $CMD_LOG + $* + ret=$? + if [ $ret -ne 0 ]; then + echo "Exit with error code $ret: $*" + exit $ret + fi +} + +mount | grep $DATA_DIR > /dev/null +if [ $? -ne 0 ]; then + echo "Create tmpfs at $DATA_DIR to store testing images." + if [ ! -e $DATA_DIR ]; then mkdir -p $DATA_DIR ; fi + invoke "mount -t tmpfs none $DATA_DIR -o size=4G" + if [ $? -ne 0 ]; then exit 1; fi +fi + +/bin/rm -f $CMD_LOG $DATA_DIR/* +touch $CMD_LOG + +while [ -t ]; do +for cache in none writethrough writeback; do +for cluster_size in 65536 ; do +for io_size in 1048576 ; do + count=$[$count + 1] + echo "Round $count" >> $CMD_LOG + + # QCOW2 image is about 1G + img_size=$[(1073741824 + ($RANDOM$RANDOM$RANDOM % 104857600)) / 512 * 512] + + # base image is about 500MB + base_size=$[(536870912 + ($RANDOM$RANDOM$RANDOM % 104857600)) / 512 * 512] + + invoke "/bin/rm -rf $TRUTH_IMG $TEST_IMG $TEST_BASE" + invoke "$QEMU_IO --auto --create=$TEST_BASE --seed=$seed --block_size=1048576 --empty_block_prob=0 --empty_block_chain=1 --file_size=$base_size" + invoke "cp --sparse=always $TEST_BASE $TRUTH_IMG" + invoke "dd if=/dev/zero of=$TRUTH_IMG count=0 bs=1 seek=$img_size" + invoke "$QEMU_IMG create -f qcow2 -ocluster_size=$cluster_size,backing_fmt=blksim -b $TEST_BASE $TEST_IMG $img_size" + + invoke "$QEMU_IO --auto --cache=$cache --seed=$seed --truth=$TRUTH_IMG --format=qcow2 --test="blksim:$TEST_IMG" --verify_write=true --compare_before=false --compare_after=true --round=$round --parallel=$parallel --io_size=$io_size --fail_prob=$fail_prob --cancel_prob=$cancel_prob --instant_qemubh=$instant_qemubh" + + seed=$[$seed + 1] +done; done; done; done -- 1.7.0.4