1e930d201SMiroslav Rezanina#!/bin/bash 2e930d201SMiroslav Rezanina## 3e930d201SMiroslav Rezanina## qemu-img compare test 4e930d201SMiroslav Rezanina## 5e930d201SMiroslav Rezanina## 6e930d201SMiroslav Rezanina## Copyright (C) 2013 Red Hat, Inc. 7e930d201SMiroslav Rezanina## 8e930d201SMiroslav Rezanina## This program is free software; you can redistribute it and/or modify 9e930d201SMiroslav Rezanina## it under the terms of the GNU General Public License as published by 10e930d201SMiroslav Rezanina## the Free Software Foundation; either version 2 of the License, or 11e930d201SMiroslav Rezanina## (at your option) any later version. 12e930d201SMiroslav Rezanina## 13e930d201SMiroslav Rezanina## This program is distributed in the hope that it will be useful, 14e930d201SMiroslav Rezanina## but WITHOUT ANY WARRANTY; without even the implied warranty of 15e930d201SMiroslav Rezanina## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16e930d201SMiroslav Rezanina## GNU General Public License for more details. 17e930d201SMiroslav Rezanina## 18e930d201SMiroslav Rezanina## You should have received a copy of the GNU General Public License 19e930d201SMiroslav Rezanina## along with this program. If not, see <http://www.gnu.org/licenses/>. 20e930d201SMiroslav Rezanina## 21e930d201SMiroslav Rezanina# 22e930d201SMiroslav Rezanina# creator 23e930d201SMiroslav Rezaninaowner=mrezanin@redhat.com 24e930d201SMiroslav Rezanina 25e930d201SMiroslav Rezaninaseq=`basename $0` 26e930d201SMiroslav Rezaninaecho "QA output created by $seq" 27e930d201SMiroslav Rezanina 28e930d201SMiroslav Rezaninastatus=1 # failure is the default! 29e930d201SMiroslav Rezanina 30e930d201SMiroslav Rezanina_cleanup() 31e930d201SMiroslav Rezanina{ 32e930d201SMiroslav Rezanina echo "Cleanup" 33e930d201SMiroslav Rezanina _cleanup_test_img 34fef9c191SJeff Cody rm "${TEST_IMG2}" 35e930d201SMiroslav Rezanina} 36e930d201SMiroslav Rezaninatrap "_cleanup; exit \$status" 0 1 2 3 15 37e930d201SMiroslav Rezanina 38e930d201SMiroslav Rezanina_compare() 39e930d201SMiroslav Rezanina{ 40fef9c191SJeff Cody $QEMU_IMG compare "$@" "$TEST_IMG" "${TEST_IMG2}" 41e930d201SMiroslav Rezanina echo $? 42e930d201SMiroslav Rezanina} 43e930d201SMiroslav Rezanina 44e930d201SMiroslav Rezanina# get standard environment, filters and checks 45e930d201SMiroslav Rezanina. ./common.rc 46e930d201SMiroslav Rezanina. ./common.filter 47e930d201SMiroslav Rezanina. ./common.pattern 48e930d201SMiroslav Rezanina 49e930d201SMiroslav Rezanina_supported_fmt raw qcow qcow2 qed 50e930d201SMiroslav Rezanina_supported_proto file 51e930d201SMiroslav Rezanina_supported_os Linux 52e930d201SMiroslav Rezanina 53e930d201SMiroslav Rezanina# Setup test basic parameters 54e930d201SMiroslav RezaninaTEST_IMG2=$TEST_IMG.2 55e930d201SMiroslav RezaninaCLUSTER_SIZE=4096 56e930d201SMiroslav Rezaninasize=1024M 57e930d201SMiroslav Rezanina 58e930d201SMiroslav Rezanina_make_test_img $size 59e930d201SMiroslav Rezaninaio_pattern write 524288 $CLUSTER_SIZE $CLUSTER_SIZE 4 45 60e930d201SMiroslav Rezanina 61e930d201SMiroslav Rezanina# Compare identical images 62fef9c191SJeff Codycp "$TEST_IMG" "${TEST_IMG2}" 63e930d201SMiroslav Rezanina_compare 64e930d201SMiroslav Rezanina_compare -q 65e930d201SMiroslav Rezanina 66e930d201SMiroslav Rezanina# Compare images with different size 67fef9c191SJeff Cody$QEMU_IMG resize "$TEST_IMG" +512M 68e930d201SMiroslav Rezanina_compare 69e930d201SMiroslav Rezanina_compare -s 70e930d201SMiroslav Rezanina 71e930d201SMiroslav Rezanina# Compare images with different content 72e930d201SMiroslav Rezaninaio_pattern write 1228800 $CLUSTER_SIZE 0 1 67 73e930d201SMiroslav Rezanina_compare 74e930d201SMiroslav Rezaninaio_pattern write 0 $CLUSTER_SIZE 0 1 123 75e930d201SMiroslav Rezanina_compare 76e930d201SMiroslav Rezanina 77*36452f12SFam Zheng# Test unaligned case of mismatch offsets in allocated clusters 78*36452f12SFam Zheng_make_test_img $size 79*36452f12SFam Zhengio_pattern write 0 512 0 1 100 80*36452f12SFam Zhengcp "$TEST_IMG" "$TEST_IMG2" 81*36452f12SFam Zhengio_pattern write 512 512 0 1 101 82*36452f12SFam Zheng_compare 83*36452f12SFam Zheng 84*36452f12SFam Zheng# Test cluster allocated in one, with IO error 85*36452f12SFam Zhengcat > "$TEST_DIR/blkdebug.conf"<<EOF 86*36452f12SFam Zheng[inject-error] 87*36452f12SFam Zhengevent = "read_aio" 88*36452f12SFam Zhengerrno = "5" 89*36452f12SFam Zhengonce ="off" 90*36452f12SFam ZhengEOF 91*36452f12SFam Zheng_make_test_img $size 92*36452f12SFam Zhengcp "$TEST_IMG" "$TEST_IMG2" 93*36452f12SFam Zhengio_pattern write 512 512 0 1 102 94*36452f12SFam ZhengTEST_IMG="blkdebug:$TEST_DIR/blkdebug.conf:$TEST_IMG" _compare 2>&1 |\ 95*36452f12SFam Zheng _filter_testdir | _filter_imgfmt 96*36452f12SFam Zheng 97*36452f12SFam Zheng# Test cluster allocated in one, with different sizes and IO error in the part 98*36452f12SFam Zheng# that exists only in one image 99*36452f12SFam Zhengcat > "$TEST_DIR/blkdebug.conf"<<EOF 100*36452f12SFam Zheng[inject-error] 101*36452f12SFam Zhengevent = "read_aio" 102*36452f12SFam Zhengerrno = "5" 103*36452f12SFam Zhengonce ="off" 104*36452f12SFam ZhengEOF 105*36452f12SFam Zheng_make_test_img $size 106*36452f12SFam ZhengTEST_IMG="$TEST_IMG2" _make_test_img 0 107*36452f12SFam Zhengio_pattern write 512 512 0 1 102 108*36452f12SFam ZhengTEST_IMG="blkdebug:$TEST_DIR/blkdebug.conf:$TEST_IMG" _compare 2>&1 |\ 109*36452f12SFam Zheng _filter_testdir | _filter_imgfmt 110*36452f12SFam Zheng 111e930d201SMiroslav Rezanina# Cleanup 112e930d201SMiroslav Rezaninastatus=0 113