[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 09/10] iotests: Add poke_file_[bl]e functions
From: |
Max Reitz |
Subject: |
[PULL 09/10] iotests: Add poke_file_[bl]e functions |
Date: |
Thu, 26 Mar 2020 15:29:32 +0100 |
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 <address@hidden>
Code-suggested-by: Eric Blake <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Max Reitz <address@hidden>
---
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
- [PULL 00/10] Block patches for 5.0-rc1, Max Reitz, 2020/03/26
- [PULL 01/10] block/mirror: fix use after free of local_err, Max Reitz, 2020/03/26
- [PULL 02/10] block: pass BlockDriver reference to the .bdrv_co_create, Max Reitz, 2020/03/26
- [PULL 03/10] block: trickle down the fallback image creation function use to the block drivers, Max Reitz, 2020/03/26
- [PULL 04/10] qcow2: Comment typo fixes, Max Reitz, 2020/03/26
- [PULL 05/10] qcow2: List autoclear bit names in header, Max Reitz, 2020/03/26
- [PULL 07/10] sheepdog: Consistently set bdrv_has_zero_init_truncate, Max Reitz, 2020/03/26
- [PULL 06/10] qcow2: Avoid feature name extension on small cluster size, Max Reitz, 2020/03/26
- [PULL 08/10] qemu-img: Fix check's leak/corruption fix report, Max Reitz, 2020/03/26
- [PULL 09/10] iotests: Add poke_file_[bl]e functions,
Max Reitz <=
- [PULL 10/10] iotests/138: Test leaks/corruptions fixed report, Max Reitz, 2020/03/26
- Re: [PULL 00/10] Block patches for 5.0-rc1, Peter Maydell, 2020/03/26