]> git.proxmox.com Git - mirror_qemu.git/blame - tests/qemu-iotests/109
iotests: define group in each iotest
[mirror_qemu.git] / tests / qemu-iotests / 109
CommitLineData
11a82d14 1#!/usr/bin/env bash
9dd003a9 2# group: rw
00e04792
KW
3#
4# Test writing image headers of other formats into raw images
5#
6# Copyright (C) 2014 Red Hat, Inc.
7#
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.
12#
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.
17#
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/>.
20#
21
22# creator
23owner=kwolf@redhat.com
24
25seq="$(basename $0)"
26echo "QA output created by $seq"
27
00e04792
KW
28status=1 # failure is the default!
29
30_cleanup()
31{
ecfa1854 32 _cleanup_qemu
f91ecbd7
HR
33 _rm_test_img "$TEST_IMG.src"
34 _cleanup_test_img
00e04792
KW
35}
36trap "_cleanup; exit \$status" 0 1 2 3 15
37
38# get standard environment, filters and checks
39. ./common.rc
40. ./common.filter
41. ./common.qemu
42
43_supported_fmt raw
44_supported_proto file
45_supported_os Linux
503034ef 46_require_drivers qcow qcow2 qed vdi vmdk vpc
00e04792
KW
47
48qemu_comm_method=qmp
49
8cedcffd 50run_qemu()
00e04792
KW
51{
52 local raw_img="$1"
53 local source_img="$2"
54 local qmp_format="$3"
55 local qmp_event="$4"
56
8dff69b9 57 _launch_qemu -drive file="${source_img}",format=raw,cache=${CACHEMODE},aio=${AIOMODE},id=src
00e04792
KW
58 _send_qemu_cmd $QEMU_HANDLE "{ 'execute': 'qmp_capabilities' }" "return"
59
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"
65
66 _send_qemu_cmd $QEMU_HANDLE '' "$qmp_event"
0a4c0c3f 67 if test "$qmp_event" = BLOCK_JOB_ERROR; then
1dac83f1 68 _send_qemu_cmd $QEMU_HANDLE '' '"status": "null"'
0a4c0c3f 69 fi
00e04792 70 _send_qemu_cmd $QEMU_HANDLE '{"execute":"query-block-jobs"}' "return"
53dd4015
CR
71 _send_qemu_cmd $QEMU_HANDLE '{"execute":"quit"}' "return"
72 wait=1 _cleanup_qemu
00e04792
KW
73}
74
75for fmt in qcow qcow2 qed vdi vmdk vpc; do
76
77 echo
78 echo "=== Writing a $fmt header into raw ==="
79 echo
80
00e04792 81 TEST_IMG="$TEST_IMG.src" IMGFMT=$fmt _make_test_img 64M
ffa41a62 82 _make_test_img $(du -b "$TEST_IMG.src" | cut -f1) | _filter_img_create_size
00e04792
KW
83
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
24dfdfd0
FZ
86 run_qemu "$TEST_IMG" "$TEST_IMG.src" "" "BLOCK_JOB_ERROR" |
87 _filter_block_job_len
ffa41a62 88 $QEMU_IO -c 'read -P 0 0 512' "$TEST_IMG" | _filter_qemu_io
00e04792
KW
89
90
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"
94
95done
96
97
98for sample_img in empty.bochs iotest-dirtylog-10G-4M.vhdx parallels-v1 \
99 simple-pattern.cloop; do
100
101 echo
102 echo "=== Copying sample image $sample_img into raw ==="
103 echo
104
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)
00e04792 107 bzcat "$SAMPLE_IMG_DIR/$sample_img.bz2" > "$TEST_IMG.src"
ffa41a62 108 _make_test_img $(du -b "$TEST_IMG.src" | cut -f1) | _filter_img_create_size
00e04792 109
24dfdfd0
FZ
110 run_qemu "$TEST_IMG" "$TEST_IMG.src" "" "BLOCK_JOB_ERROR" |
111 _filter_block_job_offset | _filter_block_job_len
ffa41a62 112 $QEMU_IO -c 'read -P 0 0 512' "$TEST_IMG" | _filter_qemu_io
00e04792
KW
113
114 run_qemu "$TEST_IMG" "$TEST_IMG.src" "'format': 'raw'," "BLOCK_JOB_READY"
00e04792
KW
115 $QEMU_IMG compare -f raw -F raw "$TEST_IMG" "$TEST_IMG.src"
116done
117
118echo
119echo "=== Write legitimate MBR into raw ==="
120echo
121
122for sample_img in grub_mbr.raw; do
00e04792 123 bzcat "$SAMPLE_IMG_DIR/$sample_img.bz2" > "$TEST_IMG.src"
ffa41a62 124 _make_test_img $(du -b "$TEST_IMG.src" | cut -f1) | _filter_img_create_size
00e04792
KW
125
126 run_qemu "$TEST_IMG" "$TEST_IMG.src" "" "BLOCK_JOB_READY"
127 $QEMU_IMG compare -f raw -F raw "$TEST_IMG" "$TEST_IMG.src"
128
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"
131done
132
133
134# success, all done
135echo '*** done'
136rm -f $seq.full
137status=0