Philippe Mathieu-Daudé | 11a82d1 | 2019-03-07 15:58:38 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Kevin Wolf | 00e0479 | 2014-11-20 16:27:14 +0100 | [diff] [blame] | 2 | # |
| 3 | # Test writing image headers of other formats into raw images |
| 4 | # |
| 5 | # Copyright (C) 2014 Red Hat, Inc. |
| 6 | # |
| 7 | # This program is free software; you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by |
| 9 | # the Free Software Foundation; either version 2 of the License, or |
| 10 | # (at your option) any later version. |
| 11 | # |
| 12 | # This program is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License |
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # |
| 20 | |
| 21 | # creator |
| 22 | owner=kwolf@redhat.com |
| 23 | |
| 24 | seq="$(basename $0)" |
| 25 | echo "QA output created by $seq" |
| 26 | |
Kevin Wolf | 00e0479 | 2014-11-20 16:27:14 +0100 | [diff] [blame] | 27 | status=1 # failure is the default! |
| 28 | |
| 29 | _cleanup() |
| 30 | { |
Jeff Cody | ecfa185 | 2017-04-18 15:42:41 -0400 | [diff] [blame] | 31 | _cleanup_qemu |
Max Reitz | f91ecbd | 2019-11-07 17:37:01 +0100 | [diff] [blame] | 32 | _rm_test_img "$TEST_IMG.src" |
| 33 | _cleanup_test_img |
Kevin Wolf | 00e0479 | 2014-11-20 16:27:14 +0100 | [diff] [blame] | 34 | } |
| 35 | trap "_cleanup; exit \$status" 0 1 2 3 15 |
| 36 | |
| 37 | # get standard environment, filters and checks |
| 38 | . ./common.rc |
| 39 | . ./common.filter |
| 40 | . ./common.qemu |
| 41 | |
| 42 | _supported_fmt raw |
| 43 | _supported_proto file |
| 44 | _supported_os Linux |
| 45 | |
| 46 | qemu_comm_method=qmp |
| 47 | |
Eric Blake | 8cedcff | 2018-11-16 15:50:02 -0600 | [diff] [blame] | 48 | run_qemu() |
Kevin Wolf | 00e0479 | 2014-11-20 16:27:14 +0100 | [diff] [blame] | 49 | { |
| 50 | local raw_img="$1" |
| 51 | local source_img="$2" |
| 52 | local qmp_format="$3" |
| 53 | local qmp_event="$4" |
| 54 | |
Aarushi Mehta | 8dff69b | 2020-01-20 14:18:58 +0000 | [diff] [blame] | 55 | _launch_qemu -drive file="${source_img}",format=raw,cache=${CACHEMODE},aio=${AIOMODE},id=src |
Kevin Wolf | 00e0479 | 2014-11-20 16:27:14 +0100 | [diff] [blame] | 56 | _send_qemu_cmd $QEMU_HANDLE "{ 'execute': 'qmp_capabilities' }" "return" |
| 57 | |
| 58 | _send_qemu_cmd $QEMU_HANDLE \ |
| 59 | "{'execute':'drive-mirror', 'arguments':{ |
| 60 | 'device': 'src', 'target': '$raw_img', $qmp_format |
| 61 | 'mode': 'existing', 'sync': 'full'}}" \ |
| 62 | "return" |
| 63 | |
| 64 | _send_qemu_cmd $QEMU_HANDLE '' "$qmp_event" |
Paolo Bonzini | 0a4c0c3 | 2016-11-09 17:20:07 +0100 | [diff] [blame] | 65 | if test "$qmp_event" = BLOCK_JOB_ERROR; then |
Kevin Wolf | 1dac83f | 2018-04-30 19:09:46 +0200 | [diff] [blame] | 66 | _send_qemu_cmd $QEMU_HANDLE '' '"status": "null"' |
Paolo Bonzini | 0a4c0c3 | 2016-11-09 17:20:07 +0100 | [diff] [blame] | 67 | fi |
Kevin Wolf | 00e0479 | 2014-11-20 16:27:14 +0100 | [diff] [blame] | 68 | _send_qemu_cmd $QEMU_HANDLE '{"execute":"query-block-jobs"}' "return" |
Cleber Rosa | 53dd401 | 2017-08-01 17:31:27 -0400 | [diff] [blame] | 69 | _send_qemu_cmd $QEMU_HANDLE '{"execute":"quit"}' "return" |
| 70 | wait=1 _cleanup_qemu |
Kevin Wolf | 00e0479 | 2014-11-20 16:27:14 +0100 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | for fmt in qcow qcow2 qed vdi vmdk vpc; do |
| 74 | |
| 75 | echo |
| 76 | echo "=== Writing a $fmt header into raw ===" |
| 77 | echo |
| 78 | |
| 79 | _make_test_img 64M |
| 80 | TEST_IMG="$TEST_IMG.src" IMGFMT=$fmt _make_test_img 64M |
| 81 | |
| 82 | # This first test should fail: The image format was probed, we may not |
| 83 | # write an image header at the start of the image |
Fam Zheng | 24dfdfd | 2017-04-20 08:54:28 +0800 | [diff] [blame] | 84 | run_qemu "$TEST_IMG" "$TEST_IMG.src" "" "BLOCK_JOB_ERROR" | |
| 85 | _filter_block_job_len |
Kevin Wolf | 00e0479 | 2014-11-20 16:27:14 +0100 | [diff] [blame] | 86 | $QEMU_IO -c 'read -P 0 0 64k' "$TEST_IMG" | _filter_qemu_io |
| 87 | |
| 88 | |
| 89 | # When raw was explicitly specified, the same must succeed |
| 90 | run_qemu "$TEST_IMG" "$TEST_IMG.src" "'format': 'raw'," "BLOCK_JOB_READY" |
| 91 | $QEMU_IMG compare -f raw -F raw "$TEST_IMG" "$TEST_IMG.src" |
| 92 | |
| 93 | done |
| 94 | |
| 95 | |
| 96 | for sample_img in empty.bochs iotest-dirtylog-10G-4M.vhdx parallels-v1 \ |
| 97 | simple-pattern.cloop; do |
| 98 | |
| 99 | echo |
| 100 | echo "=== Copying sample image $sample_img into raw ===" |
| 101 | echo |
| 102 | |
| 103 | # Can't use _use_sample_img because that isn't designed to be used multiple |
| 104 | # times and it overwrites $TEST_IMG (both breaks cleanup) |
| 105 | _make_test_img 64M |
| 106 | bzcat "$SAMPLE_IMG_DIR/$sample_img.bz2" > "$TEST_IMG.src" |
| 107 | |
Fam Zheng | 24dfdfd | 2017-04-20 08:54:28 +0800 | [diff] [blame] | 108 | run_qemu "$TEST_IMG" "$TEST_IMG.src" "" "BLOCK_JOB_ERROR" | |
| 109 | _filter_block_job_offset | _filter_block_job_len |
Kevin Wolf | 00e0479 | 2014-11-20 16:27:14 +0100 | [diff] [blame] | 110 | $QEMU_IO -c 'read -P 0 0 64k' "$TEST_IMG" | _filter_qemu_io |
| 111 | |
| 112 | run_qemu "$TEST_IMG" "$TEST_IMG.src" "'format': 'raw'," "BLOCK_JOB_READY" |
Kevin Wolf | 00e0479 | 2014-11-20 16:27:14 +0100 | [diff] [blame] | 113 | $QEMU_IMG compare -f raw -F raw "$TEST_IMG" "$TEST_IMG.src" |
| 114 | done |
| 115 | |
| 116 | echo |
| 117 | echo "=== Write legitimate MBR into raw ===" |
| 118 | echo |
| 119 | |
| 120 | for sample_img in grub_mbr.raw; do |
| 121 | _make_test_img 64M |
| 122 | bzcat "$SAMPLE_IMG_DIR/$sample_img.bz2" > "$TEST_IMG.src" |
| 123 | |
| 124 | run_qemu "$TEST_IMG" "$TEST_IMG.src" "" "BLOCK_JOB_READY" |
| 125 | $QEMU_IMG compare -f raw -F raw "$TEST_IMG" "$TEST_IMG.src" |
| 126 | |
| 127 | run_qemu "$TEST_IMG" "$TEST_IMG.src" "'format': 'raw'," "BLOCK_JOB_READY" |
| 128 | $QEMU_IMG compare -f raw -F raw "$TEST_IMG" "$TEST_IMG.src" |
| 129 | done |
| 130 | |
| 131 | |
| 132 | # success, all done |
| 133 | echo '*** done' |
| 134 | rm -f $seq.full |
| 135 | status=0 |