From patchwork Tue Jul 16 00:01:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1132347 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45ngZF1Qq3z9sBt for ; Tue, 16 Jul 2019 10:02:29 +1000 (AEST) Received: from localhost ([::1]:44426 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnAvK-0001M5-NL for incoming@patchwork.ozlabs.org; Mon, 15 Jul 2019 20:02:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44548) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnAuO-0006lR-Gf for qemu-devel@nongnu.org; Mon, 15 Jul 2019 20:01:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnAuM-0007SA-4W for qemu-devel@nongnu.org; Mon, 15 Jul 2019 20:01:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44572) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hnAuJ-0007OV-Ex; Mon, 15 Jul 2019 20:01:23 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9D14D308427C; Tue, 16 Jul 2019 00:01:22 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-130.bos.redhat.com [10.18.17.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id BBE3F608E4; Tue, 16 Jul 2019 00:01:21 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Mon, 15 Jul 2019 20:01:07 -0400 Message-Id: <20190716000117.25219-2-jsnow@redhat.com> In-Reply-To: <20190716000117.25219-1-jsnow@redhat.com> References: <20190716000117.25219-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 16 Jul 2019 00:01:22 +0000 (UTC) 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 v2 01/11] iotests/257: add Pattern class 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 , vsementsov@virtuozzo.com, Markus Armbruster , Max Reitz , John Snow Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Just kidding, this is easier to manage with a full class instead of a namedtuple. Signed-off-by: John Snow Reviewed-by: Max Reitz --- tests/qemu-iotests/257 | 58 +++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/tests/qemu-iotests/257 b/tests/qemu-iotests/257 index 3952683749..02f9ae0649 100755 --- a/tests/qemu-iotests/257 +++ b/tests/qemu-iotests/257 @@ -19,7 +19,6 @@ # # owner=jsnow@redhat.com -from collections import namedtuple import math import os @@ -29,10 +28,18 @@ from iotests import log, qemu_img SIZE = 64 * 1024 * 1024 GRANULARITY = 64 * 1024 -Pattern = namedtuple('Pattern', ['byte', 'offset', 'size']) -def mkpattern(byte, offset, size=GRANULARITY): - """Constructor for Pattern() with default size""" - return Pattern(byte, offset, size) + +class Pattern: + def __init__(self, byte, offset, size=GRANULARITY): + self.byte = byte + self.offset = offset + self.size = size + + def bits(self, granularity): + lower = self.offset // granularity + upper = (self.offset + self.size - 1) // granularity + return set(range(lower, upper + 1)) + class PatternGroup: """Grouping of Pattern objects. Initialize with an iterable of Patterns.""" @@ -43,40 +50,39 @@ class PatternGroup: """Calculate the unique bits dirtied by this pattern grouping""" res = set() for pattern in self.patterns: - lower = pattern.offset // granularity - upper = (pattern.offset + pattern.size - 1) // granularity - res = res | set(range(lower, upper + 1)) + res |= pattern.bits(granularity) return res + GROUPS = [ PatternGroup([ # Batch 0: 4 clusters - mkpattern('0x49', 0x0000000), - mkpattern('0x6c', 0x0100000), # 1M - mkpattern('0x6f', 0x2000000), # 32M - mkpattern('0x76', 0x3ff0000)]), # 64M - 64K + Pattern('0x49', 0x0000000), + Pattern('0x6c', 0x0100000), # 1M + Pattern('0x6f', 0x2000000), # 32M + Pattern('0x76', 0x3ff0000)]), # 64M - 64K PatternGroup([ # Batch 1: 6 clusters (3 new) - mkpattern('0x65', 0x0000000), # Full overwrite - mkpattern('0x77', 0x00f8000), # Partial-left (1M-32K) - mkpattern('0x72', 0x2008000), # Partial-right (32M+32K) - mkpattern('0x69', 0x3fe0000)]), # Adjacent-left (64M - 128K) + Pattern('0x65', 0x0000000), # Full overwrite + Pattern('0x77', 0x00f8000), # Partial-left (1M-32K) + Pattern('0x72', 0x2008000), # Partial-right (32M+32K) + Pattern('0x69', 0x3fe0000)]), # Adjacent-left (64M - 128K) PatternGroup([ # Batch 2: 7 clusters (3 new) - mkpattern('0x74', 0x0010000), # Adjacent-right - mkpattern('0x69', 0x00e8000), # Partial-left (1M-96K) - mkpattern('0x6e', 0x2018000), # Partial-right (32M+96K) - mkpattern('0x67', 0x3fe0000, - 2*GRANULARITY)]), # Overwrite [(64M-128K)-64M) + Pattern('0x74', 0x0010000), # Adjacent-right + Pattern('0x69', 0x00e8000), # Partial-left (1M-96K) + Pattern('0x6e', 0x2018000), # Partial-right (32M+96K) + Pattern('0x67', 0x3fe0000, + 2*GRANULARITY)]), # Overwrite [(64M-128K)-64M) PatternGroup([ # Batch 3: 8 clusters (5 new) # Carefully chosen such that nothing re-dirties the one cluster # that copies out successfully before failure in Group #1. - mkpattern('0xaa', 0x0010000, - 3*GRANULARITY), # Overwrite and 2x Adjacent-right - mkpattern('0xbb', 0x00d8000), # Partial-left (1M-160K) - mkpattern('0xcc', 0x2028000), # Partial-right (32M+160K) - mkpattern('0xdd', 0x3fc0000)]), # New; leaving a gap to the right + Pattern('0xaa', 0x0010000, + 3*GRANULARITY), # Overwrite and 2x Adjacent-right + Pattern('0xbb', 0x00d8000), # Partial-left (1M-160K) + Pattern('0xcc', 0x2028000), # Partial-right (32M+160K) + Pattern('0xdd', 0x3fc0000)]), # New; leaving a gap to the right ] class Drive: