111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 2*9dd003a9SVladimir Sementsov-Ogievskiy# group: img auto quick 3e930d201SMiroslav Rezanina## 4e930d201SMiroslav Rezanina## qemu-img compare test 5e930d201SMiroslav Rezanina## 6e930d201SMiroslav Rezanina## 7e930d201SMiroslav Rezanina## Copyright (C) 2013 Red Hat, Inc. 8e930d201SMiroslav Rezanina## 9e930d201SMiroslav Rezanina## This program is free software; you can redistribute it and/or modify 10e930d201SMiroslav Rezanina## it under the terms of the GNU General Public License as published by 11e930d201SMiroslav Rezanina## the Free Software Foundation; either version 2 of the License, or 12e930d201SMiroslav Rezanina## (at your option) any later version. 13e930d201SMiroslav Rezanina## 14e930d201SMiroslav Rezanina## This program is distributed in the hope that it will be useful, 15e930d201SMiroslav Rezanina## but WITHOUT ANY WARRANTY; without even the implied warranty of 16e930d201SMiroslav Rezanina## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17e930d201SMiroslav Rezanina## GNU General Public License for more details. 18e930d201SMiroslav Rezanina## 19e930d201SMiroslav Rezanina## You should have received a copy of the GNU General Public License 20e930d201SMiroslav Rezanina## along with this program. If not, see <http://www.gnu.org/licenses/>. 21e930d201SMiroslav Rezanina## 22e930d201SMiroslav Rezanina# 23e930d201SMiroslav Rezanina# creator 24e930d201SMiroslav Rezaninaowner=mrezanin@redhat.com 25e930d201SMiroslav Rezanina 26e930d201SMiroslav Rezaninaseq=`basename $0` 27e930d201SMiroslav Rezaninaecho "QA output created by $seq" 28e930d201SMiroslav Rezanina 29e930d201SMiroslav Rezaninastatus=1 # failure is the default! 30e930d201SMiroslav Rezanina 31e930d201SMiroslav Rezanina_cleanup() 32e930d201SMiroslav Rezanina{ 33e930d201SMiroslav Rezanina echo "Cleanup" 34e930d201SMiroslav Rezanina _cleanup_test_img 35f91ecbd7SMax Reitz _rm_test_img "${TEST_IMG_FILE2}" 36e930d201SMiroslav Rezanina} 37e930d201SMiroslav Rezaninatrap "_cleanup; exit \$status" 0 1 2 3 15 38e930d201SMiroslav Rezanina 39e930d201SMiroslav Rezanina_compare() 40e930d201SMiroslav Rezanina{ 414e9b25fbSDaniel P. Berrange $QEMU_IMG compare $QEMU_IMG_EXTRA_ARGS "$@" "$TEST_IMG" "${TEST_IMG2}" 42e930d201SMiroslav Rezanina echo $? 43e930d201SMiroslav Rezanina} 44e930d201SMiroslav Rezanina 45e930d201SMiroslav Rezanina# get standard environment, filters and checks 46e930d201SMiroslav Rezanina. ./common.rc 47e930d201SMiroslav Rezanina. ./common.filter 48e930d201SMiroslav Rezanina. ./common.pattern 49e930d201SMiroslav Rezanina 5006af39ecSDaniel P. Berrange_supported_fmt raw qcow2 qed luks 51e930d201SMiroslav Rezanina_supported_proto file 52e930d201SMiroslav Rezanina_supported_os Linux 533be2024aSMax Reitz# Using 'cp' is incompatible with external data files 543be2024aSMax Reitz_unsupported_imgopts data_file 55e930d201SMiroslav Rezanina 564e9b25fbSDaniel P. Berrange# Remove once all tests are fixed to use TEST_IMG_FILE 574e9b25fbSDaniel P. Berrange# correctly and common.rc sets it unconditionally 584e9b25fbSDaniel P. Berrangetest -z "$TEST_IMG_FILE" && TEST_IMG_FILE=$TEST_IMG 594e9b25fbSDaniel P. Berrange 60e930d201SMiroslav Rezanina# Setup test basic parameters 61e930d201SMiroslav RezaninaTEST_IMG2=$TEST_IMG.2 624e9b25fbSDaniel P. BerrangeTEST_IMG_FILE2=$TEST_IMG_FILE.2 63e930d201SMiroslav RezaninaCLUSTER_SIZE=4096 644e9b25fbSDaniel P. Berrangesize=128M 65e930d201SMiroslav Rezanina 66e930d201SMiroslav Rezanina_make_test_img $size 67e930d201SMiroslav Rezaninaio_pattern write 524288 $CLUSTER_SIZE $CLUSTER_SIZE 4 45 68e930d201SMiroslav Rezanina 69e930d201SMiroslav Rezanina# Compare identical images 704e9b25fbSDaniel P. Berrangecp "$TEST_IMG_FILE" "${TEST_IMG_FILE2}" 71e930d201SMiroslav Rezanina_compare 72e930d201SMiroslav Rezanina_compare -q 73e930d201SMiroslav Rezanina 74e930d201SMiroslav Rezanina# Compare images with different size 754e9b25fbSDaniel P. Berrangeif [ "$IMGOPTSSYNTAX" = "true" ]; then 764e9b25fbSDaniel P. Berrange $QEMU_IMG resize $QEMU_IMG_EXTRA_ARGS "$TEST_IMG" +32M 774e9b25fbSDaniel P. Berrangeelse 784e9b25fbSDaniel P. Berrange $QEMU_IMG resize -f $IMGFMT "$TEST_IMG" +32M 794e9b25fbSDaniel P. Berrangefi 804e9b25fbSDaniel P. Berrange# Ensure extended space is zero-initialized 814e9b25fbSDaniel P. Berrange$QEMU_IO "$TEST_IMG" -c "write -z $size 32M" | _filter_qemu_io 824e9b25fbSDaniel P. Berrange 83e930d201SMiroslav Rezanina_compare 84e930d201SMiroslav Rezanina_compare -s 85e930d201SMiroslav Rezanina 86e930d201SMiroslav Rezanina# Compare images with different content 87e930d201SMiroslav Rezaninaio_pattern write 1228800 $CLUSTER_SIZE 0 1 67 88e930d201SMiroslav Rezanina_compare 89e930d201SMiroslav Rezaninaio_pattern write 0 $CLUSTER_SIZE 0 1 123 90e930d201SMiroslav Rezanina_compare 91e930d201SMiroslav Rezanina 9236452f12SFam Zheng# Test unaligned case of mismatch offsets in allocated clusters 9336452f12SFam Zheng_make_test_img $size 9436452f12SFam Zhengio_pattern write 0 512 0 1 100 954e9b25fbSDaniel P. Berrangecp "$TEST_IMG_FILE" "$TEST_IMG_FILE2" 9636452f12SFam Zhengio_pattern write 512 512 0 1 101 9736452f12SFam Zheng_compare 9836452f12SFam Zheng 99e930d201SMiroslav Rezanina# Cleanup 100e930d201SMiroslav Rezaninastatus=0 101