xref: /qemu/tests/qemu-iotests/087 (revision bfa3ab61)
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 | _filter_qemu \
49                          | sed -e 's/\("actual-size":\s*\)[0-9]\+/\1SIZE/g'
50}
51
52size=128M
53
54_make_test_img $size
55
56echo
57echo === Missing ID ===
58echo
59
60run_qemu <<EOF
61{ "execute": "qmp_capabilities" }
62{ "execute": "blockdev-add",
63  "arguments": {
64      "options": {
65        "driver": "$IMGFMT",
66        "file": {
67            "driver": "file",
68            "filename": "$TEST_IMG"
69        }
70      }
71    }
72  }
73{ "execute": "quit" }
74EOF
75
76echo
77echo === Duplicate ID ===
78echo
79
80run_qemu <<EOF
81{ "execute": "qmp_capabilities" }
82{ "execute": "blockdev-add",
83  "arguments": {
84      "options": {
85        "driver": "$IMGFMT",
86        "id": "disk",
87        "node-name": "test-node",
88        "file": {
89            "driver": "file",
90            "filename": "$TEST_IMG"
91        }
92      }
93    }
94  }
95{ "execute": "blockdev-add",
96  "arguments": {
97      "options": {
98        "driver": "$IMGFMT",
99        "id": "disk",
100        "file": {
101            "driver": "file",
102            "filename": "$TEST_IMG"
103        }
104      }
105    }
106  }
107{ "execute": "blockdev-add",
108  "arguments": {
109      "options": {
110        "driver": "$IMGFMT",
111        "id": "test-node",
112        "file": {
113            "driver": "file",
114            "filename": "$TEST_IMG"
115        }
116      }
117    }
118  }
119{ "execute": "blockdev-add",
120  "arguments": {
121      "options": {
122        "driver": "$IMGFMT",
123        "id": "disk2",
124        "node-name": "disk",
125        "file": {
126            "driver": "file",
127            "filename": "$TEST_IMG"
128        }
129      }
130    }
131  }
132{ "execute": "blockdev-add",
133  "arguments": {
134      "options": {
135        "driver": "$IMGFMT",
136        "id": "disk2",
137        "node-name": "test-node",
138        "file": {
139            "driver": "file",
140            "filename": "$TEST_IMG"
141        }
142      }
143    }
144  }
145{ "execute": "blockdev-add",
146  "arguments": {
147      "options": {
148        "driver": "$IMGFMT",
149        "id": "disk3",
150        "node-name": "disk3",
151        "file": {
152            "driver": "file",
153            "filename": "$TEST_IMG"
154        }
155      }
156    }
157  }
158{ "execute": "quit" }
159EOF
160
161echo
162echo === aio=native without O_DIRECT ===
163echo
164
165run_qemu <<EOF
166{ "execute": "qmp_capabilities" }
167{ "execute": "blockdev-add",
168  "arguments": {
169      "options": {
170        "driver": "$IMGFMT",
171        "id": "disk",
172        "aio": "native",
173        "file": {
174            "driver": "file",
175            "filename": "$TEST_IMG"
176        }
177      }
178    }
179  }
180{ "execute": "quit" }
181EOF
182
183echo
184echo === Encrypted image ===
185echo
186
187_make_test_img -o encryption=on $size
188run_qemu -S <<EOF
189{ "execute": "qmp_capabilities" }
190{ "execute": "blockdev-add",
191  "arguments": {
192      "options": {
193        "driver": "$IMGFMT",
194        "id": "disk",
195        "file": {
196            "driver": "file",
197            "filename": "$TEST_IMG"
198        }
199      }
200    }
201  }
202{ "execute": "quit" }
203EOF
204
205run_qemu <<EOF
206{ "execute": "qmp_capabilities" }
207{ "execute": "blockdev-add",
208  "arguments": {
209      "options": {
210        "driver": "$IMGFMT",
211        "id": "disk",
212        "file": {
213            "driver": "file",
214            "filename": "$TEST_IMG"
215        }
216      }
217    }
218  }
219{ "execute": "quit" }
220EOF
221
222echo
223echo === Missing driver ===
224echo
225
226_make_test_img -o encryption=on $size
227run_qemu -S <<EOF
228{ "execute": "qmp_capabilities" }
229{ "execute": "blockdev-add",
230  "arguments": {
231      "options": {
232        "id": "disk"
233      }
234    }
235  }
236{ "execute": "quit" }
237EOF
238
239# success, all done
240echo "*** done"
241rm -f $seq.full
242status=0
243