xref: /openbmc/qemu/tests/qemu-iotests/184 (revision 60e58bd9)
1#!/bin/bash
2#
3# Test I/O throttle block filter driver interface
4#
5# Copyright (C) 2017 Manos Pitsidianakis
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="Manos Pitsidianakis"
23
24seq=`basename $0`
25echo "QA output created by $seq"
26
27here=`pwd`
28status=1	# failure is the default!
29
30_cleanup()
31{
32    _cleanup_test_img
33}
34trap "_cleanup; exit \$status" 0 1 2 3 15
35
36# get standard environment, filters and checks
37. ./common.rc
38. ./common.filter
39
40_supported_fmt qcow2
41_supported_proto file
42_supported_os Linux
43
44function do_run_qemu()
45{
46    echo Testing: "$@" | _filter_imgfmt
47    $QEMU -nographic -qmp-pretty stdio -serial none "$@"
48    echo
49}
50
51function run_qemu()
52{
53    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp\
54                          | _filter_qemu_io | _filter_generated_node_ids \
55                          | _filter_actual_image_size
56}
57
58_make_test_img 64M
59test_throttle=$($QEMU_IMG --help|grep throttle)
60[ "$test_throttle" = "" ] && _supported_fmt throttle
61
62echo
63echo "== checking interface =="
64
65run_qemu <<EOF
66{ "execute": "qmp_capabilities" }
67{ "execute": "blockdev-add",
68  "arguments": {
69    "driver": "$IMGFMT",
70    "node-name": "disk0",
71    "file": {
72      "driver": "file",
73      "filename": "$TEST_IMG"
74    }
75  }
76}
77{ "execute": "object-add",
78  "arguments": {
79    "qom-type": "throttle-group",
80    "id": "group0",
81    "props": {
82      "limits" : {
83        "iops-total": 1000
84      }
85    }
86  }
87}
88{ "execute": "blockdev-add",
89  "arguments": {
90    "driver": "throttle",
91    "node-name": "throttle0",
92    "throttle-group": "group0",
93    "file": "disk0"
94  }
95}
96{ "execute": "query-named-block-nodes" }
97{ "execute": "query-block" }
98{ "execute": "quit" }
99EOF
100
101echo
102echo "== property changes in ThrottleGroup =="
103
104run_qemu <<EOF
105{ "execute": "qmp_capabilities" }
106{ "execute": "object-add",
107  "arguments": {
108    "qom-type": "throttle-group",
109    "id": "group0",
110    "props" : {
111      "limits": {
112          "iops-total": 1000
113      }
114    }
115  }
116}
117{ "execute" : "qom-get",
118  "arguments" : {
119    "path" : "group0",
120    "property" : "limits"
121  }
122}
123{ "execute" : "qom-set",
124    "arguments" : {
125        "path" : "group0",
126        "property" : "limits",
127        "value" : {
128            "iops-total" : 0
129        }
130    }
131}
132{ "execute" : "qom-get",
133  "arguments" : {
134    "path" : "group0",
135    "property" : "limits"
136  }
137}
138{ "execute": "quit" }
139EOF
140
141echo
142echo "== object creation/set errors  =="
143
144run_qemu <<EOF
145{ "execute": "qmp_capabilities" }
146{ "execute": "object-add",
147  "arguments": {
148    "qom-type": "throttle-group",
149    "id": "group0",
150    "props" : {
151      "limits": {
152          "iops-total": 1000
153      }
154    }
155  }
156}
157{ "execute" : "qom-set",
158  "arguments" : {
159    "path" : "group0",
160    "property" : "x-iops-total",
161    "value" : 0
162  }
163}
164{ "execute" : "qom-set",
165    "arguments" : {
166        "path" : "group0",
167        "property" : "limits",
168        "value" : {
169            "iops-total" : 10,
170            "iops-read" : 10
171        }
172    }
173}
174{ "execute": "quit" }
175EOF
176
177echo
178echo "== don't specify group =="
179
180run_qemu <<EOF
181{ "execute": "qmp_capabilities" }
182{ "execute": "blockdev-add",
183  "arguments": {
184    "driver": "$IMGFMT",
185    "node-name": "disk0",
186    "file": {
187      "driver": "file",
188      "filename": "$TEST_IMG"
189    }
190  }
191}
192{ "execute": "blockdev-add",
193  "arguments": {
194    "driver": "throttle",
195    "node-name": "throttle0",
196    "file": "disk0"
197  }
198}
199{ "execute": "quit" }
200EOF
201
202echo
203# success, all done
204echo "*** done"
205rm -f $seq.full
206status=0
207