qemu

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

048 (2523B)


      1 #!/usr/bin/env bash
      2 # group: img auto quick
      3 ##
      4 ## qemu-img compare test
      5 ##
      6 ##
      7 ## Copyright (C) 2013 Red Hat, Inc.
      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=mrezanin@redhat.com
     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     echo "Cleanup"
     34     _cleanup_test_img
     35     _rm_test_img "${TEST_IMG_FILE2}"
     36 }
     37 trap "_cleanup; exit \$status" 0 1 2 3 15
     38 
     39 _compare()
     40 {
     41     $QEMU_IMG compare $QEMU_IMG_EXTRA_ARGS "$@" "$TEST_IMG" "${TEST_IMG2}"
     42     echo $?
     43 }
     44 
     45 # get standard environment, filters and checks
     46 . ./common.rc
     47 . ./common.filter
     48 . ./common.pattern
     49 
     50 _supported_fmt raw qcow2 qed luks
     51 _supported_proto file
     52 _supported_os Linux
     53 # Using 'cp' is incompatible with external data files
     54 _unsupported_imgopts data_file
     55 
     56 # Remove once all tests are fixed to use TEST_IMG_FILE
     57 # correctly and common.rc sets it unconditionally
     58 test -z "$TEST_IMG_FILE" && TEST_IMG_FILE=$TEST_IMG
     59 
     60 # Setup test basic parameters
     61 TEST_IMG2=$TEST_IMG.2
     62 TEST_IMG_FILE2=$TEST_IMG_FILE.2
     63 CLUSTER_SIZE=4096
     64 size=128M
     65 
     66 _make_test_img $size
     67 io_pattern write 524288 $CLUSTER_SIZE $CLUSTER_SIZE 4 45
     68 
     69 # Compare identical images
     70 cp "$TEST_IMG_FILE" "${TEST_IMG_FILE2}"
     71 _compare
     72 _compare -q
     73 
     74 # Compare images with different size
     75 if [ "$IMGOPTSSYNTAX" = "true" ]; then
     76     $QEMU_IMG resize $QEMU_IMG_EXTRA_ARGS "$TEST_IMG" +32M
     77 else
     78     $QEMU_IMG resize -f $IMGFMT "$TEST_IMG" +32M
     79 fi
     80 # Ensure extended space is zero-initialized
     81 $QEMU_IO "$TEST_IMG" -c "write -z $size 32M" | _filter_qemu_io
     82 
     83 _compare
     84 _compare -s
     85 
     86 # Compare images with different content
     87 io_pattern write 1228800 $CLUSTER_SIZE 0 1 67
     88 _compare
     89 io_pattern write 0 $CLUSTER_SIZE 0 1 123
     90 _compare
     91 
     92 # Test unaligned case of mismatch offsets in allocated clusters
     93 _make_test_img $size
     94 io_pattern write 0 512 0 1 100
     95 cp "$TEST_IMG_FILE" "$TEST_IMG_FILE2"
     96 io_pattern write 512 512 0 1 101
     97 _compare
     98 
     99 # Cleanup
    100 status=0