From nobody Sun May 19 19:00:59 2024 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=1594292583; cv=none; d=zohomail.com; s=zohoarc; b=luegtcV1k7D5LFcrnRNcWaD39tBvYMl3Rd84Mh+FODBRRCdDtqJmUrT2pwx2+s7czOVFrHt57RaAJw+qFsF0CxjRB8U/9hwNPzkKywiIjM3IR470cYGS7FSvhrLn+B8aklyC8VGN5MroHmE6u11PKiu2etuAzuTnlmyOdhgCmRs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594292583; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=Os62HM816HWFtB8DH8AfDZzFOxdciiOj3PSe7qaj0C4=; b=YzxqvszqllI9UwpYRckWYWVGY9goZCJAe0RzG+fsXLTAMYW2juQ3pp11di5mRsJrbqv7QWZta/cHfprXh/YordQnoR+KeNB2TyQaxWeWsppRX6zMs20/Dz3rqYdTIbWEB1OcI7xCcpOUe/6S0ev32NPvgP30Izl2b5SZH14Lnbw= 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 1594292583328430.65713018946974; Thu, 9 Jul 2020 04:03:03 -0700 (PDT) Received: from localhost ([::1]:46294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jtUKT-0001Cb-TE for importer@patchew.org; Thu, 09 Jul 2020 07:03:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38776) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jtUJn-0000cn-H3 for qemu-devel@nongnu.org; Thu, 09 Jul 2020 07:02:19 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:25836 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jtUJl-0004Ym-8V for qemu-devel@nongnu.org; Thu, 09 Jul 2020 07:02:19 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-358-e-e-f9AAMbmDlTLtRGW2Ng-1; Thu, 09 Jul 2020 07:02:14 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AE63E1932480; Thu, 9 Jul 2020 11:02:13 +0000 (UTC) Received: from localhost (ovpn-113-127.ams2.redhat.com [10.36.113.127]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E67F76FEDA; Thu, 9 Jul 2020 11:02:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594292536; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Os62HM816HWFtB8DH8AfDZzFOxdciiOj3PSe7qaj0C4=; b=fQEif+7KD64bEfYST49eOs4H4Xjc5UGJDwlB7sGt4nCMfRQjn58MZ695aXfE4+/FIQNf1W pOfWD/+VsTnGszVW9Rj2pSapbe2ION7/HavB70sHYy3E3AEeLDdLFkGCyvh4Re1uSCyH7G yqELX47QKaMXxfoh0oQYaHBViHRpG0I= X-MC-Unique: e-e-f9AAMbmDlTLtRGW2Ng-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH] iotests: Simplify _filter_img_create() a bit Date: Thu, 9 Jul 2020 13:02:05 +0200 Message-Id: <20200709110205.310942-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=205.139.110.61; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/09 04:20:09 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz 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" Not only is it a bit stupid to try to filter multi-line "Formatting" output (because we only need it for a single test, which can easily be amended to no longer need it), it is also problematic when there can be output after a "Formatting" line that we do not want to filter as if it were part of it. So rename _filter_img_create to _do_filter_img_create, let it filter only a single line, and let _filter_img_create loop over all input lines, calling _do_filter_img_create only on those that match /^Formatting/ (basically, what _filter_img_create_in_qmp did already). (And fix 020 to work with that.) Reported-by: Kevin Wolf Signed-off-by: Max Reitz --- Kevin noted that the changes to _filter_img_create broke Eric's patch to flush the Formatting line out before a potential error message. This patch should fix it (and the diff stat is negative, so that's nice). --- tests/qemu-iotests/020 | 29 ++++++++------- tests/qemu-iotests/020.out | 13 +------ tests/qemu-iotests/141 | 2 +- tests/qemu-iotests/common.filter | 62 ++++++++++++++------------------ 4 files changed, 45 insertions(+), 61 deletions(-) diff --git a/tests/qemu-iotests/020 b/tests/qemu-iotests/020 index 20f8f185d0..b488000cb9 100755 --- a/tests/qemu-iotests/020 +++ b/tests/qemu-iotests/020 @@ -115,18 +115,23 @@ TEST_IMG=3D"$TEST_IMG.base" _make_test_img 1M # Create an image with a null backing file to which committing will fail (= with # ENOSPC so we can distinguish the result from some generic EIO which may = be # generated anywhere in the block layer) -_make_test_img -b "json:{'driver': '$IMGFMT', - 'file': { - 'driver': 'blkdebug', - 'inject-error': [{ - 'event': 'write_aio', - 'errno': 28, - 'once': true - }], - 'image': { - 'driver': 'file', - 'filename': '$TEST_IMG.base' - }}}" +backing=3D"json:{'driver': '$IMGFMT', + 'file': { + 'driver': 'blkdebug', + 'inject-error': [{ + 'event': 'write_aio', + 'errno': 28, + 'once': true + }], + 'image': { + 'driver': 'file', + 'filename': '$TEST_IMG.base' + }}}" + +# Filter out newlines and collapse spaces +backing=3D$(echo "$backing" | tr -d '\n' | tr -s ' ') + +_make_test_img -b "$backing" =20 # Just write anything so committing will not be a no-op $QEMU_IO -c 'writev 0 64k' "$TEST_IMG" | _filter_qemu_io diff --git a/tests/qemu-iotests/020.out b/tests/qemu-iotests/020.out index 4b722b2dd0..4668ac59df 100644 --- a/tests/qemu-iotests/020.out +++ b/tests/qemu-iotests/020.out @@ -1079,18 +1079,7 @@ No errors were found on the image. Testing failing commit =20 Formatting 'TEST_DIR/t.IMGFMT.base', fmt=3DIMGFMT size=3D1048576 -Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 backing_file= =3Djson:{'driver': 'IMGFMT',, - 'file': { - 'driver': 'blkdebug',, - 'inject-error': [{ - 'event': 'write_aio',, - 'errno': 28,, - 'once': true - }],, - 'image': { - 'driver': 'file',, - 'filename': 'TEST_DIR/t.IMGFMT.base' - }}} +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 backing_file= =3Djson:{'driver': 'IMGFMT',, 'file': { 'driver': 'blkdebug',, 'inject-erro= r': [{ 'event': 'write_aio',, 'errno': 28,, 'once': true }],, 'image': { 'd= river': 'file',, 'filename': 'TEST_DIR/t.IMGFMT.base' }}} wrote 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qemu-img: Block job failed: No space left on device diff --git a/tests/qemu-iotests/141 b/tests/qemu-iotests/141 index 6d1b7b0d4c..5192d256e3 100755 --- a/tests/qemu-iotests/141 +++ b/tests/qemu-iotests/141 @@ -68,7 +68,7 @@ test_blockjob() _send_qemu_cmd $QEMU_HANDLE \ "$1" \ "$2" \ - | _filter_img_create_in_qmp | _filter_qmp_empty_return + | _filter_img_create | _filter_qmp_empty_return =20 # We want this to return an error because the block job is still runni= ng _send_qemu_cmd $QEMU_HANDLE \ diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.f= ilter index d967adc59a..3833206327 100644 --- a/tests/qemu-iotests/common.filter +++ b/tests/qemu-iotests/common.filter @@ -119,8 +119,21 @@ _filter_actual_image_size() $SED -s 's/\("actual-size":\s*\)[0-9]\+/\1SIZE/g' } =20 +# Filename filters for qemu-img create +_filter_img_create_filenames() +{ + $SED \ + -e "s#$REMOTE_TEST_DIR#TEST_DIR#g" \ + -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \ + -e "s#$TEST_DIR#TEST_DIR#g" \ + -e "s#$SOCK_DIR#SOCK_DIR#g" \ + -e "s#$IMGFMT#IMGFMT#g" \ + -e 's#nbd:127.0.0.1:[0-9]\\+#TEST_DIR/t.IMGFMT#g' \ + -e 's#nbd+unix:///\??socket=3DSOCK_DIR/nbd#TEST_DIR/t.IMGFMT#g' +} + # replace driver-specific options in the "Formatting..." line -_filter_img_create() +_do_filter_img_create() { # Split the line into the pre-options part ($filename_part, which # precedes ", fmt=3D") and the options part ($options, which starts @@ -128,23 +141,10 @@ _filter_img_create() # (And just echo everything before the first "^Formatting") readarray formatting_line < <($SED -e 's/, fmt=3D/\n/') =20 - filename_part=3D'' - options=3D'' - lines=3D${#formatting_line[@]} - for ((i =3D 0; i < $lines; i++)); do - line=3D${formatting_line[i]} - unset formatting_line[i] - - filename_part=3D"$filename_part$line" + filename_part=3D${formatting_line[0]} + unset formatting_line[0] =20 - if echo "$line" | grep -q '^Formatting'; then - next_i=3D$((i + 1)) - if [ -n "${formatting_line[next_i]}" ]; then - options=3D"fmt=3D${formatting_line[@]}" - fi - break - fi - done + options=3D"fmt=3D${formatting_line[@]}" =20 # Set grep_data_file to '\|data_file' to keep it; make it empty # to drop it. @@ -156,17 +156,7 @@ _filter_img_create() grep_data_file=3D() fi =20 - filename_filters=3D( - -e "s#$REMOTE_TEST_DIR#TEST_DIR#g" \ - -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \ - -e "s#$TEST_DIR#TEST_DIR#g" \ - -e "s#$SOCK_DIR#SOCK_DIR#g" \ - -e "s#$IMGFMT#IMGFMT#g" \ - -e 's#nbd:127.0.0.1:[0-9]\\+#TEST_DIR/t.IMGFMT#g' \ - -e 's#nbd+unix:///\??socket=3DSOCK_DIR/nbd#TEST_DIR/t.IMGFMT#g' - ) - - filename_part=3D$(echo "$filename_part" | $SED "${filename_filters[@]}= ") + filename_part=3D$(echo "$filename_part" | _filter_img_create_filenames) =20 # Break the option line before each option (preserving pre-existing # line breaks by replacing them by \0 and restoring them at the end), @@ -179,7 +169,8 @@ _filter_img_create() | $SED -e 's/ \([a-z0-9_.-]*\)=3D/\n\1=3D/g' \ | grep -a -e '^fmt' -e '^size' -e '^backing' -e '^preallocation' \ -e '^encryption' "${grep_data_file[@]}" \ - | $SED "${filename_filters[@]}" \ + | _filter_img_create_filenames \ + | $SED \ -e 's/^\(fmt\)/0-\1/' \ -e 's/^\(size\)/1-\1/' \ -e 's/^\(backing\)/2-\1/' \ @@ -199,17 +190,16 @@ _filter_img_create() fi } =20 -# Filter the "Formatting..." line in QMP output (leaving the QMP output -# untouched) -# (In contrast to _filter_img_create(), this function does not support -# multi-line Formatting output) -_filter_img_create_in_qmp() +# Filter qemu-img create output: +# Pipe all ^Formatting lines through _do_filter_img_create, and all +# other lines through _filter_img_create_filenames +_filter_img_create() { while read -r line; do if echo "$line" | grep -q '^Formatting'; then - echo "$line" | _filter_img_create + echo "$line" | _do_filter_img_create else - echo "$line" + echo "$line" | _filter_img_create_filenames fi done } --=20 2.26.2