xref: /openbmc/qemu/tests/qemu-iotests/048 (revision 812b31d3)
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
24owner=mrezanin@redhat.com
25
26seq=`basename $0`
27echo "QA output created by $seq"
28
29status=1        # failure is the default!
30
31_cleanup()
32{
33    echo "Cleanup"
34    _cleanup_test_img
35    _rm_test_img "${TEST_IMG_FILE2}"
36}
37trap "_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
58test -z "$TEST_IMG_FILE" && TEST_IMG_FILE=$TEST_IMG
59
60# Setup test basic parameters
61TEST_IMG2=$TEST_IMG.2
62TEST_IMG_FILE2=$TEST_IMG_FILE.2
63CLUSTER_SIZE=4096
64size=128M
65
66_make_test_img $size
67io_pattern write 524288 $CLUSTER_SIZE $CLUSTER_SIZE 4 45
68
69# Compare identical images
70cp "$TEST_IMG_FILE" "${TEST_IMG_FILE2}"
71_compare
72_compare -q
73
74# Compare images with different size
75if [ "$IMGOPTSSYNTAX" = "true" ]; then
76    $QEMU_IMG resize $QEMU_IMG_EXTRA_ARGS "$TEST_IMG" +32M
77else
78    $QEMU_IMG resize -f $IMGFMT "$TEST_IMG" +32M
79fi
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
87io_pattern write 1228800 $CLUSTER_SIZE 0 1 67
88_compare
89io_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
94io_pattern write 0 512 0 1 100
95cp "$TEST_IMG_FILE" "$TEST_IMG_FILE2"
96io_pattern write 512 512 0 1 101
97_compare
98
99# Cleanup
100status=0
101