From nobody Sat Feb 7 08:58:21 2026 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=1564606497; cv=none; d=zoho.com; s=zohoarc; b=R/wi3g5njJ8FBTrlr1E/G0vBsiyuvr0Z4V3VQLpYwwJunGIo1bil9tL+bqSPxIp3qxvIPNVS3NvezmptzMPbpFT4f3d4qim7HPI4KKcondbzd3ejZMLJH4UYl7GAtRjTI05RaZB4BQlyStEf38P9BhhXnK5WVQWUtZSyEZME/ZQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564606497; 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=b8JWS2tTRmbOzxEYyQMjbEd57Grvqsbep3KxtpTMUa0=; b=JfUxZtzK+0nWwWX4FDV7PeXbZ6PNkVOZjvxIf7jCK/v482F/3PxrMKBeo1k3hHBqG7ig8AkxvgHkCeoXpewvf/3kHn31GF53DaApV8zTXdnk4fexQo2PtIZk1x7q0U5OsRHKDpvgDD+sRCqyre5axcRdl/UafdbsBkpGGqH1kTw= 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 (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1564606497163420.1987273409378; Wed, 31 Jul 2019 13:54:57 -0700 (PDT) Received: from localhost ([::1]:44544 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsvcd-00065P-WB for importer@patchew.org; Wed, 31 Jul 2019 16:54:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34050) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsvQM-0003nS-ST for qemu-devel@nongnu.org; Wed, 31 Jul 2019 16:42:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsvQL-0005ml-Iz for qemu-devel@nongnu.org; Wed, 31 Jul 2019 16:42:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46966) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hsvQI-0005kj-NT; Wed, 31 Jul 2019 16:42:10 -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 0BE4F300C72A; Wed, 31 Jul 2019 20:42:10 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-122.ams2.redhat.com [10.36.116.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF14A5C207; Wed, 31 Jul 2019 20:42:08 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 31 Jul 2019 22:42:02 +0200 Message-Id: <20190731204203.10732-3-kwolf@redhat.com> In-Reply-To: <20190731204203.10732-1-kwolf@redhat.com> References: <20190731204203.10732-1-kwolf@redhat.com> MIME-Version: 1.0 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.45]); Wed, 31 Jul 2019 20:42:10 +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 2/3] iotests/118: Create test classes dynamically 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: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" We're getting a ridiculous number of child classes of TestInitiallyFilled and TestInitiallyEmpty that differ only in a few attributes that we want to test in all combinations. Instead of explicitly writing down every combination, let's use a loop and create those classes dynamically. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- tests/qemu-iotests/118 | 69 +++++++++++++----------------------------- 1 file changed, 21 insertions(+), 48 deletions(-) diff --git a/tests/qemu-iotests/118 b/tests/qemu-iotests/118 index 3c20d2d61f..c281259215 100755 --- a/tests/qemu-iotests/118 +++ b/tests/qemu-iotests/118 @@ -294,15 +294,15 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass): class TestInitiallyFilled(GeneralChangeTestsBaseClass): was_empty =3D False =20 - def setUp(self, media, interface): + def setUp(self): qemu_img('create', '-f', iotests.imgfmt, old_img, '1440k') qemu_img('create', '-f', iotests.imgfmt, new_img, '1440k') self.vm =3D iotests.VM() - self.vm.add_drive(old_img, 'media=3D%s' % media, 'none') - if interface =3D=3D 'scsi': + self.vm.add_drive(old_img, 'media=3D%s' % self.media, 'none') + if self.interface =3D=3D 'scsi': self.vm.add_device('virtio-scsi-pci') self.vm.add_device('%s,drive=3Ddrive0,id=3D%s' % - (interface_to_device_name(interface), + (interface_to_device_name(self.interface), self.device_name)) self.vm.launch() =20 @@ -331,13 +331,13 @@ class TestInitiallyFilled(GeneralChangeTestsBaseClass= ): class TestInitiallyEmpty(GeneralChangeTestsBaseClass): was_empty =3D True =20 - def setUp(self, media, interface): + def setUp(self): qemu_img('create', '-f', iotests.imgfmt, new_img, '1440k') - self.vm =3D iotests.VM().add_drive(None, 'media=3D%s' % media, 'no= ne') - if interface =3D=3D 'scsi': + self.vm =3D iotests.VM().add_drive(None, 'media=3D%s' % self.media= , 'none') + if self.interface =3D=3D 'scsi': self.vm.add_device('virtio-scsi-pci') self.vm.add_device('%s,drive=3Ddrive0,id=3D%s' % - (interface_to_device_name(interface), + (interface_to_device_name(self.interface), self.device_name)) self.vm.launch() =20 @@ -355,50 +355,23 @@ class TestInitiallyEmpty(GeneralChangeTestsBaseClass): # Should be a no-op self.assert_qmp(result, 'return', {}) =20 -class TestCDInitiallyFilled(TestInitiallyFilled): - TestInitiallyFilled =3D TestInitiallyFilled - has_real_tray =3D True - - def setUp(self): - self.TestInitiallyFilled.setUp(self, 'cdrom', 'ide') - -class TestCDInitiallyEmpty(TestInitiallyEmpty): - TestInitiallyEmpty =3D TestInitiallyEmpty - has_real_tray =3D True - - def setUp(self): - self.TestInitiallyEmpty.setUp(self, 'cdrom', 'ide') +# Do this in a function to avoid leaking variables like case into the glob= al +# name space (otherwise tests would be run for the abstract base classes) +def create_basic_test_classes(): + for (media, interface, has_real_tray) in [ ('cdrom', 'ide', True), + ('cdrom', 'scsi', True), + ('disk', 'floppy', False) ]: =20 -class TestSCSICDInitiallyFilled(TestInitiallyFilled): - TestInitiallyFilled =3D TestInitiallyFilled - has_real_tray =3D True + for case in [ TestInitiallyFilled, TestInitiallyEmpty ]: =20 - def setUp(self): - self.TestInitiallyFilled.setUp(self, 'cdrom', 'scsi') + attr =3D { 'media': media, + 'interface': interface, + 'has_real_tray': has_real_tray } =20 -class TestSCSICDInitiallyEmpty(TestInitiallyEmpty): - TestInitiallyEmpty =3D TestInitiallyEmpty - has_real_tray =3D True + name =3D '%s_%s_%s' % (case.__name__, media, interface) + globals()[name] =3D type(name, (case, ), attr) =20 - def setUp(self): - self.TestInitiallyEmpty.setUp(self, 'cdrom', 'scsi') - -class TestFloppyInitiallyFilled(TestInitiallyFilled): - TestInitiallyFilled =3D TestInitiallyFilled - has_real_tray =3D False - - def setUp(self): - self.TestInitiallyFilled.setUp(self, 'disk', 'floppy') - -class TestFloppyInitiallyEmpty(TestInitiallyEmpty): - TestInitiallyEmpty =3D TestInitiallyEmpty - has_real_tray =3D False - - def setUp(self): - self.TestInitiallyEmpty.setUp(self, 'disk', 'floppy') - # FDDs not having a real tray and there not being a medium inside = the - # tray at startup means the tray will be considered open - self.has_opened =3D True +create_basic_test_classes() =20 class TestChangeReadOnly(ChangeBaseClass): device_name =3D 'qdev0' --=20 2.20.1