qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, andrey.shinkevich@virtuozzo.com,
	qemu-block@nongnu.org, Kevin Wolf <kwolf@redhat.com>,
	mreitz@redhat.com
Subject: Re: [PATCH] iotests: Fix nonportable use of od --endian
Date: Wed, 19 Feb 2020 08:46:14 -0600	[thread overview]
Message-ID: <596f14e4-8412-f984-8bcc-6140a914bb31@redhat.com> (raw)
In-Reply-To: <20200219144103.2919292-1-eblake@redhat.com>

On 2/19/20 8:41 AM, Eric Blake wrote:
> Tests 261 and 272 fail on RHEL 7 with coreutils 8.22, since od
> --endian was not added until coreutils 8.23.  Fix this by manually
> constructing the final value one byte at a time.
> 
> Fixes: fc8ba423
> Reported-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
> Signed-off-by: Eric Blake <eblake@redhat.com>
> ---
>   tests/qemu-iotests/common.rc | 22 +++++++++++++++++-----
>   1 file changed, 17 insertions(+), 5 deletions(-)
> 
> diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
> index 8a6366c09daf..b77ef3d22cd1 100644
> --- a/tests/qemu-iotests/common.rc
> +++ b/tests/qemu-iotests/common.rc
> @@ -56,6 +56,12 @@ poke_file()
>   # peek_file_le 'test.img' 512 2 => 65534
>   peek_file_le()
>   {
> -    # Wrap in echo $() to strip spaces
> -    echo $(od -j"$2" -N"$3" --endian=little -An -vtu"$3" "$1")
> +    local val=0 shift=0 i
> +
> +    # coreutils' od --endian is not portable, so manually assemble bytes.
> +    for i in $(od -j"$2" -N"$3" -An -v -tu1 "$1"); do
> +        val=$(( val | (i << shift) ))
> +        shift=$((shift + 8))
> +    done
> +    echo $val

Reports large 8-byte values as negative, whereas the pre-patch version 
reported them as positive.  To preserve behavior, we should squash in:

diff --git i/tests/qemu-iotests/common.rc w/tests/qemu-iotests/common.rc
index 8966ad5cde78..a596856d4d8c 100644
--- i/tests/qemu-iotests/common.rc
+++ w/tests/qemu-iotests/common.rc
@@ -63,7 +63,7 @@ peek_file_le()
          val=$(( val | (i << shift) ))
          shift=$((shift + 8))
      done
-    echo $val
+    printf %llu $val
  }

  # peek_file_be 'test.img' 512 2 => 65279
@@ -75,7 +75,7 @@ peek_file_be()
      for i in $(od -j"$2" -N"$3" -An -v -tu1 "$1"); do
          val=$(( (val << 8) | i ))
      done
-    echo $val
+    printf %llu $val
  }

  # peek_file_raw 'test.img' 512 2 => '\xff\xfe'. Do not use if the raw data



-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org



  reply	other threads:[~2020-02-19 14:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-19 14:41 [PATCH] iotests: Fix nonportable use of od --endian Eric Blake
2020-02-19 14:46 ` Eric Blake [this message]
2020-02-25 17:43 ` Max Reitz
2020-02-26 12:49   ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=596f14e4-8412-f984-8bcc-6140a914bb31@redhat.com \
    --to=eblake@redhat.com \
    --cc=andrey.shinkevich@virtuozzo.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).