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 344e9b25fbSDaniel P. Berrange rm "${TEST_IMG_FILE2}" 35e930d201SMiroslav Rezanina} 36e930d201SMiroslav Rezaninatrap "_cleanup; exit \$status" 0 1 2 3 15 37e930d201SMiroslav Rezanina 38e930d201SMiroslav Rezanina_compare() 39e930d201SMiroslav Rezanina{ 404e9b25fbSDaniel P. Berrange $QEMU_IMG compare $QEMU_IMG_EXTRA_ARGS "$@" "$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 49*06af39ecSDaniel P. Berrange_supported_fmt raw qcow2 qed luks 50e930d201SMiroslav Rezanina_supported_proto file 51e930d201SMiroslav Rezanina_supported_os Linux 52e930d201SMiroslav Rezanina 534e9b25fbSDaniel P. Berrange# Remove once all tests are fixed to use TEST_IMG_FILE 544e9b25fbSDaniel P. Berrange# correctly and common.rc sets it unconditionally 554e9b25fbSDaniel P. Berrangetest -z "$TEST_IMG_FILE" && TEST_IMG_FILE=$TEST_IMG 564e9b25fbSDaniel P. Berrange 57e930d201SMiroslav Rezanina# Setup test basic parameters 58e930d201SMiroslav RezaninaTEST_IMG2=$TEST_IMG.2 594e9b25fbSDaniel P. BerrangeTEST_IMG_FILE2=$TEST_IMG_FILE.2 60e930d201SMiroslav RezaninaCLUSTER_SIZE=4096 614e9b25fbSDaniel P. Berrangesize=128M 62e930d201SMiroslav Rezanina 63e930d201SMiroslav Rezanina_make_test_img $size 64e930d201SMiroslav Rezaninaio_pattern write 524288 $CLUSTER_SIZE $CLUSTER_SIZE 4 45 65e930d201SMiroslav Rezanina 66e930d201SMiroslav Rezanina# Compare identical images 674e9b25fbSDaniel P. Berrangecp "$TEST_IMG_FILE" "${TEST_IMG_FILE2}" 68e930d201SMiroslav Rezanina_compare 69e930d201SMiroslav Rezanina_compare -q 70e930d201SMiroslav Rezanina 71e930d201SMiroslav Rezanina# Compare images with different size 724e9b25fbSDaniel P. Berrangeif [ "$IMGOPTSSYNTAX" = "true" ]; then 734e9b25fbSDaniel P. Berrange $QEMU_IMG resize $QEMU_IMG_EXTRA_ARGS "$TEST_IMG" +32M 744e9b25fbSDaniel P. Berrangeelse 754e9b25fbSDaniel P. Berrange $QEMU_IMG resize -f $IMGFMT "$TEST_IMG" +32M 764e9b25fbSDaniel P. Berrangefi 774e9b25fbSDaniel P. Berrange# Ensure extended space is zero-initialized 784e9b25fbSDaniel P. Berrange$QEMU_IO "$TEST_IMG" -c "write -z $size 32M" | _filter_qemu_io 794e9b25fbSDaniel P. Berrange 80e930d201SMiroslav Rezanina_compare 81e930d201SMiroslav Rezanina_compare -s 82e930d201SMiroslav Rezanina 83e930d201SMiroslav Rezanina# Compare images with different content 84e930d201SMiroslav Rezaninaio_pattern write 1228800 $CLUSTER_SIZE 0 1 67 85e930d201SMiroslav Rezanina_compare 86e930d201SMiroslav Rezaninaio_pattern write 0 $CLUSTER_SIZE 0 1 123 87e930d201SMiroslav Rezanina_compare 88e930d201SMiroslav Rezanina 8936452f12SFam Zheng# Test unaligned case of mismatch offsets in allocated clusters 9036452f12SFam Zheng_make_test_img $size 9136452f12SFam Zhengio_pattern write 0 512 0 1 100 924e9b25fbSDaniel P. Berrangecp "$TEST_IMG_FILE" "$TEST_IMG_FILE2" 9336452f12SFam Zhengio_pattern write 512 512 0 1 101 9436452f12SFam Zheng_compare 9536452f12SFam Zheng 96e930d201SMiroslav Rezanina# Cleanup 97e930d201SMiroslav Rezaninastatus=0 98