iotests: Make some tests less flaky
v2 cover iotests: Make some tests less flaky
There are a couple of tests that fail (on my machine) from time to time (and by that I mean that recently I've rarely ever had a test run with both 083 and 136 working on first try).
This series should fix most (at least the issues I am aware of).
Notes:
- 083 might have another issue, but if so it occurs extremely rarely and so I was unable to debug it.
- 129 is flaky, too, because it tries to use block jobs with BB throttling -- however, block jobs ignore that these days. Making it use a throttle filter node will require quite a bit of work. See
http://lists.nongnu.org/archive/html/qemu-block/2017-11/msg00111.html
for more.
- 194 sometimes hangs because the source VM fails to drain its drive. This is probably not an issue with the test, but actually an issue in qemu. See
http://lists.nongnu.org/archive/html/qemu-block/2017-11/msg00256.html
for more.
v2:
- Spelling fixes [Eric]
- Contract grep | sed to a single sed in 083 [Eric]
git-backport-diff against v1:
Key:
[----] : patches are identical
[####] : number of functional differences between upstream/downstream patch [down] : patch is downstream-only
The flags [FC] indicate (F)unctional and (C)ontextual differences, respectively
001/5:[----] [--] 'iotests: Make 030 less flaky' 002/5:[----] [--] 'iotests: Add missing 'blkdebug::' in 040' 003/5:[----] [--] 'iotests: Make 055 less flaky' 004/5:[0003] [FC] 'iotests: Make 083 less flaky' 005/5:[----] [--] 'iotests: Make 136 less flaky'
Max Reitz (5):
iotests: Make 030 less flaky
iotests: Add missing 'blkdebug::' in 040
iotests: Make 055 less flaky
iotests: Make 083 less flaky
iotests: Make 136 less flaky
tests/qemu-iotests/030 | 8 ++++++-- tests/qemu-iotests/040 | 2 +- tests/qemu-iotests/055 | 25 ++++++++++++++++--------- tests/qemu-iotests/083 | 4 +++- tests/qemu-iotests/136 | 14 +++++++++++++- 5 files changed, 39 insertions(+), 14 deletions(-)
Signature · 1 line
2.13.6
PATCH v2 1/5 iotests: Make 030 less flaky
This patch fixes two race conditions in 030:
1. The first is in TestENOSPC.test_enospc(). After resuming the job, querying it to confirm it is no longer paused may fail because in the meantime it might have completed already. The same was fixed in TestEIO.test_ignore() already (in commit 2c3b44da07d341557a8203cc509ea07fe3605e11).
2. The second is in TestSetSpeed.test_set_speed_invalid(): Here, a stream job is started on a drive without any break points, with a block-job-set-speed invoked subsequently. However, without any break points, the job might have completed in the meantime (on tmpfs at least); or it might complete before cancel_and_wait() which expects the job to still exist. This can be fixed like everywhere else by pausing the drive (installing break points) before starting the job and letting cancel_and_wait() resume it.
--- tests/qemu-iotests/030 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
tests/qemu-iotests/030 +6 -2
@@ -666,6 +666,7 @@ class TestENOSPC(TestErrors): if event['event'] == 'BLOCK_JOB_ERROR': self.assert_qmp(event, 'data/device', 'drive0') self.assert_qmp(event, 'data/operation', 'read') + error = True result = self.vm.qmp('query-block-jobs') self.assert_qmp(result, 'return[0]/paused', True)
@@ -676,9 +677,11 @@ class TestENOSPC(TestErrors): self.assert_qmp(result, 'return', {}) result = self.vm.qmp('query-block-jobs') + if result == {'return': []}: + # Race; likely already finished. Check. + continue self.assert_qmp(result, 'return[0]/paused', False) self.assert_qmp(result, 'return[0]/io-status', 'ok') - error = True elif event['event'] == 'BLOCK_JOB_COMPLETED': self.assertTrue(error, 'job completed unexpectedly') self.assert_qmp(event, 'data/type', 'stream')
@@ -792,13 +795,14 @@ class TestSetSpeed(iotests.QMPTestCase): self.assert_no_active_block_jobs() + self.vm.pause_drive('drive0') result = self.vm.qmp('block-stream', device='drive0') self.assert_qmp(result, 'return', {}) result = self.vm.qmp('block-job-set-speed', device='drive0', speed=-1) self.assert_qmp(result, 'error/class', 'GenericError') - self.cancel_and_wait() + self.cancel_and_wait(resume=True) if __name__ == '__main__': iotests.main(supported_fmts=['qcow2', 'qed'])
Signature · 1 line
2.13.6
PATCH v2 2/5 iotests: Add missing 'blkdebug::' in 040
In reply to Max Reitz040 tries to invoke pause_drive() on a drive that does not use blkdebug. Good idea, but let's use blkdebug to make it actually work.
--- tests/qemu-iotests/040 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qemu-iotests/040 +1 -1
@@ -289,7 +289,7 @@ class TestSetSpeed(ImageCommitTestCase): qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % mid_img, test_img) qemu_io('-f', iotests.imgfmt, '-c', 'write -P 0x1 0 512', test_img) qemu_io('-f', iotests.imgfmt, '-c', 'write -P 0xef 524288 524288', mid_img) - self.vm = iotests.VM().add_drive(test_img) + self.vm = iotests.VM().add_drive('blkdebug::' + test_img) self.vm.launch() def tearDown(self):
Signature · 1 line
2.13.6
PATCH v2 3/5 iotests: Make 055 less flaky
In reply to Max ReitzFirst of all, test 055 does a valiant job of invoking pause_drive() sometimes, but that is worth nothing without blkdebug. So the first thing to do is to sprinkle a couple of "blkdebug::" in there -- with the exception of the transaction tests, because the blkdebug break points make the transaction QMP command hang (which is bad). In that case, we can get away with throttling the block job that it effectively is paused.
Then, 055 usually does not pause the drive before starting a block job that should be cancelled. This means that the backup job might be completed already before block-job-cancel is invoked; thus making the test either fail (currently) or moot if cancel_and_wait() ignored this condition. Fix this by pausing the drive before starting the job.
--- tests/qemu-iotests/055 | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)
tests/qemu-iotests/055 +16 -9
@@ -48,7 +48,7 @@ class TestSingleDrive(iotests.QMPTestCase): def setUp(self): qemu_img('create', '-f', iotests.imgfmt, blockdev_target_img, str(image_len)) - self.vm = iotests.VM().add_drive(test_img) + self.vm = iotests.VM().add_drive('blkdebug::' + test_img) self.vm.add_drive(blockdev_target_img, interface="none") if iotests.qemu_default_machine == 'pc': self.vm.add_drive(None, 'media=cdrom', 'ide')
@@ -65,10 +65,11 @@ class TestSingleDrive(iotests.QMPTestCase): def do_test_cancel(self, cmd, target): self.assert_no_active_block_jobs() + self.vm.pause_drive('drive0') result = self.vm.qmp(cmd, device='drive0', target=target, sync='full') self.assert_qmp(result, 'return', {}) - event = self.cancel_and_wait() + event = self.cancel_and_wait(resume=True) self.assert_qmp(event, 'data/type', 'backup') def test_cancel_drive_backup(self):
@@ -166,7 +167,7 @@ class TestSetSpeed(iotests.QMPTestCase): def setUp(self): qemu_img('create', '-f', iotests.imgfmt, blockdev_target_img, str(image_len)) - self.vm = iotests.VM().add_drive(test_img) + self.vm = iotests.VM().add_drive('blkdebug::' + test_img) self.vm.add_drive(blockdev_target_img, interface="none") self.vm.launch()
@@ -246,6 +247,8 @@ class TestSetSpeed(iotests.QMPTestCase): def test_set_speed_invalid_blockdev_backup(self): self.do_test_set_speed_invalid('blockdev-backup', 'drive1') +# Note: We cannot use pause_drive() here, or the transaction command +# would stall. Instead, we limit the block job speed here. class TestSingleTransaction(iotests.QMPTestCase): def setUp(self): qemu_img('create', '-f', iotests.imgfmt, blockdev_target_img, str(image_len))
@@ -271,7 +274,8 @@ class TestSingleTransaction(iotests.QMPTestCase): 'type': cmd, 'data': { 'device': 'drive0', 'target': target, - 'sync': 'full' }, + 'sync': 'full', + 'speed': 64 * 1024 }, } ])
@@ -289,12 +293,12 @@ class TestSingleTransaction(iotests.QMPTestCase): def do_test_pause(self, cmd, target, image): self.assert_no_active_block_jobs() - self.vm.pause_drive('drive0') result = self.vm.qmp('transaction', actions=[{ 'type': cmd, 'data': { 'device': 'drive0', 'target': target, - 'sync': 'full' }, + 'sync': 'full', + 'speed': 64 * 1024 }, } ]) self.assert_qmp(result, 'return', {})
@@ -302,7 +306,9 @@ class TestSingleTransaction(iotests.QMPTestCase): result = self.vm.qmp('block-job-pause', device='drive0') self.assert_qmp(result, 'return', {}) - self.vm.resume_drive('drive0') + result = self.vm.qmp('block-job-set-speed', device='drive0', speed=0) + self.assert_qmp(result, 'return', {}) + self.pause_job('drive0') result = self.vm.qmp('query-block-jobs')
@@ -461,7 +467,7 @@ class TestDriveCompression(iotests.QMPTestCase): pass def do_prepare_drives(self, fmt, args, attach_target): - self.vm = iotests.VM().add_drive(test_img) + self.vm = iotests.VM().add_drive('blkdebug::' + test_img) qemu_img('create', '-f', fmt, blockdev_target_img, str(TestDriveCompression.image_len), *args)
@@ -500,10 +506,11 @@ class TestDriveCompression(iotests.QMPTestCase): self.assert_no_active_block_jobs() + self.vm.pause_drive('drive0') result = self.vm.qmp(cmd, device='drive0', sync='full', compress=True, **args) self.assert_qmp(result, 'return', {}) - event = self.cancel_and_wait() + event = self.cancel_and_wait(resume=True) self.assert_qmp(event, 'data/type', 'backup') self.vm.shutdown()
Signature · 1 line
2.13.6
PATCH v2 4/5 iotests: Make 083 less flaky
In reply to Max Reitz083 has (at least) two issues:
1. By launching the nbd-fault-injector in background, it may not be scheduled until the first grep on its output file is executed. However, until then, that file may not have been created yet -- so it either does not exist yet (thus making the grep emit an error), or it does exist but contains stale data (thus making the rest of the test case work connect to a wrong address).
Fix this by explicitly overwriting the output file before executing nbd-fault-injector.
2. The nbd-fault-injector prints things other than "Listening on...". It also prints a "Closing connection" message from time to time. We currently invoke sed on the whole file in the hope of it only containing the "Listening on..." line yet. That hope is sometimes shattered by the brutal reality of race conditions, so invoke grep before sed.
--- tests/qemu-iotests/083 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tests/qemu-iotests/083 +3 -1
@@ -86,6 +86,7 @@ EOF rm -f "$TEST_DIR/nbd.sock" + echo > "$TEST_DIR/nbd-fault-injector.out" $PYTHON nbd-fault-injector.py $extra_args "$nbd_addr" "$TEST_DIR/nbd-fault-injector.conf" >"$TEST_DIR/nbd-fault-injector.out" 2>&1 & # Wait for server to be ready
@@ -94,7 +95,8 @@ EOF done # Extract the final address (port number has now been assigned in tcp case) - nbd_addr=$(sed 's/Listening on \(.*\)$/\1/' "$TEST_DIR/nbd-fault-injector.out") + nbd_addr=$(sed -n 's/^Listening on //p' \ + "$TEST_DIR/nbd-fault-injector.out") if [ "$proto" = "tcp" ]; then nbd_url="nbd+tcp://$nbd_addr/$export_name"
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v2 4/5] iotests: Make 083 less flaky
Quoted 11 lines · Max Reitz
083 has (at least) two issues:
1. By launching the nbd-fault-injector in background, it may not be scheduled until the first grep on its output file is executed. However, until then, that file may not have been created yet -- so it either does not exist yet (thus making the grep emit an error), or it does exist but contains stale data (thus making the rest of the test case work connect to a wrong address).
Fix this by explicitly overwriting the output file before executing nbd-fault-injector.
Quoted 6 lines
2. The nbd-fault-injector prints things other than "Listening on...". It also prints a "Closing connection" message from time to time. We currently invoke sed on the whole file in the hope of it only containing the "Listening on..." line yet. That hope is sometimes shattered by the brutal reality of race conditions, so invoke grep before sed.
Comment is now stale; s/invoke grep before sed/make the sed script more robust/
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v2 4/5] iotests: Make 083 less flaky
Quoted 19 lines · Eric Blake
Quoted 11 lines · Max Reitz
083 has (at least) two issues:
1. By launching the nbd-fault-injector in background, it may not be scheduled until the first grep on its output file is executed. However, until then, that file may not have been created yet -- so it either does not exist yet (thus making the grep emit an error), or it does exist but contains stale data (thus making the rest of the test case work connect to a wrong address).
Fix this by explicitly overwriting the output file before executing nbd-fault-injector.Quoted 6 lines
2. The nbd-fault-injector prints things other than "Listening on...". It also prints a "Closing connection" message from time to time. We currently invoke sed on the whole file in the hope of it only containing the "Listening on..." line yet. That hope is sometimes shattered by the brutal reality of race conditions, so invoke grep before sed.
Quoted 2 lines
Comment is now stale; s/invoke grep before sed/make the sed script more robust/
*sigh*
It appears my hope of easily fixing patches is often shattered by the brutal reality, too.
Quoted 1 line
Reviewed-by Eric Blake <[email protected]>
Thanks! I'll fix the sentence when applying the series.
Max
Re: [Qemu-devel] [Qemu-block] [PATCH v2 4/5] iotests: Make 083 less flaky
In reply to Max Reitztests/qemu-iotests/083 EOF · line 90
Quoted 2 lines · Max Reitz
tests/qemu-iotests/083 +1
-0+ echo > "$TEST_DIR/nbd-fault-injector.out" $PYTHON nbd-fault-injector.py $extra_args "$nbd_addr" "$TEST_DIR/nbd-fault-injector.conf" >"$TEST_DIR/nbd-fault-injector.out" 2>&1 &
It seems that in this patch you're indenting with spaces but this file uses tabs.
Berto
Re: [Qemu-devel] [Qemu-block] [PATCH v2 4/5] iotests: Make 083 less flaky
Quoted 6 lines · Alberto Garcia
tests/qemu-iotests/083 EOF · line 90
Quoted 2 lines · Max Reitz
tests/qemu-iotests/083 +1
-0+ echo > "$TEST_DIR/nbd-fault-injector.out" $PYTHON nbd-fault-injector.py $extra_args "$nbd_addr" "$TEST_DIR/nbd-fault-injector.conf" >"$TEST_DIR/nbd-fault-injector.out" 2>&1 &It seems that in this patch you're indenting with spaces but this file uses tabs.
Yes, but tabs are wrong. :-)
Max
Re: [Qemu-devel] [Qemu-block] [PATCH v2 4/5] iotests: Make 083 less flaky
Quoted 9 lines · Max Reitz
Quoted 6 lines · Alberto Garcia
tests/qemu-iotests/083 EOF · line 90
Quoted 2 lines · Max Reitz
tests/qemu-iotests/083 +1
-0+ echo > "$TEST_DIR/nbd-fault-injector.out" $PYTHON nbd-fault-injector.py $extra_args "$nbd_addr" "$TEST_DIR/nbd-fault-injector.conf" >"$TEST_DIR/nbd-fault-injector.out" 2>&1 &It seems that in this patch you're indenting with spaces but this file uses tabs.
Yes, but tabs are wrong. :-)
I actually agree with you, but don't mix them in the file :-)
Berto
Re: [Qemu-devel] [Qemu-block] [PATCH v2 4/5] iotests: Make 083 less flaky
Quoted 6 lines · Alberto Garcia
Quoted 5 lines · Max Reitz
Quoted 4 lines · Alberto Garcia
Quoted 2 lines · Max Reitz
tests/qemu-iotests/083 +1
-0+ echo > "$TEST_DIR/nbd-fault-injector.out" $PYTHON nbd-fault-injector.py $extra_args "$nbd_addr" "$TEST_DIR/nbd-fault-injector.conf" >"$TEST_DIR/nbd-fault-injector.out" 2>&1 &
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
It seems that in this patch you're indenting with spaces but this file uses tabs.
Yes, but tabs are wrong. :-)
I actually agree with you, but don't mix them in the file :-)
I can whistle and say here, too, that Eric liked it. O:-)
And I really don't want to use tabs in the second hunk of this patch, as it's broken over two lines.
Max
Re: [Qemu-devel] [Qemu-block] [PATCH v2 4/5] iotests: Make 083 less flaky
Quoted 8 lines · Max Reitz
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
It seems that in this patch you're indenting with spaces but this file uses tabs.
Yes, but tabs are wrong. :-)
I actually agree with you, but don't mix them in the file :-)
I can whistle and say here, too, that Eric liked it. O:-)
I don't really pay attention to which files have pre-existing TABs. You're right that preserving whole-file TABs is a bit nicer from consistency than reformatting a file wholesale; but then you have to tell checkpatch that preserving TABs was intentional. Mixed mode indentation is not as consistent, but at least keeps checkpatch happy without effort, and may make it easier for a patch down the road to finally do wholesale conversion of the rest of the file to avoid TABs.
So when it comes to a file with existing TABs, I'm okay whether the patch preserves TABs (with documentation that it is doing so intentionally) or switches to mixed-mode spaces.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
PATCH v2 5/5 iotests: Make 136 less flaky
In reply to Max Reitz136 executes some AIO requests without a final aio_flush; then it advances the virtual clock and thus expects the last access time of the device to be less than the current time when queried (i.e. idle_time_ns to be greater than 0). However, without the aio_flush, some requests may be settled after the clock_step invocation. In that case, idle_time_ns would be 0 and the test fails.
Fix this by adding an aio_flush if any AIO request other than some other aio_flush has been executed.
--- tests/qemu-iotests/136 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
tests/qemu-iotests/136 +13 -1
@@ -238,6 +238,18 @@ sector = "%d" for i in range(failed_wr_ops): ops.append("aio_write %d 512" % bad_offset) + # We need an extra aio_flush to settle all outstanding AIO + # operations before we can advance the virtual clock, so that + # the last access happens before clock_step and idle_time_ns + # will be greater than 0 + extra_flush = 0 + if rd_ops + wr_ops + invalid_rd_ops + invalid_wr_ops + \ + failed_rd_ops + failed_wr_ops > 0: + extra_flush = 1 + + if extra_flush > 0: + ops.append("aio_flush") + if failed_wr_ops > 0: highest_offset = max(highest_offset, bad_offset + 512)
@@ -251,7 +263,7 @@ sector = "%d" self.total_wr_bytes += wr_ops * wr_size self.total_wr_ops += wr_ops self.total_wr_merged += wr_merged - self.total_flush_ops += flush_ops + self.total_flush_ops += flush_ops + extra_flush self.invalid_rd_ops += invalid_rd_ops self.invalid_wr_ops += invalid_wr_ops self.failed_rd_ops += failed_rd_ops
Signature · 1 line
2.13.6
Quoted 4 lines · Max Reitz
There are a couple of tests that fail (on my machine) from time to time (and by that I mean that recently I've rarely ever had a test run with both 083 and 136 working on first try).
This series should fix most (at least the issues I am aware of).
Fixed the commit message in patch 4 as suggested by Eric and applied to my block branch:
https://github.com/XanClic/qemu/commits/block
Max