111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 2*9dd003a9SVladimir Sementsov-Ogievskiy# group: rw auto quick 3b2e10493SAlexandre Derumier# 4b2e10493SAlexandre Derumier# test of qemu-img convert -n - convert without creation 5b2e10493SAlexandre Derumier# 6b2e10493SAlexandre Derumier# Copyright (C) 2009 Red Hat, Inc. 7b2e10493SAlexandre Derumier# Copyright (C) 2013 Alex Bligh (alex@alex.org.uk) 8b2e10493SAlexandre Derumier# 9b2e10493SAlexandre Derumier# This program is free software; you can redistribute it and/or modify 10b2e10493SAlexandre Derumier# it under the terms of the GNU General Public License as published by 11b2e10493SAlexandre Derumier# the Free Software Foundation; either version 2 of the License, or 12b2e10493SAlexandre Derumier# (at your option) any later version. 13b2e10493SAlexandre Derumier# 14b2e10493SAlexandre Derumier# This program is distributed in the hope that it will be useful, 15b2e10493SAlexandre Derumier# but WITHOUT ANY WARRANTY; without even the implied warranty of 16b2e10493SAlexandre Derumier# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17b2e10493SAlexandre Derumier# GNU General Public License for more details. 18b2e10493SAlexandre Derumier# 19b2e10493SAlexandre Derumier# You should have received a copy of the GNU General Public License 20b2e10493SAlexandre Derumier# along with this program. If not, see <http://www.gnu.org/licenses/>. 21b2e10493SAlexandre Derumier# 22b2e10493SAlexandre Derumier 23b2e10493SAlexandre Derumier# creator 24b2e10493SAlexandre Derumierowner=alex@alex.org.uk 25b2e10493SAlexandre Derumier 26b2e10493SAlexandre Derumierseq=`basename $0` 27b2e10493SAlexandre Derumierecho "QA output created by $seq" 28b2e10493SAlexandre Derumier 29b2e10493SAlexandre Derumierstatus=1 # failure is the default! 30b2e10493SAlexandre Derumier 31b2e10493SAlexandre Derumier_cleanup() 32b2e10493SAlexandre Derumier{ 33b2e10493SAlexandre Derumier _cleanup_test_img 34f91ecbd7SMax Reitz for img in "$TEST_IMG".{orig,raw1,raw2,target}; do 35f91ecbd7SMax Reitz _rm_test_img "$img" 36f91ecbd7SMax Reitz done 37b2e10493SAlexandre Derumier} 38b2e10493SAlexandre Derumiertrap "_cleanup; exit \$status" 0 1 2 3 15 39b2e10493SAlexandre Derumier 40b2e10493SAlexandre Derumier# get standard environment, filters and checks 41b2e10493SAlexandre Derumier. ./common.rc 42b2e10493SAlexandre Derumier. ./common.filter 43b2e10493SAlexandre Derumier. ./common.pattern 44b2e10493SAlexandre Derumier 45b2e10493SAlexandre Derumier_supported_fmt qcow qcow2 vmdk qed raw 461f7bf7d0SPeter Lieven_supported_proto file 47d2329f27SFam Zheng_unsupported_imgopts "subformat=monolithicFlat" \ 48d2329f27SFam Zheng "subformat=twoGbMaxExtentFlat" \ 49325dd915SMax Reitz "subformat=twoGbMaxExtentSparse" \ 50325dd915SMax Reitz "subformat=streamOptimized" 51b2e10493SAlexandre Derumier 52b2e10493SAlexandre Derumier_make_test_img 4M 53b2e10493SAlexandre Derumier 54b2e10493SAlexandre Derumierecho "== Testing conversion with -n fails with no target file ==" 55fef9c191SJeff Codyif $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -n "$TEST_IMG" "$TEST_IMG.orig" >/dev/null 2>&1; then 56b2e10493SAlexandre Derumier exit 1 57b2e10493SAlexandre Derumierfi 58b2e10493SAlexandre Derumier 59b2e10493SAlexandre Derumierecho "== Testing conversion with -n succeeds with a target file ==" 60d88bef19SMax Reitz_rm_test_img "$TEST_IMG.orig" 61d88bef19SMax ReitzTEST_IMG="$TEST_IMG.orig" _make_test_img 4M 62fef9c191SJeff Codyif ! $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -n "$TEST_IMG" "$TEST_IMG.orig" ; then 63b2e10493SAlexandre Derumier exit 1 64b2e10493SAlexandre Derumierfi 65b2e10493SAlexandre Derumier 66b2e10493SAlexandre Derumierecho "== Testing conversion to raw is the same after conversion with -n ==" 67b2e10493SAlexandre Derumier# compare the raw files 68fef9c191SJeff Codyif ! $QEMU_IMG convert -f $IMGFMT -O raw "$TEST_IMG" "$TEST_IMG.raw1" ; then 69b2e10493SAlexandre Derumier exit 1 70b2e10493SAlexandre Derumierfi 71b2e10493SAlexandre Derumier 72fef9c191SJeff Codyif ! $QEMU_IMG convert -f $IMGFMT -O raw "$TEST_IMG.orig" "$TEST_IMG.raw2" ; then 73b2e10493SAlexandre Derumier exit 1 74b2e10493SAlexandre Derumierfi 75b2e10493SAlexandre Derumier 76fef9c191SJeff Codyif ! cmp "$TEST_IMG.raw1" "$TEST_IMG.raw2" ; then 77b2e10493SAlexandre Derumier exit 1 78b2e10493SAlexandre Derumierfi 79b2e10493SAlexandre Derumier 80b2e10493SAlexandre Derumierecho "== Testing conversion back to original format ==" 81fef9c191SJeff Codyif ! $QEMU_IMG convert -f raw -O $IMGFMT -n "$TEST_IMG.raw2" "$TEST_IMG" ; then 82b2e10493SAlexandre Derumier exit 1 83b2e10493SAlexandre Derumierfi 84b2e10493SAlexandre Derumier_check_test_img 85b2e10493SAlexandre Derumier 86b2e10493SAlexandre Derumierecho "== Testing conversion to a smaller file fails ==" 87d88bef19SMax ReitzTEST_IMG="$TEST_IMG.target" _make_test_img 2M 88d88bef19SMax Reitzif $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -n "$TEST_IMG" "$TEST_IMG.target" >/dev/null 2>&1; then 89b2e10493SAlexandre Derumier exit 1 90b2e10493SAlexandre Derumierfi 91b2e10493SAlexandre Derumier 92e06f4639SFam Zhengecho "== Regression testing for copy offloading bug ==" 93e06f4639SFam Zheng 94e06f4639SFam Zheng_make_test_img 1M 95e06f4639SFam ZhengTEST_IMG="$TEST_IMG.target" _make_test_img 1M 96e06f4639SFam Zheng$QEMU_IO -c 'write -P 1 0 512k' -c 'write -P 2 512k 512k' "$TEST_IMG" | _filter_qemu_io 97e06f4639SFam Zheng$QEMU_IO -c 'write -P 4 512k 512k' -c 'write -P 3 0 512k' "$TEST_IMG.target" | _filter_qemu_io 98e06f4639SFam Zheng$QEMU_IMG convert -n -O $IMGFMT "$TEST_IMG" "$TEST_IMG.target" 99e06f4639SFam Zheng$QEMU_IMG compare "$TEST_IMG" "$TEST_IMG.target" 100e06f4639SFam Zheng 101b2e10493SAlexandre Derumierecho "*** done" 102b2e10493SAlexandre Derumierrm -f $seq.full 103b2e10493SAlexandre Derumierstatus=0 104b2e10493SAlexandre Derumierexit 0 105