tests/qtest/bios-tables-test: Check for dup2() failure
[qemu/ar7.git] / tests / qemu-iotests / 249
blob28bffd4d57125706924aa0e246a2ffec42040c35
1 #!/usr/bin/env bash
2 # group: rw auto quick
4 # Test that a backing image is put back in read-only mode after
5 # block-commit (both when it fails and when it succeeds).
7 # Copyright (C) 2019 Igalia, S.L.
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.
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.
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/>.
23 # creator
24 owner=berto@igalia.com
26 seq="$(basename $0)"
27 echo "QA output created by $seq"
29 status=1 # failure is the default!
31 _cleanup()
33 _cleanup_test_img
34 _rm_test_img "$TEST_IMG.base"
35 _rm_test_img "$TEST_IMG.int"
37 trap "_cleanup; exit \$status" 0 1 2 3 15
39 # get standard environment, filters and checks
40 . ./common.rc
41 . ./common.filter
42 . ./common.qemu
44 # Any format implementing BlockDriver.bdrv_change_backing_file
45 _supported_fmt qcow2 qed
46 _supported_proto file fuse
47 _supported_os Linux
49 IMG_SIZE=1M
51 # Create the images: base <- int <- active
52 TEST_IMG="$TEST_IMG.base" _make_test_img $IMG_SIZE
53 TEST_IMG="$TEST_IMG.int" _make_test_img -b "$TEST_IMG.base" -F $IMGFMT
54 _make_test_img -b "$TEST_IMG.int" -F $IMGFMT
56 # Launch QEMU with these two drives:
57 # none0: base (read-only)
58 # none1: base <- int <- active
59 _launch_qemu -drive if=none,file="${TEST_IMG}.base",node-name=base,read-only=on \
60 -drive if=none,file="${TEST_IMG}",backing.node-name=int,backing.backing=base
62 _send_qemu_cmd $QEMU_HANDLE \
63 "{ 'execute': 'qmp_capabilities' }" \
64 'return'
66 echo
67 echo '=== Send a write command to a drive opened in read-only mode (1)'
68 echo
69 _send_qemu_cmd $QEMU_HANDLE \
70 "{ 'execute': 'human-monitor-command',
71 'arguments': {'command-line': 'qemu-io none0 \"aio_write 0 2k\"'}}" \
72 'return'
74 echo
75 echo '=== Run block-commit on base using an invalid filter node name'
76 echo
77 _send_qemu_cmd $QEMU_HANDLE \
78 "{ 'execute': 'block-commit',
79 'arguments': {'job-id': 'job0', 'device': 'none1', 'top-node': 'int',
80 'filter-node-name': '1234'}}" \
81 'error'
83 echo
84 echo '=== Send a write command to a drive opened in read-only mode (2)'
85 echo
86 _send_qemu_cmd $QEMU_HANDLE \
87 "{ 'execute': 'human-monitor-command',
88 'arguments': {'command-line': 'qemu-io none0 \"aio_write 0 2k\"'}}" \
89 'return'
91 echo
92 echo '=== Run block-commit on base using the default filter node name'
93 echo
94 _send_qemu_cmd $QEMU_HANDLE \
95 "{ 'execute': 'block-commit',
96 'arguments': {'job-id': 'job0', 'device': 'none1', 'top-node': 'int'}}" \
97 'return'
99 # Wait for block-commit to finish
100 _send_qemu_cmd $QEMU_HANDLE '' \
101 '"status": "null"'
103 echo
104 echo '=== Send a write command to a drive opened in read-only mode (3)'
105 echo
106 _send_qemu_cmd $QEMU_HANDLE \
107 "{ 'execute': 'human-monitor-command',
108 'arguments': {'command-line': 'qemu-io none0 \"aio_write 0 2k\"'}}" \
109 'return'
111 _cleanup_qemu
113 # success, all done
114 echo "*** done"
115 rm -f $seq.full
116 status=0