qemu

FORK: QEMU emulator
git clone https://git.neptards.moe/neptards/qemu.git
Log | Files | Refs | Submodules | LICENSE

063 (3133B)


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