xref: /openbmc/qemu/tests/qemu-iotests/184 (revision 083fab02)
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}
56
57_make_test_img 64M
58test_throttle=$($QEMU_IMG --help|grep throttle)
59[ "$test_throttle" = "" ] && _supported_fmt throttle
60
61echo
62echo "== checking interface =="
63
64run_qemu <<EOF
65{ "execute": "qmp_capabilities" }
66{ "execute": "blockdev-add",
67  "arguments": {
68    "driver": "$IMGFMT",
69    "node-name": "disk0",
70    "file": {
71      "driver": "file",
72      "filename": "$TEST_IMG"
73    }
74  }
75}
76{ "execute": "object-add",
77  "arguments": {
78    "qom-type": "throttle-group",
79    "id": "group0",
80    "props": {
81      "limits" : {
82        "iops-total": 1000
83      }
84    }
85  }
86}
87{ "execute": "blockdev-add",
88  "arguments": {
89    "driver": "throttle",
90    "node-name": "throttle0",
91    "throttle-group": "group0",
92    "file": "disk0"
93  }
94}
95{ "execute": "query-named-block-nodes" }
96{ "execute": "query-block" }
97{ "execute": "quit" }
98EOF
99
100echo
101echo "== property changes in ThrottleGroup =="
102
103run_qemu <<EOF
104{ "execute": "qmp_capabilities" }
105{ "execute": "object-add",
106  "arguments": {
107    "qom-type": "throttle-group",
108    "id": "group0",
109    "props" : {
110      "limits": {
111          "iops-total": 1000
112      }
113    }
114  }
115}
116{ "execute" : "qom-get",
117  "arguments" : {
118    "path" : "group0",
119    "property" : "limits"
120  }
121}
122{ "execute" : "qom-set",
123    "arguments" : {
124        "path" : "group0",
125        "property" : "limits",
126        "value" : {
127            "iops-total" : 0
128        }
129    }
130}
131{ "execute" : "qom-get",
132  "arguments" : {
133    "path" : "group0",
134    "property" : "limits"
135  }
136}
137{ "execute": "quit" }
138EOF
139
140echo
141echo "== object creation/set errors  =="
142
143run_qemu <<EOF
144{ "execute": "qmp_capabilities" }
145{ "execute": "object-add",
146  "arguments": {
147    "qom-type": "throttle-group",
148    "id": "group0",
149    "props" : {
150      "limits": {
151          "iops-total": 1000
152      }
153    }
154  }
155}
156{ "execute" : "qom-set",
157  "arguments" : {
158    "path" : "group0",
159    "property" : "x-iops-total",
160    "value" : 0
161  }
162}
163{ "execute" : "qom-set",
164    "arguments" : {
165        "path" : "group0",
166        "property" : "limits",
167        "value" : {
168            "iops-total" : 10,
169            "iops-read" : 10
170        }
171    }
172}
173{ "execute": "quit" }
174EOF
175
176echo
177echo "== don't specify group =="
178
179run_qemu <<EOF
180{ "execute": "qmp_capabilities" }
181{ "execute": "blockdev-add",
182  "arguments": {
183    "driver": "$IMGFMT",
184    "node-name": "disk0",
185    "file": {
186      "driver": "file",
187      "filename": "$TEST_IMG"
188    }
189  }
190}
191{ "execute": "blockdev-add",
192  "arguments": {
193    "driver": "throttle",
194    "node-name": "throttle0",
195    "file": "disk0"
196  }
197}
198{ "execute": "quit" }
199EOF
200
201echo
202# success, all done
203echo "*** done"
204rm -f $seq.full
205status=0
206