From nobody Tue Nov 11 04:57:25 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560993836; cv=none; d=zoho.com; s=zohoarc; b=VXmqK+8KhljByl1rnU5QIIyzhJwkNEAgH5mfesCTEuiF4KA4AsR8Ndo60iBtTD8uEI7r05pPaZjZuIM9zcgG8n5F4MhJuuSL2CXa/+ZbGRjVwS+wkCrnEp0k0m7G4mmdDuVPc3bpJ5/8W/Opti5a+J+Hc03whq1OBw+UAL9it9w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560993836; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=2U2mFN2GUl76RH8xoQ/zZYokIDnhQqQAni6YU+M1TTo=; b=LTh4434IZo09SsyCBdmeolXuIHOj+FbccTCxe/UMIfcYFlxjCqZUB3KtBuqJl+COT0bxeYwcxSlU8h24dLRJQ82jU97tp9ZW26f2sDWiTfDNoUPObKOJaphJVWLwODJXn5kaT9kL8LCUtH6fzDXoiUK/zU2d1DyGJjpeTC4H4qk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560993836292725.4900621574716; Wed, 19 Jun 2019 18:23:56 -0700 (PDT) Received: from localhost ([::1]:42972 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdlnZ-0002LY-5j for importer@patchew.org; Wed, 19 Jun 2019 21:23:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40681) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdle5-0002Dv-8V for qemu-devel@nongnu.org; Wed, 19 Jun 2019 21:13:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hdlUt-0004tz-Kz for qemu-devel@nongnu.org; Wed, 19 Jun 2019 21:04:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35954) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hdlUs-0004sD-2J; Wed, 19 Jun 2019 21:04:14 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 50B4E3092673; Thu, 20 Jun 2019 01:04:13 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-164.bos.redhat.com [10.18.17.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39E521001E67; Thu, 20 Jun 2019 01:04:12 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Wed, 19 Jun 2019 21:03:52 -0400 Message-Id: <20190620010356.19164-9-jsnow@redhat.com> In-Reply-To: <20190620010356.19164-1-jsnow@redhat.com> References: <20190620010356.19164-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 20 Jun 2019 01:04:13 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 08/12] iotests: add testing shim for script-style python tests X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , vsementsov@virtuozzo.com, Wen Congyang , Xie Changlong , Markus Armbruster , Max Reitz , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Because the new-style python tests don't use the iotests.main() test launcher, we don't turn on the debugger logging for these scripts when invoked via ./check -d. Refactor the launcher shim into new and old style shims so that they share environmental configuration. Two cleanup notes: debug was not actually used as a global, and there was no reason to create a class in an inner scope just to achieve default variables; we can simply create an instance of the runner with the values we want instead. Signed-off-by: John Snow Reviewed-by: Max Reitz --- tests/qemu-iotests/iotests.py | 40 +++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 3ecef5bc90..fcad957d63 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -61,7 +61,6 @@ cachemode =3D os.environ.get('CACHEMODE') qemu_default_machine =3D os.environ.get('QEMU_DEFAULT_MACHINE') =20 socket_scm_helper =3D os.environ.get('SOCKET_SCM_HELPER', 'socket_scm_help= er') -debug =3D False =20 luks_default_secret_object =3D 'secret,id=3Dkeysec0,data=3D' + \ os.environ.get('IMGKEYSECRET', '') @@ -834,11 +833,22 @@ def skip_if_unsupported(required_formats=3D[], read_o= nly=3DFalse): return func_wrapper return skip_test_decorator =20 -def main(supported_fmts=3D[], supported_oses=3D['linux'], supported_cache_= modes=3D[], - unsupported_fmts=3D[]): - '''Run tests''' +def execute_unittest(output, verbosity, debug): + runner =3D unittest.TextTestRunner(stream=3Doutput, descriptions=3DTru= e, + verbosity=3Dverbosity) + try: + # unittest.main() will use sys.exit(); so expect a SystemExit + # exception + unittest.main(testRunner=3Drunner) + finally: + if not debug: + sys.stderr.write(re.sub(r'Ran (\d+) tests? in [\d.]+s', + r'Ran \1 tests', output.getvalue())) =20 - global debug +def execute_test(test_function=3DNone, + supported_fmts=3D[], supported_oses=3D['linux'], + supported_cache_modes=3D[], unsupported_fmts=3D[]): + """Run either unittest or script-style tests.""" =20 # We are using TEST_DIR and QEMU_DEFAULT_MACHINE as proxies to # indicate that we're not being run via "check". There may be @@ -870,13 +880,15 @@ def main(supported_fmts=3D[], supported_oses=3D['linu= x'], supported_cache_modes=3D[], =20 logging.basicConfig(level=3D(logging.DEBUG if debug else logging.WARN)) =20 - class MyTestRunner(unittest.TextTestRunner): - def __init__(self, stream=3Doutput, descriptions=3DTrue, verbosity= =3Dverbosity): - unittest.TextTestRunner.__init__(self, stream, descriptions, v= erbosity) + if not test_function: + execute_unittest(output, verbosity, debug) + else: + test_function() =20 - # unittest.main() will use sys.exit() so expect a SystemExit exception - try: - unittest.main(testRunner=3DMyTestRunner) - finally: - if not debug: - sys.stderr.write(re.sub(r'Ran (\d+) tests? in [\d.]+s', r'Ran = \1 tests', output.getvalue())) +def script_main(test_function, *args, **kwargs): + """Run script-style tests outside of the unittest framework""" + execute_test(test_function, *args, **kwargs) + +def main(*args, **kwargs): + """Run tests using the unittest framework""" + execute_test(None, *args, **kwargs) --=20 2.21.0