From nobody Tue Feb 10 14:49:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1616526557; cv=none; d=zohomail.com; s=zohoarc; b=IED2Sxjk3X6wM/7vLvtxwGTXgxJswMNWd7DXy9WBDwM5QWvqnC/U312/UaU3rjZ/nA/hzP9k2lmkzY4F6+8PrtZX3tHeAtNX/XuxJfLV1mJMq0PJY9JLA4i6DAAKpst5ADWp8/Nq2dPDWSjh+h/HOQ/XXF5mC0tcDtwT6EQuu7Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616526557; 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; bh=czzHm2ccyhhF9zSRE5fhZxlUCkJ2TFJg6JtCeRoNsII=; b=h8spJgbGYUCymh+DEE3GT4r1qb4vbhF2YVGfqlfNk5Cnx0Fw8aKRvHvQiMQECJ5i3Pv+63Y5KMnewWlyGP/BZfw1YqaX2thKC3WTG8ZsoD0JEHTLQDZfAjt48sXjqowhv4l4wIdweJqIHIQRwVZzZnKC54YTos1HAQG+FsJuzVU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 16165265573456.67007998492727; Tue, 23 Mar 2021 12:09:17 -0700 (PDT) Received: from localhost ([::1]:59634 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOmOy-0006b2-7D for importer@patchew.org; Tue, 23 Mar 2021 15:09:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53922) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOlcu-000832-Ei; Tue, 23 Mar 2021 14:19:41 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]:34413) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lOlcq-0006dp-3E; Tue, 23 Mar 2021 14:19:36 -0400 Received: by mail-wm1-x332.google.com with SMTP id n11-20020a05600c4f8bb029010e5cf86347so1581294wmq.1; Tue, 23 Mar 2021 11:19:31 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id u8sm24204412wrr.42.2021.03.23.11.19.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 11:19:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=czzHm2ccyhhF9zSRE5fhZxlUCkJ2TFJg6JtCeRoNsII=; b=UcGeb9ITWEsSMOagHb5hleTDdLK1TCpT8rYKJ3jGDFpugHB5u34CzyzKPrkaLTPGCt fteBHuesRVO8ncne+4PMjsBMGPn0Tu9Ox35fXyMgSDasrGZbl/zBZrIGhHLgmVCTcTQX ZI4q2avTT9/innG2P38mZH0oxkVX2un46Vmb+J5ynJEl9P9qFbdnHF9FW6PuYCYVdven VHZ1ZFZrW3aKZ7/ufpxdmbnOrBvEcY0l1lLtit3y9360neiHAZJF+kp0RrbKR2bXMszK I/F4r/NzDoyQRsF2OcDHP6nJEzss2Zw7XRTaFFMGS0goUMc/HgKmlwptf1U48/3EkQR9 kN5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=czzHm2ccyhhF9zSRE5fhZxlUCkJ2TFJg6JtCeRoNsII=; b=dR0tYUgc/qF7p/Wpkpw+Qu2r3MmrCsZchAeVmQJB69jwxtZqolR/eUYRxdQr6u25Zh nLL0fC6X1Oo05GGP0dpSWhX0PuyQirty5eZaIrl43wS83+I7HIhkPzvi3BgWaEmASMpV lSsgwWu3v/2o6PUooCsdDMlccxVABxtVjAh03GskQireTCf7jxIl3vKLoLupKe62ujTn weMCiTe/R8NAVihDbJp6UBks+TDOcgCUPyfwLZEVlKt5F2o3WimICyRWXjxR8DPnlIaj 7t7ZYfXR2e6yQcNxtEHUXXDvPtIVlk6zO5V3oe/47rT/vQfiH347AE/USHk7XYcyIqZN gk2w== X-Gm-Message-State: AOAM530YNvAy7GVfF3OMDKCTV/LQrhXCMSPjVveO7FIIO/s1WJAu5jKN htVYnQMn6Nb4e/i4qWDKigF6glzRQOw= X-Google-Smtp-Source: ABdhPJzzzq1BkRmLbWQCcMug1+blxbmiWPQ+4GWRl1qSknnzePYQUH/ibYTugYGS1UCc/VQnzEKf2g== X-Received: by 2002:a1c:6309:: with SMTP id x9mr4588914wmb.62.1616523570473; Tue, 23 Mar 2021 11:19:30 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 1/5] qemu-iotests: do not buffer the test output Date: Tue, 23 Mar 2021 19:19:23 +0100 Message-Id: <20210323181928.311862-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210323181928.311862-1-pbonzini@redhat.com> References: <20210323181928.311862-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x332.google.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_OTHER_BAD_TLD=1.999, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action 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: eesposit@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Instead of buffering the test output into a StringIO, patch it on the fly by wrapping sys.stdout's write method. This can be done unconditionally, even if using -d, which makes execute_unittest a bit simpler. Signed-off-by: Paolo Bonzini Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/iotests.py | 68 ++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 28 deletions(-) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 90d0b62523..0521235030 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -32,7 +32,7 @@ import sys import time from typing import (Any, Callable, Dict, Iterable, - List, Optional, Sequence, Tuple, TypeVar) + List, Optional, Sequence, Tuple, Type, TypeVar) import unittest =20 from contextlib import contextmanager @@ -1271,37 +1271,49 @@ def func_wrapper(*args, **kwargs): return func(*args, **kwargs) return func_wrapper =20 +# We need to filter out the time taken from the output so that +# qemu-iotest can reliably diff the results against master output, +# and hide skipped tests from the reference output. + +class ReproducibleTestResult(unittest.TextTestResult): + def addSkip(self, test, reason): + # Same as TextTestResult, but print dot instead of "s" + unittest.TestResult.addSkip(self, test, reason) + if self.showAll: + self.stream.writeln("skipped {0!r}".format(reason)) + elif self.dots: + self.stream.write(".") + self.stream.flush() + +class ReproducibleStreamWrapper(object): + def __init__(self, stream): + self.stream =3D stream + + def __getattr__(self, attr): + if attr in ('stream', '__getstate__'): + raise AttributeError(attr) + return getattr(self.stream,attr) + + def write(self, arg=3DNone): + arg =3D re.sub(r'Ran (\d+) tests? in [\d.]+s', r'Ran \1 tests', ar= g) + arg =3D re.sub(r' \(skipped=3D\d+\)', r'', arg) + self.stream.write(arg) + +class ReproducibleTestRunner(unittest.TextTestRunner): + def __init__(self, stream: Optional[io.TextIOBase] =3D None, + resultclass: Type =3D ReproducibleTestResult, *args, **kw= args): + rstream =3D ReproducibleStreamWrapper(stream or sys.stdout) + super().__init__(stream=3Drstream, # type: ignore + descriptions=3DTrue, + resultclass=3Dresultclass, + *args, **kwargs) + def execute_unittest(debug=3DFalse): """Executes unittests within the calling module.""" =20 verbosity =3D 2 if debug else 1 - - if debug: - output =3D sys.stdout - else: - # We need to filter out the time taken from the output so that - # qemu-iotest can reliably diff the results against master output. - output =3D io.StringIO() - - 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: - # We need to filter out the time taken from the output so that - # qemu-iotest can reliably diff the results against master output. - if not debug: - out =3D output.getvalue() - out =3D re.sub(r'Ran (\d+) tests? in [\d.]+s', r'Ran \1 tests'= , out) - - # Hide skipped tests from the reference output - out =3D re.sub(r'OK \(skipped=3D\d+\)', 'OK', out) - out_first_line, out_rest =3D out.split('\n', 1) - out =3D out_first_line.replace('s', '.') + '\n' + out_rest - - sys.stderr.write(out) + runner =3D unittest.ReproducibleTestRunner(verbosity=3Dverbosity) + unittest.main(testRunner=3Drunner) =20 def execute_setup_common(supported_fmts: Sequence[str] =3D (), supported_platforms: Sequence[str] =3D (), --=20 2.30.1