From nobody Wed Nov 5 00:33:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15006498882492.6645426009558832; Fri, 21 Jul 2017 08:11:28 -0700 (PDT) Received: from localhost ([::1]:43690 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYZaP-00025s-Gx for importer@patchew.org; Fri, 21 Jul 2017 11:11:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48557) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYZZa-0001kS-VF for qemu-devel@nongnu.org; Fri, 21 Jul 2017 11:10:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYZZZ-0007AG-JD for qemu-devel@nongnu.org; Fri, 21 Jul 2017 11:10:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43420) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYZZU-00075b-F4; Fri, 21 Jul 2017 11:10:28 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4E2E88B125; Fri, 21 Jul 2017 15:10:25 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-185.ams2.redhat.com [10.36.116.185]) by smtp.corp.redhat.com (Postfix) with ESMTP id 46B1D58856; Fri, 21 Jul 2017 15:10:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4E2E88B125 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4E2E88B125 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 21 Jul 2017 17:10:20 +0200 Message-Id: <1500649820-30450-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 21 Jul 2017 15:10:25 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] qemu-iotests: Avoid unnecessary sleeps X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Test cases 030, 041 and 055 used to sleep for a second after calling block-job-pause to make sure that the block job had time to actually get into paused state. We can instead poll its status and use that one second only as a timeout. The tests also slept a second for checking that the block jobs don't make progress while being paused. Half a second is more than enough for this. These changes reduce the total time for the three tests by 25 seconds on my laptop (from 155 seconds to 130). Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- tests/qemu-iotests/030 | 7 ++++--- tests/qemu-iotests/041 | 12 ++++-------- tests/qemu-iotests/055 | 15 +++++++++------ tests/qemu-iotests/iotests.py | 27 +++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 17 deletions(-) diff --git a/tests/qemu-iotests/030 b/tests/qemu-iotests/030 index feee861..d745cb4 100755 --- a/tests/qemu-iotests/030 +++ b/tests/qemu-iotests/030 @@ -89,18 +89,19 @@ class TestSingleDrive(iotests.QMPTestCase): result =3D self.vm.qmp('block-job-pause', device=3D'drive0') self.assert_qmp(result, 'return', {}) =20 - time.sleep(1) + self.vm.resume_drive('drive0') + self.pause_job('drive0') + result =3D self.vm.qmp('query-block-jobs') offset =3D self.dictpath(result, 'return[0]/offset') =20 - time.sleep(1) + time.sleep(0.5) result =3D self.vm.qmp('query-block-jobs') self.assert_qmp(result, 'return[0]/offset', offset) =20 result =3D self.vm.qmp('block-job-resume', device=3D'drive0') self.assert_qmp(result, 'return', {}) =20 - self.vm.resume_drive('drive0') self.wait_until_completed() =20 self.assert_no_active_block_jobs() diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 index 60f09cc..4cda540 100755 --- a/tests/qemu-iotests/041 +++ b/tests/qemu-iotests/041 @@ -103,14 +103,12 @@ class TestSingleDrive(iotests.QMPTestCase): target=3Dself.qmp_target) self.assert_qmp(result, 'return', {}) =20 - result =3D self.vm.qmp('block-job-pause', device=3D'drive0') - self.assert_qmp(result, 'return', {}) + self.pause_job('drive0') =20 - time.sleep(1) result =3D self.vm.qmp('query-block-jobs') offset =3D self.dictpath(result, 'return[0]/offset') =20 - time.sleep(1) + time.sleep(0.5) result =3D self.vm.qmp('query-block-jobs') self.assert_qmp(result, 'return[0]/offset', offset) =20 @@ -896,14 +894,12 @@ class TestRepairQuorum(iotests.QMPTestCase): target=3Dquorum_repair_img, format=3Diotests.= imgfmt) self.assert_qmp(result, 'return', {}) =20 - result =3D self.vm.qmp('block-job-pause', device=3D'job0') - self.assert_qmp(result, 'return', {}) + self.pause_job('job0') =20 - time.sleep(1) result =3D self.vm.qmp('query-block-jobs') offset =3D self.dictpath(result, 'return[0]/offset') =20 - time.sleep(1) + time.sleep(0.5) result =3D self.vm.qmp('query-block-jobs') self.assert_qmp(result, 'return[0]/offset', offset) =20 diff --git a/tests/qemu-iotests/055 b/tests/qemu-iotests/055 index ba4da65..e1206ca 100755 --- a/tests/qemu-iotests/055 +++ b/tests/qemu-iotests/055 @@ -89,11 +89,12 @@ class TestSingleDrive(iotests.QMPTestCase): self.assert_qmp(result, 'return', {}) =20 self.vm.resume_drive('drive0') - time.sleep(1) + self.pause_job('drive0') + result =3D self.vm.qmp('query-block-jobs') offset =3D self.dictpath(result, 'return[0]/offset') =20 - time.sleep(1) + time.sleep(0.5) result =3D self.vm.qmp('query-block-jobs') self.assert_qmp(result, 'return[0]/offset', offset) =20 @@ -302,11 +303,12 @@ class TestSingleTransaction(iotests.QMPTestCase): self.assert_qmp(result, 'return', {}) =20 self.vm.resume_drive('drive0') - time.sleep(1) + self.pause_job('drive0') + result =3D self.vm.qmp('query-block-jobs') offset =3D self.dictpath(result, 'return[0]/offset') =20 - time.sleep(1) + time.sleep(0.5) result =3D self.vm.qmp('query-block-jobs') self.assert_qmp(result, 'return[0]/offset', offset) =20 @@ -529,11 +531,12 @@ class TestDriveCompression(iotests.QMPTestCase): self.assert_qmp(result, 'return', {}) =20 self.vm.resume_drive('drive0') - time.sleep(1) + self.pause_job('drive0') + result =3D self.vm.qmp('query-block-jobs') offset =3D self.dictpath(result, 'return[0]/offset') =20 - time.sleep(1) + time.sleep(0.5) result =3D self.vm.qmp('query-block-jobs') self.assert_qmp(result, 'return[0]/offset', offset) =20 diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index abcf3c1..22439c4 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -27,6 +27,7 @@ sys.path.append(os.path.join(os.path.dirname(__file__), '= ..', '..', 'scripts')) import qtest import struct import json +import signal =20 =20 # This will not work if arguments contain spaces but is necessary if we @@ -137,6 +138,20 @@ def log(msg, filters=3D[]): msg =3D flt(msg) print msg =20 +class Timeout: + def __init__(self, seconds, errmsg =3D "Timeout"): + self.seconds =3D seconds + self.errmsg =3D errmsg + def __enter__(self): + signal.signal(signal.SIGALRM, self.timeout) + signal.setitimer(signal.ITIMER_REAL, self.seconds) + return self + def __exit__(self, type, value, traceback): + signal.setitimer(signal.ITIMER_REAL, 0) + return False + def timeout(self, signum, frame): + raise Exception(self.errmsg) + class VM(qtest.QEMUQtestMachine): '''A QEMU VM''' =20 @@ -346,6 +361,18 @@ class QMPTestCase(unittest.TestCase): event =3D self.wait_until_completed(drive=3Ddrive) self.assert_qmp(event, 'data/type', 'mirror') =20 + def pause_job(self, job_id=3D'job0'): + result =3D self.vm.qmp('block-job-pause', device=3Djob_id) + self.assert_qmp(result, 'return', {}) + + with Timeout(1, "Timeout waiting for job to pause"): + while True: + result =3D self.vm.qmp('query-block-jobs') + for job in result['return']: + if job['device'] =3D=3D job_id and job['paused'] =3D= =3D True and job['busy'] =3D=3D False: + return job + + def notrun(reason): '''Skip this test suite''' # Each test in qemu-iotests has a number ("seq") --=20 1.8.3.1