From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>
Subject: [PATCH for-5.0 v2 2/3] iotests: Add poke_file_[bl]e functions
Date: Tue, 24 Mar 2020 18:27:56 +0100 [thread overview]
Message-ID: <20200324172757.1173824-3-mreitz@redhat.com> (raw)
In-Reply-To: <20200324172757.1173824-1-mreitz@redhat.com>
Similarly to peek_file_[bl]e, we may want to write binary integers into
a file. Currently, this often means messing around with poke_file and
raw binary strings. I hope these functions make it a bit more
comfortable.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Code-suggested-by: Eric Blake <eblake@redhat.com>
---
tests/qemu-iotests/common.rc | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
index 4c246c0450..bf3b9fdea0 100644
--- a/tests/qemu-iotests/common.rc
+++ b/tests/qemu-iotests/common.rc
@@ -53,6 +53,30 @@ poke_file()
printf "$3" | dd "of=$1" bs=1 "seek=$2" conv=notrunc &>/dev/null
}
+# poke_file_le $img_filename $offset $byte_width $value
+# Example: poke_file_le "$TEST_IMG" 512 2 65534
+poke_file_le()
+{
+ local img=$1 ofs=$2 len=$3 val=$4 str=''
+
+ while ((len--)); do
+ str+=$(printf '\\x%02x' $((val & 0xff)))
+ val=$((val >> 8))
+ done
+
+ poke_file "$img" "$ofs" "$str"
+}
+
+# poke_file_be $img_filename $offset $byte_width $value
+# Example: poke_file_be "$TEST_IMG" 512 2 65279
+poke_file_be()
+{
+ local img=$1 ofs=$2 len=$3 val=$4
+ local str=$(printf "%0$((len * 2))x\n" $val | sed 's/\(..\)/\\x\1/g')
+
+ poke_file "$img" "$ofs" "$str"
+}
+
# peek_file_le 'test.img' 512 2 => 65534
peek_file_le()
{
--
2.25.1
next prev parent reply other threads:[~2020-03-24 17:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-24 17:27 [PATCH for-5.0 v2 0/3] qemu-img: Fix check's leak/corruption fix report Max Reitz
2020-03-24 17:27 ` [PATCH for-5.0 v2 1/3] " Max Reitz
2020-03-24 17:27 ` Max Reitz [this message]
2020-03-24 17:51 ` [PATCH for-5.0 v2 2/3] iotests: Add poke_file_[bl]e functions Eric Blake
2020-03-24 17:27 ` [PATCH for-5.0 v2 3/3] iotests/138: Test leaks/corruptions fixed report Max Reitz
2020-03-24 17:56 ` Eric Blake
2020-03-26 13:53 ` [PATCH for-5.0 v2 0/3] qemu-img: Fix check's leak/corruption fix report Max Reitz
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=20200324172757.1173824-3-mreitz@redhat.com \
--to=mreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.