3 # Tests for image streaming.
5 # Copyright (C) 2012 IBM Corp.
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.
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.
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/>.
24 from iotests
import qemu_img
, qemu_io
26 backing_img
= os
.path
.join(iotests
.test_dir
, 'backing.img')
27 mid_img
= os
.path
.join(iotests
.test_dir
, 'mid.img')
28 test_img
= os
.path
.join(iotests
.test_dir
, 'test.img')
30 class TestSingleDrive(iotests
.QMPTestCase
):
31 image_len
= 1 * 1024 * 1024 # MB
34 iotests
.create_image(backing_img
, TestSingleDrive
.image_len
)
35 qemu_img('create', '-f', iotests
.imgfmt
, '-o', 'backing_file=%s' % backing_img
, mid_img
)
36 qemu_img('create', '-f', iotests
.imgfmt
, '-o', 'backing_file=%s' % mid_img
, test_img
)
37 qemu_io('-f', 'raw', '-c', 'write -P 0x1 0 512', backing_img
)
38 qemu_io('-f', iotests
.imgfmt
, '-c', 'write -P 0x1 524288 512', mid_img
)
39 self
.vm
= iotests
.VM().add_drive("blkdebug::" + test_img
, "backing.node-name=mid")
46 os
.remove(backing_img
)
48 def test_stream(self
):
49 self
.assert_no_active_block_jobs()
51 result
= self
.vm
.qmp('block-stream', device
='drive0')
52 self
.assert_qmp(result
, 'return', {})
54 self
.wait_until_completed()
56 self
.assert_no_active_block_jobs()
59 self
.assertEqual(qemu_io('-f', 'raw', '-c', 'map', backing_img
),
60 qemu_io('-f', iotests
.imgfmt
, '-c', 'map', test_img
),
61 'image file map does not match backing file after streaming')
63 def test_stream_intermediate(self
):
64 self
.assert_no_active_block_jobs()
66 self
.assertNotEqual(qemu_io('-f', 'raw', '-c', 'map', backing_img
),
67 qemu_io('-f', iotests
.imgfmt
, '-c', 'map', mid_img
),
68 'image file map matches backing file before streaming')
70 result
= self
.vm
.qmp('block-stream', device
='mid', job_id
='stream-mid')
71 self
.assert_qmp(result
, 'return', {})
73 self
.wait_until_completed(drive
='stream-mid')
75 self
.assert_no_active_block_jobs()
78 self
.assertEqual(qemu_io('-f', 'raw', '-c', 'map', backing_img
),
79 qemu_io('-f', iotests
.imgfmt
, '-c', 'map', mid_img
),
80 'image file map does not match backing file after streaming')
82 def test_stream_pause(self
):
83 self
.assert_no_active_block_jobs()
85 self
.vm
.pause_drive('drive0')
86 result
= self
.vm
.qmp('block-stream', device
='drive0')
87 self
.assert_qmp(result
, 'return', {})
89 result
= self
.vm
.qmp('block-job-pause', device
='drive0')
90 self
.assert_qmp(result
, 'return', {})
93 result
= self
.vm
.qmp('query-block-jobs')
94 offset
= self
.dictpath(result
, 'return[0]/offset')
97 result
= self
.vm
.qmp('query-block-jobs')
98 self
.assert_qmp(result
, 'return[0]/offset', offset
)
100 result
= self
.vm
.qmp('block-job-resume', device
='drive0')
101 self
.assert_qmp(result
, 'return', {})
103 self
.vm
.resume_drive('drive0')
104 self
.wait_until_completed()
106 self
.assert_no_active_block_jobs()
109 self
.assertEqual(qemu_io('-f', 'raw', '-c', 'map', backing_img
),
110 qemu_io('-f', iotests
.imgfmt
, '-c', 'map', test_img
),
111 'image file map does not match backing file after streaming')
113 def test_stream_no_op(self
):
114 self
.assert_no_active_block_jobs()
116 # The image map is empty before the operation
117 empty_map
= qemu_io('-f', iotests
.imgfmt
, '-c', 'map', test_img
)
119 # This is a no-op: no data should ever be copied from the base image
120 result
= self
.vm
.qmp('block-stream', device
='drive0', base
=mid_img
)
121 self
.assert_qmp(result
, 'return', {})
123 self
.wait_until_completed()
125 self
.assert_no_active_block_jobs()
128 self
.assertEqual(qemu_io('-f', iotests
.imgfmt
, '-c', 'map', test_img
),
129 empty_map
, 'image file map changed after a no-op')
131 def test_stream_partial(self
):
132 self
.assert_no_active_block_jobs()
134 result
= self
.vm
.qmp('block-stream', device
='drive0', base
=backing_img
)
135 self
.assert_qmp(result
, 'return', {})
137 self
.wait_until_completed()
139 self
.assert_no_active_block_jobs()
142 self
.assertEqual(qemu_io('-f', iotests
.imgfmt
, '-c', 'map', mid_img
),
143 qemu_io('-f', iotests
.imgfmt
, '-c', 'map', test_img
),
144 'image file map does not match backing file after streaming')
146 def test_device_not_found(self
):
147 result
= self
.vm
.qmp('block-stream', device
='nonexistent')
148 self
.assert_qmp(result
, 'error/class', 'GenericError')
151 class TestParallelOps(iotests
.QMPTestCase
):
152 num_ops
= 4 # Number of parallel block-stream operations
153 num_imgs
= num_ops
* 2 + 1
154 image_len
= num_ops
* 1024 * 1024
161 # Initialize file names and command-line options
162 for i
in range(self
.num_imgs
):
163 img_depth
= self
.num_imgs
- i
- 1
164 opts
.append("backing." * img_depth
+ "node-name=node%d" % i
)
165 self
.imgs
.append(os
.path
.join(iotests
.test_dir
, 'img-%d.img' % i
))
168 iotests
.create_image(self
.imgs
[0], self
.image_len
)
169 for i
in range(1, self
.num_imgs
):
170 qemu_img('create', '-f', iotests
.imgfmt
,
171 '-o', 'backing_file=%s' % self
.imgs
[i
-1], self
.imgs
[i
])
173 # Put data into the images we are copying data from
174 for i
in range(self
.num_imgs
/ 2):
175 img_index
= i
* 2 + 1
176 # Alternate between 512k and 1M.
177 # This way jobs will not finish in the same order they were created
178 num_kb
= 512 + 512 * (i
% 2)
179 qemu_io('-f', iotests
.imgfmt
,
180 '-c', 'write -P %d %d %d' % (i
, i
*1024*1024, num_kb
* 1024),
181 self
.imgs
[img_index
])
183 # Attach the drive to the VM
184 self
.vm
= iotests
.VM()
185 self
.vm
.add_drive(self
.imgs
[-1], ','.join(opts
))
190 for img
in self
.imgs
:
193 # Test that it's possible to run several block-stream operations
194 # in parallel in the same snapshot chain
195 def test_stream_parallel(self
):
196 self
.assert_no_active_block_jobs()
198 # Check that the maps don't match before the streaming operations
199 for i
in range(2, self
.num_imgs
, 2):
200 self
.assertNotEqual(qemu_io('-f', iotests
.imgfmt
, '-c', 'map', self
.imgs
[i
]),
201 qemu_io('-f', iotests
.imgfmt
, '-c', 'map', self
.imgs
[i
-1]),
202 'image file map matches backing file before streaming')
204 # Create all streaming jobs
206 for i
in range(2, self
.num_imgs
, 2):
207 node_name
= 'node%d' % i
208 job_id
= 'stream-%s' % node_name
209 pending_jobs
.append(job_id
)
210 result
= self
.vm
.qmp('block-stream', device
=node_name
, job_id
=job_id
, base
=self
.imgs
[i
-2], speed
=512*1024)
211 self
.assert_qmp(result
, 'return', {})
213 # Wait for all jobs to be finished.
214 while len(pending_jobs
) > 0:
215 for event
in self
.vm
.get_qmp_events(wait
=True):
216 if event
['event'] == 'BLOCK_JOB_COMPLETED':
217 job_id
= self
.dictpath(event
, 'data/device')
218 self
.assertTrue(job_id
in pending_jobs
)
219 self
.assert_qmp_absent(event
, 'data/error')
220 pending_jobs
.remove(job_id
)
222 self
.assert_no_active_block_jobs()
225 # Check that all maps match now
226 for i
in range(2, self
.num_imgs
, 2):
227 self
.assertEqual(qemu_io('-f', iotests
.imgfmt
, '-c', 'map', self
.imgs
[i
]),
228 qemu_io('-f', iotests
.imgfmt
, '-c', 'map', self
.imgs
[i
-1]),
229 'image file map does not match backing file after streaming')
231 # Test that it's not possible to perform two block-stream
232 # operations if there are nodes involved in both.
233 def test_overlapping_1(self
):
234 self
.assert_no_active_block_jobs()
236 # Set a speed limit to make sure that this job blocks the rest
237 result
= self
.vm
.qmp('block-stream', device
='node4', job_id
='stream-node4', base
=self
.imgs
[1], speed
=1024*1024)
238 self
.assert_qmp(result
, 'return', {})
240 result
= self
.vm
.qmp('block-stream', device
='node5', job_id
='stream-node5', base
=self
.imgs
[2])
241 self
.assert_qmp(result
, 'error/class', 'GenericError')
243 result
= self
.vm
.qmp('block-stream', device
='node3', job_id
='stream-node3', base
=self
.imgs
[2])
244 self
.assert_qmp(result
, 'error/class', 'GenericError')
246 result
= self
.vm
.qmp('block-stream', device
='node4', job_id
='stream-node4-v2')
247 self
.assert_qmp(result
, 'error/class', 'GenericError')
249 # block-commit should also fail if it touches nodes used by the stream job
250 result
= self
.vm
.qmp('block-commit', device
='drive0', base
=self
.imgs
[4], job_id
='commit-node4')
251 self
.assert_qmp(result
, 'error/class', 'GenericError')
253 result
= self
.vm
.qmp('block-commit', device
='drive0', base
=self
.imgs
[1], top
=self
.imgs
[3], job_id
='commit-node1')
254 self
.assert_qmp(result
, 'error/class', 'GenericError')
256 # This fails because it needs to modify the backing string in node2, which is blocked
257 result
= self
.vm
.qmp('block-commit', device
='drive0', base
=self
.imgs
[0], top
=self
.imgs
[1], job_id
='commit-node0')
258 self
.assert_qmp(result
, 'error/class', 'GenericError')
260 self
.wait_until_completed(drive
='stream-node4')
261 self
.assert_no_active_block_jobs()
263 # Similar to test_overlapping_1, but with block-commit
264 # blocking the other jobs
265 def test_overlapping_2(self
):
266 self
.assertLessEqual(9, self
.num_imgs
)
267 self
.assert_no_active_block_jobs()
269 # Set a speed limit to make sure that this job blocks the rest
270 result
= self
.vm
.qmp('block-commit', device
='drive0', top
=self
.imgs
[5], base
=self
.imgs
[3], job_id
='commit-node3', speed
=1024*1024)
271 self
.assert_qmp(result
, 'return', {})
273 result
= self
.vm
.qmp('block-stream', device
='node3', job_id
='stream-node3')
274 self
.assert_qmp(result
, 'error/class', 'GenericError')
276 result
= self
.vm
.qmp('block-stream', device
='node6', base
=self
.imgs
[2], job_id
='stream-node6')
277 self
.assert_qmp(result
, 'error/class', 'GenericError')
279 result
= self
.vm
.qmp('block-stream', device
='node4', base
=self
.imgs
[2], job_id
='stream-node4')
280 self
.assert_qmp(result
, 'error/class', 'GenericError')
282 result
= self
.vm
.qmp('block-stream', device
='node6', base
=self
.imgs
[4], job_id
='stream-node6-v2')
283 self
.assert_qmp(result
, 'error/class', 'GenericError')
285 # This fails because block-commit needs to block node6, the overlay of the 'top' image
286 result
= self
.vm
.qmp('block-stream', device
='node7', base
=self
.imgs
[5], job_id
='stream-node6-v3')
287 self
.assert_qmp(result
, 'error/class', 'GenericError')
289 # This fails because block-commit currently blocks the active layer even if it's not used
290 result
= self
.vm
.qmp('block-stream', device
='drive0', base
=self
.imgs
[5], job_id
='stream-drive0')
291 self
.assert_qmp(result
, 'error/class', 'GenericError')
293 self
.wait_until_completed(drive
='commit-node3')
295 # Similar to test_overlapping_2, but here block-commit doesn't use the 'top' parameter.
296 # Internally this uses a mirror block job, hence the separate test case.
297 def test_overlapping_3(self
):
298 self
.assertLessEqual(8, self
.num_imgs
)
299 self
.assert_no_active_block_jobs()
301 # Set a speed limit to make sure that this job blocks the rest
302 result
= self
.vm
.qmp('block-commit', device
='drive0', base
=self
.imgs
[3], job_id
='commit-drive0', speed
=1024*1024)
303 self
.assert_qmp(result
, 'return', {})
305 result
= self
.vm
.qmp('block-stream', device
='node5', base
=self
.imgs
[3], job_id
='stream-node6')
306 self
.assert_qmp(result
, 'error/class', 'GenericError')
308 event
= self
.vm
.get_qmp_event(wait
=True)
309 self
.assertEqual(event
['event'], 'BLOCK_JOB_READY')
310 self
.assert_qmp(event
, 'data/device', 'commit-drive0')
311 self
.assert_qmp(event
, 'data/type', 'commit')
312 self
.assert_qmp_absent(event
, 'data/error')
314 result
= self
.vm
.qmp('block-job-complete', device
='commit-drive0')
315 self
.assert_qmp(result
, 'return', {})
317 self
.wait_until_completed(drive
='commit-drive0')
318 self
.assert_no_active_block_jobs()
320 class TestSmallerBackingFile(iotests
.QMPTestCase
):
321 backing_len
= 1 * 1024 * 1024 # MB
322 image_len
= 2 * backing_len
325 iotests
.create_image(backing_img
, self
.backing_len
)
326 qemu_img('create', '-f', iotests
.imgfmt
, '-o', 'backing_file=%s' % backing_img
, test_img
, str(self
.image_len
))
327 self
.vm
= iotests
.VM().add_drive(test_img
)
330 # If this hangs, then you are missing a fix to complete streaming when the
331 # end of the backing file is reached.
332 def test_stream(self
):
333 self
.assert_no_active_block_jobs()
335 result
= self
.vm
.qmp('block-stream', device
='drive0')
336 self
.assert_qmp(result
, 'return', {})
338 self
.wait_until_completed()
340 self
.assert_no_active_block_jobs()
343 class TestErrors(iotests
.QMPTestCase
):
344 image_len
= 2 * 1024 * 1024 # MB
346 # this should match STREAM_BUFFER_SIZE/512 in block/stream.c
347 STREAM_BUFFER_SIZE
= 512 * 1024
349 def create_blkdebug_file(self
, name
, event
, errno
):
350 file = open(name
, 'w')
369 ''' % (event
, errno
, self
.STREAM_BUFFER_SIZE
/ 512, event
, event
))
372 class TestEIO(TestErrors
):
374 self
.blkdebug_file
= backing_img
+ ".blkdebug"
375 iotests
.create_image(backing_img
, TestErrors
.image_len
)
376 self
.create_blkdebug_file(self
.blkdebug_file
, "read_aio", 5)
377 qemu_img('create', '-f', iotests
.imgfmt
,
378 '-o', 'backing_file=blkdebug:%s:%s,backing_fmt=raw'
379 % (self
.blkdebug_file
, backing_img
),
381 self
.vm
= iotests
.VM().add_drive(test_img
)
387 os
.remove(backing_img
)
388 os
.remove(self
.blkdebug_file
)
390 def test_report(self
):
391 self
.assert_no_active_block_jobs()
393 result
= self
.vm
.qmp('block-stream', device
='drive0')
394 self
.assert_qmp(result
, 'return', {})
399 for event
in self
.vm
.get_qmp_events(wait
=True):
400 if event
['event'] == 'BLOCK_JOB_ERROR':
401 self
.assert_qmp(event
, 'data/device', 'drive0')
402 self
.assert_qmp(event
, 'data/operation', 'read')
404 elif event
['event'] == 'BLOCK_JOB_COMPLETED':
405 self
.assertTrue(error
, 'job completed unexpectedly')
406 self
.assert_qmp(event
, 'data/type', 'stream')
407 self
.assert_qmp(event
, 'data/device', 'drive0')
408 self
.assert_qmp(event
, 'data/error', 'Input/output error')
409 self
.assert_qmp(event
, 'data/offset', self
.STREAM_BUFFER_SIZE
)
410 self
.assert_qmp(event
, 'data/len', self
.image_len
)
413 self
.assert_no_active_block_jobs()
416 def test_ignore(self
):
417 self
.assert_no_active_block_jobs()
419 result
= self
.vm
.qmp('block-stream', device
='drive0', on_error
='ignore')
420 self
.assert_qmp(result
, 'return', {})
425 for event
in self
.vm
.get_qmp_events(wait
=True):
426 if event
['event'] == 'BLOCK_JOB_ERROR':
427 self
.assert_qmp(event
, 'data/device', 'drive0')
428 self
.assert_qmp(event
, 'data/operation', 'read')
429 result
= self
.vm
.qmp('query-block-jobs')
430 self
.assert_qmp(result
, 'return[0]/paused', False)
432 elif event
['event'] == 'BLOCK_JOB_COMPLETED':
433 self
.assertTrue(error
, 'job completed unexpectedly')
434 self
.assert_qmp(event
, 'data/type', 'stream')
435 self
.assert_qmp(event
, 'data/device', 'drive0')
436 self
.assert_qmp(event
, 'data/error', 'Input/output error')
437 self
.assert_qmp(event
, 'data/offset', self
.image_len
)
438 self
.assert_qmp(event
, 'data/len', self
.image_len
)
441 self
.assert_no_active_block_jobs()
445 self
.assert_no_active_block_jobs()
447 result
= self
.vm
.qmp('block-stream', device
='drive0', on_error
='stop')
448 self
.assert_qmp(result
, 'return', {})
453 for event
in self
.vm
.get_qmp_events(wait
=True):
454 if event
['event'] == 'BLOCK_JOB_ERROR':
456 self
.assert_qmp(event
, 'data/device', 'drive0')
457 self
.assert_qmp(event
, 'data/operation', 'read')
459 result
= self
.vm
.qmp('query-block-jobs')
460 self
.assert_qmp(result
, 'return[0]/paused', True)
461 self
.assert_qmp(result
, 'return[0]/offset', self
.STREAM_BUFFER_SIZE
)
462 self
.assert_qmp(result
, 'return[0]/io-status', 'failed')
464 result
= self
.vm
.qmp('block-job-resume', device
='drive0')
465 self
.assert_qmp(result
, 'return', {})
467 result
= self
.vm
.qmp('query-block-jobs')
468 if result
== {'return': []}:
469 # Race; likely already finished. Check.
471 self
.assert_qmp(result
, 'return[0]/paused', False)
472 self
.assert_qmp(result
, 'return[0]/io-status', 'ok')
473 elif event
['event'] == 'BLOCK_JOB_COMPLETED':
474 self
.assertTrue(error
, 'job completed unexpectedly')
475 self
.assert_qmp(event
, 'data/type', 'stream')
476 self
.assert_qmp(event
, 'data/device', 'drive0')
477 self
.assert_qmp_absent(event
, 'data/error')
478 self
.assert_qmp(event
, 'data/offset', self
.image_len
)
479 self
.assert_qmp(event
, 'data/len', self
.image_len
)
482 self
.assert_no_active_block_jobs()
485 def test_enospc(self
):
486 self
.assert_no_active_block_jobs()
488 result
= self
.vm
.qmp('block-stream', device
='drive0', on_error
='enospc')
489 self
.assert_qmp(result
, 'return', {})
494 for event
in self
.vm
.get_qmp_events(wait
=True):
495 if event
['event'] == 'BLOCK_JOB_ERROR':
496 self
.assert_qmp(event
, 'data/device', 'drive0')
497 self
.assert_qmp(event
, 'data/operation', 'read')
499 elif event
['event'] == 'BLOCK_JOB_COMPLETED':
500 self
.assertTrue(error
, 'job completed unexpectedly')
501 self
.assert_qmp(event
, 'data/type', 'stream')
502 self
.assert_qmp(event
, 'data/device', 'drive0')
503 self
.assert_qmp(event
, 'data/error', 'Input/output error')
504 self
.assert_qmp(event
, 'data/offset', self
.STREAM_BUFFER_SIZE
)
505 self
.assert_qmp(event
, 'data/len', self
.image_len
)
508 self
.assert_no_active_block_jobs()
511 class TestENOSPC(TestErrors
):
513 self
.blkdebug_file
= backing_img
+ ".blkdebug"
514 iotests
.create_image(backing_img
, TestErrors
.image_len
)
515 self
.create_blkdebug_file(self
.blkdebug_file
, "read_aio", 28)
516 qemu_img('create', '-f', iotests
.imgfmt
,
517 '-o', 'backing_file=blkdebug:%s:%s,backing_fmt=raw'
518 % (self
.blkdebug_file
, backing_img
),
520 self
.vm
= iotests
.VM().add_drive(test_img
)
526 os
.remove(backing_img
)
527 os
.remove(self
.blkdebug_file
)
529 def test_enospc(self
):
530 self
.assert_no_active_block_jobs()
532 result
= self
.vm
.qmp('block-stream', device
='drive0', on_error
='enospc')
533 self
.assert_qmp(result
, 'return', {})
538 for event
in self
.vm
.get_qmp_events(wait
=True):
539 if event
['event'] == 'BLOCK_JOB_ERROR':
540 self
.assert_qmp(event
, 'data/device', 'drive0')
541 self
.assert_qmp(event
, 'data/operation', 'read')
543 result
= self
.vm
.qmp('query-block-jobs')
544 self
.assert_qmp(result
, 'return[0]/paused', True)
545 self
.assert_qmp(result
, 'return[0]/offset', self
.STREAM_BUFFER_SIZE
)
546 self
.assert_qmp(result
, 'return[0]/io-status', 'nospace')
548 result
= self
.vm
.qmp('block-job-resume', device
='drive0')
549 self
.assert_qmp(result
, 'return', {})
551 result
= self
.vm
.qmp('query-block-jobs')
552 self
.assert_qmp(result
, 'return[0]/paused', False)
553 self
.assert_qmp(result
, 'return[0]/io-status', 'ok')
555 elif event
['event'] == 'BLOCK_JOB_COMPLETED':
556 self
.assertTrue(error
, 'job completed unexpectedly')
557 self
.assert_qmp(event
, 'data/type', 'stream')
558 self
.assert_qmp(event
, 'data/device', 'drive0')
559 self
.assert_qmp_absent(event
, 'data/error')
560 self
.assert_qmp(event
, 'data/offset', self
.image_len
)
561 self
.assert_qmp(event
, 'data/len', self
.image_len
)
564 self
.assert_no_active_block_jobs()
567 class TestStreamStop(iotests
.QMPTestCase
):
568 image_len
= 8 * 1024 * 1024 * 1024 # GB
571 qemu_img('create', backing_img
, str(TestStreamStop
.image_len
))
572 qemu_io('-f', 'raw', '-c', 'write -P 0x1 0 32M', backing_img
)
573 qemu_img('create', '-f', iotests
.imgfmt
, '-o', 'backing_file=%s' % backing_img
, test_img
)
574 qemu_io('-f', iotests
.imgfmt
, '-c', 'write -P 0x1 32M 32M', test_img
)
575 self
.vm
= iotests
.VM().add_drive("blkdebug::" + test_img
)
581 os
.remove(backing_img
)
583 def test_stream_stop(self
):
584 self
.assert_no_active_block_jobs()
586 self
.vm
.pause_drive('drive0')
587 result
= self
.vm
.qmp('block-stream', device
='drive0')
588 self
.assert_qmp(result
, 'return', {})
591 events
= self
.vm
.get_qmp_events(wait
=False)
592 self
.assertEqual(events
, [], 'unexpected QMP event: %s' % events
)
594 self
.cancel_and_wait(resume
=True)
596 class TestSetSpeed(iotests
.QMPTestCase
):
597 image_len
= 80 * 1024 * 1024 # MB
600 qemu_img('create', backing_img
, str(TestSetSpeed
.image_len
))
601 qemu_io('-f', 'raw', '-c', 'write -P 0x1 0 32M', backing_img
)
602 qemu_img('create', '-f', iotests
.imgfmt
, '-o', 'backing_file=%s' % backing_img
, test_img
)
603 qemu_io('-f', iotests
.imgfmt
, '-c', 'write -P 0x1 32M 32M', test_img
)
604 self
.vm
= iotests
.VM().add_drive('blkdebug::' + test_img
)
610 os
.remove(backing_img
)
612 # This is a short performance test which is not run by default.
613 # Invoke "IMGFMT=qed ./030 TestSetSpeed.perf_test_throughput"
614 def perf_test_throughput(self
):
615 self
.assert_no_active_block_jobs()
617 result
= self
.vm
.qmp('block-stream', device
='drive0')
618 self
.assert_qmp(result
, 'return', {})
620 result
= self
.vm
.qmp('block-job-set-speed', device
='drive0', speed
=8 * 1024 * 1024)
621 self
.assert_qmp(result
, 'return', {})
623 self
.wait_until_completed()
625 self
.assert_no_active_block_jobs()
627 def test_set_speed(self
):
628 self
.assert_no_active_block_jobs()
630 self
.vm
.pause_drive('drive0')
631 result
= self
.vm
.qmp('block-stream', device
='drive0')
632 self
.assert_qmp(result
, 'return', {})
635 result
= self
.vm
.qmp('query-block-jobs')
636 self
.assert_qmp(result
, 'return[0]/device', 'drive0')
637 self
.assert_qmp(result
, 'return[0]/speed', 0)
639 result
= self
.vm
.qmp('block-job-set-speed', device
='drive0', speed
=8 * 1024 * 1024)
640 self
.assert_qmp(result
, 'return', {})
642 # Ensure the speed we set was accepted
643 result
= self
.vm
.qmp('query-block-jobs')
644 self
.assert_qmp(result
, 'return[0]/device', 'drive0')
645 self
.assert_qmp(result
, 'return[0]/speed', 8 * 1024 * 1024)
647 self
.cancel_and_wait(resume
=True)
648 self
.vm
.pause_drive('drive0')
650 # Check setting speed in block-stream works
651 result
= self
.vm
.qmp('block-stream', device
='drive0', speed
=4 * 1024 * 1024)
652 self
.assert_qmp(result
, 'return', {})
654 result
= self
.vm
.qmp('query-block-jobs')
655 self
.assert_qmp(result
, 'return[0]/device', 'drive0')
656 self
.assert_qmp(result
, 'return[0]/speed', 4 * 1024 * 1024)
658 self
.cancel_and_wait(resume
=True)
660 def test_set_speed_invalid(self
):
661 self
.assert_no_active_block_jobs()
663 result
= self
.vm
.qmp('block-stream', device
='drive0', speed
=-1)
664 self
.assert_qmp(result
, 'error/class', 'GenericError')
666 self
.assert_no_active_block_jobs()
668 result
= self
.vm
.qmp('block-stream', device
='drive0')
669 self
.assert_qmp(result
, 'return', {})
671 result
= self
.vm
.qmp('block-job-set-speed', device
='drive0', speed
=-1)
672 self
.assert_qmp(result
, 'error/class', 'GenericError')
674 self
.cancel_and_wait()
676 if __name__
== '__main__':
677 iotests
.main(supported_fmts
=['qcow2', 'qed'])