xref: /openbmc/qemu/tests/qemu-iotests/087 (revision fe509ee2373078435fb8c4f68eebd2740c4e388f)
1c75203c8SKevin Wolf#!/bin/bash
2c75203c8SKevin Wolf#
3c75203c8SKevin Wolf# Test unsupported blockdev-add cases
4c75203c8SKevin Wolf#
5c75203c8SKevin Wolf# Copyright (C) 2014 Red Hat, Inc.
6c75203c8SKevin Wolf#
7c75203c8SKevin Wolf# This program is free software; you can redistribute it and/or modify
8c75203c8SKevin Wolf# it under the terms of the GNU General Public License as published by
9c75203c8SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
10c75203c8SKevin Wolf# (at your option) any later version.
11c75203c8SKevin Wolf#
12c75203c8SKevin Wolf# This program is distributed in the hope that it will be useful,
13c75203c8SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
14c75203c8SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15c75203c8SKevin Wolf# GNU General Public License for more details.
16c75203c8SKevin Wolf#
17c75203c8SKevin Wolf# You should have received a copy of the GNU General Public License
18c75203c8SKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19c75203c8SKevin Wolf#
20c75203c8SKevin Wolf
21c75203c8SKevin Wolf# creator
22c75203c8SKevin Wolfowner=kwolf@redhat.com
23c75203c8SKevin Wolf
24c75203c8SKevin Wolfseq=`basename $0`
25c75203c8SKevin Wolfecho "QA output created by $seq"
26c75203c8SKevin Wolf
27c75203c8SKevin Wolfhere=`pwd`
28c75203c8SKevin Wolftmp=/tmp/$$
29c75203c8SKevin Wolfstatus=1	# failure is the default!
30c75203c8SKevin Wolf
31c75203c8SKevin Wolf# get standard environment, filters and checks
32c75203c8SKevin Wolf. ./common.rc
33c75203c8SKevin Wolf. ./common.filter
34c75203c8SKevin Wolf
35c75203c8SKevin Wolf_supported_fmt qcow2
36c75203c8SKevin Wolf_supported_proto file
37c75203c8SKevin Wolf_supported_os Linux
38c75203c8SKevin Wolf
39c75203c8SKevin Wolffunction do_run_qemu()
40c75203c8SKevin Wolf{
41c75203c8SKevin Wolf    echo Testing: "$@"
42c75203c8SKevin Wolf    $QEMU -nographic -qmp stdio -serial none "$@"
43c75203c8SKevin Wolf    echo
44c75203c8SKevin Wolf}
45c75203c8SKevin Wolf
46c75203c8SKevin Wolffunction run_qemu()
47c75203c8SKevin Wolf{
48c75203c8SKevin Wolf    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp | sed -e 's/\("actual-size":\s*\)[0-9]\+/\1SIZE/g'
49c75203c8SKevin Wolf}
50c75203c8SKevin Wolf
51c75203c8SKevin Wolfsize=128M
52c75203c8SKevin Wolf
53c75203c8SKevin Wolf_make_test_img $size
54c75203c8SKevin Wolf
55c75203c8SKevin Wolfecho
56c75203c8SKevin Wolfecho === Missing ID ===
57c75203c8SKevin Wolfecho
58c75203c8SKevin Wolf
59c75203c8SKevin Wolfrun_qemu <<EOF
60c75203c8SKevin Wolf{ "execute": "qmp_capabilities" }
61c75203c8SKevin Wolf{ "execute": "blockdev-add",
62c75203c8SKevin Wolf  "arguments": {
63c75203c8SKevin Wolf      "options": {
64c75203c8SKevin Wolf        "driver": "$IMGFMT",
65c75203c8SKevin Wolf        "file": {
66c75203c8SKevin Wolf            "driver": "file",
67c75203c8SKevin Wolf            "filename": "$TEST_IMG"
68c75203c8SKevin Wolf        }
69c75203c8SKevin Wolf      }
70c75203c8SKevin Wolf    }
71c75203c8SKevin Wolf  }
72c75203c8SKevin Wolf{ "execute": "quit" }
73c75203c8SKevin WolfEOF
74c75203c8SKevin Wolf
75c75203c8SKevin Wolfecho
76f2d953ecSKevin Wolfecho === Duplicate ID ===
77f2d953ecSKevin Wolfecho
78f2d953ecSKevin Wolf
79f2d953ecSKevin Wolfrun_qemu <<EOF
80f2d953ecSKevin Wolf{ "execute": "qmp_capabilities" }
81f2d953ecSKevin Wolf{ "execute": "blockdev-add",
82f2d953ecSKevin Wolf  "arguments": {
83f2d953ecSKevin Wolf      "options": {
84f2d953ecSKevin Wolf        "driver": "$IMGFMT",
85f2d953ecSKevin Wolf        "id": "disk",
8690d9d301SKevin Wolf        "node-name": "test-node",
87f2d953ecSKevin Wolf        "file": {
88f2d953ecSKevin Wolf            "driver": "file",
89f2d953ecSKevin Wolf            "filename": "$TEST_IMG"
90f2d953ecSKevin Wolf        }
91f2d953ecSKevin Wolf      }
92f2d953ecSKevin Wolf    }
93f2d953ecSKevin Wolf  }
94f2d953ecSKevin Wolf{ "execute": "blockdev-add",
95f2d953ecSKevin Wolf  "arguments": {
96f2d953ecSKevin Wolf      "options": {
97f2d953ecSKevin Wolf        "driver": "$IMGFMT",
98f2d953ecSKevin Wolf        "id": "disk",
99f2d953ecSKevin Wolf        "file": {
100f2d953ecSKevin Wolf            "driver": "file",
101f2d953ecSKevin Wolf            "filename": "$TEST_IMG"
102f2d953ecSKevin Wolf        }
103f2d953ecSKevin Wolf      }
104f2d953ecSKevin Wolf    }
105f2d953ecSKevin Wolf  }
10690d9d301SKevin Wolf{ "execute": "blockdev-add",
10790d9d301SKevin Wolf  "arguments": {
10890d9d301SKevin Wolf      "options": {
10990d9d301SKevin Wolf        "driver": "$IMGFMT",
11090d9d301SKevin Wolf        "id": "test-node",
11190d9d301SKevin Wolf        "file": {
11290d9d301SKevin Wolf            "driver": "file",
11390d9d301SKevin Wolf            "filename": "$TEST_IMG"
11490d9d301SKevin Wolf        }
11590d9d301SKevin Wolf      }
11690d9d301SKevin Wolf    }
11790d9d301SKevin Wolf  }
11890d9d301SKevin Wolf{ "execute": "blockdev-add",
11990d9d301SKevin Wolf  "arguments": {
12090d9d301SKevin Wolf      "options": {
12190d9d301SKevin Wolf        "driver": "$IMGFMT",
12290d9d301SKevin Wolf        "id": "disk2",
12390d9d301SKevin Wolf        "node-name": "disk",
12490d9d301SKevin Wolf        "file": {
12590d9d301SKevin Wolf            "driver": "file",
12690d9d301SKevin Wolf            "filename": "$TEST_IMG"
12790d9d301SKevin Wolf        }
12890d9d301SKevin Wolf      }
12990d9d301SKevin Wolf    }
13090d9d301SKevin Wolf  }
13190d9d301SKevin Wolf{ "execute": "blockdev-add",
13290d9d301SKevin Wolf  "arguments": {
13390d9d301SKevin Wolf      "options": {
13490d9d301SKevin Wolf        "driver": "$IMGFMT",
13590d9d301SKevin Wolf        "id": "disk2",
13690d9d301SKevin Wolf        "node-name": "test-node",
13790d9d301SKevin Wolf        "file": {
13890d9d301SKevin Wolf            "driver": "file",
13990d9d301SKevin Wolf            "filename": "$TEST_IMG"
14090d9d301SKevin Wolf        }
14190d9d301SKevin Wolf      }
14290d9d301SKevin Wolf    }
14390d9d301SKevin Wolf  }
14490d9d301SKevin Wolf{ "execute": "blockdev-add",
14590d9d301SKevin Wolf  "arguments": {
14690d9d301SKevin Wolf      "options": {
14790d9d301SKevin Wolf        "driver": "$IMGFMT",
14890d9d301SKevin Wolf        "id": "disk3",
14990d9d301SKevin Wolf        "node-name": "disk3",
15090d9d301SKevin Wolf        "file": {
15190d9d301SKevin Wolf            "driver": "file",
15290d9d301SKevin Wolf            "filename": "$TEST_IMG"
15390d9d301SKevin Wolf        }
15490d9d301SKevin Wolf      }
15590d9d301SKevin Wolf    }
15690d9d301SKevin Wolf  }
157f2d953ecSKevin Wolf{ "execute": "quit" }
158f2d953ecSKevin WolfEOF
159f2d953ecSKevin Wolf
160f2d953ecSKevin Wolfecho
161c75203c8SKevin Wolfecho === aio=native without O_DIRECT ===
162c75203c8SKevin Wolfecho
163c75203c8SKevin Wolf
164c75203c8SKevin Wolfrun_qemu <<EOF
165c75203c8SKevin Wolf{ "execute": "qmp_capabilities" }
166c75203c8SKevin Wolf{ "execute": "blockdev-add",
167c75203c8SKevin Wolf  "arguments": {
168c75203c8SKevin Wolf      "options": {
169c75203c8SKevin Wolf        "driver": "$IMGFMT",
170c75203c8SKevin Wolf        "id": "disk",
171c75203c8SKevin Wolf        "aio": "native",
172c75203c8SKevin Wolf        "file": {
173c75203c8SKevin Wolf            "driver": "file",
174c75203c8SKevin Wolf            "filename": "$TEST_IMG"
175c75203c8SKevin Wolf        }
176c75203c8SKevin Wolf      }
177c75203c8SKevin Wolf    }
178c75203c8SKevin Wolf  }
179c75203c8SKevin Wolf{ "execute": "quit" }
180c75203c8SKevin WolfEOF
181c75203c8SKevin Wolf
182c75203c8SKevin Wolfecho
183c75203c8SKevin Wolfecho === Encrypted image ===
184c75203c8SKevin Wolfecho
185c75203c8SKevin Wolf
186c75203c8SKevin Wolf_make_test_img -o encryption=on $size
187c3adb58fSMarkus Armbrusterrun_qemu -S <<EOF
188c3adb58fSMarkus Armbruster{ "execute": "qmp_capabilities" }
189c3adb58fSMarkus Armbruster{ "execute": "blockdev-add",
190c3adb58fSMarkus Armbruster  "arguments": {
191c3adb58fSMarkus Armbruster      "options": {
192c3adb58fSMarkus Armbruster        "driver": "$IMGFMT",
193c3adb58fSMarkus Armbruster        "id": "disk",
194c3adb58fSMarkus Armbruster        "file": {
195c3adb58fSMarkus Armbruster            "driver": "file",
196c3adb58fSMarkus Armbruster            "filename": "$TEST_IMG"
197c3adb58fSMarkus Armbruster        }
198c3adb58fSMarkus Armbruster      }
199c3adb58fSMarkus Armbruster    }
200c3adb58fSMarkus Armbruster  }
201c3adb58fSMarkus Armbruster{ "execute": "quit" }
202c3adb58fSMarkus ArmbrusterEOF
203c3adb58fSMarkus Armbruster
204c75203c8SKevin Wolfrun_qemu <<EOF
205c75203c8SKevin Wolf{ "execute": "qmp_capabilities" }
206c75203c8SKevin Wolf{ "execute": "blockdev-add",
207c75203c8SKevin Wolf  "arguments": {
208c75203c8SKevin Wolf      "options": {
209c75203c8SKevin Wolf        "driver": "$IMGFMT",
210c75203c8SKevin Wolf        "id": "disk",
211c75203c8SKevin Wolf        "file": {
212c75203c8SKevin Wolf            "driver": "file",
213c75203c8SKevin Wolf            "filename": "$TEST_IMG"
214c75203c8SKevin Wolf        }
215c75203c8SKevin Wolf      }
216c75203c8SKevin Wolf    }
217c75203c8SKevin Wolf  }
218c75203c8SKevin Wolf{ "execute": "quit" }
219c75203c8SKevin WolfEOF
220c75203c8SKevin Wolf
221*fe509ee2SFam Zhengecho
222*fe509ee2SFam Zhengecho === Missing driver ===
223*fe509ee2SFam Zhengecho
224*fe509ee2SFam Zheng
225*fe509ee2SFam Zheng_make_test_img -o encryption=on $size
226*fe509ee2SFam Zhengrun_qemu -S <<EOF
227*fe509ee2SFam Zheng{ "execute": "qmp_capabilities" }
228*fe509ee2SFam Zheng{ "execute": "blockdev-add",
229*fe509ee2SFam Zheng  "arguments": {
230*fe509ee2SFam Zheng      "options": {
231*fe509ee2SFam Zheng        "id": "disk"
232*fe509ee2SFam Zheng      }
233*fe509ee2SFam Zheng    }
234*fe509ee2SFam Zheng  }
235*fe509ee2SFam Zheng{ "execute": "quit" }
236*fe509ee2SFam ZhengEOF
237*fe509ee2SFam Zheng
238c75203c8SKevin Wolf# success, all done
239c75203c8SKevin Wolfecho "*** done"
240c75203c8SKevin Wolfrm -f $seq.full
241c75203c8SKevin Wolfstatus=0
242