Merge remote-tracking branch 'remotes/nvme/tags/nvme-fixes-20210407-pull-request...
[qemu/ar7.git] / tests / qemu-iotests / 109
blobe207a555f371b65846fec9da513b145bb7ccb920
1 #!/usr/bin/env bash
2 # group: rw
4 # Test writing image headers of other formats into raw images
6 # Copyright (C) 2014 Red Hat, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # creator
23 owner=kwolf@redhat.com
25 seq="$(basename $0)"
26 echo "QA output created by $seq"
28 status=1 # failure is the default!
30 _cleanup()
32 _cleanup_qemu
33 _rm_test_img "$TEST_IMG.src"
34 _cleanup_test_img
36 trap "_cleanup; exit \$status" 0 1 2 3 15
38 # get standard environment, filters and checks
39 . ./common.rc
40 . ./common.filter
41 . ./common.qemu
43 _supported_fmt raw
44 _supported_proto file
45 _supported_os Linux
46 _require_drivers qcow qcow2 qed vdi vmdk vpc
48 qemu_comm_method=qmp
50 run_qemu()
52 local raw_img="$1"
53 local source_img="$2"
54 local qmp_format="$3"
55 local qmp_event="$4"
57 _launch_qemu -drive file="${source_img}",format=raw,cache=${CACHEMODE},aio=${AIOMODE},id=src
58 _send_qemu_cmd $QEMU_HANDLE "{ 'execute': 'qmp_capabilities' }" "return"
60 _send_qemu_cmd $QEMU_HANDLE \
61 "{'execute':'drive-mirror', 'arguments':{
62 'device': 'src', 'target': '$raw_img', $qmp_format
63 'mode': 'existing', 'sync': 'full'}}" \
64 "return"
66 _send_qemu_cmd $QEMU_HANDLE '' "$qmp_event"
67 if test "$qmp_event" = BLOCK_JOB_ERROR; then
68 _send_qemu_cmd $QEMU_HANDLE '' '"status": "null"'
70 _send_qemu_cmd $QEMU_HANDLE '{"execute":"query-block-jobs"}' "return"
71 _send_qemu_cmd $QEMU_HANDLE '{"execute":"quit"}' "return"
72 wait=1 _cleanup_qemu
75 for fmt in qcow qcow2 qed vdi vmdk vpc; do
77 echo
78 echo "=== Writing a $fmt header into raw ==="
79 echo
81 TEST_IMG="$TEST_IMG.src" IMGFMT=$fmt _make_test_img 64M
82 _make_test_img $(du -b "$TEST_IMG.src" | cut -f1) | _filter_img_create_size
84 # This first test should fail: The image format was probed, we may not
85 # write an image header at the start of the image
86 run_qemu "$TEST_IMG" "$TEST_IMG.src" "" "BLOCK_JOB_ERROR" |
87 _filter_block_job_len
88 $QEMU_IO -c 'read -P 0 0 512' "$TEST_IMG" | _filter_qemu_io
91 # When raw was explicitly specified, the same must succeed
92 run_qemu "$TEST_IMG" "$TEST_IMG.src" "'format': 'raw'," "BLOCK_JOB_READY"
93 $QEMU_IMG compare -f raw -F raw "$TEST_IMG" "$TEST_IMG.src"
95 done
98 for sample_img in empty.bochs iotest-dirtylog-10G-4M.vhdx parallels-v1 \
99 simple-pattern.cloop; do
101 echo
102 echo "=== Copying sample image $sample_img into raw ==="
103 echo
105 # Can't use _use_sample_img because that isn't designed to be used multiple
106 # times and it overwrites $TEST_IMG (both breaks cleanup)
107 bzcat "$SAMPLE_IMG_DIR/$sample_img.bz2" > "$TEST_IMG.src"
108 _make_test_img $(du -b "$TEST_IMG.src" | cut -f1) | _filter_img_create_size
110 run_qemu "$TEST_IMG" "$TEST_IMG.src" "" "BLOCK_JOB_ERROR" |
111 _filter_block_job_offset | _filter_block_job_len
112 $QEMU_IO -c 'read -P 0 0 512' "$TEST_IMG" | _filter_qemu_io
114 run_qemu "$TEST_IMG" "$TEST_IMG.src" "'format': 'raw'," "BLOCK_JOB_READY"
115 $QEMU_IMG compare -f raw -F raw "$TEST_IMG" "$TEST_IMG.src"
116 done
118 echo
119 echo "=== Write legitimate MBR into raw ==="
120 echo
122 for sample_img in grub_mbr.raw; do
123 bzcat "$SAMPLE_IMG_DIR/$sample_img.bz2" > "$TEST_IMG.src"
124 _make_test_img $(du -b "$TEST_IMG.src" | cut -f1) | _filter_img_create_size
126 run_qemu "$TEST_IMG" "$TEST_IMG.src" "" "BLOCK_JOB_READY"
127 $QEMU_IMG compare -f raw -F raw "$TEST_IMG" "$TEST_IMG.src"
129 run_qemu "$TEST_IMG" "$TEST_IMG.src" "'format': 'raw'," "BLOCK_JOB_READY"
130 $QEMU_IMG compare -f raw -F raw "$TEST_IMG" "$TEST_IMG.src"
131 done
134 # success, all done
135 echo '*** done'
136 rm -f $seq.full
137 status=0