xref: /qemu/tests/qemu-iotests/087 (revision afc47486)
1#!/bin/bash
2#
3# Test unsupported blockdev-add cases
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
22owner=kwolf@redhat.com
23
24seq=`basename $0`
25echo "QA output created by $seq"
26
27here=`pwd`
28tmp=/tmp/$$
29status=1	# failure is the default!
30
31# get standard environment, filters and checks
32. ./common.rc
33. ./common.filter
34
35_supported_fmt qcow2
36_supported_proto file
37_supported_os Linux
38
39function do_run_qemu()
40{
41    echo Testing: "$@"
42    $QEMU -nographic -qmp stdio -serial none "$@"
43    echo
44}
45
46function run_qemu()
47{
48    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \
49                          | _filter_qemu | _filter_imgfmt \
50                          | sed -e 's/\("actual-size":\s*\)[0-9]\+/\1SIZE/g'
51}
52
53size=128M
54
55_make_test_img $size
56
57echo
58echo === Missing ID and node-name ===
59echo
60
61run_qemu <<EOF
62{ "execute": "qmp_capabilities" }
63{ "execute": "blockdev-add",
64  "arguments": {
65      "options": {
66        "driver": "$IMGFMT",
67        "file": {
68            "driver": "file",
69            "filename": "$TEST_IMG"
70        }
71      }
72    }
73  }
74{ "execute": "quit" }
75EOF
76
77echo
78echo === Duplicate ID ===
79echo
80
81run_qemu <<EOF
82{ "execute": "qmp_capabilities" }
83{ "execute": "blockdev-add",
84  "arguments": {
85      "options": {
86        "driver": "$IMGFMT",
87        "id": "disk",
88        "node-name": "test-node",
89        "file": {
90            "driver": "file",
91            "filename": "$TEST_IMG"
92        }
93      }
94    }
95  }
96{ "execute": "blockdev-add",
97  "arguments": {
98      "options": {
99        "driver": "$IMGFMT",
100        "id": "disk",
101        "file": {
102            "driver": "file",
103            "filename": "$TEST_IMG"
104        }
105      }
106    }
107  }
108{ "execute": "blockdev-add",
109  "arguments": {
110      "options": {
111        "driver": "$IMGFMT",
112        "id": "test-node",
113        "file": {
114            "driver": "file",
115            "filename": "$TEST_IMG"
116        }
117      }
118    }
119  }
120{ "execute": "blockdev-add",
121  "arguments": {
122      "options": {
123        "driver": "$IMGFMT",
124        "id": "disk2",
125        "node-name": "disk",
126        "file": {
127            "driver": "file",
128            "filename": "$TEST_IMG"
129        }
130      }
131    }
132  }
133{ "execute": "blockdev-add",
134  "arguments": {
135      "options": {
136        "driver": "$IMGFMT",
137        "id": "disk2",
138        "node-name": "test-node",
139        "file": {
140            "driver": "file",
141            "filename": "$TEST_IMG"
142        }
143      }
144    }
145  }
146{ "execute": "blockdev-add",
147  "arguments": {
148      "options": {
149        "driver": "$IMGFMT",
150        "id": "disk3",
151        "node-name": "disk3",
152        "file": {
153            "driver": "file",
154            "filename": "$TEST_IMG"
155        }
156      }
157    }
158  }
159{ "execute": "quit" }
160EOF
161
162echo
163echo === aio=native without O_DIRECT ===
164echo
165
166run_qemu <<EOF
167{ "execute": "qmp_capabilities" }
168{ "execute": "blockdev-add",
169  "arguments": {
170      "options": {
171        "driver": "$IMGFMT",
172        "id": "disk",
173        "aio": "native",
174        "file": {
175            "driver": "file",
176            "filename": "$TEST_IMG"
177        }
178      }
179    }
180  }
181{ "execute": "quit" }
182EOF
183
184echo
185echo === Encrypted image ===
186echo
187
188_make_test_img -o encryption=on $size
189run_qemu -S <<EOF
190{ "execute": "qmp_capabilities" }
191{ "execute": "blockdev-add",
192  "arguments": {
193      "options": {
194        "driver": "$IMGFMT",
195        "id": "disk",
196        "file": {
197            "driver": "file",
198            "filename": "$TEST_IMG"
199        }
200      }
201    }
202  }
203{ "execute": "quit" }
204EOF
205
206run_qemu <<EOF
207{ "execute": "qmp_capabilities" }
208{ "execute": "blockdev-add",
209  "arguments": {
210      "options": {
211        "driver": "$IMGFMT",
212        "id": "disk",
213        "file": {
214            "driver": "file",
215            "filename": "$TEST_IMG"
216        }
217      }
218    }
219  }
220{ "execute": "quit" }
221EOF
222
223echo
224echo === Missing driver ===
225echo
226
227_make_test_img -o encryption=on $size
228run_qemu -S <<EOF
229{ "execute": "qmp_capabilities" }
230{ "execute": "blockdev-add",
231  "arguments": {
232      "options": {
233        "id": "disk"
234      }
235    }
236  }
237{ "execute": "quit" }
238EOF
239
240# success, all done
241echo "*** done"
242rm -f $seq.full
243status=0
244