qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

iotests: Add poke_file_[bl]e functions

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>
Message-Id: <20200324172757.1173824-3-mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>

+24
+24
tests/qemu-iotests/common.rc
··· 53 53 printf "$3" | dd "of=$1" bs=1 "seek=$2" conv=notrunc &>/dev/null 54 54 } 55 55 56 + # poke_file_le $img_filename $offset $byte_width $value 57 + # Example: poke_file_le "$TEST_IMG" 512 2 65534 58 + poke_file_le() 59 + { 60 + local img=$1 ofs=$2 len=$3 val=$4 str='' 61 + 62 + while ((len--)); do 63 + str+=$(printf '\\x%02x' $((val & 0xff))) 64 + val=$((val >> 8)) 65 + done 66 + 67 + poke_file "$img" "$ofs" "$str" 68 + } 69 + 70 + # poke_file_be $img_filename $offset $byte_width $value 71 + # Example: poke_file_be "$TEST_IMG" 512 2 65279 72 + poke_file_be() 73 + { 74 + local img=$1 ofs=$2 len=$3 val=$4 75 + local str=$(printf "%0$((len * 2))x\n" $val | sed 's/\(..\)/\\x\1/g') 76 + 77 + poke_file "$img" "$ofs" "$str" 78 + } 79 + 56 80 # peek_file_le 'test.img' 512 2 => 65534 57 81 peek_file_le() 58 82 {