xref: /openbmc/qemu/tests/qemu-iotests/087 (revision a557b00469bca61a058fc1db4855503cac1c3219)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
2*9dd003a9SVladimir Sementsov-Ogievskiy# group: rw quick
3c75203c8SKevin Wolf#
4c75203c8SKevin Wolf# Test unsupported blockdev-add cases
5c75203c8SKevin Wolf#
6c75203c8SKevin Wolf# Copyright (C) 2014 Red Hat, Inc.
7c75203c8SKevin Wolf#
8c75203c8SKevin Wolf# This program is free software; you can redistribute it and/or modify
9c75203c8SKevin Wolf# it under the terms of the GNU General Public License as published by
10c75203c8SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
11c75203c8SKevin Wolf# (at your option) any later version.
12c75203c8SKevin Wolf#
13c75203c8SKevin Wolf# This program is distributed in the hope that it will be useful,
14c75203c8SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
15c75203c8SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16c75203c8SKevin Wolf# GNU General Public License for more details.
17c75203c8SKevin Wolf#
18c75203c8SKevin Wolf# You should have received a copy of the GNU General Public License
19c75203c8SKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20c75203c8SKevin Wolf#
21c75203c8SKevin Wolf
22c75203c8SKevin Wolf# creator
23c75203c8SKevin Wolfowner=kwolf@redhat.com
24c75203c8SKevin Wolf
25c75203c8SKevin Wolfseq=`basename $0`
26c75203c8SKevin Wolfecho "QA output created by $seq"
27c75203c8SKevin Wolf
28c75203c8SKevin Wolfstatus=1	# failure is the default!
29c75203c8SKevin Wolf
30801ddbdaSMax Reitz_cleanup()
31801ddbdaSMax Reitz{
32801ddbdaSMax Reitz    _cleanup_test_img
33801ddbdaSMax Reitz}
34801ddbdaSMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
35801ddbdaSMax Reitz
36c75203c8SKevin Wolf# get standard environment, filters and checks
37c75203c8SKevin Wolf. ./common.rc
38c75203c8SKevin Wolf. ./common.filter
39c75203c8SKevin Wolf
40c75203c8SKevin Wolf_supported_fmt qcow2
41c75203c8SKevin Wolf_supported_proto file
42c75203c8SKevin Wolf_supported_os Linux
43d2a839edSMax Reitz_require_working_luks
44c75203c8SKevin Wolf
458cedcffdSEric Blakedo_run_qemu()
46c75203c8SKevin Wolf{
47c75203c8SKevin Wolf    echo Testing: "$@"
48c75203c8SKevin Wolf    $QEMU -nographic -qmp stdio -serial none "$@"
49c75203c8SKevin Wolf    echo
50c75203c8SKevin Wolf}
51c75203c8SKevin Wolf
528cedcffdSEric Blakerun_qemu()
53c75203c8SKevin Wolf{
54e6ff69bfSDaniel P. Berrange    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \
55e6ff69bfSDaniel P. Berrange                          | _filter_qemu | _filter_imgfmt \
5644673a0bSMax Reitz                          | _filter_actual_image_size
57c75203c8SKevin Wolf}
58c75203c8SKevin Wolf
59c75203c8SKevin Wolfsize=128M
60c75203c8SKevin Wolf
61c75203c8SKevin Wolf_make_test_img $size
62c75203c8SKevin Wolf
63c75203c8SKevin Wolfecho
64be4b67bcSMax Reitzecho === Missing ID and node-name ===
65c75203c8SKevin Wolfecho
66c75203c8SKevin Wolf
67c75203c8SKevin Wolfrun_qemu <<EOF
68c75203c8SKevin Wolf{ "execute": "qmp_capabilities" }
69c75203c8SKevin Wolf{ "execute": "blockdev-add",
70c75203c8SKevin Wolf  "arguments": {
71c75203c8SKevin Wolf      "driver": "$IMGFMT",
72c75203c8SKevin Wolf      "file": {
73c75203c8SKevin Wolf          "driver": "file",
74c75203c8SKevin Wolf          "filename": "$TEST_IMG"
75c75203c8SKevin Wolf      }
76c75203c8SKevin Wolf    }
77c75203c8SKevin Wolf  }
78c75203c8SKevin Wolf{ "execute": "quit" }
79c75203c8SKevin WolfEOF
80c75203c8SKevin Wolf
81c75203c8SKevin Wolfecho
82f2d953ecSKevin Wolfecho === Duplicate ID ===
83f2d953ecSKevin Wolfecho
84f2d953ecSKevin Wolf
855feb08edSKevin Wolfrun_qemu -drive driver=$IMGFMT,id=disk,node-name=test-node,file="$TEST_IMG" <<EOF
86f2d953ecSKevin Wolf{ "execute": "qmp_capabilities" }
87f2d953ecSKevin Wolf{ "execute": "blockdev-add",
88f2d953ecSKevin Wolf  "arguments": {
89f2d953ecSKevin Wolf      "driver": "$IMGFMT",
9090d9d301SKevin Wolf      "node-name": "disk",
9190d9d301SKevin Wolf      "file": {
92d5b8336aSFam Zheng          "driver": "null-co"
9390d9d301SKevin Wolf      }
9490d9d301SKevin Wolf    }
9590d9d301SKevin Wolf  }
9690d9d301SKevin Wolf{ "execute": "blockdev-add",
9790d9d301SKevin Wolf  "arguments": {
9890d9d301SKevin Wolf      "driver": "$IMGFMT",
9990d9d301SKevin Wolf      "node-name": "test-node",
10090d9d301SKevin Wolf      "file": {
101d5b8336aSFam Zheng          "driver": "null-co"
10290d9d301SKevin Wolf      }
10390d9d301SKevin Wolf    }
10490d9d301SKevin Wolf  }
105f2d953ecSKevin Wolf{ "execute": "quit" }
106f2d953ecSKevin WolfEOF
107f2d953ecSKevin Wolf
108f2d953ecSKevin Wolfecho
109c75203c8SKevin Wolfecho === aio=native without O_DIRECT ===
110c75203c8SKevin Wolfecho
111c75203c8SKevin Wolf
112c0012e9aSMax Reitz# Skip this test if AIO is not enabled in this build
1138cedcffdSEric Blakerun_qemu_filter_aio()
114c0012e9aSMax Reitz{
115c0012e9aSMax Reitz    run_qemu "$@" | \
116c0012e9aSMax Reitz        sed -e 's/is not supported in this build/it requires cache.direct=on, which was not specified/'
117c0012e9aSMax Reitz}
118c0012e9aSMax Reitz
119c0012e9aSMax Reitzrun_qemu_filter_aio <<EOF
120c75203c8SKevin Wolf{ "execute": "qmp_capabilities" }
121c75203c8SKevin Wolf{ "execute": "blockdev-add",
122c75203c8SKevin Wolf  "arguments": {
123c75203c8SKevin Wolf      "driver": "$IMGFMT",
1245feb08edSKevin Wolf      "node-name": "disk",
125c75203c8SKevin Wolf      "file": {
126c75203c8SKevin Wolf          "driver": "file",
1270a4279d9SKevin Wolf          "filename": "$TEST_IMG",
1280a4279d9SKevin Wolf          "aio": "native"
129c75203c8SKevin Wolf      }
130c75203c8SKevin Wolf    }
131c75203c8SKevin Wolf  }
132c75203c8SKevin Wolf{ "execute": "quit" }
133c75203c8SKevin WolfEOF
134c75203c8SKevin Wolf
135c75203c8SKevin Wolfecho
136426d52d8SDaniel P. Berrangeecho === Encrypted image QCow ===
137c75203c8SKevin Wolfecho
138c75203c8SKevin Wolf
139b25b387fSDaniel P. Berrange_make_test_img --object secret,id=sec0,data=123456 -o encryption=on,encrypt.key-secret=sec0 $size
140c75203c8SKevin Wolfrun_qemu <<EOF
141c75203c8SKevin Wolf{ "execute": "qmp_capabilities" }
142b25b387fSDaniel P. Berrange{ "execute": "object-add",
143b25b387fSDaniel P. Berrange  "arguments": {
144b25b387fSDaniel P. Berrange      "qom-type": "secret",
145b25b387fSDaniel P. Berrange      "id": "sec0",
146b25b387fSDaniel P. Berrange      "data": "123456"
147b25b387fSDaniel P. Berrange  }
148b25b387fSDaniel P. Berrange}
149c75203c8SKevin Wolf{ "execute": "blockdev-add",
150c75203c8SKevin Wolf  "arguments": {
151c75203c8SKevin Wolf      "driver": "$IMGFMT",
1525feb08edSKevin Wolf      "node-name": "disk",
153c75203c8SKevin Wolf      "file": {
154c75203c8SKevin Wolf          "driver": "file",
155c75203c8SKevin Wolf          "filename": "$TEST_IMG"
156b25b387fSDaniel P. Berrange      },
157b25b387fSDaniel P. Berrange      "encrypt": {
158b25b387fSDaniel P. Berrange          "format": "aes",
159b25b387fSDaniel P. Berrange          "key-secret": "sec0"
160c75203c8SKevin Wolf      }
161c75203c8SKevin Wolf    }
162c75203c8SKevin Wolf  }
163c75203c8SKevin Wolf{ "execute": "quit" }
164c75203c8SKevin WolfEOF
165c75203c8SKevin Wolf
166fe509ee2SFam Zhengecho
167426d52d8SDaniel P. Berrangeecho === Encrypted image LUKS ===
168426d52d8SDaniel P. Berrangeecho
169426d52d8SDaniel P. Berrange
170426d52d8SDaniel P. Berrange_make_test_img --object secret,id=sec0,data=123456 -o encrypt.format=luks,encrypt.key-secret=sec0 $size
171426d52d8SDaniel P. Berrangerun_qemu <<EOF
172426d52d8SDaniel P. Berrange{ "execute": "qmp_capabilities" }
173426d52d8SDaniel P. Berrange{ "execute": "object-add",
174426d52d8SDaniel P. Berrange  "arguments": {
175426d52d8SDaniel P. Berrange      "qom-type": "secret",
176426d52d8SDaniel P. Berrange      "id": "sec0",
177426d52d8SDaniel P. Berrange      "data": "123456"
178426d52d8SDaniel P. Berrange  }
179426d52d8SDaniel P. Berrange}
180426d52d8SDaniel P. Berrange{ "execute": "blockdev-add",
181426d52d8SDaniel P. Berrange  "arguments": {
182426d52d8SDaniel P. Berrange      "driver": "$IMGFMT",
183426d52d8SDaniel P. Berrange      "node-name": "disk",
184426d52d8SDaniel P. Berrange      "file": {
185426d52d8SDaniel P. Berrange          "driver": "file",
186426d52d8SDaniel P. Berrange          "filename": "$TEST_IMG"
187426d52d8SDaniel P. Berrange      },
188426d52d8SDaniel P. Berrange      "encrypt": {
189426d52d8SDaniel P. Berrange        "format": "luks",
190426d52d8SDaniel P. Berrange        "key-secret": "sec0"
191426d52d8SDaniel P. Berrange      }
192426d52d8SDaniel P. Berrange    }
193426d52d8SDaniel P. Berrange  }
194426d52d8SDaniel P. Berrange{ "execute": "quit" }
195426d52d8SDaniel P. BerrangeEOF
196426d52d8SDaniel P. Berrange
197426d52d8SDaniel P. Berrangeecho
198fe509ee2SFam Zhengecho === Missing driver ===
199fe509ee2SFam Zhengecho
200fe509ee2SFam Zheng
201b25b387fSDaniel P. Berrange_make_test_img --object secret,id=sec0,data=123456 -o encryption=on,encrypt.key-secret=sec0 $size
202fe509ee2SFam Zhengrun_qemu -S <<EOF
203fe509ee2SFam Zheng{ "execute": "qmp_capabilities" }
204fe509ee2SFam Zheng{ "execute": "blockdev-add",
205fe509ee2SFam Zheng  "arguments": {
2065feb08edSKevin Wolf      "node-name": "disk"
207fe509ee2SFam Zheng    }
208fe509ee2SFam Zheng  }
209fe509ee2SFam Zheng{ "execute": "quit" }
210fe509ee2SFam ZhengEOF
211fe509ee2SFam Zheng
212c75203c8SKevin Wolf# success, all done
213c75203c8SKevin Wolfecho "*** done"
214c75203c8SKevin Wolfrm -f $seq.full
215c75203c8SKevin Wolfstatus=0
216